Skip to content

Mixing #[serde(tag = ...)] and #[repr] on an enum leads to invalid OpenAPI output #1584

Description

@fnimick

Example enum:

#[derive(Deserialize_repr, Serialize_repr)]
#[serde(tag = "tag")]
#[repr(u8)]
enum TaggedEnum {
    One = 0,
    Two,
    Three,
}

This generates the following OpenAPI schema:

{
  "oneOf": [
    {
      "properties": {
        "tag": {
          "enum": [
            0
          ],
          "type": "integer"
        }
      },
      "required": [
        "tag"
      ],
      "type": "object"
    },
    {
      "properties": {
        "tag": {
          "enum": [
            1
          ],
          "type": "integer"
        }
      },
      "required": [
        "tag"
      ],
      "type": "object"
    },
    {
      "properties": {
        "tag": {
          "enum": [
            2
          ],
          "type": "integer"
        }
      },
      "required": [
        "tag"
      ],
      "type": "object"
    }
  ]
}

This implies that serialization results should have the shape of {"tag": 0} etc, but it actually serializes to a plain number.

See the failing tests in #1583

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