Skip to content

Commit

Permalink
Include JSON Schema input core schema in function schemas
Browse files Browse the repository at this point in the history
  • Loading branch information
Viicos committed Dec 6, 2024
1 parent 4c02cbd commit e4978a7
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions python/pydantic_core/core_schema.py
Original file line number Diff line number Diff line change
Expand Up @@ -2021,6 +2021,7 @@ def with_info_before_validator_function(
*,
field_name: str | None = None,
ref: str | None = None,
json_schema_input_schema: CoreSchema | None = None,
metadata: Dict[str, Any] | None = None,
serialization: SerSchema | None = None,
) -> BeforeValidatorFunctionSchema:
Expand Down Expand Up @@ -2050,6 +2051,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
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
metadata: Any other information you want to include with the schema, not used by pydantic-core
serialization: Custom serialization schema
"""
Expand All @@ -2058,6 +2060,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,
json_schema_input_schema=json_schema_input_schema,
metadata=metadata,
serialization=serialization,
)
Expand All @@ -2072,6 +2075,7 @@ def no_info_after_validator_function(
schema: CoreSchema,
*,
ref: str | None = None,
json_schema_input_schema: CoreSchema | None = None,
metadata: Dict[str, Any] | None = None,
serialization: SerSchema | None = None,
) -> AfterValidatorFunctionSchema:
Expand All @@ -2095,6 +2099,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
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
metadata: Any other information you want to include with the schema, not used by pydantic-core
serialization: Custom serialization schema
"""
Expand All @@ -2103,6 +2108,7 @@ def fn(v: str) -> str:
function={'type': 'no-info', 'function': function},
schema=schema,
ref=ref,
json_schema_input_schema=json_schema_input_schema,
metadata=metadata,
serialization=serialization,
)
Expand Down Expand Up @@ -2197,6 +2203,7 @@ def no_info_wrap_validator_function(
schema: CoreSchema,
*,
ref: str | None = None,
json_schema_input_schema: CoreSchema | None = None,
metadata: Dict[str, Any] | None = None,
serialization: SerSchema | None = None,
) -> WrapValidatorFunctionSchema:
Expand Down Expand Up @@ -2225,13 +2232,15 @@ 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
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
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='function-wrap',
function={'type': 'no-info', 'function': function},
schema=schema,
json_schema_input_schema=json_schema_input_schema,
ref=ref,
metadata=metadata,
serialization=serialization,
Expand All @@ -2243,6 +2252,7 @@ def with_info_wrap_validator_function(
schema: CoreSchema,
*,
field_name: str | None = None,
json_schema_input_schema: CoreSchema | None = None,
ref: str | None = None,
metadata: Dict[str, Any] | None = None,
serialization: SerSchema | None = None,
Expand Down Expand Up @@ -2273,6 +2283,7 @@ def fn(
function: The validator function to call
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
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
ref: optional unique identifier of the schema, used to reference the schema in other places
metadata: Any other information you want to include with the schema, not used by pydantic-core
serialization: Custom serialization schema
Expand All @@ -2281,6 +2292,7 @@ def fn(
type='function-wrap',
function=_dict_not_none(type='with-info', function=function, field_name=field_name),
schema=schema,
json_schema_input_schema=json_schema_input_schema,
ref=ref,
metadata=metadata,
serialization=serialization,
Expand All @@ -2299,6 +2311,7 @@ def no_info_plain_validator_function(
function: NoInfoValidatorFunction,
*,
ref: str | None = None,
json_schema_input_schema: CoreSchema | None = None,
metadata: Dict[str, Any] | None = None,
serialization: SerSchema | None = None,
) -> PlainValidatorFunctionSchema:
Expand All @@ -2320,6 +2333,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
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
metadata: Any other information you want to include with the schema, not used by pydantic-core
serialization: Custom serialization schema
"""
Expand All @@ -2337,6 +2351,7 @@ def with_info_plain_validator_function(
*,
field_name: str | None = None,
ref: str | None = None,
json_schema_input_schema: CoreSchema | None = None,
metadata: Dict[str, Any] | None = None,
serialization: SerSchema | None = None,
) -> PlainValidatorFunctionSchema:
Expand All @@ -2359,13 +2374,15 @@ 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
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
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='function-plain',
function=_dict_not_none(type='with-info', function=function, field_name=field_name),
ref=ref,
json_schema_input_schema=json_schema_input_schema,
metadata=metadata,
serialization=serialization,
)
Expand Down

0 comments on commit e4978a7

Please sign in to comment.