Skip to content

Add support for enums of integers in rust-server generator. #22915

Open
dsteeley wants to merge 3 commits intoOpenAPITools:masterfrom
dsteeley:integer-enums
Open

Add support for enums of integers in rust-server generator. #22915
dsteeley wants to merge 3 commits intoOpenAPITools:masterfrom
dsteeley:integer-enums

Conversation

@dsteeley
Copy link
Contributor

@dsteeley dsteeley commented Feb 6, 2026

Support enums of integers in rust-server generator. Previously we treated all enum values as strings which in some cases may be incorrect and result in being unable to deserialise an integer enum value.

Elements in an enum array can be any time according to 5.20 of the json schema which the openapi specification inherits for enum types. https://datatracker.ietf.org/doc/html/[draft-wright-json-schema-validation-00](https://datatracker.ietf.org/doc/html/draft-wright-json-schema-validation-00#section-5.20)#section-5.20.

PR checklist

  • Read the contribution guidelines.
  • Pull Request title clearly describes the work in the pull request and Pull Request description provides details about how to validate the work. Missing information here may result in delayed response from the community.
  • Run the following to build the project and update samples:
    ./mvnw clean package || exit
    ./bin/generate-samples.sh ./bin/configs/*.yaml || exit
    ./bin/utils/export_docs_generators.sh || exit
    
    (For Windows users, please run the script in WSL)
    Commit all changed files.
    This is important, as CI jobs will verify all generator outputs of your HEAD commit as it would merge with master.
    These must match the expectations made by your contribution.
    You may regenerate an individual generator by passing the relevant config(s) as an argument to the script, for example ./bin/generate-samples.sh bin/configs/java*.
    IMPORTANT: Do NOT purge/delete any folders/files (e.g. tests) when regenerating the samples as manually written tests may be removed.
  • File the PR against the correct branch: master (upcoming 7.x.0 minor release - breaking changes with fallbacks), 8.0.x (breaking changes without fallbacks)
  • If your PR solves a reported issue, reference it using GitHub's linking syntax (e.g., having "fixes #123" present in the PR description)
  • If your PR is targeting a particular programming language, @mention the technical committee members, so they are more likely to review the pull request.

Summary by cubic

Add support for integer enums in the rust-server generator using serde_repr so they serialize/deserialize as JSON numbers. Also fixes header conversion impls in deprecated templates to work in client builds.

  • Bug Fixes
    • Detect integer enums and set vendor extensions with the correct Rust repr; include serde_repr in Cargo only when needed.
    • Update models.mustache to derive Serialize_repr/Deserialize_repr and apply #[repr()]; string enums keep existing serde behavior.
    • Expose Vec header TryFrom impls for both client and server in rust-server-deprecated templates.

Written for commit 171d779. Summary will update on new commits.

Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 3 files

@dsteeley dsteeley marked this pull request as draft February 6, 2026 17:16
@dsteeley dsteeley marked this pull request as ready for review February 9, 2026 10:32
Copy link
Contributor

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

6 issues found across 15 files

Prompt for AI agents (all issues)

Check if these issues are valid — if so, understand the root cause of each and fix them.


<file name="samples/server/petstore/rust-server/output/multipart-v3/src/models.rs">

<violation number="1" location="samples/server/petstore/rust-server/output/multipart-v3/src/models.rs:169">
P2: List header parsing now requires a comma+space delimiter, which rejects valid list headers without whitespace (e.g., "a,b") and can cause parsing failures. HTTP list headers allow optional whitespace around commas, so the split should accept commas regardless of spaces.</violation>
</file>

<file name="samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs">

<violation number="1" location="samples/server/petstore/rust-server/output/petstore-with-fake-endpoints-models-for-testing/src/models.rs:158">
P2: Header Vec parsing now splits only on the exact ", " delimiter, so valid comma-separated header values like "a,b" or "a,  b" are not parsed into elements. This is a regression from the previous `.split(',')` behavior and can cause deserialization errors for standard header formats.</violation>
</file>

<file name="samples/server/petstore/rust-server/output/rust-server-test/src/models.rs">

<violation number="1" location="samples/server/petstore/rust-server/output/rust-server-test/src/models.rs:165">
P2: Header list parsing now requires a comma+space delimiter. Valid HTTP header lists can be comma-separated without spaces ("a,b"), so .split(", ") will treat them as a single entry and can break parsing. Use ',' as the delimiter and keep trimming each element to accept both forms.</violation>
</file>

<file name="modules/openapi-generator/src/main/resources/rust-server/models.mustache">

<violation number="1" location="modules/openapi-generator/src/main/resources/rust-server/models.mustache:686">
P2: Header list parsing now only splits on comma+space, rejecting valid header values like "a,b" (HTTP lists allow optional whitespace). This will cause enum list headers without spaces to fail parsing. Split on ',' and trim instead.</violation>
</file>

<file name="samples/server/petstore/rust-server/output/no-example-v3/src/models.rs">

<violation number="1" location="samples/server/petstore/rust-server/output/no-example-v3/src/models.rs:149">
P2: Header list parser now only splits on comma+space, rejecting valid comma-separated headers without spaces.</violation>
</file>

<file name="samples/server/petstore/rust-server/output/openapi-v3/src/models.rs">

<violation number="1" location="samples/server/petstore/rust-server/output/openapi-v3/src/models.rs:121">
P2: List header parsing now splits on ", " only, so valid header values without a space after the comma (e.g., "a,b") won't be split into multiple items and can be parsed incorrectly. Use a comma-only split and rely on trim() to handle optional whitespace.</violation>
</file>

Reply with feedback, questions, or to request a fix. Tag @cubic-dev-ai to re-run a review.

@dsteeley dsteeley force-pushed the integer-enums branch 2 times, most recently from 27b2283 to d0b3492 Compare February 9, 2026 12:37
@dsteeley
Copy link
Contributor Author

dsteeley commented Feb 9, 2026

@wing328 This PR is ready for attention.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant