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

📝 Add OpenAPI warning to "Body - Fields" docs with extra schema extensions #4846

Merged
merged 2 commits into from
May 11, 2022

Conversation

ml-evs
Copy link
Contributor

@ml-evs ml-evs commented May 1, 2022

This PR adds a warning in the docs about generating invalid OpenAPI schemas (see #3745) when using additional keys in pydantic Field specifications. This warning only effects versions fastapi>=0.66, which could be added to the note if helpful.

I would have liked to include a workaround for those who want to keep generating valid schemas, but is currently non-trivial and either involves overriding a whole chain of field info classes, or writing a custom OpenAPI schema method, to undo the effect of extra = "allow" in the fastapi.openapi.models.Schema class.
It is a bit of a shame this hasn't been acknowledged as an issue in #3745 but I hope that this warning will be helpful for those who are trying to use generic OpenAPI tools with FastAPI.

Adds a warning about generating invalid OpenAPI schemas (see fastapi#3745) when using additional keys in pydantic `Field` specifications.
@codecov
Copy link

codecov bot commented May 1, 2022

Codecov Report

Merging #4846 (1d9b364) into master (146f57b) will not change coverage.
The diff coverage is n/a.

@@            Coverage Diff            @@
##            master     #4846   +/-   ##
=========================================
  Coverage   100.00%   100.00%           
=========================================
  Files          531       531           
  Lines        13627     13629    +2     
=========================================
+ Hits         13627     13629    +2     
Impacted Files Coverage Δ
fastapi/exceptions.py 100.00% <0.00%> (ø)
fastapi/applications.py 100.00% <0.00%> (ø)
fastapi/dependencies/utils.py 100.00% <0.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 146f57b...1d9b364. Read the comment docs.

@ml-evs ml-evs changed the title Add OpenAPI warning to "Body - Fields" docs 📝 Add OpenAPI warning to "Body - Fields" docs May 1, 2022
@github-actions
Copy link
Contributor

github-actions bot commented May 1, 2022

📝 Docs preview for commit c8182fb at: https://626e94c817e90a569d91b459--fastapi.netlify.app

@github-actions
Copy link
Contributor

📝 Docs preview for commit 1d9b364 at: https://627c2d135aa774107ddd9516--fastapi.netlify.app

@tiangolo tiangolo changed the title 📝 Add OpenAPI warning to "Body - Fields" docs 📝 Add OpenAPI warning to "Body - Fields" docs with extra schema extensions May 11, 2022
@tiangolo tiangolo merged commit 4fcdb31 into fastapi:master May 11, 2022
@tiangolo
Copy link
Member

Thanks @ml-evs! I updated the tip/warning a bit to avoid mentioning const as that would mean it would also have to explain how const is valid JSON Schema v6 but not valid OpenAPI 3.0.x, although as OpenAPI 3.1.x is based on JSON Schema v7 then it is compatible there.

JeanArhancet pushed a commit to JeanArhancet/fastapi that referenced this pull request Aug 20, 2022
…sions (fastapi#4846)

Co-authored-by: Sebastián Ramírez <tiangolo@gmail.com>
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

2 participants