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

Implement schema_extra #663

Merged
merged 6 commits into from Aug 6, 2019

Conversation

@tiangolo
Copy link
Collaborator

commented Jul 15, 2019

Change Summary

This adds an attribute schema_extra to the Config 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

  • Unit tests for the changes exist
  • Tests pass on CI and coverage remains at 100%
  • Documentation reflects the changes where applicable
  • HISTORY.rst has been updated
    • if this is the first change since a release, please add a new section
    • include the issue number or this pull request number #<number>
    • include your github username @<whomever>
@codecov

This comment has been minimized.

Copy link

commented Jul 15, 2019

Codecov Report

Merging #663 into master will not change coverage.
The diff coverage is 100%.

@@          Coverage Diff          @@
##           master   #663   +/-   ##
=====================================
  Coverage     100%   100%           
=====================================
  Files          15     15           
  Lines        2725   2727    +2     
  Branches      539    539           
=====================================
+ Hits         2725   2727    +2
@samuelcolvin
Copy link
Owner

left a comment

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.


class Config:
schema_extra = {
"examples": [

This comment has been minimized.

Copy link
@samuelcolvin

samuelcolvin Jul 15, 2019

Owner

single quotes please :-)

This comment has been minimized.

Copy link
@tiangolo

tiangolo Aug 5, 2019

Author Collaborator

🤦‍♂ sorry, done. ✔️

@samuelcolvin

This comment has been minimized.

Copy link
Owner

commented Aug 5, 2019

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.

@tiangolo tiangolo force-pushed the tiangolo:schema-extra branch from 1ada90b to 3cb52b9 Aug 5, 2019

@tiangolo

This comment has been minimized.

Copy link
Collaborator Author

commented Aug 5, 2019

Thanks for your patience.

Is it ok schema_extra for you? Or would you prefer schema_update or similar?

@samuelcolvin

This comment has been minimized.

Copy link
Owner

commented Aug 5, 2019

Is it ok schema_extra for you? Or would you prefer schema_update or similar?

I personally think this is fine, it's remotely possible in future that we might allow schema_extra to be a function which takes the schema and mutates it, but now this is fine.

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

This comment has been minimized.

Copy link
@tiangolo

tiangolo Aug 5, 2019

Author Collaborator

Oh! Sorry, didn't notice I put it in the wrong place.

This comment has been minimized.

Copy link
@samuelcolvin

samuelcolvin Aug 5, 2019

Owner

no problem, we need #665.

@tiangolo

This comment has been minimized.

Copy link
Collaborator Author

commented Aug 5, 2019

Great, agreed.

@samuelcolvin samuelcolvin merged commit 6316a6a into samuelcolvin:master Aug 6, 2019

7 of 10 checks passed

Header rules No header rules processed
Details
Pages changed 1 new file uploaded
Details
Redirect rules No redirect rules processed
Details
Mixed content No mixed content detected
Details
codecov/project 100% (+0%) compared to 6be7c21
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
deploy/netlify Deploy preview ready!
Details
samuelcolvin.pydantic Build #20190805.11 succeeded
Details
samuelcolvin.pydantic (Job Python36) Job Python36 succeeded
Details
samuelcolvin.pydantic (Job Python37) Job Python37 succeeded
Details

@tiangolo tiangolo deleted the tiangolo:schema-extra branch Aug 7, 2019

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.