Skip to content

Commit

Permalink
Fix map parameter not a container (#18220)
Browse files Browse the repository at this point in the history
* Map parameters now carry their container properties when generated from map properties. This solves an issue where a map parameter was not considered a container and induced generation errors.

* Added test specification with fake endpoint for testing map parameters

---------

Co-authored-by: Samuel Kahn <[email protected]>
  • Loading branch information
Kahncode and DW-Samuel committed Apr 7, 2024
1 parent 2168851 commit d2c48e2
Show file tree
Hide file tree
Showing 2 changed files with 730 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7204,7 +7204,9 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set
codegenParameter.nameInPascalCase = camelize(codegenParameter.paramName);
codegenParameter.nameInSnakeCase = CaseFormat.UPPER_CAMEL.to(CaseFormat.UPPER_UNDERSCORE, codegenParameter.nameInPascalCase);
codegenParameter.nameInLowerCase = codegenParameter.paramName.toLowerCase(Locale.ROOT);

codegenParameter.isContainer = codegenProperty.isContainer;
codegenParameter.containerType = codegenProperty.containerType;
codegenParameter.containerTypeMapped = codegenProperty.containerTypeMapped;
codegenParameter.dataFormat = codegenProperty.dataFormat;
// non-array/map
updateCodegenPropertyEnum(codegenProperty);
Expand Down Expand Up @@ -7271,7 +7273,15 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set
}
}
} else if (ModelUtils.isTypeObjectSchema(ps)) {
if (ModelUtils.isFreeFormObject(ps)) {
if (ModelUtils.isMapSchema(ps)) {
codegenParameter.isMap = true;
codegenParameter.additionalProperties = codegenProperty.additionalProperties;
codegenParameter.setAdditionalPropertiesIsAnyType(codegenProperty.getAdditionalPropertiesIsAnyType());
codegenParameter.items = codegenProperty.items;
codegenParameter.isPrimitiveType = false;
codegenParameter.items = codegenProperty.items;
codegenParameter.mostInnerItems = codegenProperty.mostInnerItems;
} else if (ModelUtils.isFreeFormObject(ps)) {
codegenParameter.isFreeFormObject = true;
}
} else if (ModelUtils.isNullType(ps)) {
Expand All @@ -7280,10 +7290,10 @@ public CodegenParameter fromFormProperty(String name, Schema propertySchema, Set
} else if (ModelUtils.isArraySchema(ps)) {
Schema inner = ModelUtils.getSchemaItems(ps);
CodegenProperty arrayInnerProperty = fromProperty("inner", inner, false);
codegenParameter.isArray = true;
codegenParameter.items = arrayInnerProperty;
codegenParameter.mostInnerItems = arrayInnerProperty.mostInnerItems;
codegenParameter.isPrimitiveType = false;
codegenParameter.isContainer = true;
// hoist items data into the array property
// TODO this hoisting code is generator specific and should be isolated into updateFormPropertyForArray
codegenParameter.baseType = arrayInnerProperty.dataType;
Expand Down
Loading

0 comments on commit d2c48e2

Please sign in to comment.