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
Implement schema_extra #663
Conversation
Codecov Report
@@ Coverage Diff @@
## master #663 +/- ##
=====================================
Coverage 100% 100%
=====================================
Files 15 15
Lines 2725 2727 +2
Branches 539 539
=====================================
+ Hits 2725 2727 +2 |
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.
In general looks good.
Let's leave this open for a few days to allow all the people creating those issues to comment (although I assume they won't until it's released 😞).
Will need to be rebased.
docs/examples/schema4.py
Outdated
|
||
class Config: | ||
schema_extra = { | ||
"examples": [ |
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.
single quotes please :-)
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.
🤦♂️ sorry, done. ✔️
any chance we could get this fixed? I would like to get everything currently pending on the next release so I can work exclusively on v1. |
Thanks for your patience. Is it ok |
I personally think this is fine, it's remotely possible in future that we might allow |
v0.32 (unreleased) | ||
.................. | ||
* add model name to ``ValidationError`` error message, #676 by @dmontagu | ||
* **breaking change**: remove ``__getattr__`` and rename ``__values__`` to ``__dict__`` on ``BaseModel``, | ||
deprecation warning on use ``__values__`` attr, attributes access speed increased up to 14 times, #712 by @MrMrRobat | ||
* support ``ForwardRef`` (without self-referencing annotations) in Python3.6, #706 by @koxudaxi | ||
* implement ``schema_extra`` in ``Config`` sub-class, #663 by @tiangolo |
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.
Oh! Sorry, didn't notice I put it in the wrong place.
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.
no problem, we need #665.
Great, agreed. |
Change Summary
This adds an attribute
schema_extra
to theConfig
sub-class, allowing to extend/update the generated JSON Schema.For example, to include
examples
, or to override the default JSON Schema generated for some field.This doesn't change validation/parsing, it's purely for extending/documenting models with JSON Schema.
Related issue number
#627, #529, #478, #619, #637, tiangolo/fastapi#363
Checklist
HISTORY.rst
has been updated#<number>
@<whomever>