-
Notifications
You must be signed in to change notification settings - Fork 70
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merge oneOf with many compatible enums of a single value #497
Comments
Thanks for filing this. Today we get something like this: pub enum Thing {
Variant0(ThingVariant0),
Variant1(ThingVariant1),
}
pub enum ThingVariant0 {
A,
}
pub enum ThingVariant1 {
B,
} Awful! The good news is that a bunch of recent refactoring has been oriented around addressing precisely this kind of weirdness. In particular, my plan is to do a "simplification" or "canonicalization" pass in the As another example: typify/typify/tests/schemas/merged-schemas.rs Lines 904 to 919 in 1f97f16
There's no reason this shouldn't be an externally tagged variant: pub enum WeirdEnum {
#[serde(rename = "pattern")]
Pattern(String),
#[serde(rename = "patterns")]
Patterns(String),
#[serde(rename = "pattern-either")]
PatternEither(String),
#[serde(rename = "pattern-regex")]
PatternRegex(String),
} |
On closer inspection, there are two slightly different issues. The first is that the type of your schema is A more obvious error from typify is that it requires the subschemas to have |
Sorry the 'object' bit was my mistake. OAI/OpenAPI-Specification#348 (comment) says to use |
I was just observing that this is another gap in typify's logic--it should either register some sort of error saying that this type is unsatisfiable or produce some sort of |
OAI/OpenAPI-Specification#348 (comment) is apparently the best way to describe enum values, like
Typify generates a bunch of variants for the above, when they could be collapsed into a single Rust enum.
The text was updated successfully, but these errors were encountered: