Swagger 多级对象的招摇过市示例不会出现
我正试图为401响应状态代码(覆盖默认示例值)显示自定义示例,但以下代码由于某些原因(默认值保持不变)状态不会执行此操作。不会设置代码和状态。也不会设置“代理”对象,也不会进入内容Swagger 多级对象的招摇过市示例不会出现,swagger,openapi,Swagger,Openapi,我正试图为401响应状态代码(覆盖默认示例值)显示自定义示例,但以下代码由于某些原因(默认值保持不变)状态不会执行此操作。不会设置代码和状态。也不会设置“代理”对象,也不会进入内容 paths: /api/Users/Login: post: requestBody: content: application/json: schema: $ref: '#/components/sche
paths:
/api/Users/Login:
post:
requestBody:
content:
application/json:
schema:
$ref: '#/components/schemas/LoginCredentials'
responses:
'200':
description: Login OK / Agent Object
content:
'*/*':
schema:
$ref: '#/components/schemas/RestResponse'
example:
Content:
schema:
$ref: '#/components/schemas/Agent'
'401':
description: Incorrect credentials
content:
'*/*':
schema:
$ref: '#/components/schemas/RestResponse'
example:
Status:
Verbal: Error
Code: 1074
Content: null
components:
schemas:
Agent:
type: object
RestResponse:
type: object
properties:
Status:
type: object
properties:
Verbal:
type: string
example: Success
Code:
type: string
format: int32
example: 104
Content:
type: object
Exception:
type: object
LoginCredentials:
type: object
required:
- UserName
- Password
properties:
UserName:
type: string
format: email
example: user@not.net
Password:
type: string
example: password
我期望看到的响应示例:
200:
401:
401示例在最新的Swagger Editor/Swagger UI中运行良好。它不太正确,我希望它返回response{Status{“verball”:“Error”“Code”:1074}}}object抱歉,我不确定我是否遵循了。你能编辑你的帖子并添加你希望在Swagger UI中看到的完整JSON吗?@Helen我更新了问题以显示我的期望输出。我不确定是否应该对示例使用schema,还是使用components.examples
{
"Status": {
"Verbal": "Success",
"Code": 104
},
"Content": "Agent{}"
}
{
"Status": {
"Verbal": "Error",
"Code": 1074
},
"Content": null
}