我想在 openapi 3.0 YAML 中添加响应架构的示例。我已经了解了链接https://swagger.io/docs/specation/adding-examples/上的想法,但我的问题是我的响应架构对象包含其中的嵌套对象。任何人都可以帮助和指导我如何在嵌套对象时添加示例吗?
小智 12
您可以通过两种方式定义响应示例。让这是您的嵌套 json 对象响应:
{
"status": true,
"data": {
"storeId": "string",
"message": "string"
}
}
Run Code Online (Sandbox Code Playgroud)
方法1:在参数定义本身中,您可以添加示例
myschema:
type: object
properties:
status:
type: boolean
required: true
example: true
data:
type: object
properties:
"message":
type: string
example: Success
"Id":
type: string
example: 1234
Run Code Online (Sandbox Code Playgroud)
方法2:在属性定义之后,您可以定义example:这样的标签
myschema:
type: object
properties:
status:
type: boolean
required: true
data:
type: object
properties:
message:
type: string
Id:
type: string
example:
status: true
data:
Id: '1234'
message: success
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
8401 次 |
| 最近记录: |