Flask 框架的 Swagger API 文档生成 https://github.com/flasgger/flasgger

天问 2a8982de14 Update 'README.md' 9 months ago
README.md 2a8982de14 Update 'README.md' 9 months ago

README.md

flasgger

Flask 框架的 Swagger API 文档生成

Usage

安装依赖

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)

访问: http://localhost/apidocs

注意 flasgger 会读取注释来生成文档,所以注释需要规范