我正在将flask-swagger设置为一个项目,而该项目是使用flask-restful创建的。它显示了请求正文建模和示例,但未显示响应正文建模和示例,仅显示了描述。我发现它在swagger-ui生成的页面上创建了404错误。这是错误消息的示例。
{
"messages": [
"attribute paths.'/users'(get).200.application/json is unexpected"
],
"schemaValidationMessages": [
{
"level": "error",
"domain": "validation",
"keyword": "additionalProperties",
"message": "object instance has properties which are not allowed by the schema: [\"description\"]",
"schema": {
"loadingURI": "#",
"pointer": ""
},
"instance": {
"pointer": ""
}
}
]
}
我想显示响应正文建模和示例。我在下面添加了yaml文件。
class User(Resource)
def get(self):
"""
get users
---
tags:
- users
parameters:
-in: body
required:
- user_id
schema:
properties:
user_id:
type: string
description: user id
responses:
200:
description: ok
content:
application/json
schema:
type: object
properties:
user_name:
type: string
description: user name
"""
example code
return jsonify(user_name=username)