Forum Discussion

cmu's avatar
cmu
New Contributor
5 years ago

smooth transition from swagger 2.0 to OAS 3.0

I have a couple of projects that use swagger-maven-plugin 3.1.5 to build the JSON file in swagger 2.0 format. And a customized script displays all the endpoints in the Swagger UI. Now I want to use the new features of OAS3.0. I was able to add the dependencies and I was able to use the new Annotations. For example, I replaced @ApiOperation with @Operation and used @Content and @Schema to define the endpoint. But those endpoints are not recognized by swagger-maven-plugin 3.1.5 which makes sense.

 

I am looking for ways to smoothly transition from swagger 2.0 to OAS 3.0? Any ideas of how I can achieve them with minimum code changes or config changes. 

3 Replies

    • cmu's avatar
      cmu
      New 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. 

       

      • in 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