-
-
Notifications
You must be signed in to change notification settings - Fork 284
Open
Description
Hello, and thanks for building and maintaining schemars!
I've been toying around with _unstable_ref_variants to get around the nested additional properties issue, but I've ran into another one: colliding ref variant names. This is currently resolved by schemars adding a number to the name, but I would prefer to have a way to provide a better name. Normally I'd just use #[schemars(rename = "...")] for this, but that changes the constant value used for discrimination as well.
Some possible solutions:
- Adding a field attribute for enum members (perhaps
tag,nameor evenref_variant, neither of which would collide withserde) - Deriving the name from an existing field attribute like
title(not my favorite, but would work) - Deriving more specific names for the member schemas by default (perhaps using the parent enum name and tag as a suffix, so something like
"MyEnumMyTagA","MyOtherEnumB"etc. based on the example below) - There's already a way to do this and I just haven't found it 😅
Here's a quick snippet for reproducing the issue:
fn main() {
#[derive(schemars::JsonSchema)]
#[schemars(_unstable_ref_variants, tag = "MyTag")]
enum MyEnum {
A { number: f32 },
B { other: MyOtherEnum },
}
#[derive(schemars::JsonSchema)]
#[schemars(_unstable_ref_variants)]
enum MyOtherEnum {
A { string: String },
B { bool: bool },
}
println!("{:#?}", schemars::schema_for!(MyEnum));
}I would be happy to try and work on a PR if you agree with the problem.
Metadata
Metadata
Assignees
Labels
No labels