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
model_json_schema export with Annotated types misses 'required' parameters #8793
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -6,14 +6,7 @@ | |
from datetime import date, datetime, time, timedelta | ||
from decimal import Decimal | ||
from enum import Enum, IntEnum | ||
from ipaddress import ( | ||
IPv4Address, | ||
IPv4Interface, | ||
IPv4Network, | ||
IPv6Address, | ||
IPv6Interface, | ||
IPv6Network, | ||
) | ||
from ipaddress import IPv4Address, IPv4Interface, IPv4Network, IPv6Address, IPv6Interface, IPv6Network | ||
from pathlib import Path | ||
from typing import ( | ||
Any, | ||
|
@@ -75,15 +68,7 @@ | |
model_json_schema, | ||
models_json_schema, | ||
) | ||
from pydantic.networks import ( | ||
AnyUrl, | ||
EmailStr, | ||
IPvAnyAddress, | ||
IPvAnyInterface, | ||
IPvAnyNetwork, | ||
MultiHostUrl, | ||
NameEmail, | ||
) | ||
from pydantic.networks import AnyUrl, EmailStr, IPvAnyAddress, IPvAnyInterface, IPvAnyNetwork, MultiHostUrl, NameEmail | ||
from pydantic.type_adapter import TypeAdapter | ||
from pydantic.types import ( | ||
UUID1, | ||
|
@@ -5947,3 +5932,23 @@ class Model(BaseModel): | |
c: ModelC | ||
|
||
assert Model.model_json_schema() | ||
|
||
|
||
def test_json_schema_annotated_with_field() -> None: | ||
"""Check if the ellipsis in the signature is considered as a required field.""" | ||
|
||
from pydantic import create_model | ||
|
||
Model = create_model( | ||
'test_model', | ||
bar=(Annotated[int, Field(description='Bar description')], ...), | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Could you include this example as well? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Maybe with this model: Model = create_model(
'test_model',
foo=(int, ...),
bar=(Annotated[int, Field(description="Bar description")], ...),
baz=(Annotated[int, Field(..., description="Baz description")], ...),
) There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done 😄 |
||
) | ||
|
||
assert Model.model_json_schema() == { | ||
'properties': { | ||
'bar': {'description': 'Bar description', 'title': 'Bar', 'type': 'integer'}, | ||
}, | ||
'required': ['bar'], | ||
'title': 'test_model', | ||
'type': 'object', | ||
} |
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.