Skip to content

Allow #[serde] attributes even if not deriving Serialize/Deserialize #1471

@zackyancey

Description

@zackyancey

When working with untagged enums, I often derive Serialize/Deserialize manually, because serde's default error reporting for untagged enums can be very vague. However, since they still behave just like untagged enums, I'd like to be able to derive ToSchema on them. In short, I'd like this to work:

#[derive(ToSchema)]
#[serde(untagged)]
pub enum MyEnum {
    A(String),
    B(u64),
}

impl<'de> Deserialize<'de> for MyEnum {
    // Manual Deserialize implementation...
}
impl Serialize for MyEnum {
    // Manual Serialize implementation...
}

The only reason this gets rejected is because serde isn't listed as one of the helpers for ToSchema (which it is, since ToSchema looks at serde tags). It should be an easy and non-breaking change, I can make a PR for it.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions