This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch openapi3 in repository https://gitbox.apache.org/repos/asf/camel.git
commit a294023f343972c0b48342618921dfcd091f12df Author: Claus Ibsen <[email protected]> AuthorDate: Thu Feb 29 09:19:29 2024 +0100 CAMEL-20488: Drop support for old swagger v2 spec (openapi v2) --- components/camel-openapi-java/pom.xml | 80 +- .../src/main/docs/openapi-java.adoc | 2 +- .../java/org/apache/camel/openapi/OpenAPI3to2.java | 603 ---------- .../camel/openapi/OpenApiRestProducerFactory.java | 4 +- .../apache/camel/openapi/RestOpenApiReader.java | 4 +- .../apache/camel/openapi/RestOpenApiSupport.java | 8 +- .../org/apache/camel/openapi/ComplexTypesTest.java | 4 - .../openapi/OpenApiRestProducerFactoryTest.java | 7 - .../RestOpenApiDefaultProducesConsumesTest.java | 2 +- .../camel/openapi/RestOpenApiLicenseInfoTest.java | 2 +- ...estOpenApiModelApiSecurityRequirementsTest.java | 29 - .../RestOpenApiReaderApiDocsOverrideTest.java | 2 +- .../openapi/RestOpenApiReaderApiDocsTest.java | 2 +- .../openapi/RestOpenApiReaderContextPathTest.java | 38 - .../openapi/RestOpenApiReaderDayOfWeekTest.java | 11 +- .../openapi/RestOpenApiReaderDisabledTest.java | 37 - ...RestOpenApiReaderEnableVendorExtensionTest.java | 11 +- .../RestOpenApiReaderFileResponseModelTest.java | 10 +- .../RestOpenApiReaderModelApiSecurityTest.java | 40 - .../RestOpenApiReaderModelBookOrderTest.java | 33 - .../camel/openapi/RestOpenApiReaderModelTest.java | 33 - .../RestOpenApiReaderPropertyPlaceholderTest.java | 9 +- .../camel/openapi/RestOpenApiReaderTest.java | 59 - .../openapi/RestOpenApiV2SecuritySchemesTest.java | 96 -- .../openapi/RestOpenApiV3SecuritySchemesTest.java | 64 +- ...pringRestOpenApiReaderModelApiSecurityTest.java | 41 - .../src/test/resources/hello-api.json | 9 +- .../openapi/V20SchemaForComplexTypesRequest.json | 158 --- ...ForComplexTypesRequestWithSchemaAnnotation.json | 158 --- .../openapi/V20SchemaForComplexTypesResponse.json | 101 -- ...orComplexTypesResponseWithSchemaAnnotation.json | 101 -- .../src/test/resources/petstore-v3.json | 1226 +++++++++++++++++++- .../src/test/resources/petstore.json | 1 - components/camel-rest-openapi/pom.xml | 31 +- dsl/camel-jbang/camel-jbang-core/pom.xml | 31 +- 35 files changed, 1386 insertions(+), 1661 deletions(-) diff --git a/components/camel-openapi-java/pom.xml b/components/camel-openapi-java/pom.xml index 62ee5f5231e..64fd4e1785b 100644 --- a/components/camel-openapi-java/pom.xml +++ b/components/camel-openapi-java/pom.xml @@ -35,8 +35,6 @@ <properties> <firstVersion>3.1.0</firstVersion> <label>rest,api</label> - - <camel.surefire.parallel>true</camel.surefire.parallel> </properties> @@ -56,57 +54,89 @@ <artifactId>camel-tooling-util</artifactId> </dependency> + <!-- openapi --> + <dependency> + <groupId>io.swagger.core.v3</groupId> + <artifactId>swagger-core-jakarta</artifactId> + <version>${swagger-openapi3-version}</version> + </dependency> + <dependency> + <groupId>io.swagger.core.v3</groupId> + <artifactId>swagger-models-jakarta</artifactId> + <version>${swagger-openapi3-version}</version> + </dependency> + <dependency> + <groupId>io.swagger.parser.v3</groupId> + <artifactId>swagger-parser</artifactId> + <version>${swagger-openapi3-java-parser-version}</version> + <exclusions> + <exclusion> + <groupId>io.swagger.parser.v3</groupId> + <artifactId>swagger-parser-v2-converter</artifactId> + </exclusion> + <exclusion> + <groupId>io.swagger.core.v3</groupId> + <artifactId>swagger-models</artifactId> + </exclusion> + <exclusion> + <groupId>io.swagger.core.v3</groupId> + <artifactId>swagger-core</artifactId> + </exclusion> + </exclusions> + </dependency> + <!-- json --> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-annotations</artifactId> + <exclusions> + <exclusion> + <groupId>io.swagger.core.v3</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> + <exclusions> + <exclusion> + <groupId>io.swagger.core.v3</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>com.fasterxml.jackson.datatype</groupId> <artifactId>jackson-datatype-joda</artifactId> + <exclusions> + <exclusion> + <groupId>io.swagger.core.v3</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> <artifactId>jackson-dataformat-yaml</artifactId> - </dependency> - <dependency> - <groupId>com.fasterxml.jackson.jakarta.rs</groupId> - <artifactId>jackson-jakarta-rs-json-provider</artifactId> - </dependency> - <dependency> - <groupId>io.swagger.core.v3</groupId> - <artifactId>swagger-models</artifactId> - <version>${swagger-openapi3-version}</version> - </dependency> - <dependency> - <groupId>io.swagger.parser.v3</groupId> - <artifactId>swagger-parser</artifactId> - <version>${swagger-openapi3-java-parser-version}</version> <exclusions> <exclusion> <groupId>io.swagger.core.v3</groupId> - <artifactId>swagger-core</artifactId> + <artifactId>*</artifactId> </exclusion> - </exclusions> + </exclusions> </dependency> - <dependency> - <groupId>io.swagger.core.v3</groupId> - <artifactId>swagger-core-jakarta</artifactId> - <version>${swagger-openapi3-version}</version> + <groupId>com.fasterxml.jackson.jakarta.rs</groupId> + <artifactId>jackson-jakarta-rs-json-provider</artifactId> <exclusions> <exclusion> <groupId>io.swagger.core.v3</groupId> - <artifactId>swagger-models-jakarta</artifactId> + <artifactId>*</artifactId> </exclusion> - </exclusions> + </exclusions> </dependency> - <!-- servlet api --> <dependency> <groupId>jakarta.servlet</groupId> diff --git a/components/camel-openapi-java/src/main/docs/openapi-java.adoc b/components/camel-openapi-java/src/main/docs/openapi-java.adoc index 1400c76fbe5..bfe1a7e9a49 100644 --- a/components/camel-openapi-java/src/main/docs/openapi-java.adoc +++ b/components/camel-openapi-java/src/main/docs/openapi-java.adoc @@ -86,7 +86,7 @@ with `api.xxx` is configured using `apiProperty` dsl. browser, and not the actual access to the REST services. The default is false. -|openapi.version |String |OpenApi spec version. Is default 3.0. +|openapi.version |String |OpenApi spec version. Only spec version 3.x is supported. Is default 3.0. |host |String |To set up the hostname. If not configured, camel-openapi-java will calculate the name as localhost based. diff --git a/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/OpenAPI3to2.java b/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/OpenAPI3to2.java deleted file mode 100644 index e096b6c34e1..00000000000 --- a/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/OpenAPI3to2.java +++ /dev/null @@ -1,603 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.openapi; - -import java.io.IOException; -import java.net.MalformedURLException; -import java.net.URL; -import java.util.Base64; -import java.util.Collection; -import java.util.Collections; -import java.util.Date; -import java.util.List; -import java.util.Map; -import java.util.Map.Entry; -import java.util.stream.Collectors; - -import com.fasterxml.jackson.core.JsonProcessingException; -import com.fasterxml.jackson.databind.JsonNode; -import com.fasterxml.jackson.databind.ObjectMapper; -import com.fasterxml.jackson.databind.SerializationFeature; -import io.swagger.models.ArrayModel; -import io.swagger.models.Contact; -import io.swagger.models.Info; -import io.swagger.models.License; -import io.swagger.models.Model; -import io.swagger.models.ModelImpl; -import io.swagger.models.Operation; -import io.swagger.models.Path; -import io.swagger.models.RefModel; -import io.swagger.models.Response; -import io.swagger.models.Scheme; -import io.swagger.models.Swagger; -import io.swagger.models.Tag; -import io.swagger.models.auth.ApiKeyAuthDefinition; -import io.swagger.models.auth.BasicAuthDefinition; -import io.swagger.models.auth.In; -import io.swagger.models.auth.OAuth2Definition; -import io.swagger.models.auth.SecuritySchemeDefinition; -import io.swagger.models.parameters.AbstractSerializableParameter; -import io.swagger.models.parameters.BodyParameter; -import io.swagger.models.parameters.CookieParameter; -import io.swagger.models.parameters.HeaderParameter; -import io.swagger.models.parameters.Parameter; -import io.swagger.models.parameters.PathParameter; -import io.swagger.models.parameters.QueryParameter; -import io.swagger.models.properties.IntegerProperty; -import io.swagger.models.properties.Property; -import io.swagger.models.properties.PropertyBuilder; -import io.swagger.models.properties.RefProperty; -import io.swagger.models.properties.StringProperty; -import io.swagger.util.Json; -import io.swagger.util.Yaml; -import io.swagger.v3.oas.models.OpenAPI; -import io.swagger.v3.oas.models.PathItem; -import io.swagger.v3.oas.models.Paths; -import io.swagger.v3.oas.models.examples.Example; -import io.swagger.v3.oas.models.headers.Header; -import io.swagger.v3.oas.models.media.ArraySchema; -import io.swagger.v3.oas.models.media.BinarySchema; -import io.swagger.v3.oas.models.media.ByteArraySchema; -import io.swagger.v3.oas.models.media.DateSchema; -import io.swagger.v3.oas.models.media.DateTimeSchema; -import io.swagger.v3.oas.models.media.FileSchema; -import io.swagger.v3.oas.models.media.IntegerSchema; -import io.swagger.v3.oas.models.media.MapSchema; -import io.swagger.v3.oas.models.media.MediaType; -import io.swagger.v3.oas.models.media.NumberSchema; -import io.swagger.v3.oas.models.media.PasswordSchema; -import io.swagger.v3.oas.models.media.Schema; -import io.swagger.v3.oas.models.media.StringSchema; -import io.swagger.v3.oas.models.parameters.Parameter.StyleEnum; -import io.swagger.v3.oas.models.parameters.RequestBody; -import io.swagger.v3.oas.models.responses.ApiResponse; -import io.swagger.v3.oas.models.security.OAuthFlows; -import io.swagger.v3.oas.models.security.Scopes; -import io.swagger.v3.oas.models.security.SecurityRequirement; -import io.swagger.v3.oas.models.security.SecurityScheme; -import io.swagger.v3.oas.models.servers.Server; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -public class OpenAPI3to2 { - - private Swagger openApi2; - private Logger log = LoggerFactory.getLogger(getClass()); - - public void convertOpenAPI3to2(OpenAPI openApi3) { - openApi2 = new Swagger() - .info(convertInfo(openApi3.getInfo())) - .tags(getTags(openApi3.getTags())) - .paths(getPaths(openApi3.getPaths())); - setServerInfo(openApi2, openApi3.getServers()); - if (openApi3.getComponents() != null && openApi3.getComponents().getSchemas() != null) { - for (Map.Entry<String, Schema> entry : openApi3.getComponents().getSchemas().entrySet()) { - openApi2.addDefinition(entry.getKey(), convertSchema(entry.getValue())); - } - } - if (openApi3.getComponents() != null && openApi3.getComponents().getSecuritySchemes() != null) { - convertSecurityDefinitions(openApi3.getComponents().getSecuritySchemes()); - } - if (openApi3.getSecurity() != null) { - for (SecurityRequirement sr : openApi3.getSecurity()) { - openApi2.addSecurity(convertSecurityRequirement(sr)); - } - } - } - - private io.swagger.models.SecurityRequirement convertSecurityRequirement(SecurityRequirement sr) { - io.swagger.models.SecurityRequirement sreq = new io.swagger.models.SecurityRequirement(); - for (Map.Entry<String, List<String>> reqMap : sr.entrySet()) { - sreq.requirement(reqMap.getKey(), reqMap.getValue()); - } - return sreq; - } - - private void convertSecurityDefinitions(Map<String, SecurityScheme> securitySchemes) { - for (Map.Entry<String, SecurityScheme> entry : securitySchemes.entrySet()) { - openApi2.addSecurityDefinition(entry.getKey(), convertSecurityScheme(entry.getValue())); - } - } - - private SecuritySchemeDefinition convertSecurityScheme(SecurityScheme securityScheme) { - SecuritySchemeDefinition swaggerScheme = null; - switch (securityScheme.getType()) { - case HTTP: - if ("basic".equals(securityScheme.getScheme())) { - swaggerScheme = new BasicAuthDefinition(); - } else { - throw new IllegalStateException("OpenAPI 2.0 does not support bearer token security schemes."); - } - break; - case APIKEY: - if (securityScheme.getIn() == SecurityScheme.In.COOKIE) { - throw new IllegalStateException("Invalid 'in' value for API Key security scheme"); - } else { - swaggerScheme - = new ApiKeyAuthDefinition(securityScheme.getName(), In.forValue(securityScheme.getIn().name())); - } - break; - case OAUTH2: - OAuth2Definition oauth2 = new OAuth2Definition(); - OAuthFlows flows = securityScheme.getFlows(); - Scopes scopes = null; - if (flows.getImplicit() != null) { - oauth2.implicit(flows.getImplicit().getAuthorizationUrl()); - scopes = flows.getImplicit().getScopes(); - } else if (flows.getPassword() != null) { - oauth2.password(flows.getPassword().getTokenUrl()); - scopes = flows.getPassword().getScopes(); - } else if (flows.getClientCredentials() != null) { - oauth2.application(flows.getClientCredentials().getTokenUrl()); - scopes = flows.getClientCredentials().getScopes(); - } else if (flows.getAuthorizationCode() != null) { - oauth2.accessCode(flows.getAuthorizationCode().getAuthorizationUrl(), - flows.getAuthorizationCode().getTokenUrl()); - scopes = flows.getAuthorizationCode().getScopes(); - } else { - // TODO: handle other - } - if (scopes != null) { - for (Map.Entry<String, String> entry : scopes.entrySet()) { - oauth2.addScope(entry.getKey(), entry.getValue()); - } - } - - swaggerScheme = oauth2; - break; - default: - throw new IllegalStateException( - "Security scheme " + securityScheme.getType().toString() - + "is not supported in OpenAPI 2"); - } - if (swaggerScheme != null && securityScheme.getDescription() != null) { - swaggerScheme.setDescription(securityScheme.getDescription()); - } - return swaggerScheme; - } - - private void setServerInfo(Swagger openApi2, List<Server> servers) { - // set host, basePath & schemas - for (Server server : servers) { - String serverUrl = server.getUrl(); - if (serverUrl != null && !serverUrl.isEmpty()) { - try { - URL url = new URL(serverUrl); - openApi2.setHost(url.getHost() + ":" + url.getPort()); - openApi2.setBasePath(url.getPath()); - Scheme scheme = Scheme.forValue(url.getProtocol()); - if (scheme != null) { - openApi2.addScheme(scheme); - } - } catch (MalformedURLException e) { - log.warn("Malformed URL in configuration: {}", serverUrl); - int basePathIndex = serverUrl.lastIndexOf('/'); - if (basePathIndex > 0) { - openApi2.setBasePath(serverUrl.substring(basePathIndex)); - } else { - basePathIndex = serverUrl.length() - 1; - } - int protIndex = serverUrl.indexOf("://"); - if (protIndex > 0) { - String protocol = serverUrl.substring(0, protIndex); - Scheme scheme = Scheme.forValue(protocol); - if (scheme != null) { - openApi2.addScheme(scheme); - } - openApi2.setHost(serverUrl.substring(protIndex + 3, basePathIndex)); - } else { - openApi2.setHost(serverUrl.substring(0, basePathIndex)); - } - } - } - } - - } - - public byte[] getSwaggerAsJson() { - ObjectMapper mapper = Json.mapper(); - mapper.enable(SerializationFeature.INDENT_OUTPUT); - // mapper.setSerializationInclusion(.Include.NON_NULL); - try { - return mapper.writeValueAsBytes(openApi2); - } catch (JsonProcessingException e) { - // TODO Auto-generated catch block - return new byte[0]; - } - } - - public byte[] getSwaggerAsYaml() { - ObjectMapper mapper = Json.mapper(); - try { - JsonNode node = mapper.readTree(getSwaggerAsJson()); - return Yaml.mapper().writerWithDefaultPrettyPrinter().writeValueAsBytes(node); - } catch (IOException e) { - // TODO Auto-generated catch block - return new byte[0]; - } - } - - private Map<String, Path> getPaths(Paths paths) { - Map<String, Path> swaggerPaths = new java.util.HashMap<>(); - for (Map.Entry<String, PathItem> pathItem : paths.entrySet()) { - swaggerPaths.put(pathItem.getKey(), convertPathItem(pathItem.getValue())); - } - return swaggerPaths; - } - - private Path convertPathItem(PathItem pathItem) { - Path path = new Path(); - for (Map.Entry<PathItem.HttpMethod, io.swagger.v3.oas.models.Operation> op : pathItem.readOperationsMap().entrySet()) { - path.set(op.getKey().name().toLowerCase(), convertOperation(op.getValue())); - } - return path; - } - - private Operation convertOperation(io.swagger.v3.oas.models.Operation openApiOp) { - Operation swaggerOp = new Operation().operationId(openApiOp.getOperationId()); - if (openApiOp.getTags() != null) { - swaggerOp.setTags(openApiOp.getTags()); - } - if (openApiOp.getExtensions() != null) { - swaggerOp.setVendorExtensions(openApiOp.getExtensions()); - } - swaggerOp.setSummary(openApiOp.getSummary()); - swaggerOp.setDeprecated(openApiOp.getDeprecated()); - if (openApiOp.getSecurity() != null) { - for (SecurityRequirement srs : openApiOp.getSecurity()) { - for (Map.Entry<String, List<String>> sr : srs.entrySet()) { - swaggerOp.addSecurity(sr.getKey(), sr.getValue()); - } - } - } - if (openApiOp.getParameters() != null) { - for (io.swagger.v3.oas.models.parameters.Parameter param : openApiOp.getParameters()) { - swaggerOp.addParameter(convertParameter(param)); - } - } - if (openApiOp.getRequestBody() != null) { - swaggerOp.addParameter(convertRequestBodyToParameter(openApiOp.getRequestBody())); - swaggerOp.setConsumes(getConsumers(openApiOp.getRequestBody())); - } - if (openApiOp.getResponses() != null) { - for (Entry<String, ApiResponse> resp : openApiOp.getResponses().entrySet()) { - swaggerOp.addResponse(resp.getKey(), convertResponse(resp.getValue())); - } - swaggerOp.setProduces(getProducers(openApiOp.getResponses().values())); - } - - return swaggerOp; - } - - private List<String> getProducers(Collection<ApiResponse> apiResponses) { - List<String> producers = new java.util.ArrayList<>(); - for (ApiResponse response : apiResponses) { - if (response.getContent() != null) { - producers.addAll(response.getContent().keySet()); - } - } - return producers; - } - - private Response convertResponse(ApiResponse apiResponse) { - Response response = new Response().description(apiResponse.getDescription()); - Map<String, Object> examples = new java.util.HashMap<>(); - if (apiResponse.getContent() != null) { - for (MediaType contentType : apiResponse.getContent().values()) { - if (contentType.getSchema() != null) { - response.setResponseSchema(convertSchema(contentType.getSchema())); - if (contentType.getExamples() != null) { - for (Map.Entry<String, Example> ex : contentType.getExamples().entrySet()) { - examples.put(ex.getKey(), ex.getValue().getValue()); - } - } - break; - } - } - } - if (!examples.isEmpty()) { - response.setExamples(examples); - } - if (apiResponse.getHeaders() != null) { - for (Map.Entry<String, Header> hdr : apiResponse.getHeaders().entrySet()) { - Property headerProp = convertHeaderToProperty(hdr.getValue()); - if (headerProp != null) { - response.addHeader(hdr.getKey(), headerProp); - } - } - } - return response; - } - - private Property convertHeaderToProperty(Header header) { - if (header.getSchema() != null) { - Property headerProp = convertSchemaToProperty(header.getSchema()); - if (header.getDescription() != null) { - headerProp.setDescription(header.getDescription()); - } - return headerProp; - } else { - log.warn("Missing schema for Header {}", header); - return null; - } - } - - private List<String> getConsumers(RequestBody requestBody) { - // set consumes for the op to all keys of contentTypes - if (requestBody.getContent() != null) { - return new java.util.ArrayList<>(requestBody.getContent().keySet()); - } else { - return Collections.emptyList(); - } - } - - private Parameter convertRequestBodyToParameter(RequestBody requestBody) { - BodyParameter bodyParam = new BodyParameter().name("body"); - if (requestBody.getRequired()) { - bodyParam.setRequired(requestBody.getRequired()); - } - if (requestBody.getDescription() != null && !requestBody.getDescription().isEmpty()) { - bodyParam.setDescription(requestBody.getDescription()); - } - if (requestBody.getContent() != null) { - for (MediaType contentType : requestBody.getContent().values()) { - if (contentType.getSchema() != null) { - bodyParam.setSchema(convertSchema(contentType.getSchema())); - break; - } - } - for (Entry<String, MediaType> contentType : requestBody.getContent().entrySet()) { - if (contentType.getValue().getExample() != null) { - bodyParam.addExample(contentType.getKey(), contentType.getValue().getExample().toString()); - } - } - - } - return bodyParam; - } - - private Model convertSchema(Schema schema) { - Model model = null; - if (schema instanceof FileSchema) { - // Special case - return new ModelImpl().type("file"); - } - if (schema.get$ref() != null) { - return new RefModel(convertRef(schema.get$ref())); - } else if (schema.getItems() != null) { - model = new ArrayModel().items(convertSchemaToProperty(schema.getItems())); - } else { - model = new ModelImpl().type(schema.getType()).format(schema.getFormat()); - // model = new ModelImpl().type(schema.getType()); - } - if (schema.getProperties() != null) { - model.setProperties(convertPropertiesMap(schema.getProperties())); - } - if (schema.getRequired() != null && model instanceof ModelImpl) { - for (Object req : schema.getRequired()) { - ((ModelImpl) model).addRequired(req.toString()); - } - } - if (schema.getDescription() != null && !schema.getDescription().isEmpty()) { - model.setDescription(schema.getDescription()); - } - if (schema.getExtensions() != null) { - ((ModelImpl) model).setVendorExtensions(schema.getExtensions()); - } - return model; - } - - private Map<String, Property> convertPropertiesMap(Map properties) { - Map<String, Property> swaggerProps = new java.util.HashMap<>(properties.size()); - for (Map.Entry<String, Schema> propEntry : ((Map<String, Schema>) properties).entrySet()) { - swaggerProps.put(propEntry.getKey(), convertSchemaToProperty(propEntry.getValue())); - } - return swaggerProps; - } - - private String convertRef(String schemaRef) { - return schemaRef.replace("#/components/schemas", "#/definitions"); - } - - private Parameter convertParameter(io.swagger.v3.oas.models.parameters.Parameter param) { - switch (param.getIn()) { - case "path": - return initParam(new PathParameter(), param); - case "query": - return initParam(new QueryParameter(), param); - case "cookie": - return initParam(new CookieParameter(), param); - case "header": - return initParam(new HeaderParameter(), param); - default: // should not happen - return null; - } - } - - private Parameter initParam( - AbstractSerializableParameter swaggerParam, io.swagger.v3.oas.models.parameters.Parameter param) { - swaggerParam.name(param.getName()).required(param.getRequired()); - if (param.getDescription() != null) { - swaggerParam.setDescription(param.getDescription()); - } - if (param.getStyle() != null) { - swaggerParam.setCollectionFormat(convertStyleToCollectionFormat(param.getStyle())); - } - if (param.getSchema() != null) { - swaggerParam.setType(param.getSchema().getType()); - swaggerParam.setFormat(param.getSchema().getFormat()); - if (param.getSchema().getDefault() != null) { - swaggerParam.setDefault(param.getSchema().getDefault()); - } - if (param.getSchema().getItems() != null) { - // Convert items schema to swagger items property - swaggerParam.setItems(convertSchemaToProperty(param.getSchema().getItems())); - } - if (param.getSchema().getEnum() != null) { - // Convert enums (ATTENTION, maybe not strings?) - List<String> enums - = ((List<?>) param.getSchema().getEnum()).stream().map(v -> { - if (v instanceof byte[]) { - return new String(Base64.getEncoder().encode((byte[]) v)); - } else if (v instanceof Date) { - return RestOpenApiSupport.DEFAULT_DATE_FORMAT.format(v); - } else { - return v.toString(); - } - }).collect(Collectors.toList()); - swaggerParam.setEnum(enums); - } - } - if (param.getExample() != null) { - swaggerParam.setExample(param.getExample().toString()); - } else if (param.getExamples() != null && !param.getExamples().isEmpty()) { - swaggerParam.setExample(param.getExamples().values().iterator().next().getValue().toString()); - } - - return swaggerParam; - } - - private String convertStyleToCollectionFormat(StyleEnum style) { - switch (style) { - case FORM: - return "csv"; - case SPACEDELIMITED: - return "ssv"; - case PIPEDELIMITED: - return "pipes"; - case DEEPOBJECT: - return "multi"; - default: - return "csv"; - } - } - - private Property convertSchemaToProperty(Schema schema) { - if (schema.get$ref() != null) { - return new RefProperty(convertRef(schema.get$ref())); - } - if (schema instanceof IntegerSchema) { - IntegerProperty prop = new IntegerProperty(); - prop.setFormat(schema.getFormat()); - return prop; - } else if (schema instanceof NumberSchema) { - if ("float".equals(schema.getFormat())) { - return new io.swagger.models.properties.FloatProperty(); - } else if ("double".equals(schema.getFormat())) { - return new io.swagger.models.properties.DoubleProperty(); - } else if ("int64".equals(schema.getFormat())) { - return new io.swagger.models.properties.LongProperty(); - } else { - return new io.swagger.models.properties.BaseIntegerProperty(schema.getFormat()); - } - } else if (schema instanceof ByteArraySchema) { - return new io.swagger.models.properties.ByteArrayProperty(); - } else if (schema instanceof BinarySchema) { - return new io.swagger.models.properties.BinaryProperty(); - } else if (schema instanceof DateSchema) { - return new io.swagger.models.properties.DateProperty(); - } else if (schema instanceof DateTimeSchema) { - return new io.swagger.models.properties.DateTimeProperty(); - } else if (schema instanceof PasswordSchema) { - return new io.swagger.models.properties.PasswordProperty(); - } else if (schema instanceof FileSchema) { - return new io.swagger.models.properties.FileProperty(); - } else if (schema instanceof StringSchema) { - StringProperty prop = new StringProperty(schema.getFormat()); - if (schema.getEnum() != null) { - prop.setEnum(schema.getEnum()); - } - return prop; - } else if (schema instanceof ArraySchema) { - return new io.swagger.models.properties.ArrayProperty(convertSchemaToProperty(schema.getItems())); - } else if (schema instanceof MapSchema) { - if (schema.getAdditionalProperties() != null && schema.getAdditionalProperties() instanceof Schema) { - return new io.swagger.models.properties.MapProperty( - convertSchemaToProperty((Schema) schema.getAdditionalProperties())); - } - if (schema.getAdditionalItems() != null) { - return new io.swagger.models.properties.MapProperty(convertSchemaToProperty(schema.getAdditionalItems())); - } else { - return new io.swagger.models.properties.MapProperty(); // should not happen? - } - } else { - // ??? - return PropertyBuilder.build(schema.getType(), schema.getFormat(), null); - } - } - - private List<Tag> getTags(List<io.swagger.v3.oas.models.tags.Tag> tags) { - if (tags != null) { - List<Tag> swaggerTags = new java.util.ArrayList<>(tags.size()); - for (io.swagger.v3.oas.models.tags.Tag tag : tags) { - swaggerTags.add(new Tag().name(tag.getName()).description(tag.getDescription())); - } - return swaggerTags; - } - return null; - } - - private Info convertInfo(io.swagger.v3.oas.models.info.Info info) { - if (info != null) { - return new Info().description(info.getDescription()) - .title(info.getTitle()) - .termsOfService(info.getTermsOfService()) - .version(info.getVersion()) - .contact(convertContact(info.getContact())) - .license(convertLicense(info.getLicense())); - } else { - return null; - } - } - - private License convertLicense(io.swagger.v3.oas.models.info.License license) { - if (license != null) { - return new License().name(license.getName()).url(license.getUrl()); - } else { - return null; - } - } - - private Contact convertContact(io.swagger.v3.oas.models.info.Contact contact) { - if (contact != null) { - return new Contact().name(contact.getName()).email(contact.getEmail()).url(contact.getUrl()); - } else { - return null; - } - } - -} diff --git a/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/OpenApiRestProducerFactory.java b/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/OpenApiRestProducerFactory.java index ce4d9ecafac..f03ae5c0273 100644 --- a/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/OpenApiRestProducerFactory.java +++ b/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/OpenApiRestProducerFactory.java @@ -19,12 +19,12 @@ package org.apache.camel.openapi; import java.util.Map; import java.util.StringJoiner; -import io.swagger.parser.OpenAPIParser; import io.swagger.v3.oas.models.OpenAPI; import io.swagger.v3.oas.models.Operation; import io.swagger.v3.oas.models.PathItem; import io.swagger.v3.oas.models.parameters.Parameter; import io.swagger.v3.oas.models.responses.ApiResponse; +import io.swagger.v3.parser.OpenAPIV3Parser; import io.swagger.v3.parser.core.models.SwaggerParseResult; import org.apache.camel.CamelContext; import org.apache.camel.Producer; @@ -86,7 +86,7 @@ public class OpenApiRestProducerFactory implements RestProducerFactory { } OpenAPI loadOpenApiModel(String apiDoc) throws Exception { - final OpenAPIParser openApiParser = new OpenAPIParser(); + final OpenAPIV3Parser openApiParser = new OpenAPIV3Parser(); final SwaggerParseResult openApi = openApiParser.readLocation(apiDoc, null, null); if (openApi != null && openApi.getOpenAPI() != null) { diff --git a/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/RestOpenApiReader.java b/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/RestOpenApiReader.java index 49753a4de42..a93d328dea4 100644 --- a/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/RestOpenApiReader.java +++ b/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/RestOpenApiReader.java @@ -179,9 +179,7 @@ public class RestOpenApiReader { private void checkCompatOpenApi2(OpenAPI openApi, BeanConfig config) { if (config.isOpenApi2()) { - // Verify that the OpenAPI 3 model can be downgraded to OpenApi 2 - OpenAPI3to2 converter = new OpenAPI3to2(); - converter.convertOpenAPI3to2(openApi); + throw new IllegalArgumentException("OpenAPI 2.x is not supported"); } } diff --git a/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/RestOpenApiSupport.java b/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/RestOpenApiSupport.java index 1046adff07d..ef2a47ccc37 100644 --- a/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/RestOpenApiSupport.java +++ b/components/camel-openapi-java/src/main/java/org/apache/camel/openapi/RestOpenApiSupport.java @@ -336,13 +336,7 @@ public class RestOpenApiSupport { public static <T extends Object> T getFromOpenAPI(OpenAPI openApi, BeanConfig config, Class<T> type, boolean json) { if (config.isOpenApi2()) { - OpenAPI3to2 converter = new OpenAPI3to2(); - converter.convertOpenAPI3to2(openApi); - byte[] bytes = converter.getSwaggerAsJson(); - if (type.equals(String.class)) { - return type.cast(new String(bytes, StandardCharsets.UTF_8)); - } - return type.cast(bytes); + throw new IllegalArgumentException("OpenAPI 2.x is not supported"); } else { ObjectMapper mapper = json ? config.isOpenApi31() ? Json31.mapper() : Json.mapper() : config.isOpenApi31() ? Yaml31.mapper() : Yaml.mapper(); diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/ComplexTypesTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/ComplexTypesTest.java index ddecb2e8c81..b39ebeaa8d5 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/ComplexTypesTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/ComplexTypesTest.java @@ -141,16 +141,12 @@ public class ComplexTypesTest extends CamelTestSupport { static Stream<Arguments> uriAndVersionVariations() { return Stream.of( - arguments("/complexRequest", "2.0"), arguments("/complexRequest", "3.0"), arguments("/complexRequest", "3.1"), - arguments("/complexResponse", "2.0"), arguments("/complexResponse", "3.0"), arguments("/complexResponse", "3.1"), - arguments("/complexRequestWithSchemaAnnotation", "2.0"), arguments("/complexRequestWithSchemaAnnotation", "3.0"), arguments("/complexRequestWithSchemaAnnotation", "3.1"), - arguments("/complexResponseWithSchemaAnnotation", "2.0"), arguments("/complexResponseWithSchemaAnnotation", "3.0"), arguments("/complexResponseWithSchemaAnnotation", "3.1")); } diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/OpenApiRestProducerFactoryTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/OpenApiRestProducerFactoryTest.java index dfefbbd0a5f..cb0d648ae2e 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/OpenApiRestProducerFactoryTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/OpenApiRestProducerFactoryTest.java @@ -22,13 +22,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; public class OpenApiRestProducerFactoryTest { - @Test - public void shouldLoadOpenApiPetStoreModel() throws Exception { - OpenApiRestProducerFactory factory = new OpenApiRestProducerFactory(); - - assertNotNull(factory.loadOpenApiModel("petstore.json")); - } - @Test public void shouldLoadOpenApiPetStoreModelV3() throws Exception { OpenApiRestProducerFactory factory = new OpenApiRestProducerFactory(); diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiDefaultProducesConsumesTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiDefaultProducesConsumesTest.java index e1848f15e56..9b4a8b547ff 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiDefaultProducesConsumesTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiDefaultProducesConsumesTest.java @@ -40,7 +40,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class RestOpenApiDefaultProducesConsumesTest { private static final ObjectMapper MAPPER = new ObjectMapper(); - private static final String[] OPENAPI_VERSIONS = { "3.1", "3.0", "2.0" }; + private static final String[] OPENAPI_VERSIONS = { "3.1", "3.0" }; private final Logger log = LoggerFactory.getLogger(getClass()); @ParameterizedTest diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiLicenseInfoTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiLicenseInfoTest.java index 530eefc6510..51493db6f17 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiLicenseInfoTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiLicenseInfoTest.java @@ -31,7 +31,7 @@ import static org.junit.jupiter.api.Assertions.assertTrue; public class RestOpenApiLicenseInfoTest { @ParameterizedTest - @ValueSource(strings = { "3.1", "3.0", "2.0" }) + @ValueSource(strings = { "3.1", "3.0" }) public void testLicenseInfo(String openApiVersion) throws Exception { CamelContext context = new DefaultCamelContext(); context.addRoutes(new RouteBuilder() { diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiModelApiSecurityRequirementsTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiModelApiSecurityRequirementsTest.java index d4ff6b60dce..4cd80fd47f0 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiModelApiSecurityRequirementsTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiModelApiSecurityRequirementsTest.java @@ -20,7 +20,6 @@ import io.swagger.v3.oas.models.OpenAPI; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.engine.DefaultClassResolver; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.slf4j.Logger; @@ -52,34 +51,6 @@ public class RestOpenApiModelApiSecurityRequirementsTest extends CamelTestSuppor }; } - @Test - public void testReaderRead() throws Exception { - BeanConfig config = new BeanConfig(); - config.setHost("localhost:8080"); - config.setSchemes(new String[] { "http" }); - config.setBasePath("/api"); - config.setTitle("Camel User store"); - config.setLicense("Apache 2.0"); - config.setLicenseUrl("https://www.apache.org/licenses/LICENSE-2.0.html"); - config.setVersion("2.0"); - RestOpenApiReader reader = new RestOpenApiReader(); - - OpenAPI openApi = reader.read(context, context.getRestDefinitions(), config, context.getName(), - new DefaultClassResolver()); - assertNotNull(openApi); - String json = RestOpenApiSupport.getJsonFromOpenAPIAsString(openApi, config); - log.info(json); - - assertTrue(json.contains("\"securityDefinitions\" : {")); - assertTrue(json.contains("\"type\" : \"oauth2\"")); - assertTrue(json.contains("\"authorizationUrl\" : \"https://petstore.swagger.io/oauth/dialog\"")); - assertTrue(json.contains("\"flow\" : \"implicit\"")); - assertTrue(json.contains("\"type\" : \"apiKey\",")); - assertTrue(json.contains("\"security\" : [ {")); - assertTrue(json.contains("\"petstore_auth\" : [ \"read\", \"write\" ]")); - assertTrue(json.contains("\"api_key\" : [ ]")); - } - @ParameterizedTest @ValueSource(strings = { "3.1", "3.0" }) public void testReaderReadV3(String version) throws Exception { diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderApiDocsOverrideTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderApiDocsOverrideTest.java index 68e4c3cadb2..d76c698b5d9 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderApiDocsOverrideTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderApiDocsOverrideTest.java @@ -58,7 +58,7 @@ public class RestOpenApiReaderApiDocsOverrideTest extends CamelTestSupport { } @ParameterizedTest - @ValueSource(strings = { "3.1", "3.0", "2.0" }) + @ValueSource(strings = { "3.1", "3.0" }) public void testReaderRead(String version) throws Exception { BeanConfig config = new BeanConfig(); config.setHost("localhost:8080"); diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderApiDocsTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderApiDocsTest.java index 95d2963ebb7..72a8396a272 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderApiDocsTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderApiDocsTest.java @@ -58,7 +58,7 @@ public class RestOpenApiReaderApiDocsTest extends CamelTestSupport { } @ParameterizedTest - @ValueSource(strings = { "3.1", "3.0", "2.0" }) + @ValueSource(strings = { "3.1", "3.0" }) public void testReaderRead(String version) throws Exception { BeanConfig config = getBeanConfig(); config.setVersion(version); diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderContextPathTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderContextPathTest.java index 36fdb3c7f65..dcf09a8d8d0 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderContextPathTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderContextPathTest.java @@ -23,7 +23,6 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.engine.DefaultClassResolver; import org.apache.camel.model.rest.RestParamType; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.slf4j.Logger; @@ -63,43 +62,6 @@ public class RestOpenApiReaderContextPathTest extends CamelTestSupport { }; } - @Test - public void testReaderRead() throws Exception { - BeanConfig config = new BeanConfig(); - config.setHost("localhost:8080"); - config.setSchemes(new String[] { "http" }); - config.setBasePath("/api"); - config.setInfo(new Info()); - config.setVersion("2.0"); - RestOpenApiReader reader = new RestOpenApiReader(); - - OpenAPI openApi = reader.read(context, context.getRestDefinitions(), config, context.getName(), - new DefaultClassResolver()); - assertNotNull(openApi); - - String json = RestOpenApiSupport.getJsonFromOpenAPIAsString(openApi, config); - - log.info(json); - - assertTrue(json.contains("\"host\" : \"localhost:8080\"")); - assertTrue(json.contains("\"basePath\" : \"/api\"")); - assertTrue(json.contains("\"/hello/bye\"")); - assertTrue(json.contains("\"summary\" : \"To update the greeting message\"")); - assertTrue(json.contains("\"/hello/bye/{name}\"")); - assertFalse(json.contains("\"/api/hello/bye/{name}\"")); - assertTrue(json.contains("\"/hello/hi/{name}\"")); - assertFalse(json.contains("\"/api/hello/hi/{name}\"")); - assertTrue(json.contains("\"type\" : \"number\"")); - assertTrue(json.contains("\"format\" : \"float\"")); - assertTrue(json.contains("\"application/xml\" : \"<hello>Hi</hello>\"")); - assertTrue(json.contains("\"x-example\" : \"Donald Duck\"")); - assertTrue(json.contains("\"success\" : \"123\"")); - assertTrue(json.contains("\"error\" : \"-1\"")); - assertTrue(json.contains("\"type\" : \"array\"")); - - context.stop(); - } - @ParameterizedTest @ValueSource(strings = { "3.1", "3.0" }) public void testReaderReadV3(String version) throws Exception { diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderDayOfWeekTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderDayOfWeekTest.java index de31da98064..d098681626d 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderDayOfWeekTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderDayOfWeekTest.java @@ -57,7 +57,7 @@ public class RestOpenApiReaderDayOfWeekTest extends CamelTestSupport { } @ParameterizedTest - @ValueSource(strings = { "3.1", "3.0", "2.0" }) + @ValueSource(strings = { "3.1", "3.0" }) public void testReaderRead(String version) throws Exception { BeanConfig config = new BeanConfig(); config.setHost("localhost:8080"); @@ -76,13 +76,8 @@ public class RestOpenApiReaderDayOfWeekTest extends CamelTestSupport { String json = RestOpenApiSupport.getJsonFromOpenAPIAsString(openApi, config); log.info(json); - if (config.isOpenApi2()) { - assertTrue(json.contains("\"host\" : \"localhost:8080\"")); - assertTrue(json.contains("\"$ref\" : \"#/definitions/DayResponse\"")); - } else { - assertTrue(json.contains("\"url\" : \"http://localhost:8080/api\"")); - assertTrue(json.contains("\"$ref\" : \"#/components/schemas/DayResponse\"")); - } + assertTrue(json.contains("\"url\" : \"http://localhost:8080/api\"")); + assertTrue(json.contains("\"$ref\" : \"#/components/schemas/DayResponse\"")); assertTrue(json.contains("\"default\" : \"friday\"")); assertTrue(json.contains("\"enum\" : [ \"monday\", \"tuesday\", \"wednesday\", \"thursday\", \"friday\" ]")); assertTrue(json.contains("\"format\" : \"org.apache.camel.openapi.DayResponse\"")); diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderDisabledTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderDisabledTest.java index 05ec77811c5..b02adf6d8da 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderDisabledTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderDisabledTest.java @@ -23,7 +23,6 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.engine.DefaultClassResolver; import org.apache.camel.model.rest.RestParamType; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.slf4j.Logger; @@ -63,42 +62,6 @@ public class RestOpenApiReaderDisabledTest extends CamelTestSupport { }; } - @Test - public void testReaderRead() throws Exception { - BeanConfig config = new BeanConfig(); - config.setHost("localhost:8080"); - config.setSchemes(new String[] { "http" }); - config.setBasePath("/api"); - config.setInfo(new Info()); - config.setVersion("2.0"); - RestOpenApiReader reader = new RestOpenApiReader(); - - OpenAPI openApi = reader.read(context, context.getRestDefinitions(), config, context.getName(), - new DefaultClassResolver()); - assertNotNull(openApi); - - String json = RestOpenApiSupport.getJsonFromOpenAPIAsString(openApi, config); - log.info(json); - - assertTrue(json.contains("\"host\" : \"localhost:8080\"")); - assertTrue(json.contains("\"basePath\" : \"/api\"")); - assertFalse(json.contains("\"/hello/bye\"")); - assertFalse(json.contains("\"summary\" : \"To update the greeting message\"")); - assertFalse(json.contains("\"/hello/bye/{name}\"")); - assertFalse(json.contains("\"/api/hello/bye/{name}\"")); - assertTrue(json.contains("\"/hello/hi/{name}\"")); - assertFalse(json.contains("\"/api/hello/hi/{name}\"")); - assertFalse(json.contains("\"type\" : \"number\"")); - assertFalse(json.contains("\"format\" : \"float\"")); - assertFalse(json.contains("\"application/xml\" : \"<hello>Hi</hello>\"")); - assertTrue(json.contains("\"x-example\" : \"Donald Duck\"")); - assertFalse(json.contains("\"success\" : \"123\"")); - assertFalse(json.contains("\"error\" : \"-1\"")); - assertTrue(json.contains("\"type\" : \"array\"")); - - context.stop(); - } - @ParameterizedTest @ValueSource(strings = { "3.1", "3.0" }) public void testReaderReadV3(String version) throws Exception { diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderEnableVendorExtensionTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderEnableVendorExtensionTest.java index 9aeeef616b3..29ef371069b 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderEnableVendorExtensionTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderEnableVendorExtensionTest.java @@ -70,7 +70,7 @@ public class RestOpenApiReaderEnableVendorExtensionTest extends CamelTestSupport } @ParameterizedTest - @ValueSource(strings = { "3.1", "3.0", "2.0" }) + @ValueSource(strings = { "3.1", "3.0" }) public void testEnableVendorExtension(String version) throws Exception { BeanConfig config = new BeanConfig(); config.setHost("localhost:8080"); @@ -91,13 +91,8 @@ public class RestOpenApiReaderEnableVendorExtensionTest extends CamelTestSupport String camelId = context.getName(); - if (config.isOpenApi2()) { - assertTrue(json.contains("\"host\" : \"localhost:8080\"")); - assertTrue(json.contains("\"$ref\" : \"#/definitions/User\"")); - } else { - assertTrue(json.contains("\"url\" : \"http://localhost:8080/api\"")); - assertTrue(json.contains("\"$ref\" : \"#/components/schemas/User\"")); - } + assertTrue(json.contains("\"url\" : \"http://localhost:8080/api\"")); + assertTrue(json.contains("\"$ref\" : \"#/components/schemas/User\"")); assertTrue(json.contains("\"description\" : \"The user returned\"")); assertFalse(json.contains("\"enum\"")); assertTrue(json.contains("\"x-camelContextId\" : \"" + camelId + "\"")); diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderFileResponseModelTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderFileResponseModelTest.java index fd80fb62cd7..fb868d90953 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderFileResponseModelTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderFileResponseModelTest.java @@ -51,7 +51,7 @@ public class RestOpenApiReaderFileResponseModelTest extends CamelTestSupport { } @ParameterizedTest - @ValueSource(strings = { "3.1", "3.0", "2.0" }) + @ValueSource(strings = { "3.1", "3.0" }) public void testReaderRead(String version) throws Exception { BeanConfig config = new BeanConfig(); config.setHost("localhost:8080"); @@ -68,12 +68,8 @@ public class RestOpenApiReaderFileResponseModelTest extends CamelTestSupport { String json = RestOpenApiSupport.getJsonFromOpenAPIAsString(openApi, config); LOG.info(json); - if (config.isOpenApi2()) { - assertTrue(json.contains("\"type\" : \"file\"")); - } else { - assertTrue(json.contains("\"format\" : \"binary\"")); - assertTrue(json.contains("\"type\" : \"string\"")); - } + assertTrue(json.contains("\"format\" : \"binary\"")); + assertTrue(json.contains("\"type\" : \"string\"")); context.stop(); } diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderModelApiSecurityTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderModelApiSecurityTest.java index a0015aea829..49ab693a256 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderModelApiSecurityTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderModelApiSecurityTest.java @@ -22,7 +22,6 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.engine.DefaultClassResolver; import org.apache.camel.model.rest.RestParamType; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.slf4j.Logger; @@ -75,45 +74,6 @@ public class RestOpenApiReaderModelApiSecurityTest extends CamelTestSupport { }; } - @Test - public void testReaderRead() throws Exception { - BeanConfig config = new BeanConfig(); - config.setHost("localhost:8080"); - config.setSchemes(new String[] { "http" }); - config.setBasePath("/api"); - config.setTitle("Camel User store"); - config.setLicense("Apache 2.0"); - config.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html"); - config.setVersion("2.0"); - RestOpenApiReader reader = new RestOpenApiReader(); - - OpenAPI openApi = reader.read(context, context.getRestDefinitions(), config, context.getName(), - new DefaultClassResolver()); - assertNotNull(openApi); - - String json = RestOpenApiSupport.getJsonFromOpenAPIAsString(openApi, config); - - log.info(json); - - assertTrue(json.contains("\"securityDefinitions\" : {")); - assertTrue(json.contains("\"type\" : \"oauth2\"")); - assertTrue(json.contains("\"authorizationUrl\" : \"http://petstore.swagger.io/oauth/dialog\"")); - assertTrue(json.contains("\"flow\" : \"implicit\"")); - assertTrue(json.contains("\"type\" : \"apiKey\",")); - assertTrue(json.contains("\"in\" : \"header\"")); - assertTrue(json.contains("\"host\" : \"localhost:8080\"")); - assertTrue(json.contains("\"security\" : [ {")); - assertTrue(json.contains("\"petstore_auth\" : [ \"write:pets\", \"read:pets\" ]")); - assertTrue(json.contains("\"api_key\" : [ ]")); - assertTrue(json.contains("\"description\" : \"The user returned\"")); - assertTrue(json.contains("\"$ref\" : \"#/definitions/User\"")); - assertTrue(json.contains("\"format\" : \"org.apache.camel.openapi.User\"")); - assertTrue(json.contains("\"type\" : \"string\"")); - assertTrue(json.contains("\"format\" : \"date\"")); - assertFalse(json.contains("\"enum\"")); - context.stop(); - } - @ParameterizedTest @ValueSource(strings = { "3.1", "3.0" }) public void testReaderReadV3(String version) throws Exception { diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderModelBookOrderTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderModelBookOrderTest.java index 4c3ef3bf376..6bda7819b24 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderModelBookOrderTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderModelBookOrderTest.java @@ -22,7 +22,6 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.engine.DefaultClassResolver; import org.apache.camel.model.rest.RestParamType; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.slf4j.Logger; @@ -70,38 +69,6 @@ public class RestOpenApiReaderModelBookOrderTest extends CamelTestSupport { }; } - @Test - public void testReaderRead() throws Exception { - BeanConfig config = new BeanConfig(); - config.setHost("localhost:8080"); - config.setSchemes(new String[] { "http" }); - config.setBasePath("/api"); - config.setTitle("Camel User store"); - config.setLicense("Apache 2.0"); - config.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html"); - config.setVersion("2.0"); - RestOpenApiReader reader = new RestOpenApiReader(); - - OpenAPI openApi = reader.read(context, context.getRestDefinitions(), config, context.getName(), - new DefaultClassResolver()); - assertNotNull(openApi); - - String json = RestOpenApiSupport.getJsonFromOpenAPIAsString(openApi, config); - - log.info(json); - - assertTrue(json.contains("\"host\" : \"localhost:8080\"")); - assertTrue(json.contains("\"description\" : \"The order returned\"")); - assertTrue(json.contains("\"BookOrder\"")); - assertTrue(json.contains("\"LineItem\"")); - assertTrue(json.contains("\"$ref\" : \"#/definitions/BookOrder\"")); - assertTrue(json.contains("\"$ref\" : \"#/definitions/LineItem\"")); - assertTrue(json.contains("\"format\" : \"org.apache.camel.openapi.BookOrder\"")); - assertTrue(json.contains("\"format\" : \"org.apache.camel.openapi.LineItem\"")); - - context.stop(); - } - @ParameterizedTest @ValueSource(strings = { "3.1", "3.0" }) public void testReaderReadV3(String version) throws Exception { diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderModelTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderModelTest.java index 9d316574076..8549856aaf0 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderModelTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderModelTest.java @@ -22,7 +22,6 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.engine.DefaultClassResolver; import org.apache.camel.model.rest.RestParamType; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.slf4j.Logger; @@ -68,38 +67,6 @@ public class RestOpenApiReaderModelTest extends CamelTestSupport { }; } - @Test - public void testReaderRead() throws Exception { - BeanConfig config = new BeanConfig(); - config.setHost("localhost:8080"); - config.setSchemes(new String[] { "http" }); - config.setBasePath("/api"); - config.setTitle("Camel User store"); - config.setLicense("Apache 2.0"); - config.setVersion("2.0"); - config.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html"); - RestOpenApiReader reader = new RestOpenApiReader(); - - OpenAPI openApi = reader.read(context, context.getRestDefinitions(), config, context.getName(), - new DefaultClassResolver()); - assertNotNull(openApi); - - String json = RestOpenApiSupport.getJsonFromOpenAPIAsString(openApi, config); - - log.info(json); - - assertTrue(json.contains("\"host\" : \"localhost:8080\"")); - assertTrue(json.contains("\"description\" : \"The user returned\"")); - assertTrue(json.contains("\"$ref\" : \"#/definitions/User\"")); - assertFalse(json.contains("\"$ref\" : \"#/definitions/org.apache.camel.openapi.User\"")); - assertTrue(json.contains("\"x-className\"")); - assertTrue(json.contains("\"format\" : \"org.apache.camel.openapi.User\"")); - assertTrue(json.contains("\"type\" : \"string\"")); - assertTrue(json.contains("\"format\" : \"date\"")); - assertFalse(json.contains("\"enum\"")); - context.stop(); - } - @ParameterizedTest @ValueSource(strings = { "3.1", "3.0" }) public void testReaderReadV3(String version) throws Exception { diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderPropertyPlaceholderTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderPropertyPlaceholderTest.java index 6f37c5717bd..a737eeedfbf 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderPropertyPlaceholderTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderPropertyPlaceholderTest.java @@ -79,7 +79,7 @@ public class RestOpenApiReaderPropertyPlaceholderTest extends CamelTestSupport { } @ParameterizedTest - @ValueSource(strings = { "3.1", "3.0", "2.0" }) + @ValueSource(strings = { "3.1", "3.0" }) public void testReaderRead(String version) throws Exception { BeanConfig config = new BeanConfig(); config.setHost("localhost:8080"); @@ -97,12 +97,7 @@ public class RestOpenApiReaderPropertyPlaceholderTest extends CamelTestSupport { String json = RestOpenApiSupport.getJsonFromOpenAPIAsString(openApi, config); log.info(json); - if (config.isOpenApi2()) { - assertTrue(json.contains("\"host\" : \"localhost:8080\"")); - assertTrue(json.contains("\"basePath\" : \"/api\"")); - } else { - assertTrue(json.contains("\"url\" : \"http://localhost:8080/api\"")); - } + assertTrue(json.contains("\"url\" : \"http://localhost:8080/api\"")); assertTrue(json.contains("\"/hello/bye\"")); assertTrue(json.contains("\"summary\" : \"To update the greeting message\"")); assertTrue(json.contains("\"/hello/bye/{name}\"")); diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderTest.java index a59cc9da3e3..6416ab51f45 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiReaderTest.java @@ -23,7 +23,6 @@ import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.engine.DefaultClassResolver; import org.apache.camel.model.rest.RestParamType; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.slf4j.Logger; @@ -216,64 +215,6 @@ public class RestOpenApiReaderTest extends CamelTestSupport { }; } - @Test - public void testReaderRead() throws Exception { - BeanConfig config = new BeanConfig(); - config.setHost("localhost:8080"); - config.setSchemes(new String[] { "http" }); - config.setBasePath("/api"); - config.setInfo(new Info()); - config.setVersion("2.0"); - - RestOpenApiReader reader = new RestOpenApiReader(); - - OpenAPI openApi = reader.read(context, context.getRestDefinitions(), config, context.getName(), - new DefaultClassResolver()); - assertNotNull(openApi); - - String json = RestOpenApiSupport.getJsonFromOpenAPIAsString(openApi, config); - String flatJson = json.replace("\n", " ").replaceAll("\\s+", " "); - - log.info(json); - - assertTrue(json.contains("\"host\" : \"localhost:8080\"")); - assertTrue(json.contains("\"basePath\" : \"/api\"")); - assertTrue(json.contains("\"/hello/bye\"")); - assertTrue(json.contains("\"summary\" : \"To update the greeting message\"")); - assertTrue(json.contains("\"/hello/bye/{name}\"")); - assertTrue(json.contains("\"/hello/hi/{name}\"")); - assertTrue(json.contains("\"type\" : \"number\"")); - assertTrue(json.contains("\"format\" : \"float\"")); - assertTrue(json.contains("\"application/xml\" : \"<hello>Hi</hello>\"")); - assertTrue(json.contains("\"x-example\" : \"Donald Duck\"")); - assertTrue(json.contains("\"success\" : \"123\"")); - assertTrue(json.contains("\"error\" : \"-1\"")); - assertTrue(json.contains("\"type\" : \"array\"")); - assertTrue(json.contains("\"enum\" : [ \"A\", \"B\", \"C\" ]")); - assertTrue(json.contains("\"enum\" : [ 1, 2, 3 ]")); - assertTrue(json.contains("\"enum\" : [ 1.0, 2.0, 3.0 ]")); - assertTrue(json.contains("\"enum\" : [ \"true\", \"false\" ]")); - assertTrue(json.contains("\"enum\" : [ \"MQ==\", \"Mg==\", \"Mw==\" ]")); - assertTrue(json.contains("\"enum\" : [ \"2023-01-01\", \"2023-02-02\", \"2023-03-03\" ]")); - assertTrue(json.contains("\"enum\" : [ \"2011-12-03T10:15:30+01:00\" ]")); - assertTrue(json.contains("\"enum\" : [ \"foo\", \"bar\", \"cheese\" ]")); - - flatJson = flatJson.replaceAll("\"operationId\" : \"[^\\\"]*\", ", "").replaceAll("\"summary\" : \"[^\\\"]*\", ", ""); - log.info(flatJson); - assertTrue(flatJson.contains( - "\"/hello/bye\" : { \"post\" : { \"tags\" : [ \"/hello\" ], \"consumes\" : [ \"application/xml\" ], \"produces\" : [ \"application/xml\" ], ")); - assertTrue(flatJson.contains( - "\"/tag/single\" : { \"get\" : { \"tags\" : [ \"Organisation\" ], \"consumes\" : [ \"application/json\" ], \"produces\" : [ \"application/json\" ], ")); - assertTrue(flatJson.contains( - "\"/tag/multiple/a\" : { \"get\" : { \"tags\" : [ \"Organisation\", \"Group A\" ], \"consumes\" : [ \"application/json\" ], \"produces\" : [ \"application/json\" ], ")); - assertTrue(flatJson.contains( - "\"/tag/multiple/b\" : { \"get\" : { \"tags\" : [ \"Organisation\", \"Group B\" ], \"consumes\" : [ \"application/json\" ], \"produces\" : [ \"application/json\" ], ")); - assertTrue(flatJson.contains( - "\"tags\" : [ { \"name\" : \"/hello\" }, { \"name\" : \"Organisation\" }, { \"name\" : \"Group A\" }, { \"name\" : \"Group B\" } ]")); - - context.stop(); - } - @ParameterizedTest @ValueSource(strings = { "3.0", "3.1" }) public void testReaderReadV3(String version) throws Exception { diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiV2SecuritySchemesTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiV2SecuritySchemesTest.java deleted file mode 100644 index e598ad04730..00000000000 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiV2SecuritySchemesTest.java +++ /dev/null @@ -1,96 +0,0 @@ -/* - * Licensed to the Apache Software Foundation (ASF) under one or more - * contributor license agreements. See the NOTICE file distributed with - * this work for additional information regarding copyright ownership. - * The ASF licenses this file to You under the Apache License, Version 2.0 - * (the "License"); you may not use this file except in compliance with - * the License. You may obtain a copy of the License at - * - * http://www.apache.org/licenses/LICENSE-2.0 - * - * Unless required by applicable law or agreed to in writing, software - * distributed under the License is distributed on an "AS IS" BASIS, - * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. - * See the License for the specific language governing permissions and - * limitations under the License. - */ -package org.apache.camel.openapi; - -import io.swagger.v3.oas.models.OpenAPI; -import org.apache.camel.builder.RouteBuilder; -import org.apache.camel.impl.engine.DefaultClassResolver; -import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; - -import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertTrue; - -public class RestOpenApiV2SecuritySchemesTest extends CamelTestSupport { - - private final Logger log = LoggerFactory.getLogger(getClass()); - - @Override - protected RouteBuilder createRouteBuilder() { - return new RouteBuilder() { - @Override - public void configure() { - rest() - .securityDefinitions() - .oauth2("petstore_auth_implicit")// OAuth implicit - .authorizationUrl("https://petstore.swagger.io/oauth/dialog") - .end() - .oauth2("oauth_password") - .flow("password") - .tokenUrl("https://petstore.swagger.io/oauth/token") - .end() - .oauth2("oauth2_accessCode")// OAuth access/authorization code - .authorizationUrl("https://petstore.swagger.io/oauth/dialog") - .tokenUrl("https://petstore.swagger.io/oauth/token") - .end() - .apiKey("api_key_header") - .withHeader("myHeader") - .end() - .apiKey("api_key_query") - .withQuery("myQuery") - .end() - .end(); - } - }; - } - - @Test - public void testSecuritySchemesV2() throws Exception { - BeanConfig config = new BeanConfig(); - config.setHost("localhost:8080"); - config.setSchemes(new String[] { "http" }); - config.setBasePath("/api"); - config.setTitle("Camel User store"); - config.setLicense("Apache 2.0"); - config.setLicenseUrl("https://www.apache.org/licenses/LICENSE-2.0.html"); - config.setVersion("2.0"); - - RestOpenApiReader reader = new RestOpenApiReader(); - OpenAPI openApi = reader.read(context, context.getRestDefinitions(), config, context.getName(), - new DefaultClassResolver()); - assertNotNull(openApi); - - String json = RestOpenApiSupport.getJsonFromOpenAPIAsString(openApi, config); - - log.info(json); - - json = json.replace("\n", " ").replaceAll("\\s+", " "); - - assertTrue(json.contains("\"petstore_auth_implicit\" : { \"type\" : \"oauth2\", \"authorizationUrl\" : " + - "\"https://petstore.swagger.io/oauth/dialog\", \"flow\" : \"implicit\" }")); - assertTrue(json.contains("\"oauth_password\" : { \"type\" : \"oauth2\", \"tokenUrl\" : " + - "\"https://petstore.swagger.io/oauth/token\", \"flow\" : \"password\" }")); - assertTrue(json.contains("\"oauth2_accessCode\" : { \"type\" : \"oauth2\", \"authorizationUrl\" : " + - "\"https://petstore.swagger.io/oauth/dialog\", \"tokenUrl\" : " + - "\"https://petstore.swagger.io/oauth/token\", \"flow\" : \"accessCode\" }")); - assertTrue( - json.contains("\"api_key_header\" : { \"type\" : \"apiKey\", \"name\" : \"myHeader\", \"in\" : \"header\" }")); - assertTrue(json.contains("\"api_key_query\" : { \"type\" : \"apiKey\", \"name\" : \"myQuery\", \"in\" : \"query\" }")); - } -} diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiV3SecuritySchemesTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiV3SecuritySchemesTest.java index c0eaca1d870..5748e49d41f 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiV3SecuritySchemesTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/RestOpenApiV3SecuritySchemesTest.java @@ -20,14 +20,12 @@ import io.swagger.v3.oas.models.OpenAPI; import org.apache.camel.builder.RouteBuilder; import org.apache.camel.impl.engine.DefaultClassResolver; import org.apache.camel.test.junit5.CamelTestSupport; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.ValueSource; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import static org.junit.jupiter.api.Assertions.assertNotNull; -import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; public class RestOpenApiV3SecuritySchemesTest extends CamelTestSupport { @@ -41,29 +39,29 @@ public class RestOpenApiV3SecuritySchemesTest extends CamelTestSupport { public void configure() { rest() .securityDefinitions() - .oauth2("petstore_auth_implicit")// OAuth implicit - .authorizationUrl("https://petstore.swagger.io/oauth/dialog") - .refreshUrl("https://petstore.swagger.io/oauth/refresh") - .end() - .oauth2("oauth_password") - .flow("password") - .tokenUrl("https://petstore.swagger.io/oauth/token") - .end() - .oauth2("oauth2_accessCode")// OAuth access code - .authorizationUrl("https://petstore.swagger.io/oauth/dialog") - .tokenUrl("https://petstore.swagger.io/oauth/token") - .end() - .apiKey("api_key_header") - .withHeader("myHeader") - .end() - .apiKey("api_key_query") - .withQuery("myQuery") - .end() - .apiKey("api_key_cookie", "API Key using cookie") - .withCookie("myCookie") - .end() - .openIdConnect("openIdConnect_auth", "https://petstore.swagger.io/openidconnect") - .mutualTLS("mutualTLS_auth") + .oauth2("petstore_auth_implicit")// OAuth implicit + .authorizationUrl("https://petstore.swagger.io/oauth/dialog") + .refreshUrl("https://petstore.swagger.io/oauth/refresh") + .end() + .oauth2("oauth_password") + .flow("password") + .tokenUrl("https://petstore.swagger.io/oauth/token") + .end() + .oauth2("oauth2_accessCode")// OAuth access code + .authorizationUrl("https://petstore.swagger.io/oauth/dialog") + .tokenUrl("https://petstore.swagger.io/oauth/token") + .end() + .apiKey("api_key_header") + .withHeader("myHeader") + .end() + .apiKey("api_key_query") + .withQuery("myQuery") + .end() + .apiKey("api_key_cookie", "API Key using cookie") + .withCookie("myCookie") + .end() + .openIdConnect("openIdConnect_auth", "https://petstore.swagger.io/openidconnect") + .mutualTLS("mutualTLS_auth") .end(); } }; @@ -111,20 +109,4 @@ public class RestOpenApiV3SecuritySchemesTest extends CamelTestSupport { assertTrue(json.contains("\"mutualTLS_auth\" : { \"type\" : \"mutualTLS\" }")); } - @Test - public void testSecuritySchemesV2() { - BeanConfig config = new BeanConfig(); - config.setHost("localhost:8080"); - config.setSchemes(new String[] { "http" }); - config.setBasePath("/api"); - config.setTitle("Camel User store"); - config.setLicense("Apache 2.0"); - config.setLicenseUrl("https://www.apache.org/licenses/LICENSE-2.0.html"); - config.setVersion("2.0"); - - RestOpenApiReader reader = new RestOpenApiReader(); - assertThrows(IllegalStateException.class, - () -> reader.read(context, context.getRestDefinitions(), config, context.getName(), - new DefaultClassResolver())); - } } diff --git a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/SpringRestOpenApiReaderModelApiSecurityTest.java b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/SpringRestOpenApiReaderModelApiSecurityTest.java index bf330b4f53d..c768b74cb24 100644 --- a/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/SpringRestOpenApiReaderModelApiSecurityTest.java +++ b/components/camel-openapi-java/src/test/java/org/apache/camel/openapi/SpringRestOpenApiReaderModelApiSecurityTest.java @@ -38,47 +38,6 @@ public class SpringRestOpenApiReaderModelApiSecurityTest extends CamelSpringTest return new ClassPathXmlApplicationContext("org/apache/camel/openapi/SpringRestOpenApiReaderModelApiSecurityTest.xml"); } - @Test - public void testReaderRead() throws Exception { - BeanConfig config = new BeanConfig(); - config.setHost("localhost:8080"); - config.setSchemes(new String[] { "http" }); - config.setBasePath("/api"); - config.setTitle("Camel User store"); - config.setLicense("Apache 2.0"); - config.setLicenseUrl("http://www.apache.org/licenses/LICENSE-2.0.html"); - config.setVersion("2.0"); - RestOpenApiReader reader = new RestOpenApiReader(); - - OpenAPI openApi = reader.read(context, context.getRestDefinitions(), config, context.getName(), - new DefaultClassResolver()); - assertNotNull(openApi); - - String json = RestOpenApiSupport.getJsonFromOpenAPIAsString(openApi, config); - - log.info(json); - - assertTrue(json.contains("\"securityDefinitions\" : {")); - assertTrue(json.contains("\"type\" : \"oauth2\"")); - assertTrue(json.contains("\"authorizationUrl\" : \"http://petstore.swagger.io/oauth/dialog\"")); - assertTrue(json.contains("\"flow\" : \"implicit\"")); - assertTrue(json.contains("\"type\" : \"apiKey\",")); - assertTrue(json.contains("\"in\" : \"header\"")); - assertTrue(json.contains("\"host\" : \"localhost:8080\"")); - assertTrue(json.contains("\"security\" : [ {")); - assertTrue(json.contains("\"petstore_auth\" : [ \"write:pets\", \"read:pets\" ]")); - assertTrue(json.contains("\"api_key\" : [ ]")); - assertTrue(json.contains("\"description\" : \"The user returned\"")); - assertTrue(json.contains("\"$ref\" : \"#/definitions/User\"")); - assertTrue(json.contains("\"x-className\"")); - assertTrue(json.contains("\"format\" : \"org.apache.camel.openapi.User\"")); - assertTrue(json.contains("\"type\" : \"string\"")); - assertTrue(json.contains("\"format\" : \"date\"")); - assertFalse(json.contains("\"enum\"")); - - context.stop(); - } - @Test public void testReaderReadV3() throws Exception { BeanConfig config = new BeanConfig(); diff --git a/components/camel-openapi-java/src/test/resources/hello-api.json b/components/camel-openapi-java/src/test/resources/hello-api.json index 6cc6a72f48f..52e789732f6 100644 --- a/components/camel-openapi-java/src/test/resources/hello-api.json +++ b/components/camel-openapi-java/src/test/resources/hello-api.json @@ -1,7 +1,10 @@ { - "swagger" : "2.0", - "host" : "localhost:8080", - "basePath" : "/api", + "openapi": "3.0.2", + "servers": [ + { + "url": "localhost:8080/api" + } + ], "tags" : [ { "name" : "hello" } ], diff --git a/components/camel-openapi-java/src/test/resources/org/apache/camel/openapi/V20SchemaForComplexTypesRequest.json b/components/camel-openapi-java/src/test/resources/org/apache/camel/openapi/V20SchemaForComplexTypesRequest.json deleted file mode 100644 index 54bcc6a854b..00000000000 --- a/components/camel-openapi-java/src/test/resources/org/apache/camel/openapi/V20SchemaForComplexTypesRequest.json +++ /dev/null @@ -1,158 +0,0 @@ -{ - "swagger" : "2.x", - "host" : "localhost:8080", - "basePath" : "/api", - "schemes" : [ "http" ], - "paths" : { - "/complexRequest" : { - "post" : { - "summary" : "Demo complex request type", - "operationId" : "verb", - "consumes" : [ "application/json" ], - "produces" : [ "text/plain" ], - "parameters" : [ { - "in" : "body", - "name" : "body", - "required" : true, - "schema" : { - "$ref" : "#/definitions/SampleComplexRequestType" - } - } ], - "responses" : { - "200" : { - "description" : "Receives a complex object as parameter", - "schema" : { - "$ref" : "#/definitions/SampleComplexResponseType_InnerClass" - } - } - }, - "x-camelContextId" : "camel" - } - } - }, - "securityDefinitions" : { - "global" : { - "type" : "oauth2", - "authorizationUrl" : "https://AUTHORIZATION_URL", - "tokenUrl" : "https://TOKEN_URL", - "flow" : "accessCode", - "scopes" : { - "groups" : "Required scopes for Camel REST APIs" - } - } - }, - "definitions" : { - "SampleComplexResponseType_InnerClass" : { - "type" : "object", - "properties" : { - "doubleField" : { - "type" : "number", - "format" : "double" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexResponseType$InnerClass", - "type" : "string" - } - }, - "CustomData" : { - "type" : "object", - "properties" : { - "customDataField" : { - "type" : "string" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.CustomData", - "type" : "string" - } - }, - "SampleComplexRequestType" : { - "type" : "object", - "required" : [ "mapOfStrings", "requestField1" ], - "properties" : { - "requestField1" : { - "type" : "string" - }, - "requestField2" : { - "type" : "string" - }, - "listOfStrings" : { - "type" : "array", - "items" : { - "type" : "string" - } - }, - "data" : { - "$ref" : "#/definitions/CustomData" - }, - "mapOfData" : { - "type" : "object", - "additionalProperties" : { - "$ref" : "#/definitions/CustomData" - } - }, - "arrayOfString" : { - "type" : "array", - "items" : { - "type" : "string" - } - }, - "mapOfMapOfData" : { - "type" : "object", - "additionalProperties" : { - "type" : "object", - "additionalProperties" : { - "$ref" : "#/definitions/CustomData" - } - } - }, - "innerClass" : { - "$ref" : "#/definitions/SampleComplexRequestType_InnerClass" - }, - "listOfListOfData" : { - "type" : "array", - "items" : { - "type" : "array", - "items" : { - "$ref" : "#/definitions/CustomData" - } - } - }, - "listOfData" : { - "type" : "array", - "items" : { - "$ref" : "#/definitions/CustomData" - } - }, - "mapOfStrings" : { - "type" : "object", - "additionalProperties" : { - "type" : "string" - } - }, - "timeUnit" : { - "type" : "string", - "enum" : [ "NANOSECONDS", "MICROSECONDS", "MILLISECONDS", "SECONDS", "MINUTES", "HOURS", "DAYS" ] - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexRequestType", - "type" : "string" - } - }, - "SampleComplexRequestType_InnerClass" : { - "type" : "object", - "properties" : { - "longField" : { - "type" : "integer", - "format" : "int64" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexRequestType$InnerClass", - "type" : "string" - } - } - } -} diff --git a/components/camel-openapi-java/src/test/resources/org/apache/camel/openapi/V20SchemaForComplexTypesRequestWithSchemaAnnotation.json b/components/camel-openapi-java/src/test/resources/org/apache/camel/openapi/V20SchemaForComplexTypesRequestWithSchemaAnnotation.json deleted file mode 100644 index d82c34fab19..00000000000 --- a/components/camel-openapi-java/src/test/resources/org/apache/camel/openapi/V20SchemaForComplexTypesRequestWithSchemaAnnotation.json +++ /dev/null @@ -1,158 +0,0 @@ -{ - "swagger" : "2.x", - "host" : "localhost:8080", - "basePath" : "/api", - "schemes" : [ "http" ], - "paths" : { - "/complexRequestWithSchemaAnnotation" : { - "post" : { - "summary" : "Demo complex request type", - "operationId" : "verb", - "consumes" : [ "application/json" ], - "produces" : [ "text/plain" ], - "parameters" : [ { - "in" : "body", - "name" : "body", - "required" : true, - "schema" : { - "$ref" : "#/definitions/sampleRequestWithSchema" - } - } ], - "responses" : { - "200" : { - "description" : "Receives a complex object as parameter", - "schema" : { - "$ref" : "#/definitions/responseInner" - } - } - }, - "x-camelContextId" : "camel" - } - } - }, - "securityDefinitions" : { - "global" : { - "type" : "oauth2", - "authorizationUrl" : "https://AUTHORIZATION_URL", - "tokenUrl" : "https://TOKEN_URL", - "flow" : "accessCode", - "scopes" : { - "groups" : "Required scopes for Camel REST APIs" - } - } - }, - "definitions" : { - "requestInner" : { - "type" : "object", - "properties" : { - "longField" : { - "type" : "integer", - "format" : "int64" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexRequestTypeWithSchemaAnnotation$InnerClass", - "type" : "string" - } - }, - "sampleRequestWithSchema" : { - "type" : "object", - "required" : [ "mapOfStrings", "requestField1" ], - "properties" : { - "requestField1" : { - "type" : "string" - }, - "requestField2" : { - "type" : "string" - }, - "listOfStrings" : { - "type" : "array", - "items" : { - "type" : "string" - } - }, - "data" : { - "$ref" : "#/definitions/customData" - }, - "mapOfData" : { - "type" : "object", - "additionalProperties" : { - "$ref" : "#/definitions/customData" - } - }, - "arrayOfString" : { - "type" : "array", - "items" : { - "type" : "string" - } - }, - "mapOfMapOfData" : { - "type" : "object", - "additionalProperties" : { - "type" : "object", - "additionalProperties" : { - "$ref" : "#/definitions/customData" - } - } - }, - "innerClass" : { - "$ref" : "#/definitions/requestInner" - }, - "listOfListOfData" : { - "type" : "array", - "items" : { - "type" : "array", - "items" : { - "$ref" : "#/definitions/customData" - } - } - }, - "listOfData" : { - "type" : "array", - "items" : { - "$ref" : "#/definitions/customData" - } - }, - "mapOfStrings" : { - "type" : "object", - "additionalProperties" : { - "type" : "string" - } - }, - "timeUnit" : { - "type" : "string", - "enum" : [ "NANOSECONDS", "MICROSECONDS", "MILLISECONDS", "SECONDS", "MINUTES", "HOURS", "DAYS" ] - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexRequestTypeWithSchemaAnnotation", - "type" : "string" - } - }, - "customData" : { - "type" : "object", - "properties" : { - "customDataField" : { - "type" : "string" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.CustomDataWithSchemaAnnotation", - "type" : "string" - } - }, - "responseInner" : { - "type" : "object", - "properties" : { - "doubleField" : { - "type" : "number", - "format" : "double" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexResponseTypeWithSchemaAnnotation$InnerClass", - "type" : "string" - } - } - } -} diff --git a/components/camel-openapi-java/src/test/resources/org/apache/camel/openapi/V20SchemaForComplexTypesResponse.json b/components/camel-openapi-java/src/test/resources/org/apache/camel/openapi/V20SchemaForComplexTypesResponse.json deleted file mode 100644 index c5fc9b0ede1..00000000000 --- a/components/camel-openapi-java/src/test/resources/org/apache/camel/openapi/V20SchemaForComplexTypesResponse.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "swagger" : "2.x", - "host" : "localhost:8080", - "basePath" : "/api", - "schemes" : [ "http" ], - "paths" : { - "/complexResponse" : { - "get" : { - "summary" : "Demo complex response type", - "operationId" : "verb", - "consumes" : [ "application/json" ], - "produces" : [ "application/json" ], - "parameters" : [ { - "in" : "body", - "name" : "body", - "required" : true, - "schema" : { - "$ref" : "#/definitions/SampleComplexRequestType_InnerClass" - } - } ], - "responses" : { - "200" : { - "description" : "Returns a complex object", - "schema" : { - "$ref" : "#/definitions/SampleComplexResponseType" - } - } - }, - "x-camelContextId" : "camel" - } - } - }, - "securityDefinitions" : { - "global" : { - "type" : "oauth2", - "authorizationUrl" : "https://AUTHORIZATION_URL", - "tokenUrl" : "https://TOKEN_URL", - "flow" : "accessCode", - "scopes" : { - "groups" : "Required scopes for Camel REST APIs" - } - } - }, - "definitions" : { - "SampleComplexResponseType_InnerClass" : { - "type" : "object", - "properties" : { - "doubleField" : { - "type" : "number", - "format" : "double" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexResponseType$InnerClass", - "type" : "string" - } - }, - "SampleComplexResponseType" : { - "type" : "object", - "required" : [ "arrayOfStrings", "responseField1" ], - "properties" : { - "innerClass" : { - "$ref" : "#/definitions/SampleComplexResponseType_InnerClass" - }, - "arrayOfStrings" : { - "type" : "array", - "items" : { - "type" : "string" - } - }, - "month" : { - "type" : "string", - "enum" : [ "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER" ] - }, - "responseField2" : { - "type" : "string" - }, - "responseField1" : { - "type" : "string" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexResponseType", - "type" : "string" - } - }, - "SampleComplexRequestType_InnerClass" : { - "type" : "object", - "properties" : { - "longField" : { - "type" : "integer", - "format" : "int64" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexRequestType$InnerClass", - "type" : "string" - } - } - } -} \ No newline at end of file diff --git a/components/camel-openapi-java/src/test/resources/org/apache/camel/openapi/V20SchemaForComplexTypesResponseWithSchemaAnnotation.json b/components/camel-openapi-java/src/test/resources/org/apache/camel/openapi/V20SchemaForComplexTypesResponseWithSchemaAnnotation.json deleted file mode 100644 index 1f31689ae3b..00000000000 --- a/components/camel-openapi-java/src/test/resources/org/apache/camel/openapi/V20SchemaForComplexTypesResponseWithSchemaAnnotation.json +++ /dev/null @@ -1,101 +0,0 @@ -{ - "swagger" : "2.x", - "host" : "localhost:8080", - "basePath" : "/api", - "schemes" : [ "http" ], - "paths" : { - "/complexResponseWithSchemaAnnotation" : { - "get" : { - "summary" : "Demo complex response type", - "operationId" : "verb", - "consumes" : [ "application/json" ], - "produces" : [ "application/json" ], - "parameters" : [ { - "in" : "body", - "name" : "body", - "required" : true, - "schema" : { - "$ref" : "#/definitions/SampleComplexRequestType_InnerClass" - } - } ], - "responses" : { - "200" : { - "description" : "Returns a complex object", - "schema" : { - "$ref" : "#/definitions/sampleResponseWithSchema" - } - } - }, - "x-camelContextId" : "camel" - } - } - }, - "securityDefinitions" : { - "global" : { - "type" : "oauth2", - "authorizationUrl" : "https://AUTHORIZATION_URL", - "tokenUrl" : "https://TOKEN_URL", - "flow" : "accessCode", - "scopes" : { - "groups" : "Required scopes for Camel REST APIs" - } - } - }, - "definitions" : { - "sampleResponseWithSchema" : { - "type" : "object", - "required" : [ "arrayOfStrings", "responseField1" ], - "properties" : { - "innerClass" : { - "$ref" : "#/definitions/responseInner" - }, - "arrayOfStrings" : { - "type" : "array", - "items" : { - "type" : "string" - } - }, - "month" : { - "type" : "string", - "enum" : [ "JANUARY", "FEBRUARY", "MARCH", "APRIL", "MAY", "JUNE", "JULY", "AUGUST", "SEPTEMBER", "OCTOBER", "NOVEMBER", "DECEMBER" ] - }, - "responseField2" : { - "type" : "string" - }, - "responseField1" : { - "type" : "string" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexResponseTypeWithSchemaAnnotation", - "type" : "string" - } - }, - "responseInner" : { - "type" : "object", - "properties" : { - "doubleField" : { - "type" : "number", - "format" : "double" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexResponseTypeWithSchemaAnnotation$InnerClass", - "type" : "string" - } - }, - "SampleComplexRequestType_InnerClass" : { - "type" : "object", - "properties" : { - "longField" : { - "type" : "integer", - "format" : "int64" - } - }, - "x-className" : { - "format" : "org.apache.camel.openapi.model.SampleComplexRequestType$InnerClass", - "type" : "string" - } - } - } -} diff --git a/components/camel-openapi-java/src/test/resources/petstore-v3.json b/components/camel-openapi-java/src/test/resources/petstore-v3.json index f01d15ec8c2..01732bb6fd1 100644 --- a/components/camel-openapi-java/src/test/resources/petstore-v3.json +++ b/components/camel-openapi-java/src/test/resources/petstore-v3.json @@ -1 +1,1225 @@ -{"openapi":"3.0.2","info":{"title":"Swagger Petstore - OpenAPI 3.0","description":"This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\nSwagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\nYou can now help us improve the API whether it's by making changes to the definition itself or to the code.\nThat way, with time, we can improve the API in general, an [...] \ No newline at end of file +{ + "openapi": "3.0.2", + "info": { + "title": "Swagger Petstore - OpenAPI 3.0", + "description": "This is a sample Pet Store Server based on the OpenAPI 3.0 specification. You can find out more about\nSwagger at [http://swagger.io](http://swagger.io). In the third iteration of the pet store, we've switched to the design first approach!\nYou can now help us improve the API whether it's by making changes to the definition itself or to the code.\nThat way, with time, we can improve the API in general, and expose some of the new features in OAS3.\n\nSome useful links [...] + "termsOfService": "http://swagger.io/terms/", + "contact": { + "email": "[email protected]" + }, + "license": { + "name": "Apache 2.0", + "url": "http://www.apache.org/licenses/LICENSE-2.0.html" + }, + "version": "1.0.4" + }, + "externalDocs": { + "description": "Find out more about Swagger", + "url": "http://swagger.io" + }, + "servers": [ + { + "url": "/api/v3" + } + ], + "tags": [ + { + "name": "pet", + "description": "Everything about your Pets", + "externalDocs": { + "description": "Find out more", + "url": "http://swagger.io" + } + }, + { + "name": "store", + "description": "Operations about user" + }, + { + "name": "user", + "description": "Access to Petstore orders", + "externalDocs": { + "description": "Find out more about our store", + "url": "http://swagger.io" + } + } + ], + "paths": { + "/pet": { + "put": { + "tags": [ + "pet" + ], + "summary": "Update an existing pet", + "description": "Update an existing pet by Id", + "operationId": "updatePet", + "requestBody": { + "description": "Update an existent pet in the store", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + }, + "application/xml": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + }, + "application/x-www-form-urlencoded": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/xml": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + }, + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + } + }, + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + }, + "405": { + "description": "Validation exception" + } + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets" + ] + } + ] + }, + "post": { + "tags": [ + "pet" + ], + "summary": "Add a new pet to the store", + "description": "Add a new pet to the store", + "operationId": "addPet", + "requestBody": { + "description": "Create a new pet in the store", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + }, + "application/xml": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + }, + "application/x-www-form-urlencoded": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + }, + "required": true + }, + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/xml": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + }, + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + } + }, + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets" + ] + } + ] + } + }, + "/pet/findByStatus": { + "get": { + "tags": [ + "pet" + ], + "summary": "Finds Pets by status", + "description": "Multiple status values can be provided with comma separated strings", + "operationId": "findPetsByStatus", + "parameters": [ + { + "name": "status", + "in": "query", + "description": "Status values that need to be considered for filter", + "required": false, + "explode": true, + "schema": { + "type": "string", + "default": "available", + "enum": [ + "available", + "pending", + "sold" + ] + } + } + ], + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/xml": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Pet" + } + } + }, + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Pet" + } + } + } + } + }, + "400": { + "description": "Invalid status value" + } + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets" + ] + } + ] + } + }, + "/pet/findByTags": { + "get": { + "tags": [ + "pet" + ], + "summary": "Finds Pets by tags", + "description": "Multiple tags can be provided with comma separated strings. Use tag1, tag2, tag3 for testing.", + "operationId": "findPetsByTags", + "parameters": [ + { + "name": "tags", + "in": "query", + "description": "Tags to filter by", + "required": false, + "explode": true, + "schema": { + "type": "array", + "items": { + "type": "string" + } + } + } + ], + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/xml": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Pet" + } + } + }, + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/Pet" + } + } + } + } + }, + "400": { + "description": "Invalid tag value" + } + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets" + ] + } + ] + } + }, + "/pet/{petId}": { + "get": { + "tags": [ + "pet" + ], + "summary": "Find pet by ID", + "description": "Returns a single pet", + "operationId": "getPetById", + "parameters": [ + { + "name": "petId", + "in": "path", + "description": "ID of pet to return", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/xml": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + }, + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + } + }, + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Pet not found" + } + }, + "security": [ + { + "api_key": [] + }, + { + "petstore_auth": [ + "write:pets", + "read:pets" + ] + } + ] + }, + "post": { + "tags": [ + "pet" + ], + "summary": "Updates a pet in the store with form data", + "description": "", + "operationId": "updatePetWithForm", + "parameters": [ + { + "name": "petId", + "in": "path", + "description": "ID of pet that needs to be updated", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + }, + { + "name": "name", + "in": "query", + "description": "Name of pet that needs to be updated", + "schema": { + "type": "string" + } + }, + { + "name": "status", + "in": "query", + "description": "Status of pet that needs to be updated", + "schema": { + "type": "string" + } + } + ], + "responses": { + "405": { + "description": "Invalid input" + } + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets" + ] + } + ] + }, + "delete": { + "tags": [ + "pet" + ], + "summary": "Deletes a pet", + "description": "", + "operationId": "deletePet", + "parameters": [ + { + "name": "api_key", + "in": "header", + "description": "", + "required": false, + "schema": { + "type": "string" + } + }, + { + "name": "petId", + "in": "path", + "description": "Pet id to delete", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "responses": { + "400": { + "description": "Invalid pet value" + } + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets" + ] + } + ] + } + }, + "/pet/{petId}/uploadImage": { + "post": { + "tags": [ + "pet" + ], + "summary": "uploads an image", + "description": "", + "operationId": "uploadFile", + "parameters": [ + { + "name": "petId", + "in": "path", + "description": "ID of pet to update", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + }, + { + "name": "additionalMetadata", + "in": "query", + "description": "Additional Metadata", + "required": false, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "content": { + "application/octet-stream": { + "schema": { + "type": "string", + "format": "binary" + } + } + } + }, + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/ApiResponse" + } + } + } + } + }, + "security": [ + { + "petstore_auth": [ + "write:pets", + "read:pets" + ] + } + ] + } + }, + "/store/inventory": { + "get": { + "tags": [ + "store" + ], + "summary": "Returns pet inventories by status", + "description": "Returns a map of status codes to quantities", + "operationId": "getInventory", + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { + "type": "object", + "additionalProperties": { + "type": "integer", + "format": "int32" + } + } + } + } + } + }, + "security": [ + { + "api_key": [] + } + ] + } + }, + "/store/order": { + "post": { + "tags": [ + "store" + ], + "summary": "Place an order for a pet", + "description": "Place a new order in the store", + "operationId": "placeOrder", + "requestBody": { + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Order" + } + }, + "application/xml": { + "schema": { + "$ref": "#/components/schemas/Order" + } + }, + "application/x-www-form-urlencoded": { + "schema": { + "$ref": "#/components/schemas/Order" + } + } + } + }, + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Order" + } + } + } + }, + "405": { + "description": "Invalid input" + } + } + } + }, + "/store/order/{orderId}": { + "get": { + "tags": [ + "store" + ], + "summary": "Find purchase order by ID", + "description": "For valid response try integer IDs with value <= 5 or > 10. Other values will generated exceptions", + "operationId": "getOrderById", + "parameters": [ + { + "name": "orderId", + "in": "path", + "description": "ID of order that needs to be fetched", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/xml": { + "schema": { + "$ref": "#/components/schemas/Order" + } + }, + "application/json": { + "schema": { + "$ref": "#/components/schemas/Order" + } + } + } + }, + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Order not found" + } + } + }, + "delete": { + "tags": [ + "store" + ], + "summary": "Delete purchase order by ID", + "description": "For valid response try integer IDs with value < 1000. Anything above 1000 or nonintegers will generate API errors", + "operationId": "deleteOrder", + "parameters": [ + { + "name": "orderId", + "in": "path", + "description": "ID of the order that needs to be deleted", + "required": true, + "schema": { + "type": "integer", + "format": "int64" + } + } + ], + "responses": { + "400": { + "description": "Invalid ID supplied" + }, + "404": { + "description": "Order not found" + } + } + } + }, + "/user": { + "post": { + "tags": [ + "user" + ], + "summary": "Create user", + "description": "This can only be done by the logged in user.", + "operationId": "createUser", + "requestBody": { + "description": "Created user object", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/User" + } + }, + "application/xml": { + "schema": { + "$ref": "#/components/schemas/User" + } + }, + "application/x-www-form-urlencoded": { + "schema": { + "$ref": "#/components/schemas/User" + } + } + } + }, + "responses": { + "default": { + "description": "successful operation", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/User" + } + }, + "application/xml": { + "schema": { + "$ref": "#/components/schemas/User" + } + } + } + } + } + } + }, + "/user/createWithList": { + "post": { + "tags": [ + "user" + ], + "summary": "Creates list of users with given input array", + "description": "Creates list of users with given input array", + "operationId": "createUsersWithListInput", + "requestBody": { + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/User" + } + } + } + } + }, + "responses": { + "200": { + "description": "Successful operation", + "content": { + "application/xml": { + "schema": { + "$ref": "#/components/schemas/User" + } + }, + "application/json": { + "schema": { + "$ref": "#/components/schemas/User" + } + } + } + }, + "default": { + "description": "successful operation" + } + } + } + }, + "/user/login": { + "get": { + "tags": [ + "user" + ], + "summary": "Logs user into the system", + "description": "", + "operationId": "loginUser", + "parameters": [ + { + "name": "username", + "in": "query", + "description": "The user name for login", + "required": false, + "schema": { + "type": "string" + } + }, + { + "name": "password", + "in": "query", + "description": "The password for login in clear text", + "required": false, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "successful operation", + "headers": { + "X-Rate-Limit": { + "description": "calls per hour allowed by the user", + "schema": { + "type": "integer", + "format": "int32" + } + }, + "X-Expires-After": { + "description": "date in UTC when toekn expires", + "schema": { + "type": "string", + "format": "date-time" + } + } + }, + "content": { + "application/xml": { + "schema": { + "type": "string" + } + }, + "application/json": { + "schema": { + "type": "string" + } + } + } + }, + "400": { + "description": "Invalid username/password supplied" + } + } + } + }, + "/user/logout": { + "get": { + "tags": [ + "user" + ], + "summary": "Logs out current logged in user session", + "description": "", + "operationId": "logoutUser", + "parameters": [], + "responses": { + "default": { + "description": "successful operation" + } + } + } + }, + "/user/{username}": { + "get": { + "tags": [ + "user" + ], + "summary": "Get user by user name", + "description": "", + "operationId": "getUserByName", + "parameters": [ + { + "name": "username", + "in": "path", + "description": "The name that needs to be fetched. Use user1 for testing. ", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "200": { + "description": "successful operation", + "content": { + "application/xml": { + "schema": { + "$ref": "#/components/schemas/User" + } + }, + "application/json": { + "schema": { + "$ref": "#/components/schemas/User" + } + } + } + }, + "400": { + "description": "Invalid username supplied" + }, + "404": { + "description": "User not found" + } + } + }, + "put": { + "tags": [ + "user" + ], + "summary": "Update user", + "description": "This can only be done by the logged in user.", + "operationId": "updateUser", + "parameters": [ + { + "name": "username", + "in": "path", + "description": "name that need to be deleted", + "required": true, + "schema": { + "type": "string" + } + } + ], + "requestBody": { + "description": "Update an existent user in the store", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/User" + } + }, + "application/xml": { + "schema": { + "$ref": "#/components/schemas/User" + } + }, + "application/x-www-form-urlencoded": { + "schema": { + "$ref": "#/components/schemas/User" + } + } + } + }, + "responses": { + "default": { + "description": "successful operation" + } + } + }, + "delete": { + "tags": [ + "user" + ], + "summary": "Delete user", + "description": "This can only be done by the logged in user.", + "operationId": "deleteUser", + "parameters": [ + { + "name": "username", + "in": "path", + "description": "The name that needs to be deleted", + "required": true, + "schema": { + "type": "string" + } + } + ], + "responses": { + "400": { + "description": "Invalid username supplied" + }, + "404": { + "description": "User not found" + } + } + } + } + }, + "components": { + "schemas": { + "Order": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64", + "example": 10 + }, + "petId": { + "type": "integer", + "format": "int64", + "example": 198772 + }, + "quantity": { + "type": "integer", + "format": "int32", + "example": 7 + }, + "shipDate": { + "type": "string", + "format": "date-time" + }, + "status": { + "type": "string", + "description": "Order Status", + "example": "approved", + "enum": [ + "placed", + "approved", + "delivered" + ] + }, + "complete": { + "type": "boolean" + } + }, + "xml": { + "name": "order" + } + }, + "Customer": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64", + "example": 100000 + }, + "username": { + "type": "string", + "example": "fehguy" + }, + "address": { + "type": "array", + "xml": { + "name": "addresses", + "wrapped": true + }, + "items": { + "$ref": "#/components/schemas/Address" + } + } + }, + "xml": { + "name": "customer" + } + }, + "Address": { + "type": "object", + "properties": { + "street": { + "type": "string", + "example": "437 Lytton" + }, + "city": { + "type": "string", + "example": "Palo Alto" + }, + "state": { + "type": "string", + "example": "CA" + }, + "zip": { + "type": "string", + "example": "94301" + } + }, + "xml": { + "name": "address" + } + }, + "Category": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64", + "example": 1 + }, + "name": { + "type": "string", + "example": "Dogs" + } + }, + "xml": { + "name": "category" + } + }, + "User": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64", + "example": 10 + }, + "username": { + "type": "string", + "example": "theUser" + }, + "firstName": { + "type": "string", + "example": "John" + }, + "lastName": { + "type": "string", + "example": "James" + }, + "email": { + "type": "string", + "example": "[email protected]" + }, + "password": { + "type": "string", + "example": "12345" + }, + "phone": { + "type": "string", + "example": "12345" + }, + "userStatus": { + "type": "integer", + "description": "User Status", + "format": "int32", + "example": 1 + } + }, + "xml": { + "name": "user" + } + }, + "Tag": { + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64" + }, + "name": { + "type": "string" + } + }, + "xml": { + "name": "tag" + } + }, + "Pet": { + "required": [ + "name", + "photoUrls" + ], + "type": "object", + "properties": { + "id": { + "type": "integer", + "format": "int64", + "example": 10 + }, + "name": { + "type": "string", + "example": "doggie" + }, + "category": { + "$ref": "#/components/schemas/Category" + }, + "photoUrls": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "type": "string", + "xml": { + "name": "photoUrl" + } + } + }, + "tags": { + "type": "array", + "xml": { + "wrapped": true + }, + "items": { + "$ref": "#/components/schemas/Tag" + } + }, + "status": { + "type": "string", + "description": "pet status in the store", + "enum": [ + "available", + "pending", + "sold" + ] + } + }, + "xml": { + "name": "pet" + } + }, + "ApiResponse": { + "type": "object", + "properties": { + "code": { + "type": "integer", + "format": "int32" + }, + "type": { + "type": "string" + }, + "message": { + "type": "string" + } + }, + "xml": { + "name": "##default" + } + } + }, + "requestBodies": { + "Pet": { + "description": "Pet object that needs to be added to the store", + "content": { + "application/json": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + }, + "application/xml": { + "schema": { + "$ref": "#/components/schemas/Pet" + } + } + } + }, + "UserArray": { + "description": "List of user object", + "content": { + "application/json": { + "schema": { + "type": "array", + "items": { + "$ref": "#/components/schemas/User" + } + } + } + } + } + }, + "securitySchemes": { + "petstore_auth": { + "type": "oauth2", + "flows": { + "implicit": { + "authorizationUrl": "https://petstore3.swagger.io/oauth/authorize", + "scopes": { + "write:pets": "modify pets in your account", + "read:pets": "read your pets" + } + } + } + }, + "api_key": { + "type": "apiKey", + "name": "api_key", + "in": "header" + } + } + } +} \ No newline at end of file diff --git a/components/camel-openapi-java/src/test/resources/petstore.json b/components/camel-openapi-java/src/test/resources/petstore.json deleted file mode 100644 index 816847f31bb..00000000000 --- a/components/camel-openapi-java/src/test/resources/petstore.json +++ /dev/null @@ -1 +0,0 @@ -{"swagger":"2.0","info":{"description":"This is a sample server Petstore server. You can find out more about Swagger at [http://swagger.io](http://swagger.io) or on [irc.freenode.net, #swagger](http://swagger.io/irc/). For this sample, you can use the api key `special-key` to test the authorization filters.","version":"1.0.0","title":"Swagger Petstore","termsOfService":"http://swagger.io/terms/","contact":{"email":"[email protected]"},"license":{"name":"Apache 2.0","url":"http://www.a [...] \ No newline at end of file diff --git a/components/camel-rest-openapi/pom.xml b/components/camel-rest-openapi/pom.xml index 61cd8a248e0..497e1a11724 100644 --- a/components/camel-rest-openapi/pom.xml +++ b/components/camel-rest-openapi/pom.xml @@ -51,13 +51,34 @@ <dependency> <groupId>io.swagger.core.v3</groupId> - <artifactId>swagger-models</artifactId> + <artifactId>swagger-core-jakarta</artifactId> + <version>${swagger-openapi3-version}</version> + </dependency> + <dependency> + <groupId>io.swagger.core.v3</groupId> + <artifactId>swagger-models-jakarta</artifactId> <version>${swagger-openapi3-version}</version> </dependency> <dependency> <groupId>io.swagger.parser.v3</groupId> - <artifactId>swagger-parser</artifactId> + <artifactId>swagger-parser-v3</artifactId> <version>${swagger-openapi3-java-parser-version}</version> + <exclusions> + <exclusion> + <groupId>io.swagger.core.v3</groupId> + <artifactId>swagger-core</artifactId> + </exclusion> + <exclusion> + <groupId>io.swagger.core.v3</groupId> + <artifactId>swagger-models</artifactId> + </exclusion> + </exclusions> + </dependency> + <!-- swagger requires javax.xml.bind.annotation.XmlElement --> + <dependency> + <groupId>javax.xml.bind</groupId> + <artifactId>jaxb-api</artifactId> + <version>2.3.1</version> </dependency> <dependency> @@ -69,6 +90,12 @@ <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId> <version>${jackson2-version}</version> + <exclusions> + <exclusion> + <groupId>io.swagger.core.v3</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>com.fasterxml.jackson.dataformat</groupId> diff --git a/dsl/camel-jbang/camel-jbang-core/pom.xml b/dsl/camel-jbang/camel-jbang-core/pom.xml index 656d2c6a182..46876c47084 100644 --- a/dsl/camel-jbang/camel-jbang-core/pom.xml +++ b/dsl/camel-jbang/camel-jbang-core/pom.xml @@ -130,15 +130,35 @@ </dependency> <!-- code generator --> <dependency> - <groupId>org.apache.camel</groupId> - <artifactId>camel-openapi-rest-dsl-generator</artifactId> - <version>${project.version}</version> + <groupId>io.swagger.core.v3</groupId> + <artifactId>swagger-core-jakarta</artifactId> + <version>${swagger-openapi3-version}</version> + </dependency> + <dependency> + <groupId>io.swagger.core.v3</groupId> + <artifactId>swagger-models-jakarta</artifactId> + <version>${swagger-openapi3-version}</version> + </dependency> + <dependency> + <groupId>io.swagger.parser.v3</groupId> + <artifactId>swagger-parser-v3</artifactId> + <version>${swagger-openapi3-java-parser-version}</version> + <exclusions> + <exclusion> + <groupId>io.swagger.core.v3</groupId> + <artifactId>*</artifactId> + </exclusion> + </exclusions> </dependency> <dependency> <groupId>org.openapitools</groupId> <artifactId>openapi-generator</artifactId> <version>${openapi-generator}</version> <exclusions> + <exclusion> + <groupId>io.swagger.parser.v3</groupId> + <artifactId>*</artifactId> + </exclusion> <exclusion> <groupId>org.slf4j</groupId> <artifactId>slf4j-api</artifactId> @@ -149,6 +169,11 @@ </exclusion> </exclusions> </dependency> + <dependency> + <groupId>org.apache.camel</groupId> + <artifactId>camel-openapi-rest-dsl-generator</artifactId> + <version>${project.version}</version> + </dependency> <dependency> <groupId>com.fasterxml.jackson.core</groupId> <artifactId>jackson-databind</artifactId>
