OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA] when using schemaMapping for models in collections, not compilable code with @Valid is generated
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
My Spec defines a compenent like this:
MyResponse:
required:
- myResponses
type: object
properties:
myResponses:
uniqueItems: true
type: array
default: []
items:
$ref: '#/components/schemas/MyResponseItem'
This results in a java Declaration like this:
@Valid
private Set<@Valid MyResponseItem> myResponses;
So far so good.
I need to use schemaMapping for MyResponseItem, e.g.
MyResponseItem=com.mycompany.MyResponseItem
(as MyResponseItem class need to be manually provided)
Now the generator generates non-compilable code:
@Valid
private Set<@Valid com.mycompan.MyResponseItem> myResponses;
as java (at least java17) only expects simle typenames after @Valid
openapi-generator version
7.2.0. But also happens with 7.1.0
OpenAPI declaration file content or url
see above
Generation Details
Steps to reproduce
see above
Related issues/PRs
Suggest a fix
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
Start with the Java generation path using the MyResponse schema and the MyResponseItem schemaMapping described in the issue. Reproduce the generated collection declaration, then compile it with Java 17; done means schema-mapped collection element types are emitted in compilable code while retaining the needed validation annotations.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 34/100