我正在使用 IBM 的 APIConnect 创建一些 API。我一直在尝试编辑我的 API 的 YAML 定义以创建对属性的引用,以便我可以将它们外部化。但到目前为止,我一直遇到引用问题。它们要么不针对“API Connect swagger 扩展架构 API 定义”进行验证,要么不针对“IBM Swagger 版本 2.0 架构 API 定义”进行验证。
这是我尝试过的两个参考:-
- 引用 securityDefinitions:如 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.
阿努知道我在这里做错了什么?PS 在这两种情况下,swagger 都会根据“Swagger 版本 2.0 架构 API 定义”进行验证。只是针对 IBM 特定的模式,他们不这样做。