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()))
|
if (_import.startsWith(apiPackage()))
|
||||||
iterator.remove();
|
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
|
// recursivly add import for mapping one type to multipe imports
|
||||||
List<Map<String, String>> recursiveImports = (List<Map<String, String>>) objs.get("imports");
|
List<Map<String, String>> recursiveImports = (List<Map<String, String>>) objs.get("imports");
|
||||||
|
@ -4,7 +4,6 @@ package {{packageName}}
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"fmt"
|
"fmt"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
{{#imports}} "{{import}}"
|
{{#imports}} "{{import}}"
|
||||||
{{/imports}}
|
{{/imports}}
|
||||||
|
@ -3,10 +3,10 @@ package swagger
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"fmt"
|
"fmt"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
"os"
|
"os"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PetApi struct {
|
type PetApi struct {
|
||||||
|
@ -3,8 +3,8 @@ package swagger
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"fmt"
|
"fmt"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StoreApi struct {
|
type StoreApi struct {
|
||||||
|
@ -3,8 +3,8 @@ package swagger
|
|||||||
import (
|
import (
|
||||||
"strings"
|
"strings"
|
||||||
"fmt"
|
"fmt"
|
||||||
"encoding/json"
|
|
||||||
"errors"
|
"errors"
|
||||||
|
"encoding/json"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserApi struct {
|
type UserApi struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user