javaswaggercxfopenapi

Migration from org.apache.cxf.jaxrs.swagger -> org.apache.cxf.jaxrs.openapi


After up Spring Boot to version 3 I try to migrate from Swagger to OpenAPI. Project depends on Apache CXF. How can I rewrite the swagger configuration?

It was before OpenApi:

@Configuration
public class SwaggerConfiguration {
@Bean
    public Swagger2Feature swagger2Feature() {
        Swagger2Feature swagger = new Swagger2Feature();
        swagger.setVersion(*version*);
        swagger.setBasePath(*basePath*);
        swagger.setPrettyPrint(true);
        swagger.setSchemes(new String[]{"https", "http"});
        swagger.setContact(*contact*);
        swagger.setDescription(*description*);
        swagger.setTitle(*title*);
        swagger.setSupportSwaggerUi(true);
        swagger.setHost(*host*);
        return swagger;
    }
}

I try just replace Swagger2Feature to OpenApiFeature but swagger ui does not open after it.

@Bean
    public OpenApiFeature openApiFeature() {
        OpenApiFeature openApi = new OpenApiFeature();
        openApi.setVersion(*version*);
        openApi.setPrettyPrint(true);
        openApi.setContactEmail(*email*);
        openApi.setDescription(*description*);
        openApi.setTitle(*title*);
        openApi.setSupportSwaggerUi(true);
        openApi.setSwaggerUiConfig(
            new SwaggerUiConfig()
                .url("/openapi.json"));
        return openApi;
    }

Solution

  • Solution: just replace @Path annotation from interface to impl. Jaxrs with openapi dont see controller if @Path annotation not on class.

    Example:

    Will not work:

        @Path(/some)
        interface ExampleController{}
        class ExampleControllerImpl implements ExampleController{}
    

    should work:

        interface ExampleController{}
        @Path(/some)
        class ExampleControllerImpl implements ExampleController{}