Feature Request
Output of python -c "import pydantic.utils; print(pydantic.utils.version_info())":
pydantic version: 1.6.1
pydantic compiled: True
install path: /Users/j/.local/share/virtualenvs/asfd-asdf-2c-XNDzz/lib/python3.7/site-packages/pydantic
python version: 3.7.5 (default, Nov 1 2019, 02:16:32) [Clang 11.0.0 (clang-1100.0.33.8)]
platform: Darwin-18.7.0-x86_64-i386-64bit
optional deps. installed: []
Description
When generating JSON schemas out of Pydantic models, all outputs come persistently with a title keyword describing each property and each model. However, as per the JSON Schema documentation, the title keyword is not a required descriptor for a property, it's optional:
JSON Schema includes a few keywords, title, description, default, examples that aren’t strictly used for validation, but are used to describe parts of a schema.
None of these “annotation” keywords are required, but they are encouraged for good practice, and can make your schema “self-documenting”.
It should be the responsibility of the developer to include good titles for their models. Otherwise titles are not required, and a developer omitting a title may have reasons to do so. The fact that Pydantic picks up on the title keyword and generates a title version of the attribute or class name seems like an arbitrary behaviour.
Request
Would it be possible to change the implementation to make it optional to generate JSON Schemas with titles only if developer explicitly provides a title for the attribute?
The script:
test.py
from pydantic import BaseModel
class Item(BaseModel):
attribute: str
item = Item(attribute='attribute')
print(item.schema_json())
{
"title": "Item",
"type": "object",
"properties": {
"attribute": {
"title": "Attribute",
"type": "string"
}
},
"required": [
"attribute"
]
}
Feature Request
Output of
python -c "import pydantic.utils; print(pydantic.utils.version_info())":Description
When generating JSON schemas out of Pydantic models, all outputs come persistently with a title keyword describing each property and each model. However, as per the JSON Schema documentation, the
titlekeyword is not a required descriptor for a property, it's optional:It should be the responsibility of the developer to include good titles for their models. Otherwise
titlesare not required, and a developer omitting atitlemay have reasons to do so. The fact that Pydantic picks up on thetitlekeyword and generates a title version of the attribute or class name seems like an arbitrary behaviour.Request
Would it be possible to change the implementation to make it optional to generate JSON Schemas with titles only if developer explicitly provides a title for the attribute?
The script:
test.py