support map in body parameter (#134)

This commit is contained in:
William Cheng 2018-04-19 09:18:13 +08:00 committed by GitHub
parent f9bc1aec9d
commit d8abd4a14b
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

View File

@ -4236,6 +4236,25 @@ public class DefaultCodegen implements CodegenConfig {
imports.add(codegenProperty.baseType); imports.add(codegenProperty.baseType);
codegenProperty = codegenProperty.items; codegenProperty = codegenProperty.items;
} }
} else if (ModelUtils.isMapSchema(schema)) {
Schema inner = (Schema) schema.getAdditionalProperties();
if (inner == null) {
inner = new StringSchema().description("//TODO automatically added by swagger-codegen");
schema.setAdditionalProperties(inner);
}
CodegenProperty codegenProperty = fromProperty("property", schema);
// only support 1-dimension map only
imports.add(codegenProperty.baseType);
codegenParameter.baseName = "request_body";
codegenParameter.paramName = toParamName("request_body");
codegenParameter.items = codegenProperty.items;
codegenParameter.dataType = getTypeDeclaration(inner);
codegenParameter.baseType = getSchemaType(inner);
codegenParameter.isContainer = Boolean.TRUE;
codegenParameter.isMapContainer = Boolean.TRUE;
setParameterBooleanFlagWithCodegenProperty(codegenParameter, codegenProperty);
} else { } else {
// HTTP request body is primitive type (e.g. integer, string, etc) // HTTP request body is primitive type (e.g. integer, string, etc)
CodegenProperty codegenProperty = fromProperty("PRIMITIVE_REQUEST_BODY", schema); CodegenProperty codegenProperty = fromProperty("PRIMITIVE_REQUEST_BODY", schema);