0

Validator

@Documented
@Target({TYPE, ANNOTATION_TYPE})
@Retention(RUNTIME)
@Constraint(validatedBy = MyValidator.class)
public @interface MyAnnotation {

Swagger:

 MyDTO:
    type:object
    x-constraints: '@MyAnnotation'
    ...
    properties:
    ...

This is how I defined the annotation and the swagger. I noticed that the DTO is generated, but the annotation is not part of the generated class. I expect this annotation to be present there. Is there something wrong?

Florin
  • 43
  • 4
  • 1
    The swagger-codegen will not add the annotation for you, you need to edit the mustache template of the generator to add it based on your custom x-constraints value, see: https://stackoverflow.com/questions/57727892/how-to-inject-custom-spring-validation-inside-swagger-codegen – Cλstor Aug 24 '21 at 14:18
  • I already changed the mustache template and it is working fine when I am using the validator with a field. What I want to achieve now is to use the validator for a type - to have the annotation on top of the class, not on a get/constructor/field.. – Florin Aug 24 '21 at 14:43

0 Answers0