diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java index cacd9a8b325..bd8f9077070 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java @@ -29,7 +29,7 @@ import java.util.*; public class CodegenParameter implements IJsonSchemaValidationProperties { public boolean isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, isContainer, - isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, isDeepObject, isAllowEmptyValue; + isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, isDeepObject, isMatrix, isAllowEmptyValue; public String baseName, paramName, dataType, datatypeWithEnum, dataFormat, contentType, collectionFormat, description, unescapedDescription, baseType, defaultValue, enumDefaultValue, enumName, style; @@ -251,6 +251,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties { output.isExplode = this.isExplode; output.style = this.style; output.isDeepObject = this.isDeepObject; + output.isMatrix = this.isMatrix; output.isAllowEmptyValue = this.isAllowEmptyValue; output.contentType = this.contentType; @@ -259,7 +260,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties { @Override public int hashCode() { - return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, isContainer, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, containerType, containerTypeMapped, defaultValue, enumDefaultValue, enumName, style, isDeepObject, isAllowEmptyValue, example, examples, jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isPassword, isFreeFormObject, isAnyType, isArray, isMap, isFile, isEnum, isEnumRef, _enum, allowableValues, items, mostInnerItems, additionalProperties, vars, requiredVars, vendorExtensions, hasValidation, getMaxProperties(), getMinProperties(), isNullable, isDeprecated, required, getMaximum(), getExclusiveMaximum(), getMinimum(), getExclusiveMinimum(), getMaxLength(), getMinLength(), getPattern(), getMaxItems(), getMinItems(), getUniqueItems(), contentType, multipleOf, isNull, isVoid, additionalPropertiesIsAnyType, hasVars, hasRequired, isShort, isUnboundedInteger, hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, schema, content, requiredVarsMap, ref, uniqueItemsBoolean, schemaIsFromAdditionalProperties); + return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, isContainer, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, containerType, containerTypeMapped, defaultValue, enumDefaultValue, enumName, style, isDeepObject, isMatrix, isAllowEmptyValue, example, examples, jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isPassword, isFreeFormObject, isAnyType, isArray, isMap, isFile, isEnum, isEnumRef, _enum, allowableValues, items, mostInnerItems, additionalProperties, vars, requiredVars, vendorExtensions, hasValidation, getMaxProperties(), getMinProperties(), isNullable, isDeprecated, required, getMaximum(), getExclusiveMaximum(), getMinimum(), getExclusiveMinimum(), getMaxLength(), getMinLength(), getPattern(), getMaxItems(), getMinItems(), getUniqueItems(), contentType, multipleOf, isNull, isVoid, additionalPropertiesIsAnyType, hasVars, hasRequired, isShort, isUnboundedInteger, hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, schema, content, requiredVarsMap, ref, uniqueItemsBoolean, schemaIsFromAdditionalProperties); } @Override @@ -341,6 +342,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties { Objects.equals(enumName, that.enumName) && Objects.equals(style, that.style) && Objects.equals(isDeepObject, that.isDeepObject) && + Objects.equals(isMatrix, that.isMatrix) && Objects.equals(isAllowEmptyValue, that.isAllowEmptyValue) && Objects.equals(example, that.example) && Objects.equals(examples, that.examples) && @@ -405,6 +407,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties { sb.append(", enumName='").append(enumName).append('\''); sb.append(", style='").append(style).append('\''); sb.append(", deepObject='").append(isDeepObject).append('\''); + sb.append(", isMatrix='").append(isMatrix).append('\''); sb.append(", allowEmptyValue='").append(isAllowEmptyValue).append('\''); sb.append(", example='").append(example).append('\''); sb.append(", examples='").append(examples).append('\''); diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java index be13495b759..e3ddcf7547c 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java @@ -5176,6 +5176,7 @@ public class DefaultCodegen implements CodegenConfig { if (parameter.getStyle() != null) { codegenParameter.style = parameter.getStyle().toString(); codegenParameter.isDeepObject = Parameter.StyleEnum.DEEPOBJECT == parameter.getStyle(); + codegenParameter.isMatrix = Parameter.StyleEnum.MATRIX == parameter.getStyle(); } // the default value is false diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaIsMatrixParameterTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaIsMatrixParameterTest.java new file mode 100644 index 00000000000..e86d4a82413 --- /dev/null +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/java/JavaIsMatrixParameterTest.java @@ -0,0 +1,48 @@ +/* + * Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) Licensed 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 https://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.openapitools.codegen.java; + +import java.util.HashSet; +import java.util.List; +import java.util.Map; + +import org.openapitools.codegen.CodegenParameter; +import org.openapitools.codegen.DefaultCodegen; +import org.openapitools.codegen.TestUtils; +import org.openapitools.codegen.languages.JavaClientCodegen; +import org.testng.Assert; +import org.testng.annotations.Test; + +import io.swagger.v3.oas.models.OpenAPI; +import io.swagger.v3.oas.models.PathItem; +import io.swagger.v3.oas.models.parameters.Parameter; + +public class JavaIsMatrixParameterTest { + + @Test(description = "test if path param flag isMatrix is correctly set") + public void testIsMatrixFlag() { + final OpenAPI openAPI = TestUtils.parseFlattenSpec("3_1/matrix-path-params-spec.json"); + final DefaultCodegen codegen = new JavaClientCodegen(); + codegen.setOpenAPI(openAPI); + + final Map paths = openAPI.getPaths(); + final PathItem pathItem = paths.get("/plainMatrixParamFlat{matrixParam}/{simpleParam}"); + Assert.assertNotNull(pathItem); + + final List parameters = pathItem.getParameters(); + Assert.assertEquals(pathItem.getParameters().size(), 2); + + final CodegenParameter matrixParameter = codegen.fromParameter(parameters.get(0), new HashSet<>()); + Assert.assertTrue(matrixParameter.isMatrix); + + final CodegenParameter simpleParameter = codegen.fromParameter(parameters.get(1), new HashSet<>()); + Assert.assertFalse(simpleParameter.isMatrix); + } +} diff --git a/modules/openapi-generator/src/test/resources/3_1/matrix-path-params-spec.json b/modules/openapi-generator/src/test/resources/3_1/matrix-path-params-spec.json new file mode 100644 index 00000000000..2a9232aeff6 --- /dev/null +++ b/modules/openapi-generator/src/test/resources/3_1/matrix-path-params-spec.json @@ -0,0 +1,40 @@ +{ + "openapi": "3.0.1", + "info": { + "title": "Matrix Path Parameter Stuff", + "description": "This API shows the usage of path parameters in matrix style", + "version": "1.0.0" + }, + "paths": { + "/plainMatrixParamFlat{matrixParam}/{simpleParam}": { + "parameters": [ + { + "name": "matrixParam", + "in": "path", + "style": "matrix", + "required": false, + "schema": { + "type": "string" + } + }, + { + "name": "simpleParam", + "in": "path", + "style": "simple", + "required": false, + "schema": { + "type": "string" + } + } + ], + "put": { + "operationId": "plainMatrixParamFlat", + "responses": { + "200": { + "description": "OK" + } + } + } + } + } +}