Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

...

Div
classconfluenceTableSmall

Option

Type

Description

corsBooleanWhether 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.versionStringSwagger spec version. Is default 1.2.
base.path

 

StringRequired: To setup the base path where the REST services is available
api.versionStringThe version of the api. Is default 0.0.0.
api.pathStringTo setup the path where the API is available (eg /api-docs)
api.titleStringRequired. The title of the application.
api.descriptionStringRequired. A short description of the application.
api.termsOfServiceUrlStringA URL to the Terms of Service of the API.
api.contactStringAn email to be used for API-related correspondence.
api.licenseStringThe license name used for the API.
api.licenseUrlStringA 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=camel/trunk/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml}

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.TODO: rest example