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
Merged

Conversation

tiangolo
Copy link
Member

@tiangolo tiangolo 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
Copy link

codecov bot 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

Copy link
Member

@samuelcolvin samuelcolvin left a 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.


class Config:
schema_extra = {
"examples": [
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

single quotes please :-)

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🤦‍♂️ sorry, done. ✔️

@samuelcolvin
Copy link
Member

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
Copy link
Member Author

tiangolo commented Aug 5, 2019

Thanks for your patience.

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

@samuelcolvin
Copy link
Member

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
Copy link
Member Author

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.

Copy link
Member

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.

@tiangolo
Copy link
Member Author

tiangolo commented Aug 5, 2019

Great, agreed.

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