@@ -134,6 +134,9 @@ class Raw(object):
134134 :param bool readonly: Is the field read only ? (for documentation purpose)
135135 :param example: An optional data example (for documentation purpose)
136136 :param callable mask: An optional mask function to be applied to output
137+ :param bool nullable: Whether the field accepts null values in input
138+ validation. When True, the generated JSON Schema will allow null
139+ values for this field during request payload validation.
137140 """
138141
139142 #: The JSON/Swagger schema type
@@ -153,6 +156,7 @@ def __init__(
153156 readonly = None ,
154157 example = None ,
155158 mask = None ,
159+ nullable = None ,
156160 ** kwargs
157161 ):
158162 self .attribute = attribute
@@ -163,6 +167,7 @@ def __init__(
163167 self .readonly = readonly
164168 self .example = example if example is not None else self .__schema_example__
165169 self .mask = mask
170+ self .nullable = nullable
166171
167172 def format (self , value ):
168173 """
@@ -284,6 +289,19 @@ def schema(self):
284289 schema ["allOf" ] = allOf
285290 else :
286291 schema ["$ref" ] = ref
292+
293+ # If nullable is True, wrap using anyOf to permit nulls for input validation
294+ if self .nullable :
295+ # Remove structural keys that conflict with anyOf composition
296+ for key in ("$ref" , "allOf" , "type" , "items" ):
297+ schema .pop (key , None )
298+ # Create anyOf with the original schema and null type
299+ anyOf = [{"$ref" : ref }]
300+ if self .as_list :
301+ anyOf = [{"type" : "array" , "items" : {"$ref" : ref }}]
302+ anyOf .append ({"type" : "null" })
303+ schema ["anyOf" ] = anyOf
304+
287305 return schema
288306
289307 def clone (self , mask = None ):
0 commit comments