Issue #2725: added condition to import json based on return type

This commit is contained in:
Guo Huang
2016-04-27 14:29:05 -07:00
parent 67b6c3f3d3
commit 2f8a8c05e0
5 changed files with 12 additions and 4 deletions

View File

@@ -375,6 +375,15 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
if (_import.startsWith(apiPackage()))
iterator.remove();
}
// if the return type is not primitive, import encoding/json
for (CodegenOperation operation : operations) {
if(operation.returnBaseType != null && needToImport(operation.returnBaseType)) {
Map<String, String> newImportMap2 = new HashMap<String, String>();
newImportMap2.put("import", "encoding/json");
imports.add(newImportMap2);
break; //just need to import once
}
}
// recursivly add import for mapping one type to multipe imports
List<Map<String, String>> recursiveImports = (List<Map<String, String>>) objs.get("imports");

View File

@@ -4,7 +4,6 @@ package {{packageName}}
import (
"strings"
"fmt"
"encoding/json"
"errors"
{{#imports}} "{{import}}"
{{/imports}}