Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork8.7k
Comments
🐛 Make sure a parameter defined as required is kept required in OpenAPI even if defined as optional in another dependency#4319
Conversation
cikay left a comment
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.
The commit message should be "Simplify conditions"
chardigio commentedMay 21, 2022
@tiangolo any chance you can check this out? It would help clear up our docs a lot 🙏🏼 |
…on-required onestaking into account recent changes to take into account location of parameter
codecovbot commentedSep 3, 2022 • edited
Loading Uh oh!
There was an error while loading.Please reload this page.
edited
Uh oh!
There was an error while loading.Please reload this page.
Codecov Report
@@ Coverage Diff @@## master #4319 +/- ##========================================= Coverage 100.00% 100.00% ========================================= Files 538 539 +1 Lines 13872 13902 +30 =========================================+ Hits 13872 13902 +30
Help us with your feedback. Take ten seconds to tell ushow you rate us. Have a feature suggestion?Share it here. |
tiangolo commentedSep 3, 2022
Thanks for the contribution @cd17822! 🍰 I updated the test to have in mind the new schemas for validation errors. And I refactored the implementation to account for the location of parameters, from a recent PR. Thanks for the interest here@cikay, nevertheless, it's not necessary to ask for some type of commit messages. I make sure the final commit message is consistent with the rest and then squash and merge. It's better to check if the implementation is correct, if it has tests, if the tests break before the fix and pass after the fix. Thanks! This will be available in the next FastAPI version, |
📝 Docs preview for commitbafa232 at:https://63137cf667cd57337c0f7914--fastapi.netlify.app |
📝 Docs preview for commitd2e3ae3 at:https://63137f52ea02943531f61914--fastapi.netlify.app |
Uh oh!
There was an error while loading.Please reload this page.
Summary
In the case where a parameter is looked for by multiple dependencies, but only required by some of them, we should reflect that in the openapi spec as
required=True.Currently
Right now the openapi spec indeterminately displays the parameter being required/optional. However, omitting the parameter will always result in a
422.Suggested
We ought not change anything about how the server acts, however we should show that the parameter is required in the openapi spec.
Rationale
As is, this is misleading and confusing for anyone trying to work with OpenAPI where this kind of situation arises. This becomes especially important when using inheritance withclass-based views. Often times you may want to look for a certain field in a base view, but only require it insome of the views that inherit from it.