Forum Discussion
cmu
7 years agoNew Contributor
Thank you. I am working on it. I need Swagger Hibernate Validations and looking for one in Maven repo, but I can't find one exact for io.swagger.core.v3 even though I searched in that group. Any idea where can I get this.
frantuma
Staff
7 years agoin v3 possibly the best option to process hibernate validation annotations (or any other/custom annotations) is to provide a custom resolver with the logic you need; here is an example handling e.g. Length annotation (extend it to apply to whatever annotations you need):
class CustomConverter extends ModelResolver {
public CustomConverter(ObjectMapper mapper) {
super(mapper);
}
@Override
protected void applyBeanValidatorAnnotations(Schema property, Annotation[] annotations, Schema parent) {
super.applyBeanValidatorAnnotations(property, annotations, parent);
Length lengthAnn = AnnotationsUtils.getAnnotation(Length.class, annotations);
if (lengthAnn != null) {
if (lengthAnn.min() != 0) property.setMinimum(new BigDecimal(lengthAnn.min()));
if (lengthAnn.max() < Integer.MAX_VALUE) property.setMaximum(new BigDecimal(lengthAnn.max()));
}
}
}
when using the maven plugin you can configure such custom converter using modelConverterClasses configuration property, setting it to fully qualified class name (e.g. foo.bar.CustomConverter). Please check also related wiki