connexion icon indicating copy to clipboard operation
connexion copied to clipboard

Multiple Swagger file on same connexion app

Open AntoineDuComptoirDesPharmacies opened this issue 3 years ago • 1 comments

Description

We would like to use connexion with Flask to serve multiple API using distinct Swagger YAML files that all use the same base path. Example : file1.yaml -> contains route /api/v1/statistics file2.yaml -> contains route /api/v1/products

In order to do this, we are calling the add_api method with each Swagger YAML file.

Expected behaviour

Both file are parsed and every routes are served through connexion/Flask.

Actual behaviour

An error occurs because Blueprint name conflicts as they are computed using base_path which is : file1.yaml -> /api/v1 file2.yaml -> /api/v1

Steps to reproduce

Same as 1032

Additional info:

As a workaround, we replace the add_api call by function that mimic add_api but allow to pass additional **options to the register_blueprint methods. Instead of :

        curr_api = connexion_app.add_api(provided_api, resolver=ApiResolver('api.provide.gen." + package_name + ".controllers'),
                          pythonic_params=True)

We do :

        api = super(type(connexion_app), connexion_app).add_api(provided_api, resolver=ApiResolver('api.provide.gen." + package_name + ".controllers'),
                          pythonic_params=True)
        connexion_app.app.register_blueprint(api.blueprint, name=provided_api)

Is there any reason to not add add_api **options parameters that could be given back to register_blueprint method ?

Output of the commands:

  • python --version => Python 3.7.5
  • pip show connexion | grep "^Version\:" => Version: 2.12.0

Thanks in advance for your help. Yours faithfully, Antoine

Hi @AntoineDuComptoirDesPharmacies

The options you mention are framework specific, while we try to keep the connexion interface framework agnostic. Other frameworks support a name parameter as well though (eg starlette), so I would not be opposed to adding the name parameter to the add_api method.

RobbeSneyders avatar Jun 01 '22 13:06 RobbeSneyders