我有一个关于API的swagger文件,它将驻留在IBM API Connect中。我从IBM教程中输入了它,我试图复制教师正在做的事情(他没有提供任何源文件,所以我不得不输入它。)
该教程可在此处获取:https://www.youtube.com/watch?v=hCvUYd67rbI 这家伙正在21:40左右在APIConnect本地设计师的文本中复制文件。
我把swagger文件放到http://editor.swagger.io/并且我得到了一堆解析器错误:
Errors
Hide
Parser error duplicated mapping key
Jump to line 31
Semantic error at definitions.shipping.properties.xyz.type
Sibling values are not allowed alongside $refs
Jump to line 86
Semantic error at definitions.shipping.properties.cek.type
Sibling values are not allowed alongside $refs
Jump to line 89
我做了一些挖掘工作,但我没有找到很多资源来解决我的问题。我仔细检查了我是否从教程中正确输入了它。也许它与教程中使用的旧版API Connect有关。
提前感谢任何可以提供帮助的人。
修改
抱歉,有点晚了所以我累了,我在yaml文件中添加了源代码:
info:
x-ibm-name: logistics
title: logistics
version: 1.0.0
schemes:
- https
basePath: /logistics
consumes:
- application/json
produces:
- application/json
securityDefinitions:
clientIdHeader:
type: apiKey
in: header
name: X-IBM-Client-Id
security:
- clientdHeader: []
x-ibm-configuration:
testable: true
enforced: true
cors:
enabled: true
gateway: datapower-gateway
catalogs:
apic-dev:
properties:
runtime-url: $(TARGET_URL)
properties:
shipping_svc_url:
value: 'http://shipping.think.ibm:5000/calculate'
description: Location of the shipping calculator service
encoded: false
paths:
/shipping:
get:
responses:
'200':
description: 200 OK
schema:
$ref: '#/definitions/shipping'
summary: Calculate shipping costs to a destination zip code
operationId: shipping.calc
parameters:
- name: zip
type: string
required: true
in: query
description: Destination zip code.
/stores:
get:
responses:
'200':
description: 200 OK
schema:
$ref: '#/definitions/store_location'
tags:
- stores
summary: Locate store near zip code
operationId: get.stores
parameters:
- name: zip
type: string
required: true
in: query
definitions:
rates:
properties:
next_day:
type: string
example: '20.00'
two_day:
type: string
example: '17.00'
ground:
type: string
example: '8.00'
required:
- two_day
- next_day
- ground
shipping:
properties:
xyz:
type: string
$ref: '#/definitions/rates'
cek:
type: string
$ref: '#/definitions/rates'
required:
- xyz
- cek
store_location:
properties:
google_maps_link:
type: string
example: 'https://www.google.com/maps?q=34.1030032,-118.4104684'
required:
- google_maps_link
答案 0 :(得分:1)
有错字:securityDefinitions
定义clientIdHeader
,但security
引用clientdHeader
(..ntd..
而不是..enId..
)。< / p>
“与$ refs一起不允许同级值”不是语法错误,而是警告。这是由这条线引起的:
definitions:
rates:
properties:
...
shipping:
properties:
xyz:
type: string # <---------------
$ref: '#/definitions/rates'
$ref
是JSON Reference,它的工作原理是用$ref
指向的内容替换自身和所有兄弟属性。因此,type
属性和$ref
旁边的任何其他属性都将被忽略。如果$ref
旁边有重要属性,警告会通知您 - 这些属性需要移至$ref
'erenced架构才能生效。
也就是说,xyz
type: string
没有意义,因为rates
是一个对象,而不是一个字符串。
您还应该考虑将type: object
添加到rates
,shipping
和store_location
定义,以表明它们是对象。