concept Swagger in category camel

This is an excerpt from Manning's book Camel in Action.
Swagger is both a specification and framework for describing, producing, consuming, and visualizing RESTful services. Applications written with the Swagger framework contain full documentation of methods, parameters, and models directly in the source code. This ensures that the implementation and documentation of RESTful services are always in sync.
In 2016, the Swagger specification was renamed the OpenAPI specification and governed by its founding group under the Linux Foundation. In this chapter, we use the popular term Swagger instead of OpenAPI.
Adding Swagger to a CXF application
To use Swagger with CXF, you need to create a
Swagger2Featureand configure it. This can be done in a JAX-RS application class, as shown in the following listing.Listing 10.17 Using a JAX-RS application to set up a REST service with Swagger
@ApplicationPath("/") public class RestOrderApplication extends Application { #1 private final RestOrderService orderService; public RestOrderApplication(RestOrderService orderService) { this.orderService = orderService; } @Override public Set<Object> getSingletons() { Swagger2Feature swagger = new Swagger2Feature(); #2 swagger.setBasePath("/"); #2 swagger.setHost("localhost:9000"); #2 swagger.setTitle("Order Service"); #2 swagger.setDescription("Rider Auto Parts Order Service"); #2 swagger.setVersion("2.0.0"); #2 swagger.setContact("rider@autoparts.com"); #2 swagger.setPrettyPrint(true); #2 Set<Object> answer = new HashSet<>(); #3 answer.add(orderService); #3 answer.add(new JacksonJsonProvider()); #3 answer.add(swagger); #3 answer.add(new LoggingFeature()); #3 return answer; } } #1 JAX-RS Application class #2 Configures Swagger feature in CXF #3 Provides a set of features to use with CXFJAX-RS allows you to set up your JAX-RS RESTful services using your own class implementation that must extend
javax.ws.rs.core.Application. You can see this in listing 10.17, where you create theRestOrderApplicationclass ❶. In thegetSingletonsmethod, you can set up the services that the RESTful application should use. To use Swagger with CXF, you need to create and configure an instance ofSwagger2Feature❷. Then you configure the Rider Auto PartsorderServiceimplementation, Jackson for JSON support, and Swagger, and then you enable logging by using theLoggingFeature❸.