forked from loafle/openapi-generator-original
made more testable, changed to use case classes + native scala lists
This commit is contained in:
parent
44d018b642
commit
e2c383bd80
@ -97,6 +97,10 @@ abstract class BasicGenerator extends CodegenConfig with PathUtil {
|
|||||||
|
|
||||||
modelFiles.map(m => {
|
modelFiles.map(m => {
|
||||||
val filename = m._1
|
val filename = m._1
|
||||||
|
|
||||||
|
val file = new java.io.File(filename)
|
||||||
|
file.getParentFile().mkdirs
|
||||||
|
|
||||||
val fw = new FileWriter(filename, false)
|
val fw = new FileWriter(filename, false)
|
||||||
fw.write(m._2 + "\n")
|
fw.write(m._2 + "\n")
|
||||||
fw.close()
|
fw.close()
|
||||||
@ -108,6 +112,10 @@ abstract class BasicGenerator extends CodegenConfig with PathUtil {
|
|||||||
|
|
||||||
apiFiles.map(m => {
|
apiFiles.map(m => {
|
||||||
val filename = m._1
|
val filename = m._1
|
||||||
|
|
||||||
|
val file = new java.io.File(filename)
|
||||||
|
file.getParentFile().mkdirs
|
||||||
|
|
||||||
val fw = new FileWriter(filename, false)
|
val fw = new FileWriter(filename, false)
|
||||||
fw.write(m._2 + "\n")
|
fw.write(m._2 + "\n")
|
||||||
fw.close()
|
fw.close()
|
||||||
|
@ -23,7 +23,8 @@ object BasicScalaGenerator extends BasicScalaGenerator {
|
|||||||
}
|
}
|
||||||
|
|
||||||
class BasicScalaGenerator extends BasicGenerator {
|
class BasicScalaGenerator extends BasicGenerator {
|
||||||
override def defaultIncludes = Set("Int",
|
override def defaultIncludes = Set(
|
||||||
|
"Int",
|
||||||
"String",
|
"String",
|
||||||
"Long",
|
"Long",
|
||||||
"Float",
|
"Float",
|
||||||
@ -78,7 +79,7 @@ class BasicScalaGenerator extends BasicGenerator {
|
|||||||
if (obj.items.ref != null) obj.items.ref
|
if (obj.items.ref != null) obj.items.ref
|
||||||
else obj.items.getType
|
else obj.items.getType
|
||||||
}
|
}
|
||||||
val e = "java.util.List[%s]" format toDeclaredType(inner)
|
val e = "List[%s]" format toDeclaredType(inner)
|
||||||
(e, toDefaultValue(inner, obj))
|
(e, toDefaultValue(inner, obj))
|
||||||
}
|
}
|
||||||
case e: String => (toDeclaredType(e), toDefaultValue(e, obj))
|
case e: String => (toDeclaredType(e), toDefaultValue(e, obj))
|
||||||
|
@ -138,7 +138,7 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers {
|
|||||||
model.items.setType("string")
|
model.items.setType("string")
|
||||||
|
|
||||||
val m = config.toDeclaration(model)
|
val m = config.toDeclaration(model)
|
||||||
m._1 should be ("java.util.List[String]")
|
m._1 should be ("List[String]")
|
||||||
m._2 should be ("_")
|
m._2 should be ("_")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -153,7 +153,7 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers {
|
|||||||
model.items.setType("int")
|
model.items.setType("int")
|
||||||
|
|
||||||
val m = config.toDeclaration(model)
|
val m = config.toDeclaration(model)
|
||||||
m._1 should be ("java.util.List[Int]")
|
m._1 should be ("List[Int]")
|
||||||
m._2 should be ("0")
|
m._2 should be ("0")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -168,7 +168,7 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers {
|
|||||||
model.items.setType("float")
|
model.items.setType("float")
|
||||||
|
|
||||||
val m = config.toDeclaration(model)
|
val m = config.toDeclaration(model)
|
||||||
m._1 should be ("java.util.List[Float]")
|
m._1 should be ("List[Float]")
|
||||||
m._2 should be ("0f")
|
m._2 should be ("0f")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -183,7 +183,7 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers {
|
|||||||
model.items.setType("double")
|
model.items.setType("double")
|
||||||
|
|
||||||
val m = config.toDeclaration(model)
|
val m = config.toDeclaration(model)
|
||||||
m._1 should be ("java.util.List[Double]")
|
m._1 should be ("List[Double]")
|
||||||
m._2 should be ("0.0")
|
m._2 should be ("0.0")
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -199,7 +199,7 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers {
|
|||||||
model.items.setType("User")
|
model.items.setType("User")
|
||||||
|
|
||||||
val m = config.toDeclaration(model)
|
val m = config.toDeclaration(model)
|
||||||
m._1 should be ("java.util.List[User]")
|
m._1 should be ("List[User]")
|
||||||
m._2 should be ("_")
|
m._2 should be ("_")
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
x
Reference in New Issue
Block a user