问题描述
使用 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
内而不是在 items
内定义 $ref
试试这个:
'200':
description: OK
content:
application/json:
schema:
$ref: '#/components/schemas/GoodResponse'