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

Get list of all Swagger UI Endpoints? #203

Closed
CalebM1987 opened this issue Aug 13, 2020 · 2 comments
Closed

Get list of all Swagger UI Endpoints? #203

CalebM1987 opened this issue Aug 13, 2020 · 2 comments
Labels
question Further information is requested

Comments

@CalebM1987
Copy link

For our Flask Apps, we usually are creating several different blueprints. Recently, we have integrated flask_restx so we can add documentation. As part of the REST API's we are creating, it would be nice to dynamically get all the Swagger UI endpoints (registered namespaces) so I can make a directory to point to the help for each blueprint. I know I can manually register a list of these and use that, but is there any way to do this programmatically so we can dynamically load all the locations of Swagger help at runtime?

We are hoping to be able to glean this from the app.config or some other way that is easily accessible if flask_restx maintains a registry of these internally. Thanks!

@CalebM1987 CalebM1987 added the question Further information is requested label Aug 13, 2020
@CalebM1987
Copy link
Author

Update: I did just try this and it seems to work, however, I don't really like my test of having to see if the view_function ends with .doc. This feels hacky and dirty, so I am still open to a better way. But this is working:

    @app.route('/swagger')
    def swagger():
        base = request.host_url
        swagger_endpoints = []
        swagger_keys = list([k for k in app.view_functions.keys() if k.endswith('.doc')])
        for key in swagger_keys:
            ext = url_for(key)
            swagger_endpoints.append(dict(
                name=ext.split('/')[1],
                url='{}{}'.format(base, ext.lstrip('/'))
            ))
        return jsonify(swagger_endpoints)

result:
image

@CalebM1987
Copy link
Author

found a working solution

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Further information is requested
Projects
None yet
Development

No branches or pull requests

1 participant