Thanks to visit codestin.com
Credit goes to github.com

Skip to content

🐛 Fix support for extending openapi_extras with parameter lists#4267

Merged
tiangolo merged 3 commits into
fastapi:masterfrom
orilevari:openapi_extras_parameters
Aug 26, 2022
Merged

🐛 Fix support for extending openapi_extras with parameter lists#4267
tiangolo merged 3 commits into
fastapi:masterfrom
orilevari:openapi_extras_parameters

Conversation

@orilevari

@orilevari orilevari commented Dec 11, 2021

Copy link
Copy Markdown

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
Copy Markdown
Member

Awesome, thanks for the contribution @orilevari! 🚀 🎉

@codecov

codecov Bot commented Aug 26, 2022

Copy link
Copy Markdown

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 fastapi:master Aug 26, 2022
@Darep

Darep commented Jan 12, 2023

Copy link
Copy Markdown

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.

3 participants