When using case-enums-any feature the generated JSON Schema only allows a single style of variant.
This is a known issue in schemars library:
GREsau/schemars#338
Minimal test:
#[test]
fn x() {
#[derive(serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
enum EnumStr {
#[serde(alias = "Bar")]
Foo,
}
let schema = schemars::schema_for!(EnumStr);
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
#[derive(serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
#[serde(tag = "kind")]
enum EnumUnnamed {
#[serde(alias = "Bar")]
Foo(Foo),
}
#[derive(serde::Deserialize, serde::Serialize, schemars::JsonSchema)]
struct Foo {
a: u32,
}
let schema = schemars::schema_for!(EnumUnnamed);
println!("{}", serde_json::to_string_pretty(&schema).unwrap());
}
Outputs:
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "EnumStr",
"type": "string",
"enum": [
"Foo"
]
}
{
"$schema": "https://json-schema.org/draft/2020-12/schema",
"title": "EnumUnnamed",
"oneOf": [
{
"type": "object",
"properties": {
"kind": {
"type": "string",
"const": "Foo"
}
},
"$ref": "#/$defs/Foo",
"required": [
"kind"
]
}
],
"$defs": {
"Foo": {
"type": "object",
"properties": {
"a": {
"type": "integer",
"format": "uint32",
"minimum": 0
}
},
"required": [
"a"
]
}
}
}
When using
case-enums-anyfeature the generated JSON Schema only allows a single style of variant.This is a known issue in
schemarslibrary:GREsau/schemars#338
Minimal test:
Outputs:
{ "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "EnumStr", "type": "string", "enum": [ "Foo" ] }{ "$schema": "https://json-schema.org/draft/2020-12/schema", "title": "EnumUnnamed", "oneOf": [ { "type": "object", "properties": { "kind": { "type": "string", "const": "Foo" } }, "$ref": "#/$defs/Foo", "required": [ "kind" ] } ], "$defs": { "Foo": { "type": "object", "properties": { "a": { "type": "integer", "format": "uint32", "minimum": 0 } }, "required": [ "a" ] } } }