[BUG] [JAVA] Improve enum converter for query parameters of non-string types to handle string input
Bug Report Checklist
- [x] Have you provided a full/minimal spec to reproduce the issue?
- [x] Have you validated the input using an OpenAPI validator?
- [x] Have you tested with the latest master to confirm the issue still exists?
- [x] Have you searched for related issues/PRs?
- [x] 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
Hi, I’ve analyzed this behavior and I believe the core problem is that the generator assumes native enum types (int/boolean) rather than handling the fact that HTTP query params are always received as strings. The correct approach would be to intercept the string value first, convert it to the base type (Integer/Boolean), and then resolve the enum.
Example approach :
fromValue(String raw) { Integer parsed = Integer.valueOf(raw); return fromValue(parsed); }
or adding a preprocessing step before enum matching.
I’d be happy to help explore and contribute a fix for this. Could a maintainer guide me to the specific template / code segment where query-param enum handling occurs (possibly within beanValidationCore.mustache or related class converters)? I’d like to investigate further and provide a PR. Thanks!