Skip to content

Commit 3a0cea9

Browse files
Viicosdavidhewitt
authored andcommitted
Include JSON Schema input core schema in function schemas (#1572)
1 parent 83ff1cf commit 3a0cea9

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
@@ -1970,13 +1970,15 @@ class _ValidatorFunctionSchema(TypedDict, total=False):
19701970

19711971
class BeforeValidatorFunctionSchema(_ValidatorFunctionSchema, total=False):
19721972
type: Required[Literal['function-before']]
1973+
json_schema_input_schema: CoreSchema
19731974

19741975

19751976
def no_info_before_validator_function(
19761977
function: NoInfoValidatorFunction,
19771978
schema: CoreSchema,
19781979
*,
19791980
ref: str | None = None,
1981+
json_schema_input_schema: CoreSchema | None = None,
19801982
metadata: Dict[str, Any] | None = None,
19811983
serialization: SerSchema | None = None,
19821984
) -> BeforeValidatorFunctionSchema:
@@ -2002,6 +2004,7 @@ def fn(v: bytes) -> str:
20022004
function: The validator function to call
20032005
schema: The schema to validate the output of the validator function
20042006
ref: optional unique identifier of the schema, used to reference the schema in other places
2007+
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
20052008
metadata: Any other information you want to include with the schema, not used by pydantic-core
20062009
serialization: Custom serialization schema
20072010
"""
@@ -2010,6 +2013,7 @@ def fn(v: bytes) -> str:
20102013
function={'type': 'no-info', 'function': function},
20112014
schema=schema,
20122015
ref=ref,
2016+
json_schema_input_schema=json_schema_input_schema,
20132017
metadata=metadata,
20142018
serialization=serialization,
20152019
)
@@ -2021,6 +2025,7 @@ def with_info_before_validator_function(
20212025
*,
20222026
field_name: str | None = None,
20232027
ref: str | None = None,
2028+
json_schema_input_schema: CoreSchema | None = None,
20242029
metadata: Dict[str, Any] | None = None,
20252030
serialization: SerSchema | None = None,
20262031
) -> BeforeValidatorFunctionSchema:
@@ -2050,6 +2055,7 @@ def fn(v: bytes, info: core_schema.ValidationInfo) -> str:
20502055
field_name: The name of the field
20512056
schema: The schema to validate the output of the validator function
20522057
ref: optional unique identifier of the schema, used to reference the schema in other places
2058+
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
20532059
metadata: Any other information you want to include with the schema, not used by pydantic-core
20542060
serialization: Custom serialization schema
20552061
"""
@@ -2058,6 +2064,7 @@ def fn(v: bytes, info: core_schema.ValidationInfo) -> str:
20582064
function=_dict_not_none(type='with-info', function=function, field_name=field_name),
20592065
schema=schema,
20602066
ref=ref,
2067+
json_schema_input_schema=json_schema_input_schema,
20612068
metadata=metadata,
20622069
serialization=serialization,
20632070
)
@@ -2072,6 +2079,7 @@ def no_info_after_validator_function(
20722079
schema: CoreSchema,
20732080
*,
20742081
ref: str | None = None,
2082+
json_schema_input_schema: CoreSchema | None = None,
20752083
metadata: Dict[str, Any] | None = None,
20762084
serialization: SerSchema | None = None,
20772085
) -> AfterValidatorFunctionSchema:
@@ -2095,6 +2103,7 @@ def fn(v: str) -> str:
20952103
function: The validator function to call after the schema is validated
20962104
schema: The schema to validate before the validator function
20972105
ref: optional unique identifier of the schema, used to reference the schema in other places
2106+
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
20982107
metadata: Any other information you want to include with the schema, not used by pydantic-core
20992108
serialization: Custom serialization schema
21002109
"""
@@ -2103,6 +2112,7 @@ def fn(v: str) -> str:
21032112
function={'type': 'no-info', 'function': function},
21042113
schema=schema,
21052114
ref=ref,
2115+
json_schema_input_schema=json_schema_input_schema,
21062116
metadata=metadata,
21072117
serialization=serialization,
21082118
)
@@ -2188,6 +2198,7 @@ class WrapValidatorFunctionSchema(TypedDict, total=False):
21882198
function: Required[WrapValidatorFunction]
21892199
schema: Required[CoreSchema]
21902200
ref: str
2201+
json_schema_input_schema: CoreSchema
21912202
metadata: Dict[str, Any]
21922203
serialization: SerSchema
21932204

@@ -2197,6 +2208,7 @@ def no_info_wrap_validator_function(
21972208
schema: CoreSchema,
21982209
*,
21992210
ref: str | None = None,
2211+
json_schema_input_schema: CoreSchema | None = None,
22002212
metadata: Dict[str, Any] | None = None,
22012213
serialization: SerSchema | None = None,
22022214
) -> WrapValidatorFunctionSchema:
@@ -2225,13 +2237,15 @@ def fn(
22252237
function: The validator function to call
22262238
schema: The schema to validate the output of the validator function
22272239
ref: optional unique identifier of the schema, used to reference the schema in other places
2240+
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
22282241
metadata: Any other information you want to include with the schema, not used by pydantic-core
22292242
serialization: Custom serialization schema
22302243
"""
22312244
return _dict_not_none(
22322245
type='function-wrap',
22332246
function={'type': 'no-info', 'function': function},
22342247
schema=schema,
2248+
json_schema_input_schema=json_schema_input_schema,
22352249
ref=ref,
22362250
metadata=metadata,
22372251
serialization=serialization,
@@ -2243,6 +2257,7 @@ def with_info_wrap_validator_function(
22432257
schema: CoreSchema,
22442258
*,
22452259
field_name: str | None = None,
2260+
json_schema_input_schema: CoreSchema | None = None,
22462261
ref: str | None = None,
22472262
metadata: Dict[str, Any] | None = None,
22482263
serialization: SerSchema | None = None,
@@ -2273,6 +2288,7 @@ def fn(
22732288
function: The validator function to call
22742289
schema: The schema to validate the output of the validator function
22752290
field_name: The name of the field this validators is applied to, if any
2291+
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
22762292
ref: optional unique identifier of the schema, used to reference the schema in other places
22772293
metadata: Any other information you want to include with the schema, not used by pydantic-core
22782294
serialization: Custom serialization schema
@@ -2281,6 +2297,7 @@ def fn(
22812297
type='function-wrap',
22822298
function=_dict_not_none(type='with-info', function=function, field_name=field_name),
22832299
schema=schema,
2300+
json_schema_input_schema=json_schema_input_schema,
22842301
ref=ref,
22852302
metadata=metadata,
22862303
serialization=serialization,
@@ -2291,6 +2308,7 @@ class PlainValidatorFunctionSchema(TypedDict, total=False):
22912308
type: Required[Literal['function-plain']]
22922309
function: Required[ValidationFunction]
22932310
ref: str
2311+
json_schema_input_schema: CoreSchema
22942312
metadata: Dict[str, Any]
22952313
serialization: SerSchema
22962314

@@ -2299,6 +2317,7 @@ def no_info_plain_validator_function(
22992317
function: NoInfoValidatorFunction,
23002318
*,
23012319
ref: str | None = None,
2320+
json_schema_input_schema: CoreSchema | None = None,
23022321
metadata: Dict[str, Any] | None = None,
23032322
serialization: SerSchema | None = None,
23042323
) -> PlainValidatorFunctionSchema:
@@ -2320,13 +2339,15 @@ def fn(v: str) -> str:
23202339
Args:
23212340
function: The validator function to call
23222341
ref: optional unique identifier of the schema, used to reference the schema in other places
2342+
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
23232343
metadata: Any other information you want to include with the schema, not used by pydantic-core
23242344
serialization: Custom serialization schema
23252345
"""
23262346
return _dict_not_none(
23272347
type='function-plain',
23282348
function={'type': 'no-info', 'function': function},
23292349
ref=ref,
2350+
json_schema_input_schema=json_schema_input_schema,
23302351
metadata=metadata,
23312352
serialization=serialization,
23322353
)
@@ -2337,6 +2358,7 @@ def with_info_plain_validator_function(
23372358
*,
23382359
field_name: str | None = None,
23392360
ref: str | None = None,
2361+
json_schema_input_schema: CoreSchema | None = None,
23402362
metadata: Dict[str, Any] | None = None,
23412363
serialization: SerSchema | None = None,
23422364
) -> PlainValidatorFunctionSchema:
@@ -2359,13 +2381,15 @@ def fn(v: str, info: core_schema.ValidationInfo) -> str:
23592381
function: The validator function to call
23602382
field_name: The name of the field this validators is applied to, if any
23612383
ref: optional unique identifier of the schema, used to reference the schema in other places
2384+
json_schema_input_schema: The core schema to be used to generate the corresponding JSON Schema input type
23622385
metadata: Any other information you want to include with the schema, not used by pydantic-core
23632386
serialization: Custom serialization schema
23642387
"""
23652388
return _dict_not_none(
23662389
type='function-plain',
23672390
function=_dict_not_none(type='with-info', function=function, field_name=field_name),
23682391
ref=ref,
2392+
json_schema_input_schema=json_schema_input_schema,
23692393
metadata=metadata,
23702394
serialization=serialization,
23712395
)

0 commit comments

Comments
 (0)