我正在尝试使用openapi
版本3.0.0
定义我的API。我生成了以下YAML文件:
openapi: 3.0.0
info:
title: My YAML
description: My YAML
version: 1.0.0
servers:
- url: http://my.server.url
paths:
/v1/service/uri:
post:
summary: Getting some information.
parameters:
- name: Content-Type
in: header
description: Content type of request body.
required: true
style: simple
explode: false
schema:
type: string
- name: Host
in: header
description: Originate host which returns the response.
required: false
style: simple
explode: false
schema:
type: string
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/MyPostRequest'
example:
my_name: "zizi"
my_age: 29
required: true
responses:
200:
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/MyPostResponse'
components:
schemas:
MyPostRequest:
type: object
properties:
my_name:
type: string
my_age:
type: integer
format: int32
MyPostResponse:
type: object
properties:
status:
type: integer
format: int32
当我将这些行复制/粘贴到Swagger Editor时,在行duplicated mapping key
上出现19
错误;用于参数description
的{{1}}部分。
我研究了openapi documentation,但是我的YAML文件没有出现任何问题。
答案 0 :(得分:3)
我不确定您为什么会收到该错误,我试图找出Swagger是用哪种语言编写的,因为那里有多个已知存在问题的YAML解析器,但无法轻易确定使用google还是维基百科。
您的文件中没有重复的密钥,但由于密钥content
的缩进(第二次出现,paths
下的一个),它无效(即,无效的YAML) →
/v1/service/uri
→post
→responses
→200
),应与
description
,因为该键不能同时具有标量(OK
)和映射节点content: ....