OpenAPITools / OpenAPITools/openapi-generator

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

Open
#22,353 1 comment 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
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?
  • 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

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 in the Java/Spring generator path that handles enum query parameters and reproduce the issue with integer or boolean enum values sent as strings. Confirm that generated code handles string input before enum conversion, then add or update a regression test for the described query-parameter case.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.