forked from loafle/openapi-generator-original
added template variable
This commit is contained in:
parent
1406c36ced
commit
5bc907f1d4
@ -14,6 +14,7 @@ public class Codegen extends DefaultGenerator {
|
|||||||
options.addOption("l", "lang", true, "client language to generate");
|
options.addOption("l", "lang", true, "client language to generate");
|
||||||
options.addOption("o", "output", true, "where to write the generated files");
|
options.addOption("o", "output", true, "where to write the generated files");
|
||||||
options.addOption("i", "input-spec", true, "location of the swagger spec, as URL or file");
|
options.addOption("i", "input-spec", true, "location of the swagger spec, as URL or file");
|
||||||
|
options.addOption("t", "template-dir", true, "folder containing the template files");
|
||||||
|
|
||||||
ClientOptInput codegenInput = new ClientOptInput();
|
ClientOptInput codegenInput = new ClientOptInput();
|
||||||
ClientOpts clientArgs = new ClientOpts();
|
ClientOpts clientArgs = new ClientOpts();
|
||||||
@ -29,10 +30,16 @@ public class Codegen extends DefaultGenerator {
|
|||||||
codegenInput.getConfig().setOutputDir(cmd.getOptionValue("o"));
|
codegenInput.getConfig().setOutputDir(cmd.getOptionValue("o"));
|
||||||
if (cmd.hasOption("i"))
|
if (cmd.hasOption("i"))
|
||||||
swagger = new SwaggerLoader().read(cmd.getOptionValue("i"));
|
swagger = new SwaggerLoader().read(cmd.getOptionValue("i"));
|
||||||
|
if (cmd.hasOption("t"))
|
||||||
|
clientArgs.getProperties().put("templateDir",
|
||||||
|
String.valueOf(cmd.getOptionValue("t")));
|
||||||
|
if (cmd.hasOption("h")) {
|
||||||
|
usage(options);
|
||||||
|
return;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
e.printStackTrace();
|
usage(options);
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -40,7 +47,6 @@ public class Codegen extends DefaultGenerator {
|
|||||||
codegenInput
|
codegenInput
|
||||||
.opts(clientArgs)
|
.opts(clientArgs)
|
||||||
.swagger(swagger);
|
.swagger(swagger);
|
||||||
|
|
||||||
new Codegen().opts(codegenInput).generate();
|
new Codegen().opts(codegenInput).generate();
|
||||||
}
|
}
|
||||||
catch (Exception e) {
|
catch (Exception e) {
|
||||||
@ -48,6 +54,11 @@ public class Codegen extends DefaultGenerator {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static void usage(Options options) {
|
||||||
|
HelpFormatter formatter = new HelpFormatter();
|
||||||
|
formatter.printHelp( "Codegen", options );
|
||||||
|
}
|
||||||
|
|
||||||
static CodegenConfig getConfig(String name) {
|
static CodegenConfig getConfig(String name) {
|
||||||
if("objc".equals(name))
|
if("objc".equals(name))
|
||||||
return new ObjcClientCodegen();
|
return new ObjcClientCodegen();
|
||||||
|
@ -20,6 +20,7 @@ public interface CodegenConfig {
|
|||||||
String escapeReservedWord(String name);
|
String escapeReservedWord(String name);
|
||||||
String getTypeDeclaration(Property p);
|
String getTypeDeclaration(Property p);
|
||||||
String getTypeDeclaration(String name);
|
String getTypeDeclaration(String name);
|
||||||
|
void processOpts();
|
||||||
|
|
||||||
Set<String> reservedWords();
|
Set<String> reservedWords();
|
||||||
|
|
||||||
|
@ -22,6 +22,12 @@ public class DefaultCodegen {
|
|||||||
protected Map<String, Object> additionalProperties = new HashMap<String, Object>();
|
protected Map<String, Object> additionalProperties = new HashMap<String, Object>();
|
||||||
protected List<SupportingFile> supportingFiles = new ArrayList<SupportingFile>();
|
protected List<SupportingFile> supportingFiles = new ArrayList<SupportingFile>();
|
||||||
|
|
||||||
|
public void processOpts(){
|
||||||
|
if(additionalProperties.containsKey("templateDir")) {
|
||||||
|
this.setTemplateDir((String)additionalProperties.get("templateDir"));
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
// override with any special post-processing
|
// override with any special post-processing
|
||||||
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
|
||||||
return objs;
|
return objs;
|
||||||
@ -214,11 +220,9 @@ public class DefaultCodegen {
|
|||||||
String inner = getSwaggerType(ap.getItems());
|
String inner = getSwaggerType(ap.getItems());
|
||||||
return "new ArrayList<" + inner + ">() ";
|
return "new ArrayList<" + inner + ">() ";
|
||||||
}
|
}
|
||||||
else {
|
else
|
||||||
// System.out.println("unhandled property default value");
|
|
||||||
return "null";
|
return "null";
|
||||||
}
|
}
|
||||||
}
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* returns the swagger type for the property
|
* returns the swagger type for the property
|
||||||
|
@ -32,6 +32,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
throw new RuntimeException("missing swagger input or config!");
|
throw new RuntimeException("missing swagger input or config!");
|
||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
|
config.processOpts();
|
||||||
Map<String, Object> models = null;
|
Map<String, Object> models = null;
|
||||||
Map<String, Object> operations = null;
|
Map<String, Object> operations = null;
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user