Skip to content

Commit 2c00ca4

Browse files
committed
Add OpenAPI mapping to internal variants
1 parent 161789d commit 2c00ca4

File tree

4 files changed

+539
-22
lines changed

4 files changed

+539
-22
lines changed

compiler-rs/clients_schema_to_openapi/src/schemas.rs

Lines changed: 30 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -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
}
14.4 KB
Binary file not shown.

0 commit comments

Comments
 (0)