From 96b3cd40ca275ea8c675829efdc57e83116f4fc0 Mon Sep 17 00:00:00 2001 From: Daniel Pezely Date: Thu, 23 Oct 2025 14:55:37 -0600 Subject: [PATCH] Obtain name from SchemaObject, else subtype_{idx} --- typify-impl/src/structs.rs | 16 ++++++++++++++-- 1 file changed, 14 insertions(+), 2 deletions(-) diff --git a/typify-impl/src/structs.rs b/typify-impl/src/structs.rs index 4e285259..964f37ec 100644 --- a/typify-impl/src/structs.rs +++ b/typify-impl/src/structs.rs @@ -288,8 +288,20 @@ impl TypeSpace { } // TODO we need a reasonable name that could be derived - // from the name of the type - let name = format!("subtype_{}", idx); + // from the name of the type. Use of SchemaObject here + // accommodates "anyOf" and "allOf" but others, TBD. e.g., + // "foo":{"items":{"anyOf":[{"$ref": "#/$defs/bar-baz"}, ...]}} + // provides "bar_baz". + let name = match schema { + Schema::Object(SchemaObject { + reference: Some(s), .. + }) => match s.rsplit_once('/') { + Some((_, name)) => name, + None => s, + } + .replace('-', "_"), + _ => format!("subtype_{}", idx), + }; Ok(StructProperty { name,