forked from loafle/openapi-generator-original
Issue #2725: added condition to import json based on return type
This commit is contained in:
parent
67b6c3f3d3
commit
2f8a8c05e0
@ -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");
|
||||
|
@ -4,7 +4,6 @@ package {{packageName}}
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
{{#imports}} "{{import}}"
|
||||
{{/imports}}
|
||||
|
@ -3,10 +3,10 @@ package swagger
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"os"
|
||||
"io/ioutil"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type PetApi struct {
|
||||
|
@ -3,8 +3,8 @@ package swagger
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type StoreApi struct {
|
||||
|
@ -3,8 +3,8 @@ package swagger
|
||||
import (
|
||||
"strings"
|
||||
"fmt"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"encoding/json"
|
||||
)
|
||||
|
||||
type UserApi struct {
|
||||
|
Loading…
x
Reference in New Issue
Block a user