-
-
Notifications
You must be signed in to change notification settings - Fork 228
Path parameters as function positional arguments #429
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
Path parameters as function positional arguments #429
Conversation
OpenAPI Specification indicates that if parameter location is `path` the `required` property is REQUIRED and its value MUST be `true` Ref: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object With this in mind, this PR: - Tighten the parsing by throwing an error for path parameters with required=false - Update the templates to pass the path parameters to the function as positional arguments instead of kwargs to improve usability
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the contribution! Requiring required seems like a good move. Only thing we'll have to work on is how we approach positional arguments since they're inherently more fragile than the kwarg-only approach we've been taking.
{# path parameters #} | ||
{% for parameter in endpoint.path_parameters %} | ||
{{ parameter.to_string() }}, | ||
{% endfor %} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Only problem with this is that the order of endpoint.path_parameters
is not guaranteed. If the declaration order swaps around or there's a slight change in implementation (e.g. at some point we decide to alphabetize kwargs) then generated clients will break and potentially do so in a way that consumers don't catch.
If we want to allow positional args, we'll have to guarantee the order for them. For Path params we could use the order in which they appear in the path, which seems the most logical solution to me. It's going to require a bit more up front parsing work though.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for the review! I will work on sort them in the order they appear in the path.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done in b9e8057
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks great, thanks! Just one suggestion which I think will make the sorting a bit more efficient.
Also fix typo Co-authored-by: Dylan Anthony <43723790+dbanty@users.noreply.github.com>
The lint is failing:
I guess I am forced to pass |
That field is intended to take and then display the part of the schema that's wrong. I think we can just omit it and include the path in the error message. |
Sorry for the delay on this @tsotnikov, I've created a branch in-repo and a PR at #464 so I can update this and finish it off. Thanks for all the hard work! |
@tsotnikov! Co-authored-by: Taras Sotnikov <taras.sotnikov@telefonica.com>
OpenAPI Specification indicates that if parameter location is
path
therequired
property is REQUIRED and its value MUST betrue
Ref: https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#parameter-object
With this in mind, this PR:
to improve usability