-
-
Notifications
You must be signed in to change notification settings - Fork 721
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
7 changed files
with
2,669 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -100,12 +100,11 @@ These all work as great opportunities to add more information to the JSON schema | |
Here's an example: | ||
|
||
```py | ||
from pydantic import BaseModel, EmailStr, Field, SecretStr | ||
from pydantic import BaseModel, Field, SecretStr | ||
|
||
|
||
class User(BaseModel): | ||
age: int = Field(description='Age of the user') | ||
email: EmailStr = Field(examples=['[email protected]']) | ||
name: str = Field(title='Username') | ||
password: SecretStr = Field( | ||
json_schema_extra={ | ||
|
@@ -121,12 +120,6 @@ print(User.model_json_schema()) | |
{ | ||
'properties': { | ||
'age': {'description': 'Age of the user', 'title': 'Age', 'type': 'integer'}, | ||
'email': { | ||
'examples': ['[email protected]'], | ||
'format': 'email', | ||
'title': 'Email', | ||
'type': 'string', | ||
}, | ||
'name': {'title': 'Username', 'type': 'string'}, | ||
'password': { | ||
'description': 'Password of the user', | ||
|
@@ -137,14 +130,14 @@ print(User.model_json_schema()) | |
'writeOnly': True, | ||
}, | ||
}, | ||
'required': ['age', 'email', 'name', 'password'], | ||
'required': ['age', 'name', 'password'], | ||
'title': 'User', | ||
'type': 'object', | ||
} | ||
""" | ||
``` | ||
|
||
## General notes on JSON schema generation | ||
# General notes on JSON schema generation | ||
|
||
- The JSON schema for Optional fields indicates that the value null is allowed. | ||
- The Decimal type is exposed in JSON schema (and serialized) as a string. | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.