Versions Compared

Key

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

...

To use this you need to configure the org.apache.camel.component.swagger.RestSwaggerApiDeclarationServlet in the WEB-INF/web.xml file as shown below:

Wiki Markup
{snippet:id=e1|lang=xml|url=camel/trunk/examples/camel-example-servlet-rest-tomcat/src/main/webapp/WEB-INF/web.xml}  <!-- to setup Camel Swagger api servlet -->
  <servlet>
    <servlet-name>ApiDeclarationServlet</servlet-name>
    <servlet-class>org.apache.camel.component.swagger.RestSwaggerApiDeclarationServlet</servlet-class>
    <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>
    <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>

Options

The org.apache.camel.component.swagger.RestSwaggerApiDeclarationServlet supports the following options which can be configured as context-param in the web.xml file.

...

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}  <!-- 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

...