OpenAPITools / OpenAPITools/openapi-generator
[BUG][JAVA][spring] Invalid annotations produced for collections with qualified types when useBeanValidation set
Nobody has claimed this yet.
- 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 (example)?
- 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 BeanValidation is used, the annotation @Valid is inserted in a way that produces invalid syntax when there are collections of a fully qualified type.
openapi-generator version
This issue is a regression and was first seen on 6.5.0. It is also present on 6.6.0-20230411.095613-12.
OpenAPI declaration file content or url
openapi: 3.0.2
info: { title: Sample, version: "1.0" }
components:
schemas:
Observation:
type: object
properties:
key: { type: string }
value: { type: integer }
required: [key, value]
Report:
type: object
properties:
observations:
type: array
items: { $ref: '#/components/schemas/Observation' }
required: [observations]
paths:
/reports:
post:
operationId: addReport
requestBody:
required: true
content:
application/json:
schema: { $ref: '#/components/schemas/Report' }
responses:
"204": { description: OK }
Generation Details
java -jar openapi-generator-cli.jar generate -i api.yaml -g spring --schema-mappings Observation=example.ObservationDTO
Steps to reproduce
See the generated src/main/java/org/openapitools/model/Report.java file.
Expected declaration:
List<example.@Valid ObservationDTO> observations
Actual declaration:
List<@Valid example.ObservationDTO> observations
Related issues/PRs
Introduced in #14736.
Suggest a fix
Instead of a simple replace operation, use a regular expression in SpringCodegen::replaceBeanValidationCollectionType
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Inspect SpringCodegen::replaceBeanValidationCollectionType and the generation path for the generated Report.java file. Reproduce the issue with the supplied OpenAPI declaration and schema mapping. Done when qualified collection element types receive valid @Valid annotation syntax without breaking ordinary collection types.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100