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

Allow defining multple flask-apispec blueprints #234

Open
lucatpa opened this issue Mar 29, 2022 · 1 comment
Open

Allow defining multple flask-apispec blueprints #234

lucatpa opened this issue Mar 29, 2022 · 1 comment

Comments

@lucatpa
Copy link

lucatpa commented Mar 29, 2022

I have an API with multiple versions and it would be nice to provide different URLs for different versions to have things more cleanly (I don't want to distract users with deprecated APIs but still provide docs for users stuck with the deprecated API).

I tried this trick to build multiple apispecs at different URLs:

    for bp in blueprints:
        app.config.update({
            'APISPEC_SPEC': APISpec(
                title='Accounts Service',
                version=bp.name,
                openapi_version='2.0',
                plugins=[MarshmallowPlugin()],
            ),
            'APISPEC_SWAGGER_URL': f'/swagger/{bp.name}',
            'APISPEC_SWAGGER_UI_URL': '/swagger/{bp.name}/ui',
        })
        spec = FlaskApiSpec(app)

        for name, endpoint in spec.app.view_functions.items():
            if not isinstance(endpoint, types.FunctionType):
                continue

            if '.' in name:
                spec.register(endpoint, blueprint=name[:name.index('.')])
            else:
                spec.register(endpoint)

But flask would complain about Both share the same name "flask-apispec". Blueprints that are created on the fly need unique names. because this blueprint name is hardcoded and can't be changed:

blueprint = flask.Blueprint(
'flask-apispec',
__name__,
static_folder='./static',
template_folder='./templates',
static_url_path='/flask-apispec/static',
)

It would be nice to provide a way to override the blueprint name.

@rprinsloo
Copy link

rprinsloo commented Apr 26, 2022

Work was done back in 2020 to allow this PR 167. The PR is stale and might need some work.

I'm picking up a project using the above fix and will report back should I have time to visit this PR to get it into mainstream (if that is desired by the project maintainers).

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

No branches or pull requests

2 participants