Skip to content

Serialize model query params #316

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

Merged
merged 6 commits into from
Feb 10, 2021

Conversation

forest-benchling
Copy link
Collaborator

@forest-benchling forest-benchling commented Jan 27, 2021

Fixes #295.

This PR serializes model query params as if style=form, explode=true. Although we don't support style and explode, we currently already act as if style=form, explode=true. In other words, in today's client, if you pass in a list query parameter, it will already be serialized as list=val&list=val2&list=val3. This is just the behavior of httpx.

Therefore, I think this PR, which will cause a dict to be serialized as key1=val1&key2=val2&key3=val3, would be consistent, as a holdover until we get to the point where we fully support all style/explode combinations.

@forest-benchling
Copy link
Collaborator Author

cc @dbanty @bowenwr

@codecov
Copy link

codecov bot commented Jan 27, 2021

Codecov Report

Merging #316 (af5e231) into main (b2adc2c) will not change coverage.
The diff coverage is 100.00%.

Impacted file tree graph

@@            Coverage Diff            @@
##              main      #316   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files           47        47           
  Lines         1390      1395    +5     
=========================================
+ Hits          1390      1395    +5     
Impacted Files Coverage Δ
...penapi_python_client/parser/properties/__init__.py 100.00% <100.00%> (ø)
..._python_client/parser/properties/model_property.py 100.00% <100.00%> (ø)
...penapi_python_client/parser/properties/property.py 100.00% <100.00%> (ø)

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update b2adc2c...8d6d644. Read the comment docs.

@forest-benchling
Copy link
Collaborator Author

@dbanty fixed merge conflicts

Copy link
Collaborator

@dbanty dbanty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good, just a couple notes. Thanks!

@@ -19,6 +19,7 @@ class ModelProperty(Property):
additional_properties: Union[bool, Property]

template: ClassVar[str] = "model_property.py.jinja"
json_is_dict: ClassVar[bool] = True
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should probably exist on the base Property as False right? I guess Jinja is handling it properly but I would expect an exception when checking if not property.json_is_dict for non- ModelProperty

"$ref": "#/components/schemas/ModelWithUnionProperty"
},
"name": "model_prop",
"in": "query"
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

You should probably also add nullable and not required and nullable examples as query params just to verify the template is working in all those cases using e2e tests.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@dbanty Is it OK if I add that test coverage in #332? Since it's not possible AFAIK to make a nullable model query parameter without making it a union type, and if I make it a union type then it depends on #332.

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yep that's fine.

if {% if not property.required %}not isinstance({{ property_name }}, Unset){% endif %}{% if not property.required and property.nullable %} and {% endif %}{% if property.nullable %}{{ property_name }} is not None{% endif %}:
if not isinstance({{ property_name }}, Unset) and {{ property_name }} is not None:
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think this was a mistake since now we get .update() twice in the generated code. Also mypy probably will get mad about non-overlapping type checks or whatever.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Oops, yeah, probably a mistake from my merge. I think the two .update()s you're referring to are actually updating different things, though.

Copy link
Collaborator

@dbanty dbanty left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Awesome, thanks! One more PR down 😄

@dbanty dbanty merged commit 6e10751 into openapi-generators:main Feb 10, 2021
dbanty added a commit that referenced this pull request Feb 10, 2021
@eli-bl eli-bl deleted the benchling-issue-295a branch November 26, 2024 22:44
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Support for Free-Form Query Parameters
2 participants