We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
1 parent 150d05e commit 96b3cd4Copy full SHA for 96b3cd4
typify-impl/src/structs.rs
@@ -288,8 +288,20 @@ impl TypeSpace {
288
}
289
290
// TODO we need a reasonable name that could be derived
291
- // from the name of the type
292
- let name = format!("subtype_{}", idx);
+ // from the name of the type. Use of SchemaObject here
+ // accommodates "anyOf" and "allOf" but others, TBD. e.g.,
293
+ // "foo":{"items":{"anyOf":[{"$ref": "#/$defs/bar-baz"}, ...]}}
294
+ // provides "bar_baz".
295
+ let name = match schema {
296
+ Schema::Object(SchemaObject {
297
+ reference: Some(s), ..
298
+ }) => match s.rsplit_once('/') {
299
+ Some((_, name)) => name,
300
+ None => s,
301
+ }
302
+ .replace('-', "_"),
303
+ _ => format!("subtype_{}", idx),
304
+ };
305
306
Ok(StructProperty {
307
name,
0 commit comments