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 38eb785410e..5bd8a369f0d 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 @@ -52,6 +52,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties { public boolean hasValidation; public boolean isNullable; public boolean isDeprecated; + private CodegenProperty schema; /** * Determines whether this parameter is mandatory. If the parameter is in "path", * this property is required and its value MUST be true. Otherwise, the property @@ -162,6 +163,9 @@ public class CodegenParameter implements IJsonSchemaValidationProperties { output.setHasDiscriminatorWithNonEmptyMapping(this.hasDiscriminatorWithNonEmptyMapping); output.setHasMultipleTypes(this.hasMultipleTypes); + if (this.schema != null) { + output.setSchema(this.schema); + } if (this.composedSchemas != null) { output.setComposedSchemas(this.getComposedSchemas()); } @@ -222,7 +226,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, defaultValue, enumName, style, isDeepObject, isAllowEmptyValue, example, jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isFreeFormObject, isAnyType, isArray, isMap, isFile, isEnum, _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, additionalPropertiesIsAnyType, hasVars, hasRequired, isShort, isUnboundedInteger, hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes); + return Objects.hash(isFormParam, isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam, isContainer, isCollectionFormatMulti, isPrimitiveType, isModel, isExplode, baseName, paramName, dataType, datatypeWithEnum, dataFormat, collectionFormat, description, unescapedDescription, baseType, defaultValue, enumName, style, isDeepObject, isAllowEmptyValue, example, jsonSchema, isString, isNumeric, isInteger, isLong, isNumber, isFloat, isDouble, isDecimal, isByteArray, isBinary, isBoolean, isDate, isDateTime, isUuid, isUri, isEmail, isFreeFormObject, isAnyType, isArray, isMap, isFile, isEnum, _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, additionalPropertiesIsAnyType, hasVars, hasRequired, isShort, isUnboundedInteger, hasDiscriminatorWithNonEmptyMapping, composedSchemas, hasMultipleTypes, schema); } @Override @@ -278,6 +282,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties { getExclusiveMaximum() == that.getExclusiveMaximum() && getExclusiveMinimum() == that.getExclusiveMinimum() && getUniqueItems() == that.getUniqueItems() && + Objects.equals(schema, that.getSchema()) && Objects.equals(composedSchemas, that.getComposedSchemas()) && Objects.equals(baseName, that.baseName) && Objects.equals(paramName, that.paramName) && @@ -403,6 +408,7 @@ public class CodegenParameter implements IJsonSchemaValidationProperties { sb.append(", getHasDiscriminatorWithNonEmptyMapping=").append(hasDiscriminatorWithNonEmptyMapping); sb.append(", composedSchemas=").append(composedSchemas); sb.append(", hasMultipleTypes=").append(hasMultipleTypes); + sb.append(", schema=").append(schema); sb.append('}'); return sb.toString(); } @@ -732,5 +738,10 @@ public class CodegenParameter implements IJsonSchemaValidationProperties { @Override public void setHasMultipleTypes(boolean hasMultipleTypes) { this.hasMultipleTypes = hasMultipleTypes; } + + public CodegenProperty getSchema() {return schema; } + + public void setSchema(CodegenProperty schema) { this.schema = schema; } + } 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 6e669ab37cd..563dc10ebc9 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 @@ -4499,6 +4499,8 @@ public class DefaultCodegen implements CodegenConfig { Schema parameterSchema; if (parameter.getSchema() != null) { parameterSchema = parameter.getSchema(); + CodegenProperty prop = fromProperty(parameter.getName(), parameterSchema); + codegenParameter.setSchema(prop); } else if (parameter.getContent() != null) { Content content = parameter.getContent(); if (content.size() > 1) { diff --git a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java index 7afce7c4391..aaede097e3d 100644 --- a/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java +++ b/modules/openapi-generator/src/test/java/org/openapitools/codegen/DefaultCodegenTest.java @@ -222,6 +222,7 @@ public class DefaultCodegenTest { CodegenParameter codegenParameter = codegen.fromFormProperty("enum_form_string", (Schema) requestBodySchema.getProperties().get("enum_form_string"), new HashSet()); Assert.assertEquals(codegenParameter.defaultValue, "-efg"); + Assert.assertEquals(codegenParameter.getSchema(), null); } @Test @@ -2035,6 +2036,9 @@ public class DefaultCodegenTest { Assert.assertEquals(parameter.dataType, "PageQuery1"); Assert.assertEquals(imports.size(), 1); Assert.assertEquals(imports.iterator().next(), "PageQuery1"); + + Assert.assertNotNull(parameter.getSchema()); + Assert.assertEquals(parameter.getSchema().baseType, "object"); } @Test