...
The Rest DSL can be integrated with the camel-swagger-java
module which is used for exposing the REST services and their APIs using Swagger.
Maven users will need to add the following dependency to their pom.xml
for this component:
...
Div |
---|
class | confluenceTableSmall |
---|
|
Option | Type | Description |
---|
cors | Boolean | Whether to enable CORS. Notice this only enables CORS for the api browser, and not the actual access to the REST services. Is default false. Instead of using this option is recommended to use the CorsFilte, see further below. | swagger.version | String | Swagger spec version. Is default 2.0. | host | String | To setup the hostname. If not configured camel-swagger-java will calculate the name as localhost based. | schemas | String | The protocol schemes to use. Multiple values can be separated by comma such as "http,https". The default value is "http". This option is deprecated from Camel 2.17 onwards due it should have been named schemes. | schemes | String | Camel 2.17: The protocol schemes schemas to use. Multiple values can be separated by comma such as "http,https". The default value is "http". | base.path | String | Required: To setup the base path where the REST services is available. The path is relative (eg do not start with http/https) and camel-swagger-java will calculate the absolute base path at runtime, which will be Code Block |
---|
protocol://host:port/context-path/base.path |
| api.path | String | To setup the path where the API is available (eg /api-docs). The path is relative (eg do not start with http/https) and camel-swagger-java will calculate the absolute base path at runtime, which will be Code Block |
---|
protocol://host:port/context-path/api.path |
So using relative paths is much easier. See above for an example. | api.version | String | The version of the api. Is default 0.0.0. | api.title | String | The title of the application. | api.description | String | A short description of the application. | api.termsOfService | String | A URL to the Terms of Service of the API. | api.contact.name | String | Name of person or organization to contact | api.contact.email | String | An email to be used for API-related correspondence. | api.contact.url | String | A URL to a website for more contact information. | api.license.name | String | The license name used for the API. | api.license.url | String | A URL to the license used for the API. | apiContextIdListing | boolean | Whether to allow listing all the CamelContext names in the JVM that has REST services. When enabled then the root path of the api-doc will list all the contexts. When disabled then no context ids is listed and the root path of the api-doc lists the current CamelContext. Is default false. | apiContextIdPattern | String | A pattern that allows to filter which CamelContext names is shown in the context listing. The pattern is using regular expression and * as wildcard. Its the same pattern matching as used by Intercept |
|
...
Code Block |
---|
<!-- 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.swagger.restservlet.RestSwaggerCorsFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>RestSwaggerCorsFilter</filter-name>
<url-pattern>/api-docs/*</url-pattern>
<url-pattern>/rest/*</url-pattern>
</filter-mapping> |
...
When contextIdListing is enabled then its 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`. The option apiContextIdPattern can be used to filter the names in this list.
JSon or Yaml
Available as of Camel 2.17
The camel-swagger-java module supports both JSon and Yaml out of the box. You can specify in the request url what you want returned by using /swagger.json or /swagger.yaml for either one. If none is specified then the HTTP Accept header is used to detect if json or yaml can be accepted. If either both is accepted or none was set as accepted then json is returned as the default format.
Examples
In the Apache Camel distribution we ship the camel-example-swagger-cdi
and camel-example-swagger-java
which a number of Swagger examples which demonstrates using this Swagger component.
...