Skip to content

Commit

Permalink
Import inner items for map (#3123)
Browse files Browse the repository at this point in the history
fix #3094
  • Loading branch information
Zomzog authored and wing328 committed Jun 9, 2019
1 parent d86f3ed commit 314f18a
Show file tree
Hide file tree
Showing 3 changed files with 383 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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 {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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);
}
}
Loading

0 comments on commit 314f18a

Please sign in to comment.