...
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 1.2. |
base.path |
String |
Required: To setup the base path where the REST services is available |
api.version |
String |
The version of the api. Is default 0.0.0. |
api.path |
String |
To setup the path where the API is available (eg /api-docs) |
api.title |
String |
Required. The title of the application. |
api.description |
String |
Required. A short description of the application. |
api.termsOfServiceUrl |
String |
A URL to the Terms of Service of the API. |
api.contact |
String |
An email to be used for API-related correspondence. |
api.license |
String |
The license name used for the API. |
api.licenseUrl |
String |
A URL to the license used for the API. |
|
Examples
...
CorsFilter
If 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 org.apache.camel.component.swagger.RestSwaggerCorsFilter
to your web.xml.
Wiki Markup |
{snippet:id=e2|lang=xml|url="">
|
The CorsFilter sets the following headers for all requests
- Access-Control-Allow-Origin = *
- Access-Control-Allow-Methods = GET, HEAD, POST, PUT, DELETE, TRACE, OPTIONS, CONNECT, PATCH
- Access-Control-Max-Age = 3600
- Access-Control-Allow-Headers = Origin, Accept, X-Requested-With, Content-Type, Access-Control-Request-Method, Access-Control-Request-Headers
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.
Examples
In the Apache Camel distribution we ship the camel-example-servlet-rest-tomcat
which demonstrates using this Swagger component.