Fuse 6 is no longer supported
As of February 2025, Red Hat Fuse 6 is no longer supported. If you are using Fuse 6, please upgrade to Red Hat build of Apache Camel.Este conteúdo não está disponível no idioma selecionado.
4.5. Swagger Integration
Overview Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
Integrated with the REST DSL, the
camel-swagger component enables users to create API docs for any REST-defined routes and endpoints in a CamelContext file. The camel-swagger component creates a servlet integrated with the CamelContext that pulls the information from each REST endpoint to generate the API docs (JSON file).
If using Maven, you need to add the
camel-swagger component to your pom.xml file:
Configuring the camelContext Copiar o linkLink copiado para a área de transferência!
Copiar o linkLink copiado para a área de transferência!
To enable Swagger, add to the CamelContext file:
- The
serviceelement, which exposes the camel-swagger servlet and initializes its parameters.In the service element, add the servlet (org.apache.camel.component.swagger.DefaultCamelSwaggerServlet) and theservice-propertiesthat configure the servlet's parameters.For details on servlet parameters, see chapter "Swagger" in "Apache Camel Component Reference". - Configure the REST implementationDefine the REST service within the
camelContextelement using therestConfigurationandrestelements.For details on configuring REST services in the CamelContext, see Section 4.2, “Defining Services with REST DSL”.
For OSGi deployments, you need to configure the servlet options
and REST configuration in the
blueprint.xml file; for example:
The following parameters are used in the above example as described here:
-
service - The
serviceelement exposes the camel swagger servlet (<bean class="org.apache.camel.component.swagger.DefaultCamelSwaggerServlet"/>) and initializes several servlet properties. -
alias - The
aliasproperty binds the camel swagger servlet to/api-docs/*. -
init-prefix - The
init-prefixproperty sets the prefix for all camel swagger servlet properties toinit.. This is analogous to usinginit-paramelements in theweb.xmlconfiguration for WAR implementations (see chapter "Swagger" in "Apache Camel Component Reference"). -
restConfiguration - In the
camelContextelement, therestConfigurationelement specifies the REST implementation to use. In this case, it is Jetty web servlet on port 8080. -
rest - In the
camelContextelement, therestelement defines a REST service and provides the base path (/say) to it. In this case, the service consists of two REST endpoints,helloandbye, which are routed to their corresponding camel endpoints defined in therouteelements.