Skip to content
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 14 additions & 2 deletions typify-impl/src/structs.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down