Flask 框架的 Swagger API 文档生成
安装依赖
pip install flasgger
main.py
from flask import Flask
from flasgger import Swagger
app = Flask(__name__)
swagger = Swagger(app)
@app.route('/hello/<name>')
def hello_world(name):
"""
A simple endpoint that returns a greeting.
---
parameters:
- name: name
in: path
type: string
required: true
description: The name to greet.
responses:
200:
description: A greeting message.
"""
return 'Hello, {}!'.format(name)
if __name__ == '__main__':
app.run(debug=True)
注意 flasgger 会读取注释来生成文档,所以注释需要规范