Connexion: Allow setting a different name for a URL parameter and its corresponding python variable

Created on 25 Apr 2019  路  4Comments  路  Source: zalando/connexion

Suppose I want to implement an endpoint /data?from=12&until=52 which accepts parameters from and until (specifying timestamps or something). The problem is that I can't do this because Connexion always uses the name of the query parameter as the name for the Python variable. It's a shame to couple these things together because there are restrictions on Python variable names that don't exist for query parameters - I can't have a Python variable called from.

What I would suggest is a solution like this:

/data:
    get:
      operationId: "controller.get_data"
      parameters:
      - name: from
        in: query
        x-parameter-name: start_time
        schema:
          type: integer
good first issue question

All 4 comments

Hi @geajack ,

Thanks for reaching out. I understand your frustration, but we would like to keep extensions to the OpenAPI spec to the minimum. The reasoning you mention here is about limitations on the naming of variables and Python variables. You can have a parameter with from name, Connexion doesn't limit you on that. What happens is that Connexion will look for a parameter with name from_, it adds an underscore to the ending of the parameter name. For more details please have a look at this piece of Connexion's code https://github.com/zalando/connexion/blob/master/connexion/decorators/parameter.py#L47

I hope that will help you. Let me know if there is any other limitations on parameter naming that you are facing and I might be missing. If this clears out this issue for you, please close it.

Thanks. That's a perfectly satisfactory solution. It should be mentioned in the documentation, possibly in the Request Handling section (which is where the x-body-name directive is documented).

I agree it should be in docs. I will leave this issue as the reference to add this new information to the docs. @geajack would you be interested in sending a PR to update the docs?

I have a similar issue: I want to use an url parameter named 'user', but it get's shadowed by 'user' from the connexion request context. is there any chance to get it other than using flask.request.args?

Was this page helpful?
0 / 5 - 0 ratings