Skip to content

Commit 98bc1e2

Browse files
authored
Include JSON Schema input core schema in function schemas (#1572)
1 parent 6a455fb commit 98bc1e2

File tree

1 file changed

+24
-0
lines changed

1 file changed

+24
-0
lines changed

python/pydantic_core/core_schema.py

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1971,13 +1971,15 @@ class _ValidatorFunctionSchema(TypedDict, total=False):
19711971

19721972
class BeforeValidatorFunctionSchema(_ValidatorFunctionSchema, total=False):
19731973
type: Required[Literal['function-before']]
1974+
json_schema_input_schema: CoreSchema
19741975

19751976

19761977
def no_info_before_validator_function(
19771978
function: NoInfoValidatorFunction,
19781979
schema: CoreSchema,
19791980
*,
19801981
ref: str | None = None,
1982+
json_schema_input_schema: CoreSchema | None = None,
19811983
metadata: Dict[str, Any] | None = None,
19821984
serialization: SerSchema | None = None,
19831985
) -> BeforeValidatorFunctionSchema:
@@ -2003,6 +2005,7 @@ def fn(v: bytes) -> str:
20032005
function: The validator function to call
20042006
schema: The schema to validate the output of the validator function
20052007
ref: optional unique identifier of the schema, used to reference the schema in other places
2008+
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
20062009
metadata: Any other information you want to include with the schema, not used by pydantic-core
20072010
serialization: Custom serialization schema
20082011
"""
@@ -2011,6 +2014,7 @@ def fn(v: bytes) -> str:
20112014
function={'type': 'no-info', 'function': function},
20122015
schema=schema,
20132016
ref=ref,
2017+
json_schema_input_schema=json_schema_input_schema,
20142018
metadata=metadata,
20152019
serialization=serialization,
20162020
)
@@ -2022,6 +2026,7 @@ def with_info_before_validator_function(
20222026
*,
20232027
field_name: str | None = None,
20242028
ref: str | None = None,
2029+
json_schema_input_schema: CoreSchema | None = None,
20252030
metadata: Dict[str, Any] | None = None,
20262031
serialization: SerSchema | None = None,
20272032
) -> BeforeValidatorFunctionSchema:
@@ -2051,6 +2056,7 @@ def fn(v: bytes, info: core_schema.ValidationInfo) -> str:
20512056
field_name: The name of the field
20522057
schema: The schema to validate the output of the validator function
20532058
ref: optional unique identifier of the schema, used to reference the schema in other places
2059+
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
20542060
metadata: Any other information you want to include with the schema, not used by pydantic-core
20552061
serialization: Custom serialization schema
20562062
"""
@@ -2059,6 +2065,7 @@ def fn(v: bytes, info: core_schema.ValidationInfo) -> str:
20592065
function=_dict_not_none(type='with-info', function=function, field_name=field_name),
20602066
schema=schema,
20612067
ref=ref,
2068+
json_schema_input_schema=json_schema_input_schema,
20622069
metadata=metadata,
20632070
serialization=serialization,
20642071
)
@@ -2073,6 +2080,7 @@ def no_info_after_validator_function(
20732080
schema: CoreSchema,
20742081
*,
20752082
ref: str | None = None,
2083+
json_schema_input_schema: CoreSchema | None = None,
20762084
metadata: Dict[str, Any] | None = None,
20772085
serialization: SerSchema | None = None,
20782086
) -> AfterValidatorFunctionSchema:
@@ -2096,6 +2104,7 @@ def fn(v: str) -> str:
20962104
function: The validator function to call after the schema is validated
20972105
schema: The schema to validate before the validator function
20982106
ref: optional unique identifier of the schema, used to reference the schema in other places
2107+
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
20992108
metadata: Any other information you want to include with the schema, not used by pydantic-core
21002109
serialization: Custom serialization schema
21012110
"""
@@ -2104,6 +2113,7 @@ def fn(v: str) -> str:
21042113
function={'type': 'no-info', 'function': function},
21052114
schema=schema,
21062115
ref=ref,
2116+
json_schema_input_schema=json_schema_input_schema,
21072117
metadata=metadata,
21082118
serialization=serialization,
21092119
)
@@ -2189,6 +2199,7 @@ class WrapValidatorFunctionSchema(TypedDict, total=False):
21892199
function: Required[WrapValidatorFunction]
21902200
schema: Required[CoreSchema]
21912201
ref: str
2202+
json_schema_input_schema: CoreSchema
21922203
metadata: Dict[str, Any]
21932204
serialization: SerSchema
21942205

@@ -2198,6 +2209,7 @@ def no_info_wrap_validator_function(
21982209
schema: CoreSchema,
21992210
*,
22002211
ref: str | None = None,
2212+
json_schema_input_schema: CoreSchema | None = None,
22012213
metadata: Dict[str, Any] | None = None,
22022214
serialization: SerSchema | None = None,
22032215
) -> WrapValidatorFunctionSchema:
@@ -2226,13 +2238,15 @@ def fn(
22262238
function: The validator function to call
22272239
schema: The schema to validate the output of the validator function
22282240
ref: optional unique identifier of the schema, used to reference the schema in other places
2241+
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
22292242
metadata: Any other information you want to include with the schema, not used by pydantic-core
22302243
serialization: Custom serialization schema
22312244
"""
22322245
return _dict_not_none(
22332246
type='function-wrap',
22342247
function={'type': 'no-info', 'function': function},
22352248
schema=schema,
2249+
json_schema_input_schema=json_schema_input_schema,
22362250
ref=ref,
22372251
metadata=metadata,
22382252
serialization=serialization,
@@ -2244,6 +2258,7 @@ def with_info_wrap_validator_function(
22442258
schema: CoreSchema,
22452259
*,
22462260
field_name: str | None = None,
2261+
json_schema_input_schema: CoreSchema | None = None,
22472262
ref: str | None = None,
22482263
metadata: Dict[str, Any] | None = None,
22492264
serialization: SerSchema | None = None,
@@ -2274,6 +2289,7 @@ def fn(
22742289
function: The validator function to call
22752290
schema: The schema to validate the output of the validator function
22762291
field_name: The name of the field this validators is applied to, if any
2292+
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
22772293
ref: optional unique identifier of the schema, used to reference the schema in other places
22782294
metadata: Any other information you want to include with the schema, not used by pydantic-core
22792295
serialization: Custom serialization schema
@@ -2282,6 +2298,7 @@ def fn(
22822298
type='function-wrap',
22832299
function=_dict_not_none(type='with-info', function=function, field_name=field_name),
22842300
schema=schema,
2301+
json_schema_input_schema=json_schema_input_schema,
22852302
ref=ref,
22862303
metadata=metadata,
22872304
serialization=serialization,
@@ -2292,6 +2309,7 @@ class PlainValidatorFunctionSchema(TypedDict, total=False):
22922309
type: Required[Literal['function-plain']]
22932310
function: Required[ValidationFunction]
22942311
ref: str
2312+
json_schema_input_schema: CoreSchema
22952313
metadata: Dict[str, Any]
22962314
serialization: SerSchema
22972315

@@ -2300,6 +2318,7 @@ def no_info_plain_validator_function(
23002318
function: NoInfoValidatorFunction,
23012319
*,
23022320
ref: str | None = None,
2321+
json_schema_input_schema: CoreSchema | None = None,
23032322
metadata: Dict[str, Any] | None = None,
23042323
serialization: SerSchema | None = None,
23052324
) -> PlainValidatorFunctionSchema:
@@ -2321,13 +2340,15 @@ def fn(v: str) -> str:
23212340
Args:
23222341
function: The validator function to call
23232342
ref: optional unique identifier of the schema, used to reference the schema in other places
2343+
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
23242344
metadata: Any other information you want to include with the schema, not used by pydantic-core
23252345
serialization: Custom serialization schema
23262346
"""
23272347
return _dict_not_none(
23282348
type='function-plain',
23292349
function={'type': 'no-info', 'function': function},
23302350
ref=ref,
2351+
json_schema_input_schema=json_schema_input_schema,
23312352
metadata=metadata,
23322353
serialization=serialization,
23332354
)
@@ -2338,6 +2359,7 @@ def with_info_plain_validator_function(
23382359
*,
23392360
field_name: str | None = None,
23402361
ref: str | None = None,
2362+
json_schema_input_schema: CoreSchema | None = None,
23412363
metadata: Dict[str, Any] | None = None,
23422364
serialization: SerSchema | None = None,
23432365
) -> PlainValidatorFunctionSchema:
@@ -2360,13 +2382,15 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str:
23602382
function: The validator function to call
23612383
field_name: The name of the field this validators is applied to, if any
23622384
ref: optional unique identifier of the schema, used to reference the schema in other places
2385+
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
23632386
metadata: Any other information you want to include with the schema, not used by pydantic-core
23642387
serialization: Custom serialization schema
23652388
"""
23662389
return _dict_not_none(
23672390
type='function-plain',
23682391
function=_dict_not_none(type='with-info', function=function, field_name=field_name),
23692392
ref=ref,
2393+
json_schema_input_schema=json_schema_input_schema,
23702394
metadata=metadata,
23712395
serialization=serialization,
23722396
)

0 commit comments

Comments
 (0)