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

Skip to content

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

Merged
tiangolo merged 2 commits into
fastapi:masterfrom
ml-evs:patch-1
May 11, 2022
Merged

📝 Add OpenAPI warning to "Body - Fields" docs with extra schema extensions#4846
tiangolo merged 2 commits into
fastapi:masterfrom
ml-evs:patch-1

Conversation

@ml-evs

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

Copy link
Copy Markdown
Contributor

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

codecov Bot commented May 1, 2022

Copy link
Copy Markdown

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

github-actions Bot commented May 1, 2022

Copy link
Copy Markdown
Contributor

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

@github-actions

Copy link
Copy Markdown
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
Copy Markdown
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
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.

2 participants