OpenAPITools / OpenAPITools/openapi-generator

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

Open
#23,450 0 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with the provided OpenAPI enum and run the rust-axum generator using the documented command. Inspect the generated LibType enum and verify JSON serialization and deserialization for numeric values. Done means integer enums use integer representations rather than string-based serde renames, with the generated output accepting values such as 1.

Written by the indexing model from the issue text.

Assessment

Tech stack
openapi, rust
Domain
api, tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Quiet
Clarity
Mostly clear
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.