Swagger Open API 3.0.1:如何为响应示例定义对象数组
Swagger Open API 3.0.1: How to define an array of object for the response example
使用 Open API 3.0.1 为 API 规范定义 swagger 定义。但是这里定义的响应示例GoodResponse并没有渲染出来。虽然语法似乎是有效的。感谢任何关于我做错了什么的指示
paths:
/java/api/play:
post:
tags:
- some-controller
operationId: someOperation
requestBody:
content:
application/xml:
schema:
$ref: '#/components/schemas/HarryKartType'
required: true
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
items:
$ref: '#/components/schemas/GoodResponse'
components:
schemas:
GoodResponse:
required:
- goodstatusCode
- goodresponseMessage
type: object
properties:
goodstatusCode:
type: integer
example: 200
goodresponseMessage:
type: array
example:
- position: 1
horseName: "TIMETOBELUCKY"
- position: 2
horseName: "HERCULES BOKO"
- position: 3
horseName: "CARGO DOOR"
items:
$ref: '#/components/schemas/GoodResponseMessage'
GoodResponseMessage:
type: object
properties:
position:
type: integer
example: 1
horseName:
type: string
example: "TIMETOBELUCKY"
您需要在 schema
中定义 $ref,而不是在 items
中
试试这个:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/GoodResponse'
使用 Open API 3.0.1 为 API 规范定义 swagger 定义。但是这里定义的响应示例GoodResponse并没有渲染出来。虽然语法似乎是有效的。感谢任何关于我做错了什么的指示
paths:
/java/api/play:
post:
tags:
- some-controller
operationId: someOperation
requestBody:
content:
application/xml:
schema:
$ref: '#/components/schemas/HarryKartType'
required: true
responses:
'200':
description: OK
content:
application/json:
schema:
type: object
items:
$ref: '#/components/schemas/GoodResponse'
components:
schemas:
GoodResponse:
required:
- goodstatusCode
- goodresponseMessage
type: object
properties:
goodstatusCode:
type: integer
example: 200
goodresponseMessage:
type: array
example:
- position: 1
horseName: "TIMETOBELUCKY"
- position: 2
horseName: "HERCULES BOKO"
- position: 3
horseName: "CARGO DOOR"
items:
$ref: '#/components/schemas/GoodResponseMessage'
GoodResponseMessage:
type: object
properties:
position:
type: integer
example: 1
horseName:
type: string
example: "TIMETOBELUCKY"
您需要在 schema
中定义 $ref,而不是在 items
中
试试这个:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/GoodResponse'