forked from loafle/openapi-generator-original
updated static template
This commit is contained in:
parent
48f05b41e4
commit
d714f097eb
@ -69,6 +69,8 @@ public class Codegen extends DefaultGenerator {
|
|||||||
return new JavaClientCodegen();
|
return new JavaClientCodegen();
|
||||||
else if("jaxrs".equals(name))
|
else if("jaxrs".equals(name))
|
||||||
return new JaxRSServerCodegen();
|
return new JaxRSServerCodegen();
|
||||||
|
else if("static".equals(name))
|
||||||
|
return new StaticDocCodegen();
|
||||||
else
|
else
|
||||||
throw new RuntimeException("unsupported client type");
|
throw new RuntimeException("unsupported client type");
|
||||||
}
|
}
|
||||||
|
@ -35,7 +35,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
try {
|
try {
|
||||||
config.processOpts();
|
config.processOpts();
|
||||||
Map<String, Object> models = null;
|
Map<String, Object> models = null;
|
||||||
Map<String, Object> operations = null;
|
List<Object> allOperations = new ArrayList<Object>();
|
||||||
|
|
||||||
// models
|
// models
|
||||||
Map<String, Model> definitions = swagger.getDefinitions();
|
Map<String, Model> definitions = swagger.getDefinitions();
|
||||||
@ -66,11 +66,12 @@ public class DefaultGenerator implements Generator {
|
|||||||
Map<String, List<CodegenOperation>> paths = processPaths(swagger.getPaths());
|
Map<String, List<CodegenOperation>> paths = processPaths(swagger.getPaths());
|
||||||
for(String tag : paths.keySet()) {
|
for(String tag : paths.keySet()) {
|
||||||
List<CodegenOperation> ops = paths.get(tag);
|
List<CodegenOperation> ops = paths.get(tag);
|
||||||
|
Map<String, Object> operation = processOperations(config, tag, ops);
|
||||||
operations = processOperations(config, tag, ops);
|
operation.put("baseName", tag);
|
||||||
operations.put("baseName", tag);
|
operation.put("modelPackage", config.modelPackage());
|
||||||
operations.put("modelPackage", config.modelPackage());
|
operation.putAll(config.additionalProperties());
|
||||||
operations.putAll(config.additionalProperties());
|
operation.put("classname", config.toApiName(tag));
|
||||||
|
allOperations.add(operation);
|
||||||
for(String templateName : config.apiTemplateFiles().keySet()) {
|
for(String templateName : config.apiTemplateFiles().keySet()) {
|
||||||
String suffix = config.apiTemplateFiles().get(templateName);
|
String suffix = config.apiTemplateFiles().get(templateName);
|
||||||
String filename = config.apiFileFolder() +
|
String filename = config.apiFileFolder() +
|
||||||
@ -88,7 +89,7 @@ public class DefaultGenerator implements Generator {
|
|||||||
.defaultValue("")
|
.defaultValue("")
|
||||||
.compile(template);
|
.compile(template);
|
||||||
|
|
||||||
writeToFile(filename, tmpl.execute(operations));
|
writeToFile(filename, tmpl.execute(operation));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -96,6 +97,11 @@ public class DefaultGenerator implements Generator {
|
|||||||
Map<String, Object> bundle = new HashMap<String, Object>();
|
Map<String, Object> bundle = new HashMap<String, Object>();
|
||||||
bundle.putAll(config.additionalProperties());
|
bundle.putAll(config.additionalProperties());
|
||||||
bundle.put("apiPackage", config.apiPackage());
|
bundle.put("apiPackage", config.apiPackage());
|
||||||
|
|
||||||
|
Map<String, Object> apis = new HashMap<String, Object>();
|
||||||
|
apis.put("apis", allOperations);
|
||||||
|
|
||||||
|
bundle.put("apiInfo", apis);
|
||||||
for(SupportingFile support : config.supportingFiles()) {
|
for(SupportingFile support : config.supportingFiles()) {
|
||||||
String outputFolder = config.outputFolder();
|
String outputFolder = config.outputFolder();
|
||||||
if(support.folder != null && !"".equals(support.folder))
|
if(support.folder != null && !"".equals(support.folder))
|
||||||
|
@ -7,7 +7,7 @@ import java.util.*;
|
|||||||
import java.io.File;
|
import java.io.File;
|
||||||
|
|
||||||
public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
protected String invokerPackage = "com.wordnik.api";
|
protected String invokerPackage = "com.wordnik.client";
|
||||||
protected String groupId = "com.wordnik";
|
protected String groupId = "com.wordnik";
|
||||||
protected String artifactId = "swagger-client";
|
protected String artifactId = "swagger-client";
|
||||||
protected String artifactVersion = "1.0.0";
|
protected String artifactVersion = "1.0.0";
|
||||||
@ -19,8 +19,8 @@ public class JavaClientCodegen extends DefaultCodegen implements CodegenConfig {
|
|||||||
modelTemplateFiles.put("model.mustache", ".java");
|
modelTemplateFiles.put("model.mustache", ".java");
|
||||||
apiTemplateFiles.put("api.mustache", ".java");
|
apiTemplateFiles.put("api.mustache", ".java");
|
||||||
templateDir = "Java";
|
templateDir = "Java";
|
||||||
apiPackage = "com.wordnik.api";
|
apiPackage = "com.wordnik.client.api";
|
||||||
modelPackage = "com.wordnik.model";
|
modelPackage = "com.wordnik.client.model";
|
||||||
|
|
||||||
additionalProperties.put("invokerPackage", invokerPackage);
|
additionalProperties.put("invokerPackage", invokerPackage);
|
||||||
additionalProperties.put("groupId", groupId);
|
additionalProperties.put("groupId", groupId);
|
||||||
|
@ -0,0 +1,64 @@
|
|||||||
|
package com.wordnik.swagger.codegen.languages;
|
||||||
|
|
||||||
|
import com.wordnik.swagger.codegen.*;
|
||||||
|
import com.wordnik.swagger.models.properties.*;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class StaticDocCodegen extends DefaultCodegen implements CodegenConfig {
|
||||||
|
protected String invokerPackage = "com.wordnik.client";
|
||||||
|
protected String groupId = "com.wordnik";
|
||||||
|
protected String artifactId = "swagger-client";
|
||||||
|
protected String artifactVersion = "1.0.0";
|
||||||
|
protected String sourceFolder = "docs";
|
||||||
|
|
||||||
|
public StaticDocCodegen() {
|
||||||
|
super();
|
||||||
|
outputFolder = "docs";
|
||||||
|
modelTemplateFiles.put("model.mustache", ".html");
|
||||||
|
apiTemplateFiles.put("operation.mustache", ".html");
|
||||||
|
templateDir = "swagger-static";
|
||||||
|
|
||||||
|
additionalProperties.put("invokerPackage", invokerPackage);
|
||||||
|
additionalProperties.put("groupId", groupId);
|
||||||
|
additionalProperties.put("artifactId", artifactId);
|
||||||
|
additionalProperties.put("artifactVersion", artifactVersion);
|
||||||
|
|
||||||
|
supportingFiles.add(new SupportingFile("package.mustache", "", "package.json"));
|
||||||
|
supportingFiles.add(new SupportingFile("main.mustache", "", "main.js"));
|
||||||
|
supportingFiles.add(new SupportingFile("assets/css/bootstrap-responsive.css",
|
||||||
|
outputFolder + "/assets/css", "bootstrap-responsive.css"));
|
||||||
|
supportingFiles.add(new SupportingFile("assets/css/bootstrap.css",
|
||||||
|
outputFolder + "/assets/css", "bootstrap.css"));
|
||||||
|
supportingFiles.add(new SupportingFile("assets/css/style.css",
|
||||||
|
outputFolder + "/assets/css", "style.css"));
|
||||||
|
supportingFiles.add(new SupportingFile("assets/images/logo.png",
|
||||||
|
outputFolder + "/assets/images", "logo.png"));
|
||||||
|
supportingFiles.add(new SupportingFile("assets/js/bootstrap.js",
|
||||||
|
outputFolder + "/assets/js", "bootstrap.js"));
|
||||||
|
supportingFiles.add(new SupportingFile("assets/js/jquery-1.8.3.min.js",
|
||||||
|
outputFolder + "/assets/js", "jquery-1.8.3.min.js"));
|
||||||
|
supportingFiles.add(new SupportingFile("assets/js/main.js",
|
||||||
|
outputFolder + "/assets/js", "main.js"));
|
||||||
|
supportingFiles.add(new SupportingFile("index.mustache",
|
||||||
|
outputFolder, "index.html"));
|
||||||
|
|
||||||
|
instantiationTypes.put("array", "ArrayList");
|
||||||
|
instantiationTypes.put("map", "HashMap");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String escapeReservedWord(String name) {
|
||||||
|
return "_" + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apiFileFolder() {
|
||||||
|
return outputFolder + File.separator + sourceFolder + File.separator + "operations";
|
||||||
|
}
|
||||||
|
|
||||||
|
public String modelFileFolder() {
|
||||||
|
return outputFolder + File.separator + sourceFolder + File.separator + "models";
|
||||||
|
}
|
||||||
|
}
|
@ -33,12 +33,12 @@
|
|||||||
{{#apis}}
|
{{#apis}}
|
||||||
<div class="section-box">
|
<div class="section-box">
|
||||||
<div class="section-header">
|
<div class="section-header">
|
||||||
<a href="#!/{{className}}">{{className}}</a>
|
<a href="#!/{{classname}}">{{classname}}</a>
|
||||||
</div>
|
</div>
|
||||||
<ul>
|
<ul>
|
||||||
{{#operations}}
|
{{#operations}}
|
||||||
{{#operation}}
|
{{#operation}}
|
||||||
<li><a href="#!/{{className}}#{{nickname}}">{{nickname}}</a></li>
|
<li><a href="#!/{{classname}}#{{nickname}}">{{nickname}}</a></li>
|
||||||
{{/operation}}
|
{{/operation}}
|
||||||
{{/operations}}
|
{{/operations}}
|
||||||
</ul>
|
</ul>
|
||||||
|
@ -5,7 +5,7 @@
|
|||||||
{{#vars}}
|
{{#vars}}
|
||||||
<ul class="parameter">
|
<ul class="parameter">
|
||||||
<li class="param-required-{{required}}">{{name}} : {{datatype}}
|
<li class="param-required-{{required}}">{{name}} : {{datatype}}
|
||||||
<br/>{description}}
|
<br/>{{description}}
|
||||||
</li>
|
</li>
|
||||||
</ul>
|
</ul>
|
||||||
{{/vars}}
|
{{/vars}}
|
||||||
|
@ -706,9 +706,6 @@
|
|||||||
"status": {
|
"status": {
|
||||||
"type": "string",
|
"type": "string",
|
||||||
"position": 0
|
"position": 0
|
||||||
},
|
|
||||||
"complete": {
|
|
||||||
"type": "boolean"
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user