我的一个蓝图中有一些端点,我希望将此蓝图的所有 API 文档添加到一个.yaml
文件中。但是,使用我当前的.yaml
文件结构和蓝图代码,flasgger 似乎无法识别正确的定义。
蓝图代码:
app_obj = Flask(name)
app_obj.register_blueprint(user_controller, url_prefix="/")
# ...
user_controller = Blueprint("controllers/user_controller", __name__)
@user_controller.route('/signup', endpoint='signup', methods=['POST'])
@swag_from('user.yml', endpoint=f'{user_controller.name}.signup')
def signup():
response = RestResponse()
try:
if request.method == "POST":
data = request.get_json()
newly_created_user = UserService.create_user(data.get("username"), data.get("email"),
data.get("password"), data.get("name"))
response.data = newly_created_user
return jsonify(response.to_dict())
except BadRequest as err:
response.data = GenericException(message=err.description).to_dict()
return jsonify(response.to_dict()), err.code
至于我的user.yaml:
definitions:
User:
type: object
properties:
id:
type: string
name:
type: string
username:
type: string
email:
type: string
created_at:
type: string
updated_at:
type: string
paths:
"/signup":
post:
parameters:
- name: name
in: body
type: string
required: true
- name: username
in: body
type: string
required: true
- name: password
in: body
type: string
required: true
- email: email
in: body
type: string
required: true
responses:
200:
description: Newly created user
schema:
$ref: '#/definitions/User'
感谢我能得到的所有帮助。谢谢!