Skip to content

Commit bb507d5

Browse files
authored
allow check for path parameters in matrix style (#16331)
* isMatrix added * tests for isMatrix flag added
1 parent 85d7b38 commit bb507d5

4 files changed

Lines changed: 94 additions & 2 deletions

File tree

modules/openapi-generator/src/main/java/org/openapitools/codegen/CodegenParameter.java

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
public class CodegenParameter implements IJsonSchemaValidationProperties {
3030
public boolean isFormParam, isQueryParam, isPathParam, isHeaderParam,
3131
isCookieParam, isBodyParam, isContainer,
32-
isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, isDeepObject, isAllowEmptyValue;
32+
isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, isDeepObject, isMatrix, isAllowEmptyValue;
3333
public String baseName, paramName, dataType, datatypeWithEnum, dataFormat, contentType,
3434
collectionFormat, description, unescapedDescription, baseType, defaultValue, enumDefaultValue, enumName, style;
3535

@@ -251,6 +251,7 @@ public CodegenParameter copy() {
251251
output.isExplode = this.isExplode;
252252
output.style = this.style;
253253
output.isDeepObject = this.isDeepObject;
254+
output.isMatrix = this.isMatrix;
254255
output.isAllowEmptyValue = this.isAllowEmptyValue;
255256
output.contentType = this.contentType;
256257

@@ -259,7 +260,7 @@ public CodegenParameter copy() {
259260

260261
@Override
261262
public int hashCode() {
262-
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);
263+
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);
263264
}
264265

265266
@Override
@@ -341,6 +342,7 @@ public boolean equals(Object o) {
341342
Objects.equals(enumName, that.enumName) &&
342343
Objects.equals(style, that.style) &&
343344
Objects.equals(isDeepObject, that.isDeepObject) &&
345+
Objects.equals(isMatrix, that.isMatrix) &&
344346
Objects.equals(isAllowEmptyValue, that.isAllowEmptyValue) &&
345347
Objects.equals(example, that.example) &&
346348
Objects.equals(examples, that.examples) &&
@@ -405,6 +407,7 @@ public String toString() {
405407
sb.append(", enumName='").append(enumName).append('\'');
406408
sb.append(", style='").append(style).append('\'');
407409
sb.append(", deepObject='").append(isDeepObject).append('\'');
410+
sb.append(", isMatrix='").append(isMatrix).append('\'');
408411
sb.append(", allowEmptyValue='").append(isAllowEmptyValue).append('\'');
409412
sb.append(", example='").append(example).append('\'');
410413
sb.append(", examples='").append(examples).append('\'');

modules/openapi-generator/src/main/java/org/openapitools/codegen/DefaultCodegen.java

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5176,6 +5176,7 @@ public CodegenParameter fromParameter(Parameter parameter, Set<String> imports)
51765176
if (parameter.getStyle() != null) {
51775177
codegenParameter.style = parameter.getStyle().toString();
51785178
codegenParameter.isDeepObject = Parameter.StyleEnum.DEEPOBJECT == parameter.getStyle();
5179+
codegenParameter.isMatrix = Parameter.StyleEnum.MATRIX == parameter.getStyle();
51795180
}
51805181

51815182
// the default value is false
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
/*
2+
* Copyright 2018 OpenAPI-Generator Contributors (https://openapi-generator.tech) Licensed under the Apache License,
3+
* Version 2.0 (the "License"); you may not use this file except in compliance with the License. You may obtain a copy
4+
* of the License at https://www.apache.org/licenses/LICENSE-2.0 Unless required by applicable law or agreed to in
5+
* writing, software distributed under the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
6+
* OF ANY KIND, either express or implied. See the License for the specific language governing permissions and
7+
* limitations under the License.
8+
*/
9+
10+
package org.openapitools.codegen.java;
11+
12+
import java.util.HashSet;
13+
import java.util.List;
14+
import java.util.Map;
15+
16+
import org.openapitools.codegen.CodegenParameter;
17+
import org.openapitools.codegen.DefaultCodegen;
18+
import org.openapitools.codegen.TestUtils;
19+
import org.openapitools.codegen.languages.JavaClientCodegen;
20+
import org.testng.Assert;
21+
import org.testng.annotations.Test;
22+
23+
import io.swagger.v3.oas.models.OpenAPI;
24+
import io.swagger.v3.oas.models.PathItem;
25+
import io.swagger.v3.oas.models.parameters.Parameter;
26+
27+
public class JavaIsMatrixParameterTest {
28+
29+
@Test(description = "test if path param flag isMatrix is correctly set")
30+
public void testIsMatrixFlag() {
31+
final OpenAPI openAPI = TestUtils.parseFlattenSpec("3_1/matrix-path-params-spec.json");
32+
final DefaultCodegen codegen = new JavaClientCodegen();
33+
codegen.setOpenAPI(openAPI);
34+
35+
final Map<String, PathItem> paths = openAPI.getPaths();
36+
final PathItem pathItem = paths.get("/plainMatrixParamFlat{matrixParam}/{simpleParam}");
37+
Assert.assertNotNull(pathItem);
38+
39+
final List<Parameter> parameters = pathItem.getParameters();
40+
Assert.assertEquals(pathItem.getParameters().size(), 2);
41+
42+
final CodegenParameter matrixParameter = codegen.fromParameter(parameters.get(0), new HashSet<>());
43+
Assert.assertTrue(matrixParameter.isMatrix);
44+
45+
final CodegenParameter simpleParameter = codegen.fromParameter(parameters.get(1), new HashSet<>());
46+
Assert.assertFalse(simpleParameter.isMatrix);
47+
}
48+
}
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"openapi": "3.0.1",
3+
"info": {
4+
"title": "Matrix Path Parameter Stuff",
5+
"description": "This API shows the usage of path parameters in matrix style",
6+
"version": "1.0.0"
7+
},
8+
"paths": {
9+
"/plainMatrixParamFlat{matrixParam}/{simpleParam}": {
10+
"parameters": [
11+
{
12+
"name": "matrixParam",
13+
"in": "path",
14+
"style": "matrix",
15+
"required": false,
16+
"schema": {
17+
"type": "string"
18+
}
19+
},
20+
{
21+
"name": "simpleParam",
22+
"in": "path",
23+
"style": "simple",
24+
"required": false,
25+
"schema": {
26+
"type": "string"
27+
}
28+
}
29+
],
30+
"put": {
31+
"operationId": "plainMatrixParamFlat",
32+
"responses": {
33+
"200": {
34+
"description": "OK"
35+
}
36+
}
37+
}
38+
}
39+
}
40+
}

0 commit comments

Comments
 (0)