Skip to content
Permalink
Browse files

Import inner items for map (#3123)

fix #3094
  • Loading branch information...
Zomzog authored and wing328 committed Jun 9, 2019
1 parent d86f3ed commit 314f18a2c142e20b3d3d33a3d5b63318d765465d
@@ -4660,9 +4660,17 @@ public CodegenParameter fromRequestBody(RequestBody body, Set<String> imports, S
schema.setAdditionalProperties(inner);
}
CodegenProperty codegenProperty = fromProperty("property", schema);
// only support 1-dimension map only

imports.add(codegenProperty.baseType);

CodegenProperty innerCp = codegenProperty;
while (innerCp != null) {
if (innerCp.complexType != null) {
imports.add(innerCp.complexType);
}
innerCp = innerCp.items;
}

if (StringUtils.isEmpty(bodyParameterName)) {
codegenParameter.baseName = "request_body";
} else {
@@ -17,6 +17,7 @@

package org.openapitools.codegen;

import com.google.common.collect.Sets;
import io.swagger.v3.oas.models.Components;
import io.swagger.v3.oas.models.OpenAPI;
import io.swagger.v3.oas.models.Operation;
@@ -638,4 +639,19 @@ public void objectQueryParamIdentifyAsObject() {
Assert.assertEquals(imports.iterator().next(), "PageQuery");
}

@Test
public void mapParamImportInnerObject() {
final OpenAPI openAPI = TestUtils.parseSpec("src/test/resources/2_0/mapArgs.yaml");
final DefaultCodegen codegen = new DefaultCodegen();
codegen.setOpenAPI(openAPI);

RequestBody requestBody = openAPI.getPaths().get("/api/instruments").getPost().getRequestBody();

HashSet<String> imports = new HashSet<>();
codegen.fromRequestBody(requestBody, imports, "");

HashSet<String> expected = Sets.newHashSet("InstrumentDefinition", "map");

Assert.assertEquals(imports, expected);
}
}

0 comments on commit 314f18a

Please sign in to comment.
You can’t perform that action at this time.