marshmallow-code / apispec

A pluggable API specification generator. Currently supports the OpenAPI Specification (f.k.a. the Swagger specification)..

Home Page:https://apispec.readthedocs.io/

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Use with flask and redoc?

caseydm opened this issue · comments

Hi all. Can anybody recommend a way to use apispec with a pure Flask project in order to display redoc documentation? I am aware of flask-smorest, fastapi, etc. But I need to stick to regular flask for my project. What I was thinking was to use apispec to automatically generate my API specification with marshmallow, then run the redoc CLI tool during the build process to generate documentation.

Does this sound feasible or I am missing an easier way?

The json (or YAML) spec is generated by apispec.

Not sure what the redoc CLI does and what you want to do.

If you want your app to host its doc, you may copy what is done in flask-smorest or other libs.

If you want to host the docs in another web server (or virtual host) you may generate the doc in the build process calling apispec. You may find inspiration in flask-smorest/spec/init.py to create a flask CLI command. Then you host that file statically.

Thank you! I saw how flask-smorest was doing it and was able to set up the same thing. I did not have to use the CLI and was able to create two routes, one that serves the api spec json, and another that serves the redoc html file that points to that other json route. Good to go!