Forum Discussion

shosei's avatar
Frequent Visitor
5 years ago

Support validation groups when reading Java annotations

I've got a Java Spring Boot project using swagger core v3 version 2.1.1 and springdoc openapi core version 1.1.49.  We're using swagger annotations on our POJOs to generate our documentation, which is very useful - each field has a @Schema annotation, and swagger automatically reads the validation annotations (@NotNull, @Size, etc) to incorporate them into the documentation.  


My question deals with those validation annotations.  In some cases, we're using validation groups (eg, @NotNull(groups = Create.class) ) to enable/disable annotations based on which endpoint is being used (eg, a field required to be Not Null on a POST might be allowed to be null on a PATCH.)  Is there a way to get swagger to automatically detect those differences and populate them to the documentation?  Currently, it's just reading the annotations and ignoring the validation groups.  In the alternative, is it possible to override the automatically-detected annotations in-code?

EDIT: The other use case we're hitting is trying to make certain fields hidden for some endpoints, but not for others.  Is there a way to update the default implementation schema in that way?

No RepliesBe the first to reply