Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Documentation to explitly specify how to serve Swagger UI using apisec ? #750

Open
mkmoisen opened this issue Feb 27, 2022 · 0 comments
Open

Comments

@mkmoisen
Copy link

mkmoisen commented Feb 27, 2022

Perhaps this is too obvious for most, but I struggled a bit figuring out how to use the result of my apispec to actually serve a Swagger UI from my Flask app.

I think other noobs might benefit if the documentation laid out clear steps on how to serve a Swagger UI, for example using Flask. I finally figured this out from this blog post here after a few hours of researching different solutions.

Beginners might waste a lot of time researching third party tools to do this simple task of serving the Swagger UI, when they are not required.


E.g, create a route that serves the base static html file from Swagger here. The css/js/image files could also be served from flask, or to make it simple in the documentation they could be linked to someone's hosted files. Line 42 of this file should look something like this:

url: "{{ url_for('serve_swagger_spec') }}",

And the route for this serve_swagger_spec can be created like so:

spec = APISpec(...)

@app.get('/swagger/spec/')
def serve_swagger_spec():
    return jsonify(spec.to_dict()), 200
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants