Skip to content
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

🐛 Fix support for extending openapi_extras with parameter lists #4267

Merged
merged 3 commits into from Aug 26, 2022

Conversation

orilevari
Copy link
Contributor

@orilevari orilevari commented Dec 11, 2021

Issue

When specifying parameters in openapi_extras for an endpoint, they will overwrite the existing query parameters with the extra parameters. This is due to deep_dict_update in utils.py overwriting list types rather than merging them together.

PR Content

This PR updates deep_dict_update to merge arrays instead of overwriting. I have also added a test case that demonstrates and verifies the desired behavior.

Testing

Ran bash scripts/test-cov-html.sh with 100% test pass including new test case

…llows query parameters to be specified in openapi_extras not be appended to the spec, not overwrite.
@tiangolo tiangolo changed the title Modify deep_dict_update to stop openapi_extras from overwriting query parameters 🐛 Fix support for extending openapi_extras with parameter lists Aug 26, 2022
@tiangolo
Copy link
Owner

Awesome, thanks for the contribution @orilevari! 🚀 🎉

@codecov
Copy link

codecov bot commented Aug 26, 2022

Codecov Report

Merging #4267 (7c8e75a) into master (92181ef) will not change coverage.
The diff coverage is 100.00%.

@@            Coverage Diff            @@
##            master     #4267   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          534       535    +1     
  Lines        13811     13830   +19     
=========================================
+ Hits         13811     13830   +19     
Impacted Files Coverage Δ
fastapi/utils.py 100.00% <100.00%> (ø)
tests/test_openapi_query_parameter_extension.py 100.00% <100.00%> (ø)

Help us with your feedback. Take ten seconds to tell us how you rate us. Have a feature suggestion? Share it here.

@tiangolo tiangolo enabled auto-merge (squash) August 26, 2022 09:24
@tiangolo tiangolo merged commit 880c8b3 into tiangolo:master Aug 26, 2022
@Darep
Copy link

Darep commented Jan 12, 2023

Is there a way to fall back to the old functionality somehow? 🤔 We have Query(default=datetime.utcnow()) and we are trying to override it like openapi_extra={"parameters": [{"schema": {"default": "Current timestamp in UTC"}}]} 😄 And this change now simply appends a new parameter in the list.

We might do include_in_schema=False and write it completely if there isn't, so no worries... 😊 (Other solutions for changing the default in the OpenAPI-schema also welcome!)

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.

None yet

3 participants