cancel
Showing results for 
Search instead for 
Did you mean: 

smooth transition from swagger 2.0 to OAS 3.0

Highlighted
cmu
New Contributor

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 3
Staff

Re: smooth transition from swagger 2.0 to OAS 3.0

OAS 3.0 is supported by `swagger-api` `swagger-maven-plugin` (latest release `2.0.8`), please check https://github.com/swagger-api/swagger-core/tree/master/modules/swagger-maven-plugin and related projects (wiki)

 

cmu
New Contributor

Re: smooth transition from swagger 2.0 to OAS 3.0

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. 

 

Staff

Re: smooth transition from swagger 2.0 to OAS 3.0

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

New Here?
Join us and watch the welcome video:
API Testing Mistake #2
APITestingMistake#2
Top Kudoed Authors