forked from loafle/openapi-generator-original
added config for model name prefix
This commit is contained in:
parent
3d1678a087
commit
b3d5b49e90
@ -132,8 +132,8 @@ abstract class BasicGenerator extends CodegenConfig with PathUtil {
|
||||
(for ((name, schema) <- models) yield {
|
||||
if (!defaultIncludes.contains(name)) {
|
||||
val m = new HashMap[String, AnyRef]
|
||||
m += "name" -> name
|
||||
m += "className" -> name
|
||||
m += "name" -> toModelName(name)
|
||||
m += "className" -> (name)
|
||||
m += "apis" -> None
|
||||
m += "models" -> List((name, schema))
|
||||
m += "package" -> modelPackage
|
||||
|
@ -95,26 +95,32 @@ class Codegen(config: CodegenConfig) {
|
||||
case None => ""
|
||||
}
|
||||
// do the mapping before removing primitives!
|
||||
allImports.foreach(i => includedModels.contains(i) match {
|
||||
allImports.foreach(i => {
|
||||
val model = config.toModelName(i)
|
||||
includedModels.contains(model) match {
|
||||
case false => {
|
||||
config.importMapping.containsKey(i) match {
|
||||
case true => imports += Map("import" -> config.importMapping(i))
|
||||
config.importMapping.containsKey(model) match {
|
||||
case true => imports += Map("import" -> config.importMapping(model))
|
||||
case false =>
|
||||
}
|
||||
}
|
||||
case true =>
|
||||
}
|
||||
})
|
||||
allImports --= config.defaultIncludes
|
||||
allImports --= primitives
|
||||
allImports --= containers
|
||||
allImports.foreach(i => includedModels.contains(i) match {
|
||||
allImports.foreach(i => {
|
||||
val model = config.toModelName(i)
|
||||
includedModels.contains(model) match {
|
||||
case false => {
|
||||
config.importMapping.containsKey(i) match {
|
||||
config.importMapping.containsKey(model) match {
|
||||
case true =>
|
||||
case false => imports += Map("import" -> (importScope + i))
|
||||
case false => imports += Map("import" -> (importScope + model))
|
||||
}
|
||||
}
|
||||
case true => // no need to add the model
|
||||
}
|
||||
})
|
||||
|
||||
val rootDir = new java.io.File(".")
|
||||
@ -152,8 +158,11 @@ class Codegen(config: CodegenConfig) {
|
||||
"models" -> modelData,
|
||||
"basePath" -> bundle.getOrElse("basePath", ""))
|
||||
|
||||
// println(m.writeValueAsString(modelData))
|
||||
|
||||
var output = engine.layout(config.templateDir + File.separator + templateFile, template, data.toMap)
|
||||
//a shutdown method will be added to scalate in an upcoming release
|
||||
|
||||
// a shutdown method will be added to scalate in an upcoming release
|
||||
engine.compiler.asInstanceOf[ScalaCompiler].compiler.askShutdown
|
||||
output
|
||||
}
|
||||
@ -168,8 +177,8 @@ class Codegen(config: CodegenConfig) {
|
||||
case true => config.importMapping(modelName)
|
||||
case false => {
|
||||
config.modelPackage match {
|
||||
case Some(p) => p + "." + modelName
|
||||
case None => modelName
|
||||
case Some(p) => p + "." + config.toModelName(modelName)
|
||||
case None => config.toModelName(modelName)
|
||||
}
|
||||
}
|
||||
})
|
||||
@ -352,7 +361,7 @@ class Codegen(config: CodegenConfig) {
|
||||
def modelToMap(className: String, model: DocumentationSchema): Map[String, AnyRef] = {
|
||||
val data: HashMap[String, AnyRef] =
|
||||
HashMap(
|
||||
"classname" -> className,
|
||||
"classname" -> config.toModelName(className),
|
||||
"classVarName" -> config.toVarName(className), // suggested name of object created from this class
|
||||
"modelPackage" -> config.modelPackage,
|
||||
"newline" -> "\n")
|
||||
@ -378,7 +387,14 @@ class Codegen(config: CodegenConfig) {
|
||||
}
|
||||
baseType = config.typeMapping.contains(baseType) match {
|
||||
case true => config.typeMapping(baseType)
|
||||
case false => imports += Map("import" -> config.typeMapping.getOrElse(baseType, baseType)); baseType
|
||||
case false => {
|
||||
imports += Map("import" -> config.typeMapping.getOrElse(baseType, baseType))
|
||||
baseType
|
||||
}
|
||||
}
|
||||
(config.defaultIncludes ++ config.languageSpecificPrimitives).toSet.contains(baseType) match {
|
||||
case true =>
|
||||
case _ => imports += Map("import" -> baseType)
|
||||
}
|
||||
|
||||
val isList = (if (isListType(propertyDocSchema.getType)) true else None)
|
||||
@ -418,7 +434,7 @@ class Codegen(config: CodegenConfig) {
|
||||
"hasMore" -> "true")
|
||||
(config.languageSpecificPrimitives.contains(baseType) || primitives.contains(baseType)) match {
|
||||
case true => properties += "isPrimitiveType" -> "true"
|
||||
case _ => properties += "complexType" -> baseType
|
||||
case _ => properties += "complexType" -> config.toModelName(baseType)
|
||||
}
|
||||
|
||||
l += properties
|
||||
@ -481,8 +497,6 @@ class Codegen(config: CodegenConfig) {
|
||||
"apis" -> apiList,
|
||||
"models" -> modelList)
|
||||
|
||||
// println(com.wordnik.swagger.codegen.util.ScalaJsonUtil.getJsonMapper.writeValueAsString(data))
|
||||
|
||||
config.supportingFiles.map(file => {
|
||||
val srcTemplate = file._1
|
||||
val outputDir = file._2
|
||||
|
@ -37,6 +37,10 @@ trait PathUtil {
|
||||
}
|
||||
}
|
||||
|
||||
def toModelName(name: String) = {
|
||||
name.charAt(0).toUpperCase + name.substring(1)
|
||||
}
|
||||
|
||||
def toApiName(name: String) = {
|
||||
name.charAt(0).toUpperCase + name.substring(1) + "Api"
|
||||
}
|
||||
|
@ -27,6 +27,7 @@ abstract class CodegenConfig {
|
||||
def packageName: String
|
||||
def templateDir: String
|
||||
def destinationDir: String
|
||||
def toModelName(name: String): String
|
||||
def toApiName(name: String): String
|
||||
def apiNameFromPath(apiPath: String): String
|
||||
def processApiMap(m: Map[String, AnyRef]): Map[String, AnyRef] = m
|
||||
|
Loading…
x
Reference in New Issue
Block a user