@@ -216,6 +216,7 @@ def Field(
216216 examples : Optional [list [Any ]] = None ,
217217 deprecated : Union [Deprecated , str , bool , None ] = None ,
218218 exclude : Union [Set [Union [int , str ]], Mapping [Union [int , str ], Any ], Any ] = None ,
219+ exclude_if : Optional [Callable [[Any ], bool ]] = None ,
219220 include : Union [Set [Union [int , str ]], Mapping [Union [int , str ], Any ], Any ] = None ,
220221 const : Optional [bool ] = None ,
221222 gt : Optional [float ] = None ,
@@ -262,6 +263,7 @@ def Field(
262263 examples : Optional [list [Any ]] = None ,
263264 deprecated : Union [Deprecated , str , bool , None ] = None ,
264265 exclude : Union [Set [Union [int , str ]], Mapping [Union [int , str ], Any ], Any ] = None ,
266+ exclude_if : Optional [Callable [[Any ], bool ]] = None ,
265267 include : Union [Set [Union [int , str ]], Mapping [Union [int , str ], Any ], Any ] = None ,
266268 const : Optional [bool ] = None ,
267269 gt : Optional [float ] = None ,
@@ -317,6 +319,7 @@ def Field(
317319 examples : Optional [list [Any ]] = None ,
318320 deprecated : Union [Deprecated , str , bool , None ] = None ,
319321 exclude : Union [Set [Union [int , str ]], Mapping [Union [int , str ], Any ], Any ] = None ,
322+ exclude_if : Optional [Callable [[Any ], bool ]] = None ,
320323 include : Union [Set [Union [int , str ]], Mapping [Union [int , str ], Any ], Any ] = None ,
321324 const : Optional [bool ] = None ,
322325 gt : Optional [float ] = None ,
@@ -353,6 +356,7 @@ def Field(
353356 examples : Optional [list [Any ]] = None ,
354357 deprecated : Union [Deprecated , str , bool , None ] = None ,
355358 exclude : Union [Set [Union [int , str ]], Mapping [Union [int , str ], Any ], Any ] = None ,
359+ exclude_if : Optional [Callable [[Any ], bool ]] = None ,
356360 include : Union [Set [Union [int , str ]], Mapping [Union [int , str ], Any ], Any ] = None ,
357361 const : Optional [bool ] = None ,
358362 gt : Optional [float ] = None ,
@@ -386,7 +390,7 @@ def Field(
386390) -> Any :
387391 current_schema_extra = schema_extra or {}
388392
389- for param_name in ("strict" , "examples" , "deprecated" ):
393+ for param_name in ("strict" , "examples" , "deprecated" , "exclude_if" ):
390394 if param_name in current_schema_extra :
391395 msg = f"Pass `{ param_name } ` parameter directly to Field instead of passing it via `schema_extra`"
392396 warnings .warn (msg , DeprecationWarning , stacklevel = 2 )
@@ -397,13 +401,15 @@ def Field(
397401 current_strict = strict or current_schema_extra .pop ("strict" , None )
398402 current_examples = examples or current_schema_extra .pop ("examples" , None )
399403 current_deprecated = deprecated or current_schema_extra .pop ("deprecated" , None )
404+ current_exclude_if = exclude_if or current_schema_extra .pop ("exclude_if" , None )
400405 field_info_kwargs = {
401406 "alias" : alias ,
402407 "title" : title ,
403408 "description" : description ,
404409 "examples" : current_examples ,
405410 "deprecated" : current_deprecated ,
406411 "exclude" : exclude ,
412+ "exclude_if" : current_exclude_if ,
407413 "include" : include ,
408414 "const" : const ,
409415 "gt" : gt ,
0 commit comments