added template variable

This commit is contained in:
Tony Tam 2014-09-23 09:14:25 -07:00
parent 1406c36ced
commit 5bc907f1d4
4 changed files with 23 additions and 6 deletions

View File

@ -14,6 +14,7 @@ public class Codegen extends DefaultGenerator {
options.addOption("l", "lang", true, "client language to generate");
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("t", "template-dir", true, "folder containing the template files");
ClientOptInput codegenInput = new ClientOptInput();
ClientOpts clientArgs = new ClientOpts();
@ -29,10 +30,16 @@ public class Codegen extends DefaultGenerator {
codegenInput.getConfig().setOutputDir(cmd.getOptionValue("o"));
if (cmd.hasOption("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) {
e.printStackTrace();
usage(options);
return;
}
@ -40,7 +47,6 @@ public class Codegen extends DefaultGenerator {
codegenInput
.opts(clientArgs)
.swagger(swagger);
new Codegen().opts(codegenInput).generate();
}
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) {
if("objc".equals(name))
return new ObjcClientCodegen();

View File

@ -20,6 +20,7 @@ public interface CodegenConfig {
String escapeReservedWord(String name);
String getTypeDeclaration(Property p);
String getTypeDeclaration(String name);
void processOpts();
Set<String> reservedWords();

View File

@ -22,6 +22,12 @@ public class DefaultCodegen {
protected Map<String, Object> additionalProperties = new HashMap<String, Object>();
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
public Map<String, Object> postProcessModels(Map<String, Object> objs) {
return objs;
@ -214,10 +220,8 @@ public class DefaultCodegen {
String inner = getSwaggerType(ap.getItems());
return "new ArrayList<" + inner + ">() ";
}
else {
// System.out.println("unhandled property default value");
else
return "null";
}
}
/**

View File

@ -32,6 +32,7 @@ public class DefaultGenerator implements Generator {
throw new RuntimeException("missing swagger input or config!");
}
try {
config.processOpts();
Map<String, Object> models = null;
Map<String, Object> operations = null;