Add ConstraintValidator to DTO from dependency library generated by OpenApi

81 Views Asked by At

I have a dependency (API lib) with DTOs and Controller Interfaces generated by openApi.

In the micro-service code I add the lib and implement interfaces. Now I want to add custom validation.

The usual way is to add some annotation e.g. @ValidPerson, create ConstraintValidator, and put the annotation to a controller method.

But it's not possible because DTOs and Controller Interfaces are from library.

Can anyone suggest the solution?

I've tried adding annotation to DTO with x-... in openApi, but then I have to define a validation annotation and ConstraintValidator in the lib, but that's not the way because I'd like to have the code of ConstraintValidator in the micro-service code.

Also it can be resolved "manually" with HandlerInterceptor, but I still hope there is a solution with ConstraintValidator

0

There are 0 best solutions below