Open GREsau opened 4 years ago
Since aliases are only signifcant when deserializing, this is a case where the schema would be different depending on whether it represents the contract for serialization or deserialization, so I'm not sure what the best way to handle this is.
e.g. consider this enum with an aliased variant:
#[derive(Serialize, Deserialize, JsonSchema)]
enum MyEnum {
#[serde(alias = "MyAlias")]
MyVariant1,
MyVariant2,
}
What should the schema for MyEnum be?
{"enum": ["MyVariant1","MyAlias","MyVariant2"]}
{"enum": ["MyVariant1","MyVariant2"]}
This could also be configurable, either by an attribute e.g.:
#[derive(Serialize, Deserialize, JsonSchema)]
#[schemars(include_aliases)]
enum MyEnum {
#[serde(alias = "MyAlias")]
MyVariant1,
MyVariant2,
}
...or by adding a new schema setting e.g.:
let settings = SchemaSettings::draft07().with(|s| {
s.variant_aliases = Aliases::Include // or Aliases::Ignore
});
let schema = settings.into_generator().into_root_schema_for::<MyEnum>();
@GREsau what would you prefer concerning the deserialize vs. serialize problematic? I have only the deserialize case and would benefit greatly by having this implemented and would therefor be willing to tackle this (in #136) there is already an initial implementation of just the aliasing.
Closing in favour of https://github.com/GREsau/schemars/issues/48
Reopening, because the general mechanism for separate serialize/deserialize schemas is done in alpha.15, but alias
attributes are not yet respected
Received via email
https://serde.rs/variant-attrs.html#alias