You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The current setup in a project I'm maintaining has a route factory that takes a Flask app object and a url, and for every OpenAPI spec file in the project:
Creates a FlaskApp with a given name (con = connexion.FlaskApp(app.name))
Adds an api via FlaskApp.add_api() with a provided swagger file, a basic Resolver, and arguments={'api_path': url}, expecting an api object as a return value (api = con.add_api(swagger_file, resolver=ResolverImpl(**kwargs), arguments={'api_path': url})
Calls app.register_blueprint(api.blueprint, url_prefix=url) <- this breaks!
I'm guessing this was undocumented behaviour, because even 2.7.0 docs don't do anything with the return value, yet it works fine. With the version specified in the question title, FlaskApp.add_api() specifically returns None (which the Ask AI feature states is expected behavior for the latest version), so the whole process breaks, and I can't even find anything pertaining to a breaking change in that regard.
I've tried printing the underlying app blueprints and they don't change (expected, I guess?). How do I fix this?
Updates
U1: The created FlaskApp doesn't have any blueprints in it either -- con.app.blueprints is an empty dict before and after the con.add_api call.
U2: Digging into connexion's internals, the AbstractApp.add_api is typehinted as returning an Any type object, with an explicit mention in the docstring: :return: The Api registered on the middleware application wrapping the framework.
All it does, however, is return ConnexionMiddleware.add_api(), which explicitly returns None! Documentation fail?
U3: Apparently, only FlaskASGIApp returns the API object in 3.3.0.
In 2.7.0, FlaskApp.add_api calls super(FlaskApp, self).add_api(), which returns an instance of AbstractApp.api_cls, namely FlaskApi in the case of FlaskApp. It also registers the blueprint of the resulting API in the FlaskApp.add_api() call
In 3.3.0, FlaskApp doesn't override the add_api method call at all, only FlaskASGIApp does. FlaskApp does register FlaskASGIApp as its _middleware_app, and saves the FlaskASGIApp.app as its app, but AbstractApp.add_api() calls ConnexionMiddleware.add_api(), which only saves the registered API to an internal list and registers the list in FlaskASGIApp with blueprints when _build_middleware_stack() is called.
I suppose there's a reason blueprints of registered APIs were made completely unavailable, but I still have to ask why.
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
The current setup in a project I'm maintaining has a route factory that takes a Flask
appobject and a url, and for every OpenAPI spec file in the project:con = connexion.FlaskApp(app.name))FlaskApp.add_api()with a provided swagger file, a basicResolver, andarguments={'api_path': url}, expecting an api object as a return value (api = con.add_api(swagger_file, resolver=ResolverImpl(**kwargs), arguments={'api_path': url})app.register_blueprint(api.blueprint, url_prefix=url)<- this breaks!I'm guessing this was undocumented behaviour, because even 2.7.0 docs don't do anything with the return value, yet it works fine. With the version specified in the question title,
FlaskApp.add_api()specifically returns None (which the Ask AI feature states is expected behavior for the latest version), so the whole process breaks, and I can't even find anything pertaining to a breaking change in that regard.I've tried printing the underlying
appblueprints and they don't change (expected, I guess?). How do I fix this?Updates
U1: The created
FlaskAppdoesn't have any blueprints in it either --con.app.blueprintsis an empty dict before and after thecon.add_apicall.U2: Digging into
connexion's internals, theAbstractApp.add_apiis typehinted as returning anAnytype object, with an explicit mention in the docstring::return: The Api registered on the middleware application wrapping the framework.All it does, however, is return
ConnexionMiddleware.add_api(), which explicitly returnsNone! Documentation fail?U3: Apparently, only
FlaskASGIAppreturns the API object in 3.3.0.FlaskApp.add_apicallssuper(FlaskApp, self).add_api(), which returns an instance ofAbstractApp.api_cls, namelyFlaskApiin the case ofFlaskApp. It also registers the blueprint of the resulting API in theFlaskApp.add_api()callFlaskAppdoesn't override theadd_apimethod call at all, onlyFlaskASGIAppdoes.FlaskAppdoes registerFlaskASGIAppas its_middleware_app, and saves theFlaskASGIApp.appas itsapp, butAbstractApp.add_api()callsConnexionMiddleware.add_api(), which only saves the registered API to an internal list and registers the list inFlaskASGIAppwith blueprints when_build_middleware_stack()is called.I suppose there's a reason blueprints of registered APIs were made completely unavailable, but I still have to ask why.
Beta Was this translation helpful? Give feedback.
All reactions