@@ -88,20 +88,38 @@ def transform(
8888 finally :
8989 schema ["type" ] = original_type # restore original type
9090 all_of = schema .get ("allOf" )
91- if all_of is not None :
92- subschema = _validate_subschemas (all_of , message , ref_registry , ref_resolver )
93- if subschema is not None :
94- return transform (ctx , subschema , ref_registry , ref_resolver , path , message , field_transform )
9591 any_of = schema .get ("anyOf" )
96- if any_of is not None :
97- subschema = _validate_subschemas (any_of , message , ref_registry , ref_resolver )
98- if subschema is not None :
99- return transform (ctx , subschema , ref_registry , ref_resolver , path , message , field_transform )
10092 one_of = schema .get ("oneOf" )
101- if one_of is not None :
102- subschema = _validate_subschemas (one_of , message , ref_registry , ref_resolver )
103- if subschema is not None :
104- return transform (ctx , subschema , ref_registry , ref_resolver , path , message , field_transform )
93+ if all_of is not None or any_of is not None or one_of is not None :
94+ if all_of is not None :
95+ for subschema in all_of :
96+ message = transform (ctx , subschema , ref_registry , ref_resolver , path , message , field_transform )
97+ elif one_of is not None :
98+ for subschema in one_of :
99+ resolved = _validate_subschema (subschema , message , ref_registry , ref_resolver )
100+ if resolved is not None :
101+ message = transform (ctx , resolved , ref_registry , ref_resolver , path , message , field_transform )
102+ break
103+ elif any_of is not None :
104+ for subschema in any_of :
105+ resolved = _validate_subschema (subschema , message , ref_registry , ref_resolver )
106+ if resolved is not None :
107+ message = transform (ctx , resolved , ref_registry , ref_resolver , path , message , field_transform )
108+ # Also visit sibling properties/items at this level
109+ # (siblings to allOf/anyOf/oneOf).
110+ props = schema .get ("properties" )
111+ if props is not None and isinstance (message , dict ):
112+ for prop_name , prop_schema in props .items ():
113+ if isinstance (prop_schema , dict ):
114+ _transform_field (
115+ ctx , path , prop_name , message , prop_schema , ref_registry , ref_resolver , field_transform
116+ )
117+ items = schema .get ("items" )
118+ if items is not None and isinstance (message , list ):
119+ message = [
120+ transform (ctx , items , ref_registry , ref_resolver , path , item , field_transform ) for item in message
121+ ]
122+ return message
105123 items = schema .get ("items" )
106124 if items is not None :
107125 if isinstance (message , list ):
@@ -197,23 +215,39 @@ def _validate_subschemas(
197215 The validated schema if the message is valid against the subschemas, otherwise None.
198216 """
199217 for subschema in subschemas :
200- if isinstance (subschema , dict ):
201- try :
202- ref = subschema .get ("$ref" )
203- if ref is not None :
204- resolved = resolver .lookup (ref )
205- subschema = resolved .contents
206- # Pass _resolver (not resolver) to use the new referencing library's
207- # Resolver with correct context for nested $ref resolution
208- validate (instance = message , schema = subschema , registry = registry , _resolver = resolved .resolver )
209- else :
210- validate (instance = message , schema = subschema , registry = registry )
211- return subschema
212- except ValidationError :
213- pass
218+ resolved = _validate_subschema (subschema , message , registry , resolver )
219+ if resolved is not None :
220+ return resolved
214221 return None
215222
216223
224+ def _validate_subschema (
225+ subschema : JsonSchema ,
226+ message : JsonMessage ,
227+ registry : Registry ,
228+ resolver : Resolver ,
229+ ) -> Optional [JsonSchema ]:
230+ """
231+ Validate the message against a single subschema.
232+ Returns the resolved subschema (with $ref followed) if valid, otherwise None.
233+ """
234+ if not isinstance (subschema , dict ):
235+ return None
236+ try :
237+ ref = subschema .get ("$ref" )
238+ if ref is not None :
239+ resolved = resolver .lookup (ref )
240+ subschema = resolved .contents
241+ # Pass _resolver (not resolver) to use the new referencing library's
242+ # Resolver with correct context for nested $ref resolution
243+ validate (instance = message , schema = subschema , registry = registry , _resolver = resolved .resolver )
244+ else :
245+ validate (instance = message , schema = subschema , registry = registry )
246+ return subschema
247+ except ValidationError :
248+ return None
249+
250+
217251def get_type (schema : JsonSchema ) -> FieldType :
218252 if isinstance (schema , bool ):
219253 return FieldType .COMBINED
0 commit comments