Reputation: 1437
I am using Openapi generator(5.4.0), with spring (generator name) and gradle, I am trying to add an import to a generated model.
For the particular field in the api spec, I have added:
x-field-extra-annotation: "@com.fasterxml.jackson.annotation.JsonFormat ...."
This works, however I dont want to fully qualify it, and have the com.fasterxml.jackson.annotation.JsonFormat import added.
I tried adding typeMappings to genratedCode task, but that doesn't work.
importMappings = [
'JsonFormat' : 'com.fasterxml.jackson.annotation.JsonFormat'
]
Update: I can add model.mustache template to project, and add the import. ie
{{#useBeanValidation}}
...
import com.fasterxml.jackson.annotation.JsonFormat;
...
{{/useBeanValidation}}
Any ideas? Better ways. Thanks.
Upvotes: 4
Views: 7031
Reputation: 1
There is no production-ready solution (yet!) If you are not starving for this feature, wait for acceptance of related issue and PR to one of the nearest releases. https://github.com/OpenAPITools/openapi-generator/issues/13938 It will allow required customizations using x-spring-constraint: @MyAnnotation(value = 1, message = "nice") (or x-java-constraint) extension with configOption customValidationAnnotationsPackages="my.custom.package.MyAnnotaion;my.other.package.*"
Else, refer to https://bartko-mat.medium.com/openapi-generator-to-spring-boot-with-custom-java-validations-623381df9215 as tutorial for handmade solution
Upvotes: 0