OpenAPITools / OpenAPITools/openapi-generator
[BUG] [JAVA] "cannot find symbol" syntax error involving @Valid (useBeanValidation) in case of fully qualified type reference
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?
Description
Related to the change introduced by [4947][java]: adds support for validation of primitives in arrays, this schema snippet
"errors": {
"type": "array",
"items": { "$ref": "#/components/schemas/ProblemDetail" }
}
using this config
<schemaMappings>ProblemDetail=org.springframework.http.ProblemDetail</schemaMappings>
now generates invalid Java syntax:
private List<@Valid org.springframework.http.ProblemDetail> errors;
According to the JLS this should read:
private List<org.springframework.http.@Valid ProblemDetail> errors;
Of course it could be configured using
<schemaMappings>ProblemDetail=org.springframework.http.@Valid ProblemDetail</schemaMappings>
but getBeanValidation(items) in line 934 of AbstractJavaCodegen would have to return an empty string in this case to support it.
A work-around is possible by giving object as item type
"errors": {
"type": "array",
"items": { "type": "object", "$ref": "#/components/schemas/ProblemDetail" }
}
edit: this breaks validation ("Illegal schema found with $ref combined with other properties, no properties should be defined alongside a $ref")
openapi-generator version
7.2.0
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 in modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/AbstractJavaCodegen.java at the getBeanValidation(items) logic around line 934. Reproduce the issue with the schemaMappings entry and array of ProblemDetail, then inspect the generated field. Done means the generated Java uses the valid annotation placement shown in the report without requiring the invalid workaround.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, openapi
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 42/100