forked from loafle/openapi-generator-original
fixed multiple import mapping issue
This commit is contained in:
parent
e555b3ad34
commit
e7df5f9551
@ -104,7 +104,7 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
importMapping = new HashMap<String, String>();
|
importMapping = new HashMap<String, String>();
|
||||||
importMapping.put("time.Time", "time");
|
importMapping.put("time.Time", "time");
|
||||||
importMapping.put("*os.File", "os");
|
importMapping.put("*os.File", "os");
|
||||||
importMapping.put("ioutil", "io/ioutil");
|
importMapping.put("os", "io/ioutil");
|
||||||
|
|
||||||
cliOptions.clear();
|
cliOptions.clear();
|
||||||
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Go package name (convention: lowercase).")
|
cliOptions.add(new CliOption(CodegenConstants.PACKAGE_NAME, "Go package name (convention: lowercase).")
|
||||||
@ -375,6 +375,23 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// recursivly add import for mapping one type to multipe imports
|
||||||
|
List<Map<String, String>> recursiveImports = (List<Map<String, String>>) objs.get("imports");
|
||||||
|
if (recursiveImports == null)
|
||||||
|
return objs;
|
||||||
|
|
||||||
|
ListIterator<Map<String, String>> listIterator = imports.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
String _import = listIterator.next().get("import");
|
||||||
|
// if the import package happens to be found in the importMapping (key)
|
||||||
|
// add the corresponding import package to the list
|
||||||
|
if (importMapping.containsKey(_import)) {
|
||||||
|
Map<String, String> newImportMap= new HashMap<String, String>();
|
||||||
|
newImportMap.put("import", importMapping.get(_import));
|
||||||
|
listIterator.add(newImportMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return objs;
|
return objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -389,6 +406,24 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
if (_import.startsWith(prefix))
|
if (_import.startsWith(prefix))
|
||||||
iterator.remove();
|
iterator.remove();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// recursivly add import for mapping one type to multipe imports
|
||||||
|
List<Map<String, String>> recursiveImports = (List<Map<String, String>>) objs.get("imports");
|
||||||
|
if (recursiveImports == null)
|
||||||
|
return objs;
|
||||||
|
|
||||||
|
ListIterator<Map<String, String>> listIterator = imports.listIterator();
|
||||||
|
while (listIterator.hasNext()) {
|
||||||
|
String _import = listIterator.next().get("import");
|
||||||
|
// if the import package happens to be found in the importMapping (key)
|
||||||
|
// add the corresponding import package to the list
|
||||||
|
if (importMapping.containsKey(_import)) {
|
||||||
|
Map<String, String> newImportMap= new HashMap<String, String>();
|
||||||
|
newImportMap.put("import", importMapping.get(_import));
|
||||||
|
listIterator.add(newImportMap);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
return objs;
|
return objs;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -405,4 +440,4 @@ public class GoClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
public void setPackageVersion(String packageVersion) {
|
public void setPackageVersion(String packageVersion) {
|
||||||
this.packageVersion = packageVersion;
|
this.packageVersion = packageVersion;
|
||||||
}
|
}
|
||||||
}
|
}
|
@ -6,15 +6,6 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
{{#operation}}
|
|
||||||
{{#hasFormParams}}
|
|
||||||
{{#formParams}}
|
|
||||||
{{#isFile}}
|
|
||||||
"io/ioutil"
|
|
||||||
{{/isFile}}
|
|
||||||
{{/formParams}}
|
|
||||||
{{/hasFormParams}}
|
|
||||||
{{/operation}}
|
|
||||||
{{#imports}} "{{import}}"
|
{{#imports}} "{{import}}"
|
||||||
{{/imports}}
|
{{/imports}}
|
||||||
)
|
)
|
||||||
|
@ -5,8 +5,8 @@ import (
|
|||||||
"fmt"
|
"fmt"
|
||||||
"encoding/json"
|
"encoding/json"
|
||||||
"errors"
|
"errors"
|
||||||
"io/ioutil"
|
|
||||||
"os"
|
"os"
|
||||||
|
"io/ioutil"
|
||||||
)
|
)
|
||||||
|
|
||||||
type PetApi struct {
|
type PetApi struct {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user