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
For this feature request we can simply stay on the Pet Store example from the web editor
This request relates more to a general characteristic of Python code generation rather than an specific example given a config YAML.
Is your feature request related to a problem?
Connexion updated to a new major version one month ago, leading to breaking changes on common objects like connexion.request or connexion.context. Here are their docs on what's new and how we should adapt.
The following generated code example for add_pet does no longer work with connexion==3.0.1:
defadd_pet(body): # noqa: E501"""Add a new pet to the store Add a new pet to the store # noqa: E501 :param body: Create a new pet in the store :type body: dict | bytes :rtype: Pet """ifconnexion.request.is_json:
body=Pet.from_dict(connexion.request.get_json()) # noqa: E501returnmy_add_pet_function(body) # Added by myself, but usually is 'do some magic!'
Describe the solution you'd like
Following the previous example, this is how add_pet should be generated for correctly manipulating the Starlette Request object:
defadd_pet(body): # noqa: E501"""Add a new pet to the store Add a new pet to the store # noqa: E501 :param body: Create a new pet in the store :type body: dict | bytes :rtype: Pet """ifconnexion.request.mimetype=="application/json":
body=Pet.from_dict(body) # noqa: E501returnmy_add_pet_function(body) # Added by myself, but usually is 'do some magic!'
Some points about the given solution, working on our APIs:
is_json() is a method from Flask.Request which does not appear on starlette.request.Request. One has to use mimetype property instead.
body is now given on a dictionary format with the correct arguments passed by connexion middleware, instead of having to access the request by get_json
What's more, get_json method does not exist for starlette.request.Request, and its corresponding json method is an async function whose await has been already taken by connexion
Describe alternatives you've considered
I'm not fully aware of the consequences of accessing directly the body argument on controller functions, but in case it is necessary to get the request data from connexion.request I tried with asyncio.run, but it hangs permanently waiting for an object already taken.
Additional context
It is important to highlight a security issue on previous versions of Werkzeug, which depends on this new major version of connexion, that leads to certain urgency on this update for those who have on any production environment their swagger APIs.
Thanks in advance!
The text was updated successfully, but these errors were encountered:
Content & configuration
For this feature request we can simply stay on the Pet Store example from the web editor
This request relates more to a general characteristic of Python code generation rather than an specific example given a config YAML.
Is your feature request related to a problem?
Connexion updated to a new major version one month ago, leading to breaking changes on common objects like
connexion.request
orconnexion.context
. Here are their docs on what's new and how we should adapt.One 'minor' breaking change is that
request
object is now a StarletteRequest
and not a Flask one, and this is related with the generation of code when given aswagger.yaml
like the one from the pet store.The following generated code example for
add_pet
does no longer work withconnexion==3.0.1
:Describe the solution you'd like
Following the previous example, this is how
add_pet
should be generated for correctly manipulating the StarletteRequest
object:Some points about the given solution, working on our APIs:
is_json()
is a method fromFlask.Request
which does not appear onstarlette.request.Request
. One has to usemimetype
property instead.body
is now given on a dictionary format with the correct arguments passed byconnexion
middleware, instead of having to access the request byget_json
get_json
method does not exist forstarlette.request.Request
, and its correspondingjson
method is anasync
function whose await has been already taken byconnexion
Describe alternatives you've considered
I'm not fully aware of the consequences of accessing directly the
body
argument on controller functions, but in case it is necessary to get the request data fromconnexion.request
I tried withasyncio.run
, but it hangs permanently waiting for an object already taken.Additional context
It is important to highlight a security issue on previous versions of
Werkzeug
, which depends on this new major version ofconnexion
, that leads to certain urgency on this update for those who have on any production environment their swagger APIs.Thanks in advance!
The text was updated successfully, but these errors were encountered: