However, schemars doesn't support variant-level #[serde(untagged)] (https://github.com/GREsau/schemars/issues/222). One alternative is to break out the new options to a separate enum, like so:
#[derive(JsonSchema)]
enum BreakfastItem {
Spam,
Eggs,
}
// new, contains the variants that were otherwise exclusive to Breakfast
#[derive(JsonSchema)]
enum BreakfastMeal {
FullBreakfast,
}
#[derive(JsonSchema)]
// moved from the Item variant
#[serde(untagged)]
enum Breakfast {
Meal(BreakfastMeal),
Item(BreakfastItem),
}
Current and expected behavior
Sometimes you want to write an enum that adds more specific options to an otherwise generic enum. For example:
However, schemars doesn't support variant-level
#[serde(untagged)]
(https://github.com/GREsau/schemars/issues/222). One alternative is to break out the new options to a separate enum, like so:However, this generates the following schema:
which isn't structural.
Possible solution
The structuralizer should recognize that we can safely merge these
anyOf
variants, into:Additional context
No response
Environment
Client Version: v1.30.2 Kustomize Version: v5.0.4-0.20230601165947-6ce0bf390ce3 Server Version: v1.31.0+k3s1
Configuration and features
Affected crates
kube-core
Would you like to work on fixing this bug?
None