PWZER / swagger-ui-py

Swagger UI for Python web framework, such Tornado, Flask and Sanic. https://pwzer.github.io/swagger-ui-py/
https://pypi.org/project/swagger-ui-py
Apache License 2.0
68 stars 31 forks source link

Cannot add swagger ui to a flask blueprint #42

Open SpoonMeiser opened 7 months ago

SpoonMeiser commented 7 months ago

A blueprint should, for most purposes be indistinguishable from an application, and I think it makes perfect sense to have, say, a flask blueprint for an API, and add a swagger UI to that.

However, the flask handler contains this check:

    import flask
    if isinstance(doc.app, flask.Flask):
        return handler

Which fails, because flask.Blueprint is not a subclass of flask.Flask.

Perhaps the test should be:

    import flask.scaffold import Scaffold
    if isinstance(doc.app, Scaffold):
        return handler

Or perhaps it's safer like this as scaffold doesn't appear to be a documented part of the API:

    import flask
    if isinstance(doc.app, (flask.Flask, flask.Blueprint)):
        return handler