@@ -405,9 +405,38 @@ impl<'a> TypesAndComponents<'a> {
405405 }
406406 Some ( TypeAliasVariants :: InternalTag ( tag) ) => {
407407 // TODO: add tag.default_tag as an extension
408+ let mut mapping = IndexMap :: new ( ) ;
409+
410+ // Extract union members and build mapping
411+ if let ValueOf :: UnionOf ( union) = & alias. typ {
412+ for item in & union. items {
413+ if let ValueOf :: InstanceOf ( instance) = item {
414+ // Get the variant type definition
415+ if let Ok ( TypeDefinition :: Interface ( variant_itf) ) =
416+ self . model . get_type ( & instance. typ )
417+ {
418+ // Find the discriminator property in the variant
419+ if let Some ( disc_prop) = variant_itf. properties . iter ( )
420+ . find ( |p| p. name == tag. tag )
421+ {
422+ // Extract the literal value
423+ if let ValueOf :: LiteralValue ( literal) = & disc_prop. typ {
424+ let discriminator_value = literal. value . to_string ( ) ;
425+ let schema_ref = format ! (
426+ "#/components/schemas/{}" ,
427+ instance. typ. schema_name( )
428+ ) ;
429+ mapping. insert ( discriminator_value, schema_ref) ;
430+ }
431+ }
432+ }
433+ }
434+ }
435+ }
436+
408437 schema. schema_data . discriminator = Some ( Discriminator {
409438 property_name : tag. tag . clone ( ) ,
410- mapping : Default :: default ( ) ,
439+ mapping,
411440 extensions : Default :: default ( ) ,
412441 } ) ;
413442 }
0 commit comments