diff --git a/python/pydantic_core/core_schema.py b/python/pydantic_core/core_schema.py index 922900170..66df8ff0a 100644 --- a/python/pydantic_core/core_schema.py +++ b/python/pydantic_core/core_schema.py @@ -435,16 +435,141 @@ def model_ser_schema(cls: Type[Any], schema: CoreSchema) -> ModelSerSchema: ] +class PydanticMetadata(TypedDict, total=False): + """ + Assorted metadata for core schema, primarily related to JSON schema generation. + + We considered having a base PydanticMetadata class and subclassing for specific core schemas with additional configuration, + like ArgumentsSchema with json_prefer_positional_arguments, for example. However, this makes type checking more difficult, + as we often use `CoreSchema` as a generic type, and thus it's helpful then to have a single `PydanticMetadata` type. + This is similar to how we have one `CoreConfig` structure for all core schemas, despite the irrelevant settings for some schemas. + + Attributes: + json_schema_transforms: List of functions to transform the JSON schema. + Each function accepts as parameters a json schema and json schema handler. The function returns a json schema. + json_title: The title for the JSON schema. + json_description: The description for the JSON schema. + json_deprecated: Whether the corresponding type should be marked as deprecated in the JSON schema. + json_examples: List of examples to attach to the type in the JSON schema. + json_dict_extra: Extra information to update the JSON schema dict with (from `config.json_schema_extra`). + json_callable_extra: Extra information with which to update the JSON schema via a callable (from `config.json_schema_extra`). + json_prefer_positional_arguments: If `True`, the JSON schema generator will prefer positional over keyword arguments. Defaults to `False`. + json_pydantic_input_core_schema: The core schema associated with the input type for a functional validator, + used to generate the JSON schema in `'validation'` mode. + tagged_union_tag: The tag associated with a member in a tagged union schema. Sometimes stored on a member of a + union schema prior to conversion to a tagged union schema. + tagged_union_discriminator: The discriminator associated with a member in a tagged union schema. + """ + + # whereas we used to support most JSON schema modification with these callables, we now leave this residual + # support for __get_pydantic_json_schema__ + # TODO: could we transform this just into GetJsonSchemaFunction rather than list[GetJsonSchemaFunction] + json_schema_transforms: list[GetJsonSchemaFunction] + + json_title: str + json_description: str + json_deprecated: bool + json_examples: list[Any] + json_dict_extra: dict[str, Any] + json_callable_extra: JsonSchemaExtraCallable + + json_prefer_positional_arguments: bool + json_input_core_schema: CoreSchema + + # TODO: can we remove these from metadata? They don't relate to JSON schema generation, so ideally they wouldn't be here + # Unfortunately, so many types can be involved in union -> tagged union coercion that it's hard to avoid, for now + tagged_union_tag: str + tagged_union_discriminator: str + + +def pydantic_metadata( + json_schema_transforms: list[GetJsonSchemaFunction] | None = None, + json_title: str | None = None, + json_description: str | None = None, + json_deprecated: bool | None = None, + json_examples: list[Any] | None = None, + json_dict_extra: dict[str, Any] | None = None, + json_callable_extra: JsonSchemaExtraCallable | None = None, + json_prefer_positional_arguments: bool | None = None, + json_input_core_schema: CoreSchema | None = None, + tagged_union_tag: str | None = None, + tagged_union_discriminator: str | None = None, +) -> None: + """ + Returns a PydanticMetadata object, used to store assorted metadata for core schema. + + Args: + json_schema_transforms: List of functions to transform the JSON schema. + Each function accepts as parameters a json schema and json schema handler. The function returns a json schema. + json_title: The title for the JSON schema. + json_description: The description for the JSON schema. + json_deprecated: Whether the corresponding type should be marked as deprecated in the JSON schema. + json_examples: List of examples to attach to the type in the JSON schema. + json_dict_extra: Extra information to update the JSON schema dict with (from `config.json_schema_extra`). + json_callable_extra: Extra information with which to update the JSON schema via a callable (from `config.json_schema_extra`). + json_prefer_positional_arguments: If `True`, the JSON schema generator will prefer positional over keyword arguments. Defaults to `False`. + json_input_core_schema: The core schema associated with the input type for a functional validator, + used to generate the JSON schema in `'validation'` mode. + tagged_union_tag: The tag associated with a member in a tagged union schema. Sometimes stored on a member of a + union schema prior to conversion to a tagged union schema. + tagged_union_discriminator: The discriminator associated with a member in a tagged union schema. + """ + return _dict_not_none( + json_schema_transforms=json_schema_transforms, + json_title=json_title, + json_description=json_description, + json_deprecated=json_deprecated, + json_examples=json_examples, + json_dict_extra=json_dict_extra, + json_callable_extra=json_callable_extra, + json_prefer_positional_arguments=json_prefer_positional_arguments, + json_input_core_schema=json_input_core_schema, + tagged_union_tag=tagged_union_tag, + tagged_union_discriminator=tagged_union_discriminator, + ) + + +# TODO: can we leverage this concept to get rid of the Mock*Schema concepts in pydantic? +class InvalidSchema(TypedDict, total=False): + type: Required[Literal['invalid']] + ref: str + pydantic_metadata: PydanticMetadata + metadata: Dict[str, Any] + + +def invalid_schema( + ref: str | None = None, pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None +) -> InvalidSchema: + """ + Returns an invalid schema, used to indicate that a schema is invalid. + + Returns a schema that matches any value, e.g.: + + Args: + ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use + metadata: Any other information you want to include with the schema, not used by pydantic-core + """ + + return _dict_not_none(type='invalid', ref=ref, pydantic_metadta=pydantic_metadata, metadata=metadata) + + class ComputedField(TypedDict, total=False): type: Required[Literal['computed-field']] property_name: Required[str] return_schema: Required[CoreSchema] alias: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] def computed_field( - property_name: str, return_schema: CoreSchema, *, alias: str | None = None, metadata: Dict[str, Any] | None = None + property_name: str, + return_schema: CoreSchema, + *, + alias: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, + metadata: Dict[str, Any] | None = None, ) -> ComputedField: """ ComputedFields are properties of a model or dataclass that are included in serialization. @@ -453,22 +578,33 @@ def computed_field( property_name: The name of the property on the model or dataclass return_schema: The schema used for the type returned by the computed field alias: The name to use in the serialized output + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core """ return _dict_not_none( - type='computed-field', property_name=property_name, return_schema=return_schema, alias=alias, metadata=metadata + type='computed-field', + property_name=property_name, + return_schema=return_schema, + alias=alias, + pydantic_metadata=pydantic_metadata, + metadata=metadata, ) class AnySchema(TypedDict, total=False): type: Required[Literal['any']] ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema def any_schema( - *, ref: str | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None + *, + ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, + metadata: Dict[str, Any] | None = None, + serialization: SerSchema | None = None, ) -> AnySchema: """ Returns a schema that matches any value, e.g.: @@ -483,21 +619,29 @@ def any_schema( Args: ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ - return _dict_not_none(type='any', ref=ref, metadata=metadata, serialization=serialization) + return _dict_not_none( + type='any', ref=ref, pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization + ) class NoneSchema(TypedDict, total=False): type: Required[Literal['none']] ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema def none_schema( - *, ref: str | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None + *, + ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, + metadata: Dict[str, Any] | None = None, + serialization: SerSchema | None = None, ) -> NoneSchema: """ Returns a schema that matches a None value, e.g.: @@ -512,16 +656,20 @@ def none_schema( Args: ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ - return _dict_not_none(type='none', ref=ref, metadata=metadata, serialization=serialization) + return _dict_not_none( + type='none', ref=ref, pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization + ) class BoolSchema(TypedDict, total=False): type: Required[Literal['bool']] strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -529,6 +677,7 @@ class BoolSchema(TypedDict, total=False): def bool_schema( strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> BoolSchema: @@ -546,10 +695,18 @@ def bool_schema( Args: strict: Whether the value should be a bool or a value that can be converted to a bool ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ - return _dict_not_none(type='bool', strict=strict, ref=ref, metadata=metadata, serialization=serialization) + return _dict_not_none( + type='bool', + strict=strict, + ref=ref, + pydantic_metadata=pydantic_metadata, + metadata=metadata, + serialization=serialization, + ) class IntSchema(TypedDict, total=False): @@ -561,6 +718,7 @@ class IntSchema(TypedDict, total=False): gt: int strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -574,6 +732,7 @@ def int_schema( gt: int | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> IntSchema: @@ -596,6 +755,7 @@ def int_schema( gt: The value must be strictly greater than this number strict: Whether the value should be a int or a value that can be converted to a int ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -608,6 +768,7 @@ def int_schema( gt=gt, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -623,6 +784,7 @@ class FloatSchema(TypedDict, total=False): gt: float strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -637,6 +799,7 @@ def float_schema( gt: float | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> FloatSchema: @@ -660,6 +823,7 @@ def float_schema( gt: The value must be strictly greater than this number strict: Whether the value should be a float or a value that can be converted to a float ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -673,6 +837,7 @@ def float_schema( gt=gt, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -690,6 +855,7 @@ class DecimalSchema(TypedDict, total=False): decimal_places: int strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -706,6 +872,7 @@ def decimal_schema( decimal_places: int | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> DecimalSchema: @@ -732,6 +899,7 @@ def decimal_schema( decimal_places: The maximum number of decimal places allowed strict: Whether the value should be a float or a value that can be converted to a float ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -747,6 +915,7 @@ def decimal_schema( allow_inf_nan=allow_inf_nan, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -756,6 +925,7 @@ class ComplexSchema(TypedDict, total=False): type: Required[Literal['complex']] strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -764,6 +934,7 @@ def complex_schema( *, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> ComplexSchema: @@ -782,6 +953,7 @@ def complex_schema( Args: strict: Whether the value should be a complex object instance or a value that can be converted to a complex object ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -789,6 +961,7 @@ def complex_schema( type='complex', strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -806,6 +979,7 @@ class StringSchema(TypedDict, total=False): strict: bool coerce_numbers_to_str: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -822,6 +996,7 @@ def str_schema( strict: bool | None = None, coerce_numbers_to_str: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> StringSchema: @@ -852,6 +1027,7 @@ def str_schema( strict: Whether the value should be a string or a value that can be converted to a string coerce_numbers_to_str: Whether to enable coercion of any `Number` type to `str` (not applicable in `strict` mode). ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -867,6 +1043,7 @@ def str_schema( strict=strict, coerce_numbers_to_str=coerce_numbers_to_str, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -878,6 +1055,7 @@ class BytesSchema(TypedDict, total=False): min_length: int strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -888,6 +1066,7 @@ def bytes_schema( min_length: int | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> BytesSchema: @@ -907,6 +1086,7 @@ def bytes_schema( min_length: The value must be at least this length strict: Whether the value should be a bytes or a value that can be converted to a bytes ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -916,6 +1096,7 @@ def bytes_schema( min_length=min_length, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -933,6 +1114,7 @@ class DateSchema(TypedDict, total=False): # value is restricted to -86_400 < offset < 86_400 by bounds in generate_self_schema.py now_utc_offset: int ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -947,6 +1129,7 @@ def date_schema( now_op: Literal['past', 'future'] | None = None, now_utc_offset: int | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> DateSchema: @@ -971,6 +1154,7 @@ def date_schema( now_op: The value must be in the past or future relative to the current date now_utc_offset: The value must be in the past or future relative to the current date with this utc offset ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -984,6 +1168,7 @@ def date_schema( now_op=now_op, now_utc_offset=now_utc_offset, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -999,6 +1184,7 @@ class TimeSchema(TypedDict, total=False): tz_constraint: Union[Literal['aware', 'naive'], int] microseconds_precision: Literal['truncate', 'error'] ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -1013,6 +1199,7 @@ def time_schema( tz_constraint: Literal['aware', 'naive'] | int | None = None, microseconds_precision: Literal['truncate', 'error'] = 'truncate', ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> TimeSchema: @@ -1037,6 +1224,7 @@ def time_schema( tz_constraint: The value must be timezone aware or naive, or an int to indicate required tz offset microseconds_precision: The behavior when seconds have more than 6 digits or microseconds is too large ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -1050,6 +1238,7 @@ def time_schema( tz_constraint=tz_constraint, microseconds_precision=microseconds_precision, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -1069,6 +1258,7 @@ class DatetimeSchema(TypedDict, total=False): now_utc_offset: int microseconds_precision: Literal['truncate', 'error'] # default: 'truncate' ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -1085,6 +1275,7 @@ def datetime_schema( now_utc_offset: int | None = None, microseconds_precision: Literal['truncate', 'error'] = 'truncate', ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> DatetimeSchema: @@ -1113,6 +1304,7 @@ def datetime_schema( now_utc_offset: The value must be in the past or future relative to the current datetime with this utc offset microseconds_precision: The behavior when seconds have more than 6 digits or microseconds is too large ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -1128,6 +1320,7 @@ def datetime_schema( now_utc_offset=now_utc_offset, microseconds_precision=microseconds_precision, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -1142,6 +1335,7 @@ class TimedeltaSchema(TypedDict, total=False): gt: timedelta microseconds_precision: Literal['truncate', 'error'] ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -1155,6 +1349,7 @@ def timedelta_schema( gt: timedelta | None = None, microseconds_precision: Literal['truncate', 'error'] = 'truncate', ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> TimedeltaSchema: @@ -1178,6 +1373,7 @@ def timedelta_schema( gt: The value must be strictly greater than this timedelta microseconds_precision: The behavior when seconds have more than 6 digits or microseconds is too large ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -1190,6 +1386,7 @@ def timedelta_schema( gt=gt, microseconds_precision=microseconds_precision, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -1199,6 +1396,7 @@ class LiteralSchema(TypedDict, total=False): type: Required[Literal['literal']] expected: Required[List[Any]] ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -1207,6 +1405,7 @@ def literal_schema( expected: list[Any], *, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> LiteralSchema: @@ -1224,10 +1423,18 @@ def literal_schema( Args: expected: The value must be one of these values ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ - return _dict_not_none(type='literal', expected=expected, ref=ref, metadata=metadata, serialization=serialization) + return _dict_not_none( + type='literal', + expected=expected, + ref=ref, + pydantic_metadata=pydantic_metadata, + metadata=metadata, + serialization=serialization, + ) class EnumSchema(TypedDict, total=False): @@ -1238,6 +1445,7 @@ class EnumSchema(TypedDict, total=False): missing: Callable[[Any], Any] strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -1250,6 +1458,7 @@ def enum_schema( missing: Callable[[Any], Any] | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> EnumSchema: @@ -1277,6 +1486,7 @@ class Color(Enum): missing: A function to use when the value is not found in the enum, from `_missing_` strict: Whether to use strict mode, defaults to False ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -1288,6 +1498,7 @@ class Color(Enum): missing=missing, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -1302,6 +1513,7 @@ class IsInstanceSchema(TypedDict, total=False): cls: Required[Any] cls_repr: str ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -1311,6 +1523,7 @@ def is_instance_schema( *, cls_repr: str | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> IsInstanceSchema: @@ -1332,11 +1545,18 @@ class A: cls: The value must be an instance of this class cls_repr: If provided this string is used in the validator name instead of `repr(cls)` ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ return _dict_not_none( - type='is-instance', cls=cls, cls_repr=cls_repr, ref=ref, metadata=metadata, serialization=serialization + type='is-instance', + cls=cls, + cls_repr=cls_repr, + ref=ref, + pydantic_metadata=pydantic_metadata, + metadata=metadata, + serialization=serialization, ) @@ -1345,6 +1565,7 @@ class IsSubclassSchema(TypedDict, total=False): cls: Required[Type[Any]] cls_repr: str ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -1354,6 +1575,7 @@ def is_subclass_schema( *, cls_repr: str | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> IsInstanceSchema: @@ -1378,23 +1600,35 @@ class B(A): cls: The value must be a subclass of this class cls_repr: If provided this string is used in the validator name instead of `repr(cls)` ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ return _dict_not_none( - type='is-subclass', cls=cls, cls_repr=cls_repr, ref=ref, metadata=metadata, serialization=serialization + type='is-subclass', + cls=cls, + cls_repr=cls_repr, + ref=ref, + pydantic_metadata=pydantic_metadata, + metadata=metadata, + serialization=serialization, ) class CallableSchema(TypedDict, total=False): type: Required[Literal['callable']] ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema def callable_schema( - *, ref: str | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None + *, + ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, + metadata: Dict[str, Any] | None = None, + serialization: SerSchema | None = None, ) -> CallableSchema: """ Returns a schema that checks if a value is callable, equivalent to python's `callable` method, e.g.: @@ -1409,10 +1643,13 @@ def callable_schema( Args: ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ - return _dict_not_none(type='callable', ref=ref, metadata=metadata, serialization=serialization) + return _dict_not_none( + type='callable', ref=ref, pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization + ) class UuidSchema(TypedDict, total=False): @@ -1420,6 +1657,7 @@ class UuidSchema(TypedDict, total=False): version: Literal[1, 3, 4, 5] strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -1429,11 +1667,18 @@ def uuid_schema( version: Literal[1, 3, 4, 5] | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> UuidSchema: return _dict_not_none( - type='uuid', version=version, strict=strict, ref=ref, metadata=metadata, serialization=serialization + type='uuid', + version=version, + strict=strict, + ref=ref, + pydantic_metadata=pydantic_metadata, + metadata=metadata, + serialization=serialization, ) @@ -1458,6 +1703,7 @@ class ListSchema(TypedDict, total=False): fail_fast: bool strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: IncExSeqOrElseSerSchema @@ -1470,6 +1716,7 @@ def list_schema( fail_fast: bool | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: IncExSeqOrElseSerSchema | None = None, ) -> ListSchema: @@ -1491,6 +1738,7 @@ def list_schema( fail_fast: Stop validation on the first error strict: The value must be a list with exactly this many items ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -1502,6 +1750,7 @@ def list_schema( fail_fast=fail_fast, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -1514,6 +1763,7 @@ def tuple_positional_schema( extras_schema: CoreSchema | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: IncExSeqOrElseSerSchema | None = None, ) -> TupleSchema: @@ -1538,6 +1788,7 @@ def tuple_positional_schema( if the length is variable. So this field won't be set from a `typing.Tuple` annotation on a pydantic model. strict: The value must be a tuple with exactly this many items ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -1551,6 +1802,7 @@ def tuple_positional_schema( variadic_item_index=variadic_item_index, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -1564,6 +1816,7 @@ def tuple_variable_schema( max_length: int | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: IncExSeqOrElseSerSchema | None = None, ) -> TupleSchema: @@ -1586,6 +1839,7 @@ def tuple_variable_schema( max_length: The value must be a tuple with at most this many items strict: The value must be a tuple with exactly this many items ref: Optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -1596,6 +1850,7 @@ def tuple_variable_schema( max_length=max_length, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -1610,6 +1865,7 @@ class TupleSchema(TypedDict, total=False): fail_fast: bool strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: IncExSeqOrElseSerSchema @@ -1623,6 +1879,7 @@ def tuple_schema( fail_fast: bool | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: IncExSeqOrElseSerSchema | None = None, ) -> TupleSchema: @@ -1648,6 +1905,7 @@ def tuple_schema( fail_fast: Stop validation on the first error strict: The value must be a tuple with exactly this many items ref: Optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -1660,6 +1918,7 @@ def tuple_schema( fail_fast=fail_fast, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -1673,6 +1932,7 @@ class SetSchema(TypedDict, total=False): fail_fast: bool strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -1685,6 +1945,7 @@ def set_schema( fail_fast: bool | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> SetSchema: @@ -1708,6 +1969,7 @@ def set_schema( fail_fast: Stop validation on the first error strict: The value must be a set with exactly this many items ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -1719,6 +1981,7 @@ def set_schema( fail_fast=fail_fast, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -1732,6 +1995,7 @@ class FrozenSetSchema(TypedDict, total=False): fail_fast: bool strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -1744,6 +2008,7 @@ def frozenset_schema( fail_fast: bool | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> FrozenSetSchema: @@ -1767,6 +2032,7 @@ def frozenset_schema( fail_fast: Stop validation on the first error strict: The value must be a frozenset with exactly this many items ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -1778,6 +2044,7 @@ def frozenset_schema( fail_fast=fail_fast, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -1789,6 +2056,7 @@ class GeneratorSchema(TypedDict, total=False): min_length: int max_length: int ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: IncExSeqOrElseSerSchema @@ -1799,6 +2067,7 @@ def generator_schema( min_length: int | None = None, max_length: int | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: IncExSeqOrElseSerSchema | None = None, ) -> GeneratorSchema: @@ -1826,6 +2095,7 @@ def gen() -> Iterator[int]: min_length: The value must be a generator that yields at least this many items max_length: The value must be a generator that yields at most this many items ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -1835,6 +2105,7 @@ def gen() -> Iterator[int]: min_length=min_length, max_length=max_length, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -1864,6 +2135,7 @@ class DictSchema(TypedDict, total=False): max_length: int strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: IncExDictOrElseSerSchema @@ -1876,6 +2148,7 @@ def dict_schema( max_length: int | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> DictSchema: @@ -1899,6 +2172,7 @@ def dict_schema( max_length: The value must be a dict with at most this many items strict: Whether the keys and values should be validated with strict mode ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -1910,6 +2184,7 @@ def dict_schema( max_length=max_length, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -1941,6 +2216,7 @@ class _ValidatorFunctionSchema(TypedDict, total=False): function: Required[ValidationFunction] schema: Required[CoreSchema] ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -1954,6 +2230,7 @@ def no_info_before_validator_function( schema: CoreSchema, *, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> BeforeValidatorFunctionSchema: @@ -1979,6 +2256,7 @@ def fn(v: bytes) -> str: function: The validator function to call schema: The schema to validate the output of the validator function ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -1987,6 +2265,7 @@ def fn(v: bytes) -> str: function={'type': 'no-info', 'function': function}, schema=schema, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -1998,6 +2277,7 @@ def with_info_before_validator_function( *, field_name: str | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> BeforeValidatorFunctionSchema: @@ -2027,6 +2307,7 @@ def fn(v: bytes, info: core_schema.ValidationInfo) -> str: field_name: The name of the field schema: The schema to validate the output of the validator function ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -2035,6 +2316,7 @@ def fn(v: bytes, info: core_schema.ValidationInfo) -> str: function=_dict_not_none(type='with-info', function=function, field_name=field_name), schema=schema, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -2049,6 +2331,7 @@ def no_info_after_validator_function( schema: CoreSchema, *, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> AfterValidatorFunctionSchema: @@ -2072,6 +2355,7 @@ def fn(v: str) -> str: function: The validator function to call after the schema is validated schema: The schema to validate before the validator function ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -2080,6 +2364,7 @@ def fn(v: str) -> str: function={'type': 'no-info', 'function': function}, schema=schema, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -2091,6 +2376,7 @@ def with_info_after_validator_function( *, field_name: str | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> AfterValidatorFunctionSchema: @@ -2120,6 +2406,7 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str: schema: The schema to validate before the validator function field_name: The name of the field this validators is applied to, if any ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -2128,6 +2415,7 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str: function=_dict_not_none(type='with-info', function=function, field_name=field_name), schema=schema, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -2165,6 +2453,7 @@ class WrapValidatorFunctionSchema(TypedDict, total=False): function: Required[WrapValidatorFunction] schema: Required[CoreSchema] ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -2174,6 +2463,7 @@ def no_info_wrap_validator_function( schema: CoreSchema, *, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> WrapValidatorFunctionSchema: @@ -2202,6 +2492,7 @@ def fn( function: The validator function to call schema: The schema to validate the output of the validator function ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -2210,6 +2501,7 @@ def fn( function={'type': 'no-info', 'function': function}, schema=schema, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -2221,6 +2513,7 @@ def with_info_wrap_validator_function( *, field_name: str | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> WrapValidatorFunctionSchema: @@ -2251,6 +2544,7 @@ def fn( schema: The schema to validate the output of the validator function field_name: The name of the field this validators is applied to, if any ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -2259,6 +2553,7 @@ def fn( function=_dict_not_none(type='with-info', function=function, field_name=field_name), schema=schema, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -2268,6 +2563,7 @@ class PlainValidatorFunctionSchema(TypedDict, total=False): type: Required[Literal['function-plain']] function: Required[ValidationFunction] ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -2276,6 +2572,7 @@ def no_info_plain_validator_function( function: NoInfoValidatorFunction, *, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> PlainValidatorFunctionSchema: @@ -2297,6 +2594,7 @@ def fn(v: str) -> str: Args: function: The validator function to call ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -2304,6 +2602,7 @@ def fn(v: str) -> str: type='function-plain', function={'type': 'no-info', 'function': function}, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -2314,6 +2613,7 @@ def with_info_plain_validator_function( *, field_name: str | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> PlainValidatorFunctionSchema: @@ -2336,6 +2636,7 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str: function: The validator function to call field_name: The name of the field this validators is applied to, if any ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -2343,6 +2644,7 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str: type='function-plain', function=_dict_not_none(type='with-info', function=function, field_name=field_name), ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -2357,6 +2659,7 @@ class WithDefaultSchema(TypedDict, total=False): validate_default: bool # default: False strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -2370,6 +2673,7 @@ def with_default_schema( validate_default: bool | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> WithDefaultSchema: @@ -2395,6 +2699,7 @@ def with_default_schema( validate_default: Whether the default value should be validated strict: Whether the underlying schema should be validated with strict mode ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -2406,6 +2711,7 @@ def with_default_schema( validate_default=validate_default, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -2419,6 +2725,7 @@ class NullableSchema(TypedDict, total=False): schema: Required[CoreSchema] strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -2428,6 +2735,7 @@ def nullable_schema( *, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> NullableSchema: @@ -2446,11 +2754,18 @@ def nullable_schema( schema: The schema to wrap strict: Whether the underlying schema should be validated with strict mode ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ return _dict_not_none( - type='nullable', schema=schema, strict=strict, ref=ref, metadata=metadata, serialization=serialization + type='nullable', + schema=schema, + strict=strict, + ref=ref, + pydantic_metadata=pydantic_metadata, + metadata=metadata, + serialization=serialization, ) @@ -2458,6 +2773,7 @@ class UnionSchema(TypedDict, total=False): type: Required[Literal['union']] choices: Required[List[Union[CoreSchema, Tuple[CoreSchema, str]]]] # default true, whether to automatically collapse unions with one element to the inner validator + tagged_union_tag: str auto_collapse: bool custom_error_type: str custom_error_message: str @@ -2465,6 +2781,7 @@ class UnionSchema(TypedDict, total=False): mode: Literal['smart', 'left_to_right'] # default: 'smart' strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -2479,6 +2796,7 @@ def union_schema( mode: Literal['smart', 'left_to_right'] | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> UnionSchema: @@ -2505,6 +2823,7 @@ def union_schema( * `left_to_right` will return the first choice in `choices` which succeeds validation strict: Whether the underlying schemas should be validated with strict mode ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -2518,6 +2837,7 @@ def union_schema( mode=mode, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -2533,6 +2853,7 @@ class TaggedUnionSchema(TypedDict, total=False): strict: bool from_attributes: bool # default: True ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -2547,6 +2868,7 @@ def tagged_union_schema( strict: bool | None = None, from_attributes: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> TaggedUnionSchema: @@ -2602,6 +2924,7 @@ def tagged_union_schema( strict: Whether the underlying schemas should be validated with strict mode from_attributes: Whether to use the attributes of the object to retrieve the discriminator value ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -2615,6 +2938,7 @@ def tagged_union_schema( strict=strict, from_attributes=from_attributes, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -2624,6 +2948,7 @@ class ChainSchema(TypedDict, total=False): type: Required[Literal['chain']] steps: Required[List[CoreSchema]] ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -2632,6 +2957,7 @@ def chain_schema( steps: list[CoreSchema], *, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> ChainSchema: @@ -2656,10 +2982,18 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str: Args: steps: The schemas to chain ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ - return _dict_not_none(type='chain', steps=steps, ref=ref, metadata=metadata, serialization=serialization) + return _dict_not_none( + type='chain', + steps=steps, + ref=ref, + pydantic_metadata=pydantic_metadata, + metadata=metadata, + serialization=serialization, + ) class LaxOrStrictSchema(TypedDict, total=False): @@ -2668,6 +3002,7 @@ class LaxOrStrictSchema(TypedDict, total=False): strict_schema: Required[CoreSchema] strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -2678,6 +3013,7 @@ def lax_or_strict_schema( *, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> LaxOrStrictSchema: @@ -2712,6 +3048,7 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str: strict_schema: The strict schema to use strict: Whether the strict schema should be used ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -2721,6 +3058,7 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str: strict_schema=strict_schema, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -2731,6 +3069,7 @@ class JsonOrPythonSchema(TypedDict, total=False): json_schema: Required[CoreSchema] python_schema: Required[CoreSchema] ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -2740,6 +3079,7 @@ def json_or_python_schema( python_schema: CoreSchema, *, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> JsonOrPythonSchema: @@ -2770,6 +3110,7 @@ def json_or_python_schema( json_schema: The schema to use for Json inputs python_schema: The schema to use for Python inputs ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -2778,6 +3119,7 @@ def json_or_python_schema( json_schema=json_schema, python_schema=python_schema, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -2800,6 +3142,7 @@ def typed_dict_field( validation_alias: str | list[str | int] | list[list[str | int]] | None = None, serialization_alias: str | None = None, serialization_exclude: bool | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, ) -> TypedDictField: """ @@ -2817,6 +3160,7 @@ def typed_dict_field( validation_alias: The alias(es) to use to find the field in the validation data serialization_alias: The alias to use as a key when serializing serialization_exclude: Whether to exclude the field when serializing + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core """ return _dict_not_none( @@ -2826,6 +3170,7 @@ def typed_dict_field( validation_alias=validation_alias, serialization_alias=serialization_alias, serialization_exclude=serialization_exclude, + pydantic_metadata=pydantic_metadata, metadata=metadata, ) @@ -2842,6 +3187,7 @@ class TypedDictSchema(TypedDict, total=False): total: bool # default: True populate_by_name: bool # replaces `allow_population_by_field_name` in pydantic v1 ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema config: CoreConfig @@ -2858,6 +3204,7 @@ def typed_dict_schema( total: bool | None = None, populate_by_name: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, config: CoreConfig | None = None, @@ -2887,6 +3234,7 @@ class MyTypedDict(TypedDict): strict: Whether the typed dict is strict extras_schema: The extra validator to use for the typed dict ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core extra_behavior: The extra behavior to use for the typed dict total: Whether the typed dict is total @@ -2904,6 +3252,7 @@ class MyTypedDict(TypedDict): total=total, populate_by_name=populate_by_name, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, config=config, @@ -2927,6 +3276,7 @@ def model_field( serialization_alias: str | None = None, serialization_exclude: bool | None = None, frozen: bool | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, ) -> ModelField: """ @@ -2944,6 +3294,7 @@ def model_field( serialization_alias: The alias to use as a key when serializing serialization_exclude: Whether to exclude the field when serializing frozen: Whether the field is frozen + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core """ return _dict_not_none( @@ -2953,6 +3304,7 @@ def model_field( serialization_alias=serialization_alias, serialization_exclude=serialization_exclude, frozen=frozen, + pydantic_metadata=pydantic_metadata, metadata=metadata, ) @@ -2969,6 +3321,7 @@ class ModelFieldsSchema(TypedDict, total=False): populate_by_name: bool # replaces `allow_population_by_field_name` in pydantic v1 from_attributes: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -2984,6 +3337,7 @@ def model_fields_schema( populate_by_name: bool | None = None, from_attributes: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> ModelFieldsSchema: @@ -3008,6 +3362,7 @@ def model_fields_schema( strict: Whether the typed dict is strict extras_schema: The extra validator to use for the typed dict ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core extra_behavior: The extra behavior to use for the typed dict populate_by_name: Whether the typed dict should populate by name @@ -3025,6 +3380,7 @@ def model_fields_schema( populate_by_name=populate_by_name, from_attributes=from_attributes, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -3043,6 +3399,7 @@ class ModelSchema(TypedDict, total=False): extra_behavior: ExtraBehavior config: CoreConfig ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -3060,6 +3417,7 @@ def model_schema( extra_behavior: ExtraBehavior | None = None, config: CoreConfig | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> ModelSchema: @@ -3107,6 +3465,7 @@ class MyModel: extra_behavior: The extra behavior to use for the model, used in serialization config: The config to use for the model ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -3123,6 +3482,7 @@ class MyModel: extra_behavior=extra_behavior, config=config, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -3152,6 +3512,7 @@ def dataclass_field( validation_alias: str | list[str | int] | list[list[str | int]] | None = None, serialization_alias: str | None = None, serialization_exclude: bool | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, frozen: bool | None = None, ) -> DataclassField: @@ -3178,6 +3539,7 @@ def dataclass_field( validation_alias: The alias(es) to use to find the field in the validation data serialization_alias: The alias to use as a key when serializing serialization_exclude: Whether to exclude the field when serializing + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core frozen: Whether the field is frozen """ @@ -3191,6 +3553,7 @@ def dataclass_field( validation_alias=validation_alias, serialization_alias=serialization_alias, serialization_exclude=serialization_exclude, + pydantic_metadata=pydantic_metadata, metadata=metadata, frozen=frozen, ) @@ -3204,6 +3567,7 @@ class DataclassArgsSchema(TypedDict, total=False): populate_by_name: bool # default: False collect_init_only: bool # default: False ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema extra_behavior: ExtraBehavior @@ -3217,6 +3581,7 @@ def dataclass_args_schema( populate_by_name: bool | None = None, collect_init_only: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, extra_behavior: ExtraBehavior | None = None, @@ -3245,6 +3610,7 @@ def dataclass_args_schema( populate_by_name: Whether to populate by name collect_init_only: Whether to collect init only fields into a dict to pass to `__post_init__` ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema extra_behavior: How to handle extra fields @@ -3257,6 +3623,7 @@ def dataclass_args_schema( populate_by_name=populate_by_name, collect_init_only=collect_init_only, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, extra_behavior=extra_behavior, @@ -3274,6 +3641,7 @@ class DataclassSchema(TypedDict, total=False): strict: bool # default: False frozen: bool # default False ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema slots: bool @@ -3290,6 +3658,7 @@ def dataclass_schema( revalidate_instances: Literal['always', 'never', 'subclass-instances'] | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, frozen: bool | None = None, @@ -3311,6 +3680,7 @@ def dataclass_schema( should re-validate defaults to config.revalidate_instances, else 'never' strict: Whether to require an exact instance of `cls` ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema frozen: Whether the dataclass is frozen @@ -3327,6 +3697,7 @@ def dataclass_schema( revalidate_instances=revalidate_instances, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, frozen=frozen, @@ -3383,6 +3754,7 @@ class ArgumentsSchema(TypedDict, total=False): var_kwargs_mode: VarKwargsMode var_kwargs_schema: CoreSchema ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -3395,6 +3767,7 @@ def arguments_schema( var_kwargs_mode: VarKwargsMode | None = None, var_kwargs_schema: CoreSchema | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> ArgumentsSchema: @@ -3424,6 +3797,7 @@ def arguments_schema( the `var_kwargs_schema` argument must be a [`typed_dict_schema`][pydantic_core.core_schema.typed_dict_schema] var_kwargs_schema: The variable kwargs schema to use for the arguments schema ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -3435,6 +3809,7 @@ def arguments_schema( var_kwargs_mode=var_kwargs_mode, var_kwargs_schema=var_kwargs_schema, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -3447,6 +3822,7 @@ class CallSchema(TypedDict, total=False): function_name: str # default function.__name__ return_schema: CoreSchema ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -3458,6 +3834,7 @@ def call_schema( function_name: str | None = None, return_schema: CoreSchema | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> CallSchema: @@ -3490,6 +3867,7 @@ def call_schema( function_name: The function name to use for the call schema, if not provided `function.__name__` is used return_schema: The return schema to use for the call schema ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -3500,6 +3878,7 @@ def call_schema( function_name=function_name, return_schema=return_schema, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -3512,6 +3891,7 @@ class CustomErrorSchema(TypedDict, total=False): custom_error_message: str custom_error_context: Dict[str, Union[str, int, float]] ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -3523,6 +3903,7 @@ def custom_error_schema( custom_error_message: str | None = None, custom_error_context: dict[str, Any] | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> CustomErrorSchema: @@ -3547,6 +3928,7 @@ def custom_error_schema( custom_error_message: The custom error message to use for the custom error schema custom_error_context: The custom error context to use for the custom error schema ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -3557,6 +3939,7 @@ def custom_error_schema( custom_error_message=custom_error_message, custom_error_context=custom_error_context, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -3566,6 +3949,7 @@ class JsonSchema(TypedDict, total=False): type: Required[Literal['json']] schema: CoreSchema ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -3574,6 +3958,7 @@ def json_schema( schema: CoreSchema | None = None, *, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> JsonSchema: @@ -3610,10 +3995,18 @@ class MyModel: Args: schema: The schema to use for the JSON schema ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ - return _dict_not_none(type='json', schema=schema, ref=ref, metadata=metadata, serialization=serialization) + return _dict_not_none( + type='json', + schema=schema, + ref=ref, + pydantic_metadata=pydantic_metadata, + metadata=metadata, + serialization=serialization, + ) class UrlSchema(TypedDict, total=False): @@ -3626,6 +4019,7 @@ class UrlSchema(TypedDict, total=False): default_path: str strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -3640,6 +4034,7 @@ def url_schema( default_path: str | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> UrlSchema: @@ -3664,6 +4059,7 @@ def url_schema( default_path: The default path to use if the URL does not have a path strict: Whether to use strict URL parsing ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -3677,6 +4073,7 @@ def url_schema( default_path=default_path, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -3692,6 +4089,7 @@ class MultiHostUrlSchema(TypedDict, total=False): default_path: str strict: bool ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -3706,6 +4104,7 @@ def multi_host_url_schema( default_path: str | None = None, strict: bool | None = None, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> MultiHostUrlSchema: @@ -3730,6 +4129,7 @@ def multi_host_url_schema( default_path: The default path to use if the URL does not have a path strict: Whether to use strict URL parsing ref: optional unique identifier of the schema, used to reference the schema in other places + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ @@ -3743,6 +4143,7 @@ def multi_host_url_schema( default_path=default_path, strict=strict, ref=ref, + pydantic_metadata=pydantic_metadata, metadata=metadata, serialization=serialization, ) @@ -3752,6 +4153,7 @@ class DefinitionsSchema(TypedDict, total=False): type: Required[Literal['definitions']] schema: Required[CoreSchema] definitions: Required[List[CoreSchema]] + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -3783,6 +4185,7 @@ class DefinitionReferenceSchema(TypedDict, total=False): type: Required[Literal['definition-ref']] schema_ref: Required[str] ref: str + pydantic_metadata: PydanticMetadata metadata: Dict[str, Any] serialization: SerSchema @@ -3790,6 +4193,7 @@ class DefinitionReferenceSchema(TypedDict, total=False): def definition_reference_schema( schema_ref: str, ref: str | None = None, + pydantic_metadata: PydanticMetadata | None = None, metadata: Dict[str, Any] | None = None, serialization: SerSchema | None = None, ) -> DefinitionReferenceSchema: @@ -3813,11 +4217,17 @@ def definition_reference_schema( Args: schema_ref: The schema ref to use for the definition reference schema + pydantic_metadata: Information related to json schema generation intended for internal pydantic use metadata: Any other information you want to include with the schema, not used by pydantic-core serialization: Custom serialization schema """ return _dict_not_none( - type='definition-ref', schema_ref=schema_ref, ref=ref, metadata=metadata, serialization=serialization + type='definition-ref', + schema_ref=schema_ref, + ref=ref, + pydantic_metadata=pydantic_metadata, + metadata=metadata, + serialization=serialization, ) @@ -3826,6 +4236,7 @@ def definition_reference_schema( # union which kills performance not just for pydantic, but even for code using pydantic if not MYPY: CoreSchema = Union[ + InvalidSchema, AnySchema, NoneSchema, BoolSchema, @@ -3876,12 +4287,31 @@ def definition_reference_schema( UuidSchema, ComplexSchema, ] + CoreSchemaField = Union[ModelField, DataclassField, TypedDictField, ComputedField] + CoreSchemaOrField = Union[CoreSchema, CoreSchemaField] + + # Though pydantic-core doesn't manage any JSON schema generation, it's helpful to have these + # types here for reference when we do pull JSON schema generation information off of the `pydantic_metadata` dict. + # TODO: do we need to list any of these in the `False` block below? I think not, as they're just used for type checking? + JsonSchemaValue = Dict[str, Any] + GetJsonSchemaFunction = Callable[ + [CoreSchemaOrField, Callable[[CoreSchemaOrField], JsonSchemaValue]], JsonSchemaValue + ] + + JsonValue: TypeAlias = Union[int, float, str, bool, None, List['JsonValue'], 'JsonDict'] + JsonDict: TypeAlias = Dict[str, JsonValue] + + JsonSchemaExtraCallable: TypeAlias = Union[ + Callable[[JsonDict], None], + Callable[[JsonDict, Type[Any]], None], + ] elif False: CoreSchema: TypeAlias = Mapping[str, Any] # to update this, call `pytest -k test_core_schema_type_literal` and copy the output CoreSchemaType = Literal[ + 'invalid', 'any', 'none', 'bool',