Versions Compared

Key

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

...

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:

...

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.

...