🐛 Support custom OpenAPI / JSON Schema fields in the generated output OpenAPI#1429
Conversation
Pydantic supports adding custom fields other than `example` and `examples` using `BaseModel.Config.schema_extra`. This change ensures that those extra fields exist in the FastAPI generated Open API schema as well. This is in line with what the current docs say under the section `Other Info` in the docs page `Schema Extra - Example`.
Codecov Report
@@ Coverage Diff @@
## master #1429 +/- ##
=========================================
Coverage 100.00% 100.00%
=========================================
Files 248 249 +1
Lines 7717 7740 +23
=========================================
+ Hits 7717 7740 +23
Continue to review full report at Codecov.
|
|
📝 Docs preview for commit 3c20f23 at: https://60e098eaae1c69f28f225bd6--fastapi.netlify.app |
|
Good point, thanks @jmagnusson! Thanks for your contribution! ☕ And thanks for the patience 😅 |
|
Are custom fields supported by the OpenAPI spec? I saw breakages using OpenAPI generator's schema validation when custom fields started appearing in the generated schema starting in FastAPI 0.66.0, which includes this PR. A minimal reproducible example here: ormar-orm/ormar#291 |
Yes, see Specification Extensions here: https://swagger.io/specification/. All |
We ran into this when just using some pydantic |
Pydantic supports adding custom fields other than
exampleandexamplesusingBaseModel.Config.schema_extra. This change ensures that those extra fields exist in the FastAPI generated Open API schema as well.This is in line with what the current docs say:
(https://fastapi.tiangolo.com/tutorial/schema-extra-example/#other-info)