forked from loafle/openapi-generator-original
Merge pull request #3543 from guohuang/compile_issue2
[GO] Fixing compilation issue when pathParams is not presented
This commit is contained in:
commit
e8095c6a04
@ -382,13 +382,21 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
// if the return type is not primitive, import encoding/json
|
// if the return type is not primitive, import encoding/json
|
||||||
for (CodegenOperation operation : operations) {
|
for (CodegenOperation operation : operations) {
|
||||||
if(operation.returnBaseType != null && needToImport(operation.returnBaseType)) {
|
if(operation.returnBaseType != null && needToImport(operation.returnBaseType)) {
|
||||||
Map<String, String> customImport = new HashMap<String, String>();
|
imports.add(createMapping("import", "encoding/json"));
|
||||||
customImport.put("import", "encoding/json");
|
|
||||||
imports.add(customImport);
|
|
||||||
break; //just need to import once
|
break; //just need to import once
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// this will only import "strings" "fmt" if there are items in pathParams
|
||||||
|
for (CodegenOperation operation : operations) {
|
||||||
|
if(operation.pathParams != null && operation.pathParams.size() > 0) {
|
||||||
|
imports.add(createMapping("import", "fmt"));
|
||||||
|
imports.add(createMapping("import", "strings"));
|
||||||
|
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");
|
||||||
if (recursiveImports == null)
|
if (recursiveImports == null)
|
||||||
@ -400,9 +408,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
// if the import package happens to be found in the importMapping (key)
|
// if the import package happens to be found in the importMapping (key)
|
||||||
// add the corresponding import package to the list
|
// add the corresponding import package to the list
|
||||||
if (importMapping.containsKey(_import)) {
|
if (importMapping.containsKey(_import)) {
|
||||||
Map<String, String> newImportMap= new HashMap<String, String>();
|
listIterator.add(createMapping("import", importMapping.get(_import)));
|
||||||
newImportMap.put("import", importMapping.get(_import));
|
|
||||||
listIterator.add(newImportMap);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -432,9 +438,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
// if the import package happens to be found in the importMapping (key)
|
// if the import package happens to be found in the importMapping (key)
|
||||||
// add the corresponding import package to the list
|
// add the corresponding import package to the list
|
||||||
if (importMapping.containsKey(_import)) {
|
if (importMapping.containsKey(_import)) {
|
||||||
Map<String, String> newImportMap= new HashMap<String, String>();
|
listIterator.add(createMapping("import", importMapping.get(_import)));
|
||||||
newImportMap.put("import", importMapping.get(_import));
|
|
||||||
listIterator.add(newImportMap);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -465,4 +469,11 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
public String escapeUnsafeCharacters(String input) {
|
public String escapeUnsafeCharacters(String input) {
|
||||||
return input.replace("*/", "*_/").replace("/*", "/_*");
|
return input.replace("*/", "*_/").replace("/*", "/_*");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
public Map<String, String> createMapping(String key, String value){
|
||||||
|
Map<String, String> customImport = new HashMap<String, String>();
|
||||||
|
customImport.put(key, value);
|
||||||
|
|
||||||
|
return customImport;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
@ -3,10 +3,8 @@ package {{packageName}}
|
|||||||
|
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"fmt"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
{{#imports}}"{{import}}"
|
{{#imports}} "{{import}}"
|
||||||
{{/imports}}
|
{{/imports}}
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -23,12 +23,12 @@
|
|||||||
package petstore
|
package petstore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"fmt"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"os"
|
"os"
|
||||||
"io/ioutil"
|
"io/ioutil"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PetApi struct {
|
type PetApi struct {
|
||||||
|
@ -23,10 +23,10 @@
|
|||||||
package petstore
|
package petstore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"fmt"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type StoreApi struct {
|
type StoreApi struct {
|
||||||
|
@ -23,10 +23,10 @@
|
|||||||
package petstore
|
package petstore
|
||||||
|
|
||||||
import (
|
import (
|
||||||
"strings"
|
|
||||||
"fmt"
|
|
||||||
"net/url"
|
"net/url"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
|
"fmt"
|
||||||
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
type UserApi struct {
|
type UserApi struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user