OpenAPITools / OpenAPITools/openapi-generator

[JavaSpring] Bean Validation with Optional data type

Open
#4,221 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

When generating code from a .yaml file using bean validation, e.g. maxLength=5, and with useOptional set true the generated code results in @Size(max=5) Optional<String> parameter instead of Optional<@Size(max=5) String> parameter.

openapi-generator version

4.1.3

OpenAPI declaration file content or url

api.yaml

Command line used for generation

openapi-generator generate -g spring -i api.yaml --additional-properties=useOptional=true

Steps to reproduce

Generate files by using command line command. The described problem is found in generated ThingsApi.java

Suggest a fix/enhancement

Changes in the corresponding queryParams.mustache.

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 corresponding queryParams.mustache template and reproduce the issue using api.yaml and the documented openapi-generator command with useOptional=true. Inspect the generated ThingsApi.java; done means the validation annotation is placed inside Optional rather than on Optional itself, matching the expected generated parameter type.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, openapi, spring
Domain
api, backend
Issue type
Bug
Difficulty
2/5
Estimated time
1-3 hours
Activity status
Stale
Clarity
Clearly specified
Newbie friendliness
52/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.