OpenAPITools / OpenAPITools/openapi-generator
x-field-extra-annotation: "@javax.validation.Valid" properties not working when generating JAVA file from YAML
Nobody has claimed this yet.
- Dominant language
- Java
- Stars
- 26.8k
- Forks
- 7.7k
- PR merge metrics
- PR metrics pending
Description
I have a requirement to generate @Valid annotation for all generated DTO files at field level based on my Spec.
Created spec as below.
AccountDetailsRequestBody:
type: object
additionalProperties: false
x-field-extra-annotation: "@javax.validation.Valid"
properties:
payload:
type: object
x-field-extra-annotation: "@javax.validation.Valid"
additionalProperties: false
properties:
accountDetail:
$ref: '#/components/schemas/AccountDetail'
but while generating JAVA DTO file using below command, its not generating this @Valid annotation at field level.
java -Dmodels -DmodelDocs=false -jar openapi-generator-cli.jar generate -i ./input/system-api/common/indicators.yaml -g spring -o output-model/system-api -t ./spring-boot-lombok-actuator -p useActuator=true,useLombok=true,actuatorPath=/actuator
tried with latest version as well such as 6.0.0 and 7.9.0
As confirmed by another thread, its implemented in 6.0.0 itself. but not working.
Main objective is to avoid adding @Valid annotation for all nested objects to perform schema validations for request body object.
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
Reproduce the Java generation using input/system-api/common/indicators.yaml, the spring generator, and the custom template directory ./spring-boot-lombok-actuator. Compare the generated DTOs across the reported versions and inspect whether the x-field-extra-annotation entries reach the field templates; done means the requested @Valid annotations appear at field level for the nested DTO properties.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java, spring
- Domain
- backend, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 30/100