使用 openapi 3.0 获取重复的映射键错误
Gets duplicated mapping key error using openapi 3.0
我正在尝试使用 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
当我 copy/paste 这些行进入 Swagger Editor 时,它在行 19
上给我 duplicated mapping key
错误;它用于参数 Content-Type
的 description
部分。
我研究过openapi documentation,但我没有发现我的 YAML 文件有任何问题。
我不确定为什么会出现该错误,我试图找出 Swagger 是用哪种语言编写的,因为已知有几个 YAML 解析器存在问题,但无法轻易确定使用google 或维基百科。
您的文件中没有任何重复的键,但由于键 content
的缩进(第二次出现,paths
→
/v1/service/uri
→ post
→ responses
→ 200
),应该与
description
因为该键不能具有既是标量 (OK
) 又是映射节点的值节点 content: ....
我正在尝试使用 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
当我 copy/paste 这些行进入 Swagger Editor 时,它在行 19
上给我 duplicated mapping key
错误;它用于参数 Content-Type
的 description
部分。
我研究过openapi documentation,但我没有发现我的 YAML 文件有任何问题。
我不确定为什么会出现该错误,我试图找出 Swagger 是用哪种语言编写的,因为已知有几个 YAML 解析器存在问题,但无法轻易确定使用google 或维基百科。
您的文件中没有任何重复的键,但由于键 content
的缩进(第二次出现,paths
→
/v1/service/uri
→ post
→ responses
→ 200
),应该与
description
因为该键不能具有既是标量 (OK
) 又是映射节点的值节点 content: ....