This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch binding2 in repository https://gitbox.apache.org/repos/asf/camel.git
commit d5db0a2a5cd3c1c357945982f663ac6413de5b6a Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Apr 3 15:54:37 2024 +0200 CAMEL-20557: Rest DSL to use openapi spec directly --- .../openapi/RestOpenApiComponentConfigurer.java | 6 ++ .../camel/component/rest/openapi/rest-openapi.json | 59 ++++++++-------- .../rest/openapi/RestOpenApiComponent.java | 18 +++-- .../rest/openapi/RestOpenApiEndpoint.java | 16 ++++- .../rest/openapi/RestOpenApiProcessor.java | 79 +++++++++++++++++++++- .../apache/camel/model/rest/RestDefinition.java | 26 +++---- 6 files changed, 155 insertions(+), 49 deletions(-) diff --git a/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentConfigurer.java b/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentConfigurer.java index a4da07cffbb..4b19529401f 100644 --- a/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentConfigurer.java +++ b/components/camel-rest-openapi/src/generated/java/org/apache/camel/component/rest/openapi/RestOpenApiComponentConfigurer.java @@ -27,6 +27,8 @@ public class RestOpenApiComponentConfigurer extends PropertyConfigurerSupport im case "autowiredEnabled": target.setAutowiredEnabled(property(camelContext, boolean.class, value)); return true; case "basepath": case "basePath": target.setBasePath(property(camelContext, java.lang.String.class, value)); return true; + case "bindingpackagename": + case "bindingPackageName": target.setBindingPackageName(property(camelContext, java.lang.String.class, value)); return true; case "bridgeerrorhandler": case "bridgeErrorHandler": target.setBridgeErrorHandler(property(camelContext, boolean.class, value)); return true; case "clientrequestvalidation": @@ -67,6 +69,8 @@ public class RestOpenApiComponentConfigurer extends PropertyConfigurerSupport im case "autowiredEnabled": return boolean.class; case "basepath": case "basePath": return java.lang.String.class; + case "bindingpackagename": + case "bindingPackageName": return java.lang.String.class; case "bridgeerrorhandler": case "bridgeErrorHandler": return boolean.class; case "clientrequestvalidation": @@ -108,6 +112,8 @@ public class RestOpenApiComponentConfigurer extends PropertyConfigurerSupport im case "autowiredEnabled": return target.isAutowiredEnabled(); case "basepath": case "basePath": return target.getBasePath(); + case "bindingpackagename": + case "bindingPackageName": return target.getBindingPackageName(); case "bridgeerrorhandler": case "bridgeErrorHandler": return target.isBridgeErrorHandler(); case "clientrequestvalidation": diff --git a/components/camel-rest-openapi/src/generated/resources/META-INF/org/apache/camel/component/rest/openapi/rest-openapi.json b/components/camel-rest-openapi/src/generated/resources/META-INF/org/apache/camel/component/rest/openapi/rest-openapi.json index 3179dafec36..41b59cebba5 100644 --- a/components/camel-rest-openapi/src/generated/resources/META-INF/org/apache/camel/component/rest/openapi/rest-openapi.json +++ b/components/camel-rest-openapi/src/generated/resources/META-INF/org/apache/camel/component/rest/openapi/rest-openapi.json @@ -27,39 +27,40 @@ "specificationUri": { "index": 1, "kind": "property", "displayName": "Specification Uri", "group": "common", "label": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "openapi.json", "description": "Path to the OpenApi specification file. The scheme, host base path are taken from this specification, but these can be overridden with properties on the component or endpoint level. If [...] "apiContextPath": { "index": 2, "kind": "property", "displayName": "Api Context Path", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the context-path to use for servicing the OpenAPI specification" }, "bridgeErrorHandler": { "index": 3, "kind": "property", "displayName": "Bridge Error Handler", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "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 like [...] - "missingOperation": { "index": 4, "kind": "property", "displayName": "Missing Operation", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "fail", "ignore", "mock" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "fail", "description": "Whether the consumer should fail,ignore or return a mock response for OpenAPI operations that are not mapped to a corresponding route." }, - "consumerComponentName": { "index": 5, "kind": "property", "displayName": "Consumer Component Name", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of the Camel component that will service the requests. The component must be present in Camel registry and it must implement RestOpenApiConsumerFactory service provider interfac [...] - "mockIncludePattern": { "index": 6, "kind": "property", "displayName": "Mock Include Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "classpath:camel-mock\/**", "description": "Used for inclusive filtering of mock data from directories. The pattern is using Ant-path style pattern. Multiple patterns can be specified sepa [...] - "restOpenapiProcessorStrategy": { "index": 7, "kind": "property", "displayName": "Rest Openapi Processor Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.rest.openapi.RestOpenapiProcessorStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom strategy for how to process Rest DSL requests" }, - "host": { "index": 8, "kind": "property", "displayName": "Host", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Scheme hostname and port to direct the HTTP requests to in the form of https:\/\/hostname:port. Can be configured at the endpoint, component or in the corresponding REST configuration in the Camel Context. If you give this component a nam [...] - "lazyStartProducer": { "index": 9, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "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 [...] - "requestValidationEnabled": { "index": 10, "kind": "property", "displayName": "Request Validation Enabled", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Enable validation of requests against the configured OpenAPI specification" }, - "componentName": { "index": 11, "kind": "property", "displayName": "Component Name", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of the Camel component that will perform the requests. The component must be present in Camel registry and it must implement RestProducerFactory service provider interface. If not set CLASSPATH [...] - "consumes": { "index": 12, "kind": "property", "displayName": "Consumes", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component capable of consuming. Could be one type, like application\/json or multiple types as application\/json, application\/xml; q=0.5 according to the RFC7231. This equates to the va [...] - "produces": { "index": 13, "kind": "property", "displayName": "Produces", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component is producing. For example application\/json according to the RFC7231. This equates to the value of Content-Type HTTP header. If set overrides any value present in the OpenApi s [...] - "autowiredEnabled": { "index": 14, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "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 [...] - "clientRequestValidation": { "index": 15, "kind": "property", "displayName": "Client Request Validation", "group": "consumes", "label": "consumes", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to enable validation of the client request to check if the incoming request is valid according to the OpenAPI specification" }, - "sslContextParameters": { "index": 16, "kind": "property", "displayName": "Ssl Context Parameters", "group": "security", "label": "security", "required": false, "type": "object", "javaType": "org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false, "autowired": false, "secret": false, "description": "Customize TLS parameters used by the component. If not set defaults to the TLS parameters set in the Camel context" }, - "useGlobalSslContextParameters": { "index": 17, "kind": "property", "displayName": "Use Global Ssl Context Parameters", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Enable usage of global SSL context parameters." } + "clientRequestValidation": { "index": 4, "kind": "property", "displayName": "Client Request Validation", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to enable validation of the client request to check if the incoming request is valid according to the OpenAPI specification" }, + "missingOperation": { "index": 5, "kind": "property", "displayName": "Missing Operation", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "fail", "ignore", "mock" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "fail", "description": "Whether the consumer should fail,ignore or return a mock response for OpenAPI operations that are not mapped to a corresponding route." }, + "bindingPackageName": { "index": 6, "kind": "property", "displayName": "Binding Package Name", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Java package name where POJO classes are located when using binding mode is enabled for JSon or XML. Multiple package names can be separated by comma." }, + "consumerComponentName": { "index": 7, "kind": "property", "displayName": "Consumer Component Name", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of the Camel component that will service the requests. The component must be present in Camel registry and it must implement RestOpenApiConsumerFactory service provider interfac [...] + "mockIncludePattern": { "index": 8, "kind": "property", "displayName": "Mock Include Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "classpath:camel-mock\/**", "description": "Used for inclusive filtering of mock data from directories. The pattern is using Ant-path style pattern. Multiple patterns can be specified sepa [...] + "restOpenapiProcessorStrategy": { "index": 9, "kind": "property", "displayName": "Rest Openapi Processor Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.rest.openapi.RestOpenapiProcessorStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom strategy for how to process Rest DSL requests" }, + "host": { "index": 10, "kind": "property", "displayName": "Host", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Scheme hostname and port to direct the HTTP requests to in the form of https:\/\/hostname:port. Can be configured at the endpoint, component or in the corresponding REST configuration in the Camel Context. If you give this component a na [...] + "lazyStartProducer": { "index": 11, "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "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 fai [...] + "requestValidationEnabled": { "index": 12, "kind": "property", "displayName": "Request Validation Enabled", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Enable validation of requests against the configured OpenAPI specification" }, + "componentName": { "index": 13, "kind": "property", "displayName": "Component Name", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of the Camel component that will perform the requests. The component must be present in Camel registry and it must implement RestProducerFactory service provider interface. If not set CLASSPATH [...] + "consumes": { "index": 14, "kind": "property", "displayName": "Consumes", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component capable of consuming. Could be one type, like application\/json or multiple types as application\/json, application\/xml; q=0.5 according to the RFC7231. This equates to the va [...] + "produces": { "index": 15, "kind": "property", "displayName": "Produces", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component is producing. For example application\/json according to the RFC7231. This equates to the value of Content-Type HTTP header. If set overrides any value present in the OpenApi s [...] + "autowiredEnabled": { "index": 16, "kind": "property", "displayName": "Autowired Enabled", "group": "advanced", "label": "advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": true, "description": "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 [...] + "sslContextParameters": { "index": 17, "kind": "property", "displayName": "Ssl Context Parameters", "group": "security", "label": "security", "required": false, "type": "object", "javaType": "org.apache.camel.support.jsse.SSLContextParameters", "deprecated": false, "autowired": false, "secret": false, "description": "Customize TLS parameters used by the component. If not set defaults to the TLS parameters set in the Camel context" }, + "useGlobalSslContextParameters": { "index": 18, "kind": "property", "displayName": "Use Global Ssl Context Parameters", "group": "security", "label": "security", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Enable usage of global SSL context parameters." } }, "properties": { "specificationUri": { "index": 0, "kind": "path", "displayName": "Specification Uri", "group": "common", "label": "common", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "openapi.json", "description": "Path to the OpenApi specification file. The scheme, host base path are taken from this specification, but these can be overridden with properties on the component or endpoint level. If not [...] "operationId": { "index": 1, "kind": "path", "displayName": "Operation Id", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "ID of the operation from the OpenApi specification. This is required when using producer" }, "apiContextPath": { "index": 2, "kind": "parameter", "displayName": "Api Context Path", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Sets the context-path to use for servicing the OpenAPI specification" }, - "missingOperation": { "index": 3, "kind": "parameter", "displayName": "Missing Operation", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "fail", "ignore", "mock" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "fail", "description": "Whether the consumer should fail,ignore or return a mock response for OpenAPI operations that are not mapped to a corresponding route." }, - "bridgeErrorHandler": { "index": 4, "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "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 [...] - "consumerComponentName": { "index": 5, "kind": "parameter", "displayName": "Consumer Component Name", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of the Camel component that will service the requests. The component must be present in Camel registry and it must implement RestOpenApiConsumerFactory service provider interfa [...] - "exceptionHandler": { "index": 6, "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "autowired": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By def [...] - "exchangePattern": { "index": 7, "kind": "parameter", "displayName": "Exchange Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ], "deprecated": false, "autowired": false, "secret": false, "description": "Sets the exchange pattern when the consumer creates an exchange." }, - "mockIncludePattern": { "index": 8, "kind": "parameter", "displayName": "Mock Include Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "classpath:camel-mock\/**", "description": "Used for inclusive filtering of mock data from directories. The pattern is using Ant-path style pattern. Multiple patterns can be specified sep [...] - "restOpenapiProcessorStrategy": { "index": 9, "kind": "parameter", "displayName": "Rest Openapi Processor Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.rest.openapi.RestOpenapiProcessorStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom strategy for how to process Rest DSL requests" }, - "basePath": { "index": 10, "kind": "parameter", "displayName": "Base Path", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "API basePath, for example \/v3. Default is unset, if set overrides the value present in OpenApi specification and in the component configuration." }, - "consumes": { "index": 11, "kind": "parameter", "displayName": "Consumes", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component capable of consuming. Could be one type, like application\/json or multiple types as application\/json, application\/xml; q=0.5 according to the RFC7231. This equates to the value of Accept HTTP [...] - "host": { "index": 12, "kind": "parameter", "displayName": "Host", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Scheme hostname and port to direct the HTTP requests to in the form of https:\/\/hostname:port. Can be configured at the endpoint, component or in the corresponding REST configuration in the Camel Context. If you give this component a n [...] - "produces": { "index": 13, "kind": "parameter", "displayName": "Produces", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component is producing. For example application\/json according to the RFC7231. This equates to the value of Content-Type HTTP header. If set overrides any value present in the OpenApi specification. Overr [...] - "requestValidationEnabled": { "index": 14, "kind": "parameter", "displayName": "Request Validation Enabled", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Enable validation of requests against the configured OpenAPI specification" }, - "componentName": { "index": 15, "kind": "parameter", "displayName": "Component Name", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of the Camel component that will perform the requests. The component must be present in Camel registry and it must implement RestProducerFactory service provider interface. If not set CLASSPAT [...] - "lazyStartProducer": { "index": 16, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "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 produ [...] - "clientRequestValidation": { "index": 17, "kind": "parameter", "displayName": "Client Request Validation", "group": "consumes", "label": "consumes", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to enable validation of the client request to check if the incoming request is valid according to the OpenAPI specification" } + "clientRequestValidation": { "index": 3, "kind": "parameter", "displayName": "Client Request Validation", "group": "consumer", "label": "consumer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Whether to enable validation of the client request to check if the incoming request is valid according to the OpenAPI specification" }, + "consumes": { "index": 4, "kind": "parameter", "displayName": "Consumes", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component capable of consuming. Could be one type, like application\/json or multiple types as application\/json, application\/xml; q=0.5 according to the RFC7231. This equates to the value of Accept HTTP h [...] + "missingOperation": { "index": 5, "kind": "parameter", "displayName": "Missing Operation", "group": "consumer", "label": "consumer", "required": false, "type": "string", "javaType": "java.lang.String", "enum": [ "fail", "ignore", "mock" ], "deprecated": false, "autowired": false, "secret": false, "defaultValue": "fail", "description": "Whether the consumer should fail,ignore or return a mock response for OpenAPI operations that are not mapped to a corresponding route." }, + "bridgeErrorHandler": { "index": 6, "kind": "parameter", "displayName": "Bridge Error Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "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 [...] + "consumerComponentName": { "index": 7, "kind": "parameter", "displayName": "Consumer Component Name", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of the Camel component that will service the requests. The component must be present in Camel registry and it must implement RestOpenApiConsumerFactory service provider interfa [...] + "exceptionHandler": { "index": 8, "kind": "parameter", "displayName": "Exception Handler", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.spi.ExceptionHandler", "optionalPrefix": "consumer.", "deprecated": false, "autowired": false, "secret": false, "description": "To let the consumer use a custom ExceptionHandler. Notice if the option bridgeErrorHandler is enabled then this option is not in use. By def [...] + "exchangePattern": { "index": 9, "kind": "parameter", "displayName": "Exchange Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.ExchangePattern", "enum": [ "InOnly", "InOut" ], "deprecated": false, "autowired": false, "secret": false, "description": "Sets the exchange pattern when the consumer creates an exchange." }, + "mockIncludePattern": { "index": 10, "kind": "parameter", "displayName": "Mock Include Pattern", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "defaultValue": "classpath:camel-mock\/**", "description": "Used for inclusive filtering of mock data from directories. The pattern is using Ant-path style pattern. Multiple patterns can be specified se [...] + "restOpenapiProcessorStrategy": { "index": 11, "kind": "parameter", "displayName": "Rest Openapi Processor Strategy", "group": "consumer (advanced)", "label": "consumer,advanced", "required": false, "type": "object", "javaType": "org.apache.camel.component.rest.openapi.RestOpenapiProcessorStrategy", "deprecated": false, "autowired": false, "secret": false, "description": "To use a custom strategy for how to process Rest DSL requests" }, + "basePath": { "index": 12, "kind": "parameter", "displayName": "Base Path", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "API basePath, for example \/v3. Default is unset, if set overrides the value present in OpenApi specification and in the component configuration." }, + "host": { "index": 13, "kind": "parameter", "displayName": "Host", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Scheme hostname and port to direct the HTTP requests to in the form of https:\/\/hostname:port. Can be configured at the endpoint, component or in the corresponding REST configuration in the Camel Context. If you give this component a n [...] + "produces": { "index": 14, "kind": "parameter", "displayName": "Produces", "group": "producer", "label": "producer", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "What payload type this component is producing. For example application\/json according to the RFC7231. This equates to the value of Content-Type HTTP header. If set overrides any value present in the OpenApi specification. Overr [...] + "requestValidationEnabled": { "index": 15, "kind": "parameter", "displayName": "Request Validation Enabled", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "Enable validation of requests against the configured OpenAPI specification" }, + "componentName": { "index": 16, "kind": "parameter", "displayName": "Component Name", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "autowired": false, "secret": false, "description": "Name of the Camel component that will perform the requests. The component must be present in Camel registry and it must implement RestProducerFactory service provider interface. If not set CLASSPAT [...] + "lazyStartProducer": { "index": 17, "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer (advanced)", "label": "producer,advanced", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "autowired": false, "secret": false, "defaultValue": false, "description": "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 produ [...] } } diff --git a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiComponent.java b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiComponent.java index 28afc8d3fd9..b501c5eb372 100644 --- a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiComponent.java +++ b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiComponent.java @@ -29,7 +29,6 @@ import org.apache.camel.support.jsse.SSLContextParameters; import static org.apache.camel.component.rest.openapi.RestOpenApiHelper.isHostParam; import static org.apache.camel.component.rest.openapi.RestOpenApiHelper.isMediaRange; -import static org.apache.camel.util.StringHelper.notEmpty; /** * An awesome REST component backed by OpenApi specifications. Creates endpoints that connect to REST APIs defined by @@ -121,7 +120,10 @@ public final class RestOpenApiComponent extends DefaultComponent implements SSLC + " any value present in the OpenApi specification. Can be overridden in endpoint configuration.", label = "producer,advanced") private String produces; - @Metadata(label = "consumes", + @Metadata(label = "consumer,advanced", + description = "Java package name where POJO classes are located when using binding mode is enabled for JSon or XML. Multiple package names can be separated by comma.") + private String bindingPackageName; + @Metadata(label = "consumer", description = "Whether to enable validation of the client request to check if the incoming request is valid according to the OpenAPI specification") private boolean clientRequestValidation; @Metadata(label = "producer", description = "Enable validation of requests against the configured OpenAPI specification") @@ -155,6 +157,7 @@ public final class RestOpenApiComponent extends DefaultComponent implements SSLC throws Exception { RestOpenApiEndpoint endpoint = new RestOpenApiEndpoint(uri, remaining, this, parameters); endpoint.setApiContextPath(getApiContextPath()); + endpoint.setBindingPackageName(getBindingPackageName()); endpoint.setClientRequestValidation(isClientRequestValidation()); endpoint.setRequestValidationEnabled(isRequestValidationEnabled()); endpoint.setRestOpenapiProcessorStrategy(getRestOpenapiProcessorStrategy()); @@ -234,11 +237,11 @@ public final class RestOpenApiComponent extends DefaultComponent implements SSLC } public void setBasePath(final String basePath) { - this.basePath = notEmpty(basePath, "basePath"); + this.basePath = basePath; } public void setComponentName(final String componentName) { - this.componentName = notEmpty(componentName, "componentName"); + this.componentName = componentName; } public void setConsumerComponentName(String consumerComponentName) { @@ -286,4 +289,11 @@ public final class RestOpenApiComponent extends DefaultComponent implements SSLC this.clientRequestValidation = clientRequestValidation; } + public String getBindingPackageName() { + return bindingPackageName; + } + + public void setBindingPackageName(String bindingPackageName) { + this.bindingPackageName = bindingPackageName; + } } diff --git a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpoint.java b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpoint.java index d271c37924d..d2ee8cfe72b 100644 --- a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpoint.java +++ b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiEndpoint.java @@ -60,6 +60,7 @@ import org.apache.camel.Producer; import org.apache.camel.component.rest.openapi.validator.DefaultRequestValidator; import org.apache.camel.component.rest.openapi.validator.RequestValidator; import org.apache.camel.component.rest.openapi.validator.RestOpenApiOperation; +import org.apache.camel.spi.Metadata; import org.apache.camel.spi.Resource; import org.apache.camel.spi.RestConfiguration; import org.apache.camel.spi.RestOpenApiConsumerFactory; @@ -129,7 +130,7 @@ public final class RestOpenApiEndpoint extends DefaultEndpoint { + " or multiple types as `application/json, application/xml; q=0.5` according to the RFC7231. This equates" + " to the value of `Accept` HTTP header. If set overrides any value found in the OpenApi specification and." + " in the component configuration", - label = "producer") + label = "consumer") private String consumes; @UriParam(description = "What payload type this component is producing. For example `application/json`" + " according to the RFC7231. This equates to the value of `Content-Type` HTTP header. If set overrides" @@ -148,7 +149,10 @@ public final class RestOpenApiEndpoint extends DefaultEndpoint { defaultValue = RestOpenApiComponent.DEFAULT_SPECIFICATION_URI, defaultValueNote = "By default loads `openapi.json` file", label = "common") private String specificationUri; - @UriParam(label = "consumes", + @Metadata(label = "consumer,advanced", + description = "Java package name where POJO classes are located when using binding mode is enabled for JSon or XML. Multiple package names can be separated by comma.") + private String bindingPackageName; + @UriParam(label = "consumer", description = "Whether to enable validation of the client request to check if the incoming request is valid according to the OpenAPI specification") private boolean clientRequestValidation; @UriParam(label = "producer", description = "Enable validation of requests against the configured OpenAPI specification") @@ -460,6 +464,14 @@ public final class RestOpenApiEndpoint extends DefaultEndpoint { this.apiContextPath = apiContextPath; } + public String getBindingPackageName() { + return bindingPackageName; + } + + public void setBindingPackageName(String bindingPackageName) { + this.bindingPackageName = bindingPackageName; + } + Producer createProducerFor( final OpenAPI openapi, final Operation operation, final String method, final String uriTemplate) diff --git a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java index c3e46f12ce4..42bac9d22e9 100644 --- a/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java +++ b/components/camel-rest-openapi/src/main/java/org/apache/camel/component/rest/openapi/RestOpenApiProcessor.java @@ -28,6 +28,7 @@ import java.util.stream.Collectors; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.media.Content; +import io.swagger.v3.oas.models.media.Schema; import io.swagger.v3.oas.models.parameters.Parameter; import org.apache.camel.AsyncCallback; import org.apache.camel.CamelContext; @@ -398,7 +399,6 @@ public class RestOpenApiProcessor extends DelegateAsyncProcessor implements Came if (requiredHeaders != null) { bc.setRequiredHeaders(requiredHeaders); } - // TODO: should type be string/int/long for basic types? Map<String, String> defaultQueryValues = null; if (o.getParameters() != null) { defaultQueryValues = o.getParameters().stream() @@ -411,11 +411,86 @@ public class RestOpenApiProcessor extends DelegateAsyncProcessor implements Came bc.setQueryDefaultValues(defaultQueryValues); } - // TODO: type/outType + // input and output types binding to java classes + if (o.getRequestBody() != null) { + Content c = o.getRequestBody().getContent(); + if (c != null) { + for (var m : c.entrySet()) { + String mt = m.getKey(); + if (mt.contains("json") || mt.contains("xml")) { + Schema s = m.getValue().getSchema(); + // $ref is null, so we need to know the schema name via XML + if (s != null && s.getXml() != null) { + String ref = s.getXml().getName(); + boolean array = "array".equals(s.getType()); + if (ref != null) { + Class<?> clazz = loadBindingClass(camelContext, ref); + if (clazz != null) { + String name = clazz.getName(); + if (array) { + name = name + "[]"; + } + bc.setType(name); + break; // okay set this just once + } + } + } + } + } + } + } + if (o.getResponses() != null) { + for (var a : o.getResponses().values()) { + Content c = a.getContent(); + if (c != null) { + for (var m : c.entrySet()) { + String mt = m.getKey(); + if (mt.contains("json") || mt.contains("xml")) { + Schema s = m.getValue().getSchema(); + // $ref is null, so we need to know the schema name via XML + if (s != null && s.getXml() != null) { + String ref = s.getXml().getName(); + boolean array = "array".equals(s.getType()); + if (ref != null) { + Class<?> clazz = loadBindingClass(camelContext, ref); + if (clazz != null) { + String name = clazz.getName(); + if (array) { + name = name + "[]"; + } + bc.setOutType(name); + break; // okay set this just once + } + } + } + } + } + } + } + } return RestBindingAdviceFactory.build(camelContext, bc); } + private Class<?> loadBindingClass(CamelContext camelContext, String ref) { + if (ref == null) { + return null; + } + + // must refer to a class name, so upper case + ref = Character.toUpperCase(ref.charAt(0)) + ref.substring(1); + if (endpoint.getBindingPackageName() != null) { + for (String pck : endpoint.getBindingPackageName().split(",")) { + String fqn = pck + "." + ref; + Class<?> clazz = camelContext.getClassResolver().resolveClass(fqn); + if (clazz != null) { + return clazz; + } + } + } + return camelContext.getClassResolver().resolveClass(ref); + } + @Override protected void doInit() throws Exception { super.doInit(); diff --git a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestDefinition.java b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestDefinition.java index 03a6ecfa264..427f8136202 100644 --- a/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestDefinition.java +++ b/core/camel-core-model/src/main/java/org/apache/camel/model/rest/RestDefinition.java @@ -980,20 +980,22 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition> // add dummy empty stop route.getOutputs().add(new StopDefinition()); + String mode = getBindingMode(); + if (mode == null) { + mode = camelContext.getRestConfiguration().getBindingMode().name(); + } + RestBindingDefinition binding = new RestBindingDefinition(); binding.setComponent(component); - if (binding.getBindingMode() != null) { - String mode = binding.getBindingMode(); - if ("json".equals(mode)) { - binding.setConsumes("application/json"); - binding.setProduces("application/json"); - } else if ("xml".equals(mode)) { - binding.setConsumes("application/xml"); - binding.setProduces("application/xml"); - } else if ("json_xml".equals(mode)) { - binding.setConsumes("application/json;application/xml"); - binding.setProduces("application/json;application/xml"); - } + if ("json".equals(mode)) { + binding.setConsumes("application/json"); + binding.setProduces("application/json"); + } else if ("xml".equals(mode)) { + binding.setConsumes("application/xml"); + binding.setProduces("application/xml"); + } else if ("json_xml".equals(mode)) { + binding.setConsumes("application/json;application/xml"); + binding.setProduces("application/json;application/xml"); } binding.setSkipBindingOnErrorCode(getSkipBindingOnErrorCode()); binding.setClientRequestValidation(getClientRequestValidation());