问题描述
我正在通过 swagger 制作 API 文档 在我大摇大摆的编辑器中,我返回此回复
{
"id": "70020ed1-50fe-4c7e-afed","email": "[email protected]","authentication_token": "xzmsjvvkvgf448449"
}
通过下面来自swagger编辑器的代码
responses:
200:
description: User credentials.
schema:
# $ref: '#/deFinitions/User'
properties:
id:
type: string
example: 70020ed1-50fe-4c7e-afed
email:
type: string
example: [email protected]
authentication_token:
type: string
example: xzmsjvvkvgf448449
我想以一种实际的方式展示它。像这样
{
"message": "User @R_729_4045@ion & already exist","user": {
"id": "2386d9c5-5530-4950-b8fe-","email": "[email protected]","authentication_token": "kagHmoRSmPiu2R"}}
可能在用户对象中。
解决方法
您需要将 user
嵌套在一个对象中:
responses:
200:
description: User credentials.
content:
application/json:
schema:
properties:
message:
type: string
example: "User Information already exists"
user:
type: object
properties:
id:
type: string
example: 70020ed1-50fe-4c7e-afed
email:
type: string
example: [email protected]
authentication_token:
type: string
example: xzmsjvvkvgf448449
请参阅 https://swagger.io/docs/specification/data-models/data-types/#nested 了解更多信息,以及有关如何使用引用的说明。