Since we're on a major migration process of this website, some component documents here are out of sync right now. In the meantime you may want to look at the early version of the new website
https://camel.apache.org/staging/
We would very much like to receive any feedback on the new site, please join the discussion on the Camel user mailing list.
Swagger Scala Component (deprecated)Available as of Camel 2.14 The Rest DSL can be integrated with the Maven users will need to add the following dependency to their This component is deprecated. From Camel 2.16 onwards use the new Java based swagger module Swagger Java The Scala based camel-swagger module is deprecated, and to be removed in a future release. <dependency> <groupId>org.apache.camel</groupId> <artifactId>camel-swagger</artifactId> <version>x.x.x</version> <!-- use the same version as your Camel core version --> </dependency> Using with Camel 2.15.xThe default servlet supports any environment using JMX to discover the CamelContext(s) to use. The name of the servlet is Using with Camel 2.14.xThe Swagger servlet is integrated with Spring or ServletListener Component.
The servlet support the same options when using spring or servletlistener. The servlets above from Camel 2.14.x is deprecated and replaced with a single default servlet from Camel 2.15 onwards.
For example when using Spring you need to configure the If you use Camel 2.15 onwards then just use the default servlet in any kind of environment. <!-- to setup Camel Swagger api servlet when using Spring --> <servlet> <!-- Camel 2.14.x --> <servlet-name>ApiDeclarationServlet</servlet-name> <servlet-class>org.apache.camel.component.swagger.spring.SpringRestSwaggerApiDeclarationServlet</servlet-class> <!-- Camel 2.15 onwards --> <servlet-name>ApiDeclarationServlet</servlet-name> <servlet-class>org.apache.camel.component.swagger.DefaultCamelSwaggerServlet</servlet-class> <!-- Camel 2.14.x --> <init-param> <param-name>base.path</param-name> <param-value>http://localhost:8080/rest</param-value> </init-param> <init-param> <param-name>api.path</param-name> <param-value>http://localhost:8080/api-docs</param-value> </init-param> <!-- Camel 2.15 onwards --> <init-param> <!-- we specify the base.path using relative notation, that means the actual path will be calculated at runtime as http://server:port/contextpath/rest --> <param-name>base.path</param-name> <param-value>rest</param-value> </init-param> <init-param> <!-- we specify the api.path using relative notation, that means the actual path will be calculated at runtime as http://server:port/contextpath/api-docs --> <param-name>api.path</param-name> <param-value>api-docs</param-value> </init-param> <init-param> <param-name>api.version</param-name> <param-value>1.2.3</param-value> </init-param> <init-param> <param-name>api.title</param-name> <param-value>User Services</param-value> </init-param> <init-param> <param-name>api.description</param-name> <param-value>Camel Rest Example with Swagger that provides an User REST service</param-value> </init-param> <load-on-startup>2</load-on-startup> </servlet> <!-- swagger api declaration --> <servlet-mapping> <servlet-name>ApiDeclarationServlet</servlet-name> <url-pattern>/api-docs/*</url-pattern> </servlet-mapping> OptionsThe
CorsFilterIf you use the swagger ui to view the REST api then you likely need to enable support for CORS. This is needed if the swagger ui is hosted and running on another hostname/port than the actual REST apis. When doing this the swagger ui needs to be allowed to access the REST resources across the origin (CORS). The CorsFilter adds the necessary HTTP headers to enable CORS. To use CORS adds the following filter <!-- enable CORS filter so people can use swagger ui to browse and test the apis --> <filter> <filter-name>RestSwaggerCorsFilter</filter-name> <filter-class>org.apache.camel.component.swagger.RestSwaggerCorsFilter</filter-class> </filter> <filter-mapping> <filter-name>RestSwaggerCorsFilter</filter-name> <url-pattern>/api-docs/*</url-pattern> <url-pattern>/rest/*</url-pattern> </filter-mapping> The CorsFilter sets the following headers for all requests
Notice this is a very simple CORS filter. You may need to use a more sophisticated filter to set the header values differently for a given client. Or block certain clients etc. Multiple CamelContextsAvailable as of Camel 2.16 When using camel-swagger from Camel 2.16 onwards then it supports detecting all the running CamelContexts in the same JVM. These contexts are listed in the root path, eg `/api-docs` as a simple list of names in json format. To access the swagger documentation then the context-path must be appended with the Camel context id, such as `api-docs/myCamel`. ExamplesIn the Apache Camel distribution we ship the See Also
|