-
-
Notifications
You must be signed in to change notification settings - Fork 237
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
Support enum variant aliases #25
Comments
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?
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>(); |
Closing in favour of #48 |
Reopening, because the general mechanism for separate serialize/deserialize schemas is done in alpha.15, but |
Received via email
https://serde.rs/variant-attrs.html#alias
The text was updated successfully, but these errors were encountered: