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
🐛 Make sure a parameter defined as required is kept required in OpenAPI even if defined as optional in another dependency #4319
🐛 Make sure a parameter defined as required is kept required in OpenAPI even if defined as optional in another dependency #4319
Conversation
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"
@tiangolo any chance you can check this out? It would help clear up our docs a lot 🙏🏼 |
…on-required ones taking into account recent changes to take into account location of parameter
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 us how you rate us. Have a feature suggestion? Share it here. |
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 commit bafa232 at: https://63137cf667cd57337c0f7914--fastapi.netlify.app |
📝 Docs preview for commit d2e3ae3 at: https://63137f52ea02943531f61914--fastapi.netlify.app |
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 with class-based views. Often times you may want to look for a certain field in a base view, but only require it in some of the views that inherit from it.