Camel Spring Boot

REST OpenApi

Call the operations of a REST API described by an OpenAPI 3.x specification, or serve the operations of a specification by routing each request to the route of its operationId.

What’s inside

Please refer to the above links for usage and configuration details.

Maven coordinates

<dependency>
    <groupId>org.apache.camel.springboot</groupId>
    <artifactId>camel-rest-openapi-starter</artifactId>
</dependency>

Spring Boot Auto-Configuration

The starter supports 23 options, which are listed below.

Name Description Default Type

camel.component.rest-openapi.api-context-path

The path, under the base path, where the consumer serves the specification document as it is (Content-Type application/json, or text/yaml for a .yaml or .yml file), for example api-doc. The document is not served when not set.

String

camel.component.rest-openapi.autowired-enabled

Whether autowiring is enabled. This is used for automatic autowiring options (the option must be marked as autowired) by looking up in the registry to find if there is a single instance of matching type, which then gets configured on the component. This can be used for automatic configuring JDBC data sources, JMS connection factories, AWS Clients, etc.

true

Boolean

camel.component.rest-openapi.base-path

The base path of the API, for example /v3: the producer puts it before the path of the operation, and the consumer serves the operations under it. When not set: the context path of the REST configuration, then the path of the servers URL in the specification, then /.

String

camel.component.rest-openapi.binding-package-scan

Package names, separated by comma, to scan for the POJO classes the consumer binds the request and response bodies to when the REST configuration has a binding mode: the class whose simple name is the schema name (or title) of a JSON content, or the xml name of an XML content, of the operation. When not set: the bindingPackageScan of the REST configuration, then the base package scan of the CamelContext.

String

camel.component.rest-openapi.bridge-error-handler

Allows for bridging the consumer to the Camel routing Error Handler, which mean any exceptions (if possible) occurred while the Camel consumer is trying to pickup incoming messages, or the likes, will now be processed as a message and handled by the routing Error Handler. Important: This is only possible if the 3rd party component allows Camel to be alerted if an exception was thrown. Some components handle this internally only, and therefore bridgeErrorHandler is not possible. In other situations we may improve the Camel component to hook into the 3rd party component and make this possible for future releases. By default the consumer will use the org.apache.camel.spi.ExceptionHandler to deal with exceptions, that will be logged at WARN or ERROR level and ignored.

false

Boolean

camel.component.rest-openapi.client-request-validation

Whether the consumer checks each request against its operation in the specification: the Content-Type header against the requestBody content types (else HTTP 415), the Accept header against the response content types (406), the required query parameters, headers and request body (400), and that a JSON body parses (400). The body is not validated against its schema. The clientRequestValidation option of the REST configuration turns it on too.

false

Boolean

camel.component.rest-openapi.client-response-validation

Whether the consumer checks the response of the route: a body with a JSON Content-Type that does not parse is answered with HTTP 500. The response Content-Type and headers are not checked against the specification. The clientResponseValidation option of the REST configuration turns it on too.

false

Boolean

camel.component.rest-openapi.component-name

Name of the component that sends the HTTP requests of the producer, which must implement RestProducerFactory, such as http, vertx-http, undertow or netty-http; it is looked up in the registry, then as a component. When not set: the producerComponent of the REST configuration, then the first component in the CamelContext that implements RestProducerFactory, then the only RestProducerFactory in the registry, then the first of http, vertx-http, undertow and netty-http on the classpath.

String

camel.component.rest-openapi.consumer-component-name

Name of the component that receives the HTTP requests of the consumer, which must implement RestOpenApiConsumerFactory, such as platform-http; it is looked up in the registry, then as a component. When not set: the first component in the CamelContext that implements RestOpenApiConsumerFactory, then platform-http if it is on the classpath, then the only RestOpenApiConsumerFactory in the registry.

String

camel.component.rest-openapi.consumes

The media types the producer accepts in the response, which it sets as the Accept header when the message has none, such as application/json or application/json, application/xml;q=0.5 (RFC 7231). When not set: the content types of the responses of the operation in the specification. The consumer does not use it.

String

camel.component.rest-openapi.enabled

Whether to enable auto configuration of the rest-openapi component. This is enabled by default.

Boolean

camel.component.rest-openapi.external-references

Which external references ($ref) the OpenAPI specification may use: all allows any reference, local allows references to the classpath and the file system only, and none allows only references inside the document. A reference the option does not allow fails the start. Can be overridden in endpoint configuration.

all

String

camel.component.rest-openapi.host

The scheme, host and optional port of the server the producer calls, in the form http[s]://hostname[:port]. When not set: an absolute URL of the servers of the operation or of the specification (with the default values of the server variables), then the scheme, host and port of the REST configuration, then the scheme, host and port of an http or https specificationUri. The producer fails to start when none of them gives a host.

String

camel.component.rest-openapi.lazy-start-producer

Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel’s routing error handlers. Beware that when the first message is processed then creating and starting the producer may take a little time and prolong the total processing time of the processing.

false

Boolean

camel.component.rest-openapi.missing-operation

What the consumer does with the operations of the specification that have no route (with the default strategy, a route from direct: and the operationId), checked at startup: fail fails the start, ignore logs a WARN and answers their requests without a route (the response is the request message), and mock answers them with mock data (see mockIncludePattern), else with the request message for PUT, POST, DELETE and PATCH, else with the example of the 200 response in the specification, else with HTTP 204. When not set: mock with the dev profile, else fail.

fail

String

camel.component.rest-openapi.mock-include-pattern

Ant-style patterns, separated by comma, of the mock data files for missingOperation=mock, such as classpath:camel-mock/ or file:mocks/. For a request of an operation without a route, the first file whose path without extension ends with the request path is the response, with HTTP 200; when the request has a JSON or XML Content-Type, only a .json or .xml file matches.

classpath:camel-mock/**

String

camel.component.rest-openapi.produces

The media type of the request body the producer sends, which it sets as the Content-Type header when the message has none, such as application/json. When not set: the content types of the requestBody of the operation in the specification. The consumer does not use it.

String

camel.component.rest-openapi.request-validation-enabled

Whether the producer checks the message against the operation in the specification before it sends the request: the Content-Type header against the requestBody content types, that a required body is present and that a JSON body parses, that the required query and path parameters have a value (a header, an exchange variable or an endpoint parameter of that name), and that the required header parameters are headers. A failed check fails the exchange with a RestOpenApiValidationException, and no request is sent. The body is not validated against its schema.

false

Boolean

camel.component.rest-openapi.rest-openapi-processor-strategy

A custom RestOpenapiProcessorStrategy, which checks the operations of the specification against the routes at startup and processes the requests of each operation. The default strategy routes each operation to direct: and its operationId, and applies missingOperation and mockIncludePattern. Set on the component, the one strategy is used by all its endpoints. The option is a org.apache.camel.component.rest.openapi.RestOpenapiProcessorStrategy type.

RestOpenapiProcessorStrategy

camel.component.rest-openapi.specification-uri

The OpenAPI 3.x specification document, JSON or YAML, by default openapi.json on the classpath. Use the prefix classpath: (the default), file:, http: or https:, or another scheme of the Camel resource loader such as ref:. The consumer and the producer load and parse the document (with the swagger-parser) when they are created. A document over https is downloaded with the HttpURLConnection of the JDK, which uses the default trust store of the JVM (the javax.net.ssl system properties), not sslContextParameters.

String

camel.component.rest-openapi.ssl-context-parameters

The TLS configuration the producer sets on the HTTP component it delegates to (componentName). Only applied when the producer creates that component: a component already in the CamelContext is not changed (a WARN is logged), so configure TLS on that component instead. Not used to download the specification document. The option is a org.apache.camel.support.jsse.SSLContextParameters type.

SSLContextParameters

camel.component.rest-openapi.unmatched-request-handling

Who answers requests that match no operation in the OpenAPI specification: the HTTP layer (platform) or Camel via the unmatched request handler (camel). Can be overridden in endpoint configuration.

platform

String

camel.component.rest-openapi.use-global-ssl-context-parameters

Whether the producer sets useGlobalSslContextParameters on the HTTP component it delegates to (componentName), so that component uses the global SSLContextParameters of the CamelContext. Only applied when the producer creates that component: a component already in the CamelContext is not changed.

false

Boolean