Skip to content

rust-axum: Integer enums generate string-based serde(rename) instead of integer serialization #23450

@dc-codes426

Description

@dc-codes426

Bug Report Checklist

  • Have you provided a full/minimal spec to reproduce the issue?
  • Have you validated the input using an OpenAPI validator?
  • Have you tested with the latest master to confirm the issue still exists?
  • Have you searched for related issues/PRs?

Description

The rust-axum generator renders integer enums with string-based #[serde(rename = "0")] attributes instead of integer representations. This causes deserialization to fail when clients send spec-correct integer values (e.g., lib_type: 1 instead of "1").

OpenAPI declaration

LibType:
  type: integer
  description: TSS library/protocol type
  enum: [0, 1, 2]
  x-enum-varnames: [GG20, DKLS, KeyImport]

Expected generated code

An enum that serializes/deserializes as integers, e.g. using serde_repr:

#[repr(i32)]
#[derive(serde_repr::Serialize_repr, serde_repr::Deserialize_repr)]
pub enum LibType {
    GG20 = 0,
    DKLS = 1,
    KeyImport = 2,
}

Actual generated code

#[derive(serde::Serialize, serde::Deserialize)]
pub enum LibType {
    #[serde(rename = "0")]
    GG20,
    #[serde(rename = "1")]
    DKLS,
    #[serde(rename = "2")]
    KeyImport,
}

LibType::DKLS serializes as "1" (JSON string) instead of 1 (JSON number). Deserializing {"lib_type": 1} fails with a type mismatch error.

Generation details

  • Generator: rust-axum
  • Version: 7.20.0 (also reproducible on 7.21.0)
  • Command: npx @openapitools/openapi-generator-cli generate -i spec.yaml -g rust-axum -o output/

Workaround

Post-generation script that regex-replaces the generated enum blocks with serde_repr-based versions. Fragile but functional.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions