@@ -382,13 +382,12 @@ def _create_single_variant(
382382 variant ["properties" ] = new_props
383383 variant ["required" ] = new_required
384384
385- # Rewrite $refs in top-level oneOf/anyOf branches (e.g. fulfillment_destination
386- # has no properties, only oneOf with external $refs that need variant rewriting).
387- for poly_key in ["oneOf" , "anyOf" ]:
388- if poly_key in variant :
389- rewrite_refs_to_variants (
390- variant [poly_key ], op , file_path , global_variant_requirements
391- )
385+ # Rewrite all external $refs in the variant schema to point to their
386+ # corresponding request variants where applicable. This covers top-level
387+ # oneOf/anyOf/allOf branches as well as array items.
388+ rewrite_refs_to_variants (
389+ variant , op , file_path , global_variant_requirements
390+ )
392391
393392 return variant
394393
@@ -446,19 +445,28 @@ def normalize_metadata_schemas(schemas, target_dir):
446445
447446
448447def extract_external_refs (schema , path ):
449- """Finds all relative external file references in the schema properties ."""
448+ """Finds all relative external file references in the schema."""
450449 refs = []
451- props = schema .get ("properties" , {})
452- if not isinstance (props , dict ):
453- return refs
454450
455- for name , data in props . items ( ):
451+ def _scan ( name , data ):
456452 for node in iter_nodes (data ):
457453 if isinstance (node , dict ) and "$ref" in node :
458454 ref = node ["$ref" ]
459455 if "#" not in ref :
460456 abs_path = str ((path .parent / ref ).resolve ())
461457 refs .append ((name , abs_path ))
458+
459+ props = schema .get ("properties" , {})
460+ if isinstance (props , dict ):
461+ for name , data in props .items ():
462+ _scan (name , data )
463+
464+ # Also scan top-level composition keywords (oneOf, anyOf, allOf, items)
465+ for key in ["oneOf" , "anyOf" , "allOf" ]:
466+ if key in schema :
467+ _scan (key , schema [key ])
468+ if "items" in schema :
469+ _scan ("items" , schema ["items" ])
462470 return refs
463471
464472
@@ -475,23 +483,28 @@ def propagate_needs_transitive(variant_needs, schema_refs, schemas):
475483 continue
476484
477485 for op in list (variant_needs [path ]):
478- for prop_name , child_path in refs :
486+ for ref_name , child_path in refs :
479487 if child_path not in schemas :
480488 continue
481489
482- # Only propagate if the property isn't 'omit'ted for this op
483- data = (
484- schemas [path ].get ("properties" , {}).get (prop_name , {})
485- )
486- include , _ = eval_prop_inclusion (
487- prop_name , data , op , schemas [path ].get ("required" , [])
488- )
489-
490- if include :
491- target_set = variant_needs .setdefault (child_path , set ())
492- if op not in target_set :
493- target_set .add (op )
494- changed = True
490+ # For property refs, check if the property is included for this op.
491+ # For non-property refs (oneOf, anyOf, allOf, items), always propagate.
492+ props = schemas [path ].get ("properties" , {})
493+ if ref_name in props :
494+ data = props [ref_name ]
495+ include , _ = eval_prop_inclusion (
496+ ref_name ,
497+ data ,
498+ op ,
499+ schemas [path ].get ("required" , []),
500+ )
501+ if not include :
502+ continue
503+
504+ target_set = variant_needs .setdefault (child_path , set ())
505+ if op not in target_set :
506+ target_set .add (op )
507+ changed = True
495508
496509
497510# --- Main Flow ---
0 commit comments