Overview¶
Installation¶
pip install flask-marshmallow-openapi
What does it do?¶
Searches your codebase for marshmallow schemas and 🎖️ decorated 🎖️ Flask routes.
It then produces swagger.json
and injects it into self-hosted
ReDoc and
SwaggerUI documentation viewers.
api = flask.Blueprint("my_api", __name__)
class BookSchema(ma.Schema):
id = ma.fields.Integer(as_string=True)
title = ma.fields.String(allow_none=False)
publisher = ma.fields.String(allow_none=False)
isbn = ma.fields.String(allow_none=False)
@open_api.get_list(BookSchema)
@api.route("/books", methods=["GET"])
def books_list():
return "<p>Hello, World!</p>"
app = flask.Flask(__name__)
app.register_blueprint(api, url_prefix="/v1")
conf = OpenAPISettings(
api_version="v1", api_name="My API", app_package_name="my_api", mounted_at="/v1"
)
docs = OpenAPI(config=conf)
docs.init_app(app)
Contents¶
- Getting started
- Documenting GET routes
- Documenting POST routes
- Documenting PATCH routes
- Documenting DELETE routes
- Markdown and docstrings
- Documenting API authentication schemes
- Documenting URL parameters
- Grouping routes’ documentation: tags
- OpenAPI middleware
- Excluding and overriding generated endpoint documentation
- Documenting custom marshmallow field types
- Serving docs statically via nginx
- License