Skip to content

[BUG] [JAVA] Improve enum converter for query parameters of non-string types to handle string input #22353

@dcardoso25

Description

@dcardoso25

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?
  • What's the actual output vs expected output?
  • [Optional] Sponsorship to speed up the bug fix or feature request (example)
Description

When defining a query parameter in OpenAPI with type integer or boolean and an enum restriction, the generated code creates converters that expect the native type (int or boolean) directly. However, since query parameters are always transmitted as strings in HTTP requests, this leads to conversion failures.

For example, a spec like:

parameters:  
  - name: status  
    in: query  
    schema:  
      type: integer  
      enum: [0, 1, 2]  

generates a converter that doesn't account for parsing the incoming string ("0") to the enum value.

Suggestion: Update the generator to include string-to-type conversion in the enum handling for query params, ensuring it first parses the string to the base type before mapping to the enum. This would make the generated code more reliable out-of-the-box.
Tested with Java/Spring

openapi-generator version

7.13.0

OpenAPI declaration file content or url
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions