【发布时间】:2017-03-05 05:07:29
【问题描述】:
我正在使用 IBM 的 APIConnect 创建一些 API。我一直在尝试编辑我的 API 的 YAML 定义以创建对属性的引用,以便我可以将它们外部化。但到目前为止,我一直遇到引用问题。它们要么不针对“API Connect swagger 扩展架构 API 定义”进行验证,要么不针对“IBM Swagger 版本 2.0 架构 API 定义”进行验证。
这是我尝试过的两个引用:-
- 引用安全定义: 如 IBM 网站所述:https://www.ibm.com/support/knowledgecenter/en/SSMNED_5.0.0/com.ibm.apic.toolkit.doc/rapic_swagger_ref_fragment.html
我的 YAML:-
swagger: '2.0'
info:
version: 1.0.0
title: PokemonApp
x-ibm-name: pokemonapp
host: $(catalog.host)
basePath: /api
paths:
/pokemon:
get:
responses:
'200':
description: 200 OK
securityDefinitions:
$ref: ./schemas/ClientID.yaml
security:
- clientID: []
x-ibm-configuration:
assembly:
execute:
- invoke:
target-url: $(TestProperty)
properties:
TestProperty:
value: 'https://pokemons.mybluemix.net/api/pokemons'
description: ''
encoded: false
gateway: micro-gateway
以及对应的参考文件:-
clientID:
description: ''
in: query
name: client_id
type: apiKey
在对父 YAML 进行 apic 验证时,我收到以下错误:-
C:\Users\MyName\TestNotes\definitions>apic validate pokemonapp_1.0.0.yaml
Successfully validated pokemonapp_1.0.0.yaml against Swagger Version 2.0 schema API definition [pokemonapp:1.0.0].
Successfully validated pokemonapp_1.0.0.yaml against API Connect swagger extensions schema API definition [pokemonapp:1.0.0].
Error validating pokemonapp_1.0.0.yaml with IBM Swagger Version 2.0 schema API definition [pokemonapp:1.0.0].
Data does not match any schemas from "oneOf" (/securityDefinitions/$ref)
Error: Validation did not complete successfully.
- 引用属性:-
这是父 YAML:-
swagger: '2.0'
info:
version: 1.0.0
title: PokemonApp
x-ibm-name: pokemonapp
host: $(catalog.host)
basePath: /api
paths:
/pokemon:
get:
responses:
'200':
description: 200 OK
securityDefinitions:
clientID:
description: ''
in: query
name: client_id
type: apiKey
security:
- clientID: []
x-ibm-configuration:
assembly:
execute:
- invoke:
target-url: $(TestProperty)
properties:
$ref: ./schemas/properties.yaml
gateway: micro-gateway
以及对应的参考文件(./schemas/properties.yaml):-
TestProperty:
type: object
value: 'https://pokemons.mybluemix.net/api/pokemons'
description: ''
encoded: false
在验证这一点时,错误是另一个错误。此 YAML 针对 Swagger 版本 2.0 架构 API 定义和 IBM Swagger 版本 2.0 架构 API 定义进行验证,但不针对 API Connect swagger 扩展架构 API 定义进行验证。
这是错误信息:-
C:\Users\MyName\TestNotes\definitions>apic validate pokemonapp_1.0.0.yaml
Successfully validated pokemonapp_1.0.0.yaml against Swagger Version 2.0 schema API definition [pokemonapp:1.0.0].
Error validating pokemonapp_1.0.0.yaml with API Connect swagger extensions schema API definition [pokemonapp:1.0.0].
Invalid type: string (expected object) (/properties/$ref)
Successfully validated pokemonapp_1.0.0.yaml against IBM Swagger Version 2.0 schema API definition [pokemonapp:1.0.0].
Error: Validation did not complete successfully.
Anu 知道我在这里做错了什么吗? 附言在这两种情况下,swagger 都会根据“Swagger 版本 2.0 架构 API 定义”进行验证。只是针对 IBM 特定的模式,他们不这样做。
【问题讨论】:
-
您使用的是什么版本的 APIConnect?
apic --ext-version -
apic --ext-version apiconnect: v2.1.19 (API Connect: v5.0.2.1) apiconnect-cli-apis 2.1.0 apiconnect-cli-apps 2.1.0 apiconnect-cli-auth 2.1.6 apiconnect-cli-catalogs 2.1.0 apiconnect-cli-config 2.1.0 apiconnect-cli-create 2.1.1 apiconnect-cli-drafts 2.1.0 apiconnect-cli-edit 2.1.0 apiconnect-cli-loopback 2.1。 3 apiconnect-cli-orgs 2.1.0 apiconnect-cli-pm 2.1.0 微网关 1.2.0 流引擎 1.0.3 apiconnect-cli-policies 1.1.0 apiconnect-cli-products 2.1.0 apiconnect-cli-validate 2.1。 0 个插件 3.0.2
-
我希望你不是在制作 Pokemon Go 欺骗应用程序!欺骗是不好的。
标签: yaml ibm-cloud swagger-2.0 ref apiconnect