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