forked from loafle/openapi-generator-original
added apiInfo
This commit is contained in:
parent
b87bc2a908
commit
97623af8df
@ -2,6 +2,6 @@ package com.wordnik.swagger.codegen;
|
|||||||
|
|
||||||
public class CodegenParameter {
|
public class CodegenParameter {
|
||||||
public Boolean hasMore = null, isContainer = null, secondaryParam = null;
|
public Boolean hasMore = null, isContainer = null, secondaryParam = null;
|
||||||
public String baseName, paramName, dataType, collectionFormat, description;
|
public String baseName, paramName, dataType, collectionFormat, description, baseType;
|
||||||
public Boolean isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam;
|
public Boolean isQueryParam, isPathParam, isHeaderParam, isCookieParam, isBodyParam;
|
||||||
}
|
}
|
@ -644,6 +644,8 @@ public class DefaultCodegen {
|
|||||||
Property inner = qp.getItems();
|
Property inner = qp.getItems();
|
||||||
property = new ArrayProperty(inner);
|
property = new ArrayProperty(inner);
|
||||||
collectionFormat = qp.getCollectionFormat();
|
collectionFormat = qp.getCollectionFormat();
|
||||||
|
CodegenProperty pr = fromProperty("aaa", inner);
|
||||||
|
p.baseType = pr.datatype;
|
||||||
}
|
}
|
||||||
else
|
else
|
||||||
property = PropertyBuilder.build(qp.getType(), qp.getFormat(), null);
|
property = PropertyBuilder.build(qp.getType(), qp.getFormat(), null);
|
||||||
|
@ -34,6 +34,28 @@ public class DefaultGenerator implements Generator {
|
|||||||
}
|
}
|
||||||
try {
|
try {
|
||||||
config.processOpts();
|
config.processOpts();
|
||||||
|
if(swagger.getInfo() != null) {
|
||||||
|
Info info = swagger.getInfo();
|
||||||
|
if(info.getTitle() != null)
|
||||||
|
config.additionalProperties().put("appName", info.getTitle());
|
||||||
|
if(info.getDescription() != null)
|
||||||
|
config.additionalProperties().put("appDescription", info.getDescription());
|
||||||
|
if(info.getContact() != null) {
|
||||||
|
Contact contact = info.getContact();
|
||||||
|
config.additionalProperties().put("infoUrl", contact.getUrl());
|
||||||
|
if(contact.getEmail() != null)
|
||||||
|
config.additionalProperties().put("infoEmail", contact.getEmail());
|
||||||
|
}
|
||||||
|
if(info.getLicense() != null) {
|
||||||
|
License license = info.getLicense();
|
||||||
|
if(license.getName() != null)
|
||||||
|
config.additionalProperties().put("licenseInfo", license.getName());
|
||||||
|
if(license.getUrl() != null)
|
||||||
|
config.additionalProperties().put("licenseUrl", license.getUrl());
|
||||||
|
//
|
||||||
|
// licenseUrl
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
StringBuilder hostBuilder = new StringBuilder();
|
StringBuilder hostBuilder = new StringBuilder();
|
||||||
if(swagger.getSchemes() != null && swagger.getSchemes().size() > 0) {
|
if(swagger.getSchemes() != null && swagger.getSchemes().size() > 0) {
|
||||||
|
@ -0,0 +1,152 @@
|
|||||||
|
package com.wordnik.swagger.codegen.languages;
|
||||||
|
|
||||||
|
import com.wordnik.swagger.codegen.*;
|
||||||
|
import com.wordnik.swagger.models.properties.*;
|
||||||
|
import com.wordnik.swagger.util.Json;
|
||||||
|
|
||||||
|
import java.util.*;
|
||||||
|
import java.io.File;
|
||||||
|
|
||||||
|
public class ScalatraServerCodegen 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 = "src/main/scala";
|
||||||
|
|
||||||
|
public ScalatraServerCodegen() {
|
||||||
|
super();
|
||||||
|
outputFolder = "generated-code/scalatra";
|
||||||
|
modelTemplateFiles.put("model.mustache", ".scala");
|
||||||
|
apiTemplateFiles.put("api.mustache", ".scala");
|
||||||
|
templateDir = "src/main/resources/scalatra";
|
||||||
|
apiPackage = "com.wordnik.client.api";
|
||||||
|
modelPackage = "com.wordnik.client.model";
|
||||||
|
|
||||||
|
defaultIncludes = new HashSet<String>(
|
||||||
|
Arrays.asList("double",
|
||||||
|
"int",
|
||||||
|
"long",
|
||||||
|
"short",
|
||||||
|
"char",
|
||||||
|
"float",
|
||||||
|
"String",
|
||||||
|
"boolean",
|
||||||
|
"Boolean",
|
||||||
|
"Double",
|
||||||
|
"Integer",
|
||||||
|
"Long",
|
||||||
|
"Float",
|
||||||
|
"List",
|
||||||
|
"Set",
|
||||||
|
"Map")
|
||||||
|
);
|
||||||
|
|
||||||
|
additionalProperties.put("appName", "Swagger Sample");
|
||||||
|
additionalProperties.put("appName", "Swagger Sample");
|
||||||
|
additionalProperties.put("appDescription", "A sample swagger server");
|
||||||
|
additionalProperties.put("infoUrl", "http://developers.helloreverb.com");
|
||||||
|
additionalProperties.put("infoEmail", "hello@helloreverb.com");
|
||||||
|
additionalProperties.put("licenseInfo", "All rights reserved");
|
||||||
|
additionalProperties.put("licenseUrl", "http://apache.org/licenses/LICENSE-2.0.html");
|
||||||
|
additionalProperties.put("invokerPackage", invokerPackage);
|
||||||
|
additionalProperties.put("groupId", groupId);
|
||||||
|
additionalProperties.put("artifactId", artifactId);
|
||||||
|
additionalProperties.put("artifactVersion", artifactVersion);
|
||||||
|
|
||||||
|
supportingFiles.add(new SupportingFile("README.mustache", "", "README.md"));
|
||||||
|
supportingFiles.add(new SupportingFile("build.sbt", "", "build.sbt"));
|
||||||
|
supportingFiles.add(new SupportingFile("web.xml", "/src/main/webapp/WEB-INF", "web.xml"));
|
||||||
|
supportingFiles.add(new SupportingFile("JettyMain.scala", sourceFolder, "JettyMain.scala"));
|
||||||
|
supportingFiles.add(new SupportingFile("Bootstrap.mustache", sourceFolder, "ScalatraBootstrap.scala"));
|
||||||
|
supportingFiles.add(new SupportingFile("ServletApp.mustache", sourceFolder, "ServletApp.scala"));
|
||||||
|
supportingFiles.add(new SupportingFile("project/build.properties", "project", "build.properties"));
|
||||||
|
supportingFiles.add(new SupportingFile("project/plugins.sbt", "project", "plugins.sbt"));
|
||||||
|
supportingFiles.add(new SupportingFile("sbt", "", "sbt"));
|
||||||
|
|
||||||
|
languageSpecificPrimitives = new HashSet<String>(
|
||||||
|
Arrays.asList(
|
||||||
|
"String",
|
||||||
|
"boolean",
|
||||||
|
"Boolean",
|
||||||
|
"Double",
|
||||||
|
"Integer",
|
||||||
|
"Long",
|
||||||
|
"Float",
|
||||||
|
"Object")
|
||||||
|
);
|
||||||
|
instantiationTypes.put("array", "ArrayList");
|
||||||
|
instantiationTypes.put("map", "HashMap");
|
||||||
|
|
||||||
|
importMapping = new HashMap<String, String> ();
|
||||||
|
importMapping.put("BigDecimal", "java.math.BigDecimal");
|
||||||
|
importMapping.put("UUID", "java.util.UUID");
|
||||||
|
importMapping.put("File", "java.io.File");
|
||||||
|
importMapping.put("Date", "java.util.Date");
|
||||||
|
importMapping.put("Timestamp", "java.sql.Timestamp");
|
||||||
|
importMapping.put("Map", "java.util.Map");
|
||||||
|
importMapping.put("HashMap", "java.util.HashMap");
|
||||||
|
importMapping.put("Array", "java.util.List");
|
||||||
|
importMapping.put("ArrayList", "java.util.ArrayList");
|
||||||
|
importMapping.put("DateTime", "org.joda.time.DateTime");
|
||||||
|
importMapping.put("LocalDateTime", "org.joda.time.LocalDateTime");
|
||||||
|
importMapping.put("LocalDate", "org.joda.time.LocalDate");
|
||||||
|
importMapping.put("LocalTime", "org.joda.time.LocalTime");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String escapeReservedWord(String name) {
|
||||||
|
return "_" + name;
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String apiFileFolder() {
|
||||||
|
return outputFolder + "/" + sourceFolder + "/" + apiPackage().replaceAll("\\.", "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
public String modelFileFolder() {
|
||||||
|
return outputFolder + "/" + sourceFolder + "/" + modelPackage().replaceAll("\\.", "/");
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public Map<String, Object> postProcessOperations(Map<String, Object> objs) {
|
||||||
|
Map<String, Object> operations = (Map<String, Object>) objs.get("operations");
|
||||||
|
List<CodegenOperation> operationList = (List<CodegenOperation>) operations.get("operation");
|
||||||
|
for(CodegenOperation op: operationList) {
|
||||||
|
op.httpMethod = op.httpMethod.toLowerCase();
|
||||||
|
}
|
||||||
|
Json.prettyPrint(objs);
|
||||||
|
return objs;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getTypeDeclaration(Property p) {
|
||||||
|
if(p instanceof ArrayProperty) {
|
||||||
|
ArrayProperty ap = (ArrayProperty) p;
|
||||||
|
Property inner = ap.getItems();
|
||||||
|
return getSwaggerType(p) + "[" + getTypeDeclaration(inner) + "]";
|
||||||
|
}
|
||||||
|
else if (p instanceof MapProperty) {
|
||||||
|
MapProperty mp = (MapProperty) p;
|
||||||
|
Property inner = mp.getAdditionalProperties();
|
||||||
|
|
||||||
|
return getSwaggerType(p) + "[String, " + getTypeDeclaration(inner) + "]";
|
||||||
|
}
|
||||||
|
return super.getTypeDeclaration(p);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Override
|
||||||
|
public String getSwaggerType(Property p) {
|
||||||
|
String swaggerType = super.getSwaggerType(p);
|
||||||
|
String type = null;
|
||||||
|
if(typeMapping.containsKey(swaggerType)) {
|
||||||
|
type = typeMapping.get(swaggerType);
|
||||||
|
if(languageSpecificPrimitives.contains(type))
|
||||||
|
return toModelName(type);
|
||||||
|
}
|
||||||
|
else
|
||||||
|
type = swaggerType;
|
||||||
|
return toModelName(type);
|
||||||
|
}
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user