mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 19:08:52 +00:00
Fix using the typeMappings
This commit is contained in:
parent
baa0a45537
commit
2b04a5a127
12
build.sbt
12
build.sbt
@ -5,9 +5,9 @@ organization := "com.wordnik"
|
||||
|
||||
name := "swagger-codegen"
|
||||
|
||||
version := "2.0.9-SNAPSHOT"
|
||||
version := "2.0.9-WN8"
|
||||
|
||||
scalaVersion := "2.9.1"
|
||||
scalaVersion := "2.10.0"
|
||||
|
||||
javacOptions ++= Seq("-target", "1.6", "-source", "1.6", "-Xlint:unchecked", "-Xlint:deprecation")
|
||||
|
||||
@ -55,6 +55,14 @@ publishTo <<= (version) { version: String =>
|
||||
Some("Sonatype Nexus Releases" at "https://oss.sonatype.org/service/local/staging/deploy/maven2")
|
||||
}
|
||||
|
||||
publishTo <<= (version) { version: String =>
|
||||
val artifactory = "https://ci.aws.wordnik.com/artifactory/m2-"
|
||||
if (version.trim.endsWith("SNAPSHOT"))
|
||||
Some("snapshots" at artifactory + "snapshots")
|
||||
else
|
||||
Some("releases" at artifactory + "releases")
|
||||
}
|
||||
|
||||
//publishTo := Some(Resolver.file("file", new File(Path.userHome.absolutePath+"/.m2/repository")))
|
||||
|
||||
|
||||
|
@ -406,7 +406,7 @@ 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))
|
||||
imports += Map("import" -> config.toDeclaredType(baseType))
|
||||
baseType
|
||||
}
|
||||
}
|
||||
|
@ -13,6 +13,7 @@ import com.wordnik.swagger.codegen.util.{CoreUtils, ApiExtractor, ResourceExtrac
|
||||
import com.wordnik.swagger.codegen.spec.SwaggerSpecValidator
|
||||
import mojolly.inflector.InflectorImports._
|
||||
import org.rogach.scallop.{ScallopConf, Scallop}
|
||||
import scala.annotation.switch
|
||||
|
||||
case class SwaggerApi(
|
||||
clientName: String,
|
||||
@ -266,13 +267,15 @@ class ScalaAsyncClientGenerator(cfg: SwaggerGenConfig) extends BasicGenerator {
|
||||
"boolean" -> "Boolean",
|
||||
"string" -> "String",
|
||||
"int" -> "Int",
|
||||
"long" -> "Long",
|
||||
"float" -> "Float",
|
||||
"byte" -> "Byte",
|
||||
"short" -> "Short",
|
||||
"char" -> "Char",
|
||||
"long" -> "Long",
|
||||
"double" -> "Double",
|
||||
"object" -> "Any") ++ cfg.typeMapping
|
||||
"object" -> "Any",
|
||||
"file" -> "File") ++ cfg.typeMapping
|
||||
|
||||
override val defaultIncludes = Set(
|
||||
"Int",
|
||||
@ -482,20 +485,32 @@ class ScalaAsyncClientGenerator(cfg: SwaggerGenConfig) extends BasicGenerator {
|
||||
override def processResponseClass(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None //Some("Unit")
|
||||
case e: String => Some(typeMapping.getOrElse(e, e))
|
||||
case e: String => Some(toDeclaredType(e))
|
||||
}
|
||||
}
|
||||
|
||||
override def processResponseDeclaration(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None //Some("Unit")
|
||||
case e: String => Some(typeMapping.getOrElse(e, e))
|
||||
case e: String => Some(toDeclaredType(e))
|
||||
}
|
||||
}
|
||||
|
||||
override def toDeclaredType(dt: String): String = {
|
||||
val declaredType = (dt.indexOf("["): @switch) match {
|
||||
case -1 => dt
|
||||
case n: Int => {
|
||||
if (dt.substring(0, n).toLowerCase == "array")
|
||||
"List" + dt.substring(n)
|
||||
else dt
|
||||
}
|
||||
}
|
||||
typeMapping.getOrElse(declaredType, declaredType)
|
||||
}
|
||||
|
||||
override def toDeclaration(obj: ModelProperty): (String, String) = {
|
||||
obj.`type` match {
|
||||
case "Array" => {
|
||||
case "Array" | "array" => {
|
||||
val inner = {
|
||||
obj.items match {
|
||||
case Some(items) => items.ref.getOrElse(items.`type`)
|
||||
|
@ -74,7 +74,7 @@ abstract class CodegenConfig {
|
||||
def processResponseDeclaration(responseClass: String): Option[String] = {
|
||||
responseClass match {
|
||||
case "void" => None
|
||||
case e: String => Some(typeMapping.getOrElse(e, e))
|
||||
case e: String => Some(toDeclaredType(e))
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -425,7 +425,7 @@ object SwaggerSerializers {
|
||||
case json =>
|
||||
val output = new LinkedHashMap[String, ModelProperty]
|
||||
val required = (json \ "required").extract[Set[String]]
|
||||
val properties = (json \ "properties") match {
|
||||
json \ "properties" match {
|
||||
case JObject(entries) => {
|
||||
entries.map({
|
||||
case (key, value) => {
|
||||
@ -464,7 +464,7 @@ object SwaggerSerializers {
|
||||
case _ => Extraction.decompose(required)
|
||||
})) ~
|
||||
("properties" -> {
|
||||
x.properties match {
|
||||
(x.properties: @unchecked) match {
|
||||
case e: LinkedHashMap[String, ModelProperty] => Extraction.decompose(e.toMap)
|
||||
case _ => JNothing
|
||||
}
|
||||
@ -485,7 +485,7 @@ object SwaggerSerializers {
|
||||
}
|
||||
|
||||
val output = new ListBuffer[String]
|
||||
(json \ "enum") match {
|
||||
json \ "enum" match {
|
||||
case JArray(entries) => entries.map {
|
||||
case e: JInt => output += e.num.toString
|
||||
case e: JBool => output += e.value.toString
|
||||
|
@ -256,6 +256,54 @@ class OperationSerializersTest extends FlatSpec with ShouldMatchers {
|
||||
case _ => fail("wrong type returned, should be Operation")
|
||||
}
|
||||
}
|
||||
it should "deserialize an Operation with an array property" in {
|
||||
val jsonString = """
|
||||
{
|
||||
"method":"GET",
|
||||
"summary":"the summary",
|
||||
"notes":"the notes",
|
||||
"type":"string",
|
||||
"nickname":"getMeSomePets",
|
||||
"parameters":[
|
||||
{
|
||||
"name":"id",
|
||||
"description":"the id",
|
||||
"defaultValue":"-1",
|
||||
"required":false,
|
||||
"allowMultiple":true,
|
||||
"type":"array",
|
||||
"items": {
|
||||
"$ref": "Pet"
|
||||
},
|
||||
"enum":["a","b","c"],
|
||||
"paramType":"query"
|
||||
}
|
||||
]
|
||||
}
|
||||
"""
|
||||
val json = parse(jsonString)
|
||||
json.extract[Operation] match {
|
||||
case op: Operation => {
|
||||
op.method should be ("GET")
|
||||
op.summary should be ("the summary")
|
||||
op.notes should be ("the notes")
|
||||
op.responseClass should be ("array[Pet]")
|
||||
op.nickname should be ("getMeSomePets")
|
||||
op.parameters.size should be (1)
|
||||
|
||||
op.parameters.foreach(m => {
|
||||
m.name should be ("id")
|
||||
m.description should be (Some("the id"))
|
||||
m.defaultValue should be (Some("-1"))
|
||||
m.required should be (false)
|
||||
m.allowMultiple should be (true)
|
||||
m.dataType should be ("string")
|
||||
m.paramType should be ("query")
|
||||
})
|
||||
}
|
||||
case _ => fail("wrong type returned, should be Operation")
|
||||
}
|
||||
}
|
||||
|
||||
it should "serialize an operation" in {
|
||||
val op = Operation(
|
||||
|
Loading…
Reference in New Issue
Block a user