This is an automated email from the ASF dual-hosted git repository.
ffang pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/master by this push:
new 0d532b3 [CAMEL-14352]Add camel-openapi as api-doc discovered component
0d532b3 is described below
commit 0d532b3eeda40315e3051d708e422832fd93043e
Author: Freeman Fang <[email protected]>
AuthorDate: Wed Jan 8 15:23:34 2020 -0500
[CAMEL-14352]Add camel-openapi as api-doc discovered component
---
.../camel-rest/src/main/docs/rest-component.adoc | 4 +--
.../apache/camel/component/rest/RestEndpoint.java | 30 +++++++++++++++++-----
.../endpoint/dsl/RestEndpointBuilderFactory.java | 4 +--
3 files changed, 27 insertions(+), 11 deletions(-)
diff --git a/components/camel-rest/src/main/docs/rest-component.adoc
b/components/camel-rest/src/main/docs/rest-component.adoc
index e49577b..150be84 100644
--- a/components/camel-rest/src/main/docs/rest-component.adoc
+++ b/components/camel-rest/src/main/docs/rest-component.adoc
@@ -78,9 +78,9 @@ with the following path and query parameters:
| *description* (consumer) | Human description to document this REST service |
| String
| *exceptionHandler* (consumer) | To let the consumer use a custom
ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this
option is not in use. By default the consumer will deal with exceptions, that
will be logged at WARN or ERROR level and ignored. | | ExceptionHandler
| *exchangePattern* (consumer) | Sets the exchange pattern when the consumer
creates an exchange. | | ExchangePattern
-| *apiDoc* (producer) | The swagger api doc resource to use. The resource is
loaded from classpath by default and must be in JSon format. | | String
+| *apiDoc* (producer) | The openapi api doc resource to use. The resource is
loaded from classpath by default and must be in JSon format. | | String
| *bindingMode* (producer) | Configures the binding mode for the producer. If
set to anything other than 'off' the producer will try to convert the body of
the incoming message from inType to the json or xml, and the response from json
or xml to outType. | | RestBindingMode
-| *host* (producer) | Host and port of HTTP service to use (override host in
swagger schema) | | String
+| *host* (producer) | Host and port of HTTP service to use (override host in
openapi schema) | | String
| *lazyStartProducer* (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 [...]
| *producerComponentName* (producer) | The Camel Rest component to use for
(producer) the REST transport, such as http, undertow. If no component has been
explicit configured, then Camel will lookup if there is a Camel component that
integrates with the Rest DSL, or if a org.apache.camel.spi.RestProducerFactory
is registered in the registry. If either one is found, then that is being used.
| | String
| *queryParameters* (producer) | Query parameters for the HTTP service to call
| | String
diff --git
a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
index 5826271..a990ade 100644
---
a/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
+++
b/components/camel-rest/src/main/java/org/apache/camel/component/rest/RestEndpoint.java
@@ -49,7 +49,7 @@ public class RestEndpoint extends DefaultEndpoint {
public static final String[] DEFAULT_REST_CONSUMER_COMPONENTS = new
String[]{"coap", "netty-http", "jetty", "servlet", "spark-java", "undertow"};
public static final String[] DEFAULT_REST_PRODUCER_COMPONENTS = new
String[]{"http", "netty-http", "undertow"};
- public static final String DEFAULT_API_COMPONENT_NAME = "swagger";
+ public static final String DEFAULT_API_COMPONENT_NAME = "openapi";
public static final String RESOURCE_PATH =
"META-INF/services/org/apache/camel/rest/";
@UriPath(label = "common", enums =
"get,post,put,delete,patch,head,trace,connect,options") @Metadata(required =
true)
@@ -239,7 +239,7 @@ public class RestEndpoint extends DefaultEndpoint {
}
/**
- * The swagger api doc resource to use.
+ * The openapi api doc resource to use.
* The resource is loaded from classpath by default and must be in JSon
format.
*/
public void setApiDoc(String apiDoc) {
@@ -251,7 +251,7 @@ public class RestEndpoint extends DefaultEndpoint {
}
/**
- * Host and port of HTTP service to use (override host in swagger schema)
+ * Host and port of HTTP service to use (override host in openapi schema)
*/
public void setHost(String host) {
this.host = host;
@@ -298,14 +298,30 @@ public class RestEndpoint extends DefaultEndpoint {
RestProducerFactory factory = null;
if (apiDoc != null) {
- log.debug("Discovering camel-swagger-java on classpath for using
api-doc: {}", apiDoc);
- // lookup on classpath using factory finder to automatic find it
(just add camel-swagger-java to classpath etc)
+ log.debug("Discovering camel-openapi-java on classpath for using
api-doc: {}", apiDoc);
+ // lookup on classpath using factory finder to automatic find it
(just add camel-openapi-java to classpath etc)
+ FactoryFinder finder = null;
try {
- FactoryFinder finder =
getCamelContext().adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH);
+ finder =
getCamelContext().adapt(ExtendedCamelContext.class).getFactoryFinder(RESOURCE_PATH);
apiDocFactory = finder.newInstance(DEFAULT_API_COMPONENT_NAME,
RestProducerFactory.class).orElse(null);
+ if (apiDocFactory == null) {
+ throw new NoFactoryAvailableException("Cannot find
camel-openapi-java on classpath");
+ }
parameters.put("apiDoc", apiDoc);
} catch (NoFactoryAvailableException e) {
- throw new IllegalStateException("Cannot find
camel-swagger-java on classpath to use with api-doc: " + apiDoc);
+ try {
+ log.debug("Discovering camel-swagger-java on classpath as
fallback for using api-doc: {}", apiDoc);
+ Object instance = finder.newInstance("swagger").get();
+ if (instance instanceof RestProducerFactory) {
+ // this factory from camel-swagger-java will facade
the http component in use
+ apiDocFactory = (RestProducerFactory) instance;
+ }
+ parameters.put("apiDoc", apiDoc);
+ } catch (Exception ex) {
+
+ throw new IllegalStateException("Cannot find
camel-openapi-java neither camel-swagger-java on classpath to use with api-doc:
" + apiDoc);
+ }
+
}
}
diff --git
a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/RestEndpointBuilderFactory.java
b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/RestEndpointBuilderFactory.java
index 54c873e..c287646 100644
---
a/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/RestEndpointBuilderFactory.java
+++
b/core/camel-endpointdsl/src/main/java/org/apache/camel/builder/endpoint/dsl/RestEndpointBuilderFactory.java
@@ -358,7 +358,7 @@ public interface RestEndpointBuilderFactory {
return this;
}
/**
- * The swagger api doc resource to use. The resource is loaded from
+ * The openapi api doc resource to use. The resource is loaded from
* classpath by default and must be in JSon format.
*
* The option is a: <code>java.lang.String</code> type.
@@ -403,7 +403,7 @@ public interface RestEndpointBuilderFactory {
return this;
}
/**
- * Host and port of HTTP service to use (override host in swagger
+ * Host and port of HTTP service to use (override host in openapi
* schema).
*
* The option is a: <code>java.lang.String</code> type.