forked from loafle/openapi-generator-original
made extracter smarter with bool, int, string
This commit is contained in:
parent
df48f4d8a9
commit
f1f466b69f
@ -29,6 +29,8 @@ abstract class CodegenConfig {
|
|||||||
def destinationDir: String
|
def destinationDir: String
|
||||||
def toModelName(name: String): String
|
def toModelName(name: String): String
|
||||||
def toApiName(name: String): String
|
def toApiName(name: String): String
|
||||||
|
|
||||||
|
|
||||||
def toModelFilename(name: String) = name
|
def toModelFilename(name: String) = name
|
||||||
def toApiFilename(name: String) = toApiName(name)
|
def toApiFilename(name: String) = toApiName(name)
|
||||||
def apiNameFromPath(apiPath: String): String
|
def apiNameFromPath(apiPath: String): String
|
||||||
|
@ -167,8 +167,18 @@ object SwaggerSerializers {
|
|||||||
Parameter(
|
Parameter(
|
||||||
(json \ "name").extractOrElse(""),
|
(json \ "name").extractOrElse(""),
|
||||||
(json \ "description").extract[String],
|
(json \ "description").extract[String],
|
||||||
(json \ "defaultValue").extractOrElse(""),
|
(json \ "defaultValue") match {
|
||||||
(json \ "required").extractOrElse(false),
|
case e:JInt => e.num.toString
|
||||||
|
case e:JBool => e.value.toString
|
||||||
|
case e:JString => e.s
|
||||||
|
case e:JDouble => e.num.toString
|
||||||
|
case _ => ""
|
||||||
|
},
|
||||||
|
(json \ "required") match {
|
||||||
|
case e:JString => e.s.toBoolean
|
||||||
|
case e:JBool => e.value
|
||||||
|
case _ => false
|
||||||
|
},
|
||||||
(json \ "allowMultiple").extractOrElse(false),
|
(json \ "allowMultiple").extractOrElse(false),
|
||||||
(json \ "dataType").extract[String],
|
(json \ "dataType").extract[String],
|
||||||
(json \ "allowableValues").extract[AllowableValues],
|
(json \ "allowableValues").extract[AllowableValues],
|
||||||
@ -232,7 +242,11 @@ object SwaggerSerializers {
|
|||||||
implicit val fmts: Formats = formats
|
implicit val fmts: Formats = formats
|
||||||
ModelProperty(
|
ModelProperty(
|
||||||
`type` = (json \ "type").extractOrElse(""),
|
`type` = (json \ "type").extractOrElse(""),
|
||||||
required = ((json \ "required").extractOrElse(false)),
|
(json \ "required") match {
|
||||||
|
case e:JString => e.s.toBoolean
|
||||||
|
case e:JBool => e.value
|
||||||
|
case _ => false
|
||||||
|
},
|
||||||
description = (json \ "description").extractOpt[String],
|
description = (json \ "description").extractOpt[String],
|
||||||
allowableValues = (json \ "allowableValues").extract[AllowableValues],
|
allowableValues = (json \ "allowableValues").extract[AllowableValues],
|
||||||
items = {
|
items = {
|
||||||
|
@ -251,7 +251,7 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers {
|
|||||||
queryParam("swaggerDataType") should be ("string")
|
queryParam("swaggerDataType") should be ("string")
|
||||||
queryParam("allowMultiple") should be ("true")
|
queryParam("allowMultiple") should be ("true")
|
||||||
queryParam("defaultValue") should be (Some("\"available\""))
|
queryParam("defaultValue") should be (Some("\"available\""))
|
||||||
queryParam("allowableValues") should be ("LIST[available,pending,sold]")
|
queryParam("allowableValues") should be (Some("LIST[available,pending,sold]"))
|
||||||
}
|
}
|
||||||
|
|
||||||
it should "create an api file" in {
|
it should "create an api file" in {
|
||||||
|
@ -167,6 +167,24 @@ class ApiDescriptionSerializersTest extends FlatSpec with ShouldMatchers {
|
|||||||
p.path should be ("/foo/bar")
|
p.path should be ("/foo/bar")
|
||||||
p.description should be ("the description")
|
p.description should be ("the description")
|
||||||
p.operations.size should be (1)
|
p.operations.size should be (1)
|
||||||
|
p.operations.foreach(op => {
|
||||||
|
op.httpMethod should be ("GET")
|
||||||
|
op.summary should be ("the summary")
|
||||||
|
op.notes should be ("the notes")
|
||||||
|
op.responseClass should be ("string")
|
||||||
|
op.nickname should be ("getMeSomeStrings")
|
||||||
|
op.parameters.size should be (1)
|
||||||
|
|
||||||
|
op.parameters.foreach(m => {
|
||||||
|
m.name should be ("id")
|
||||||
|
m.description should be ("the id")
|
||||||
|
m.defaultValue should be ("-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 ApiDescription")
|
case _ => fail("wrong type returned, should be ApiDescription")
|
||||||
}
|
}
|
||||||
@ -227,6 +245,16 @@ class OperationSerializersTest extends FlatSpec with ShouldMatchers {
|
|||||||
op.responseClass should be ("string")
|
op.responseClass should be ("string")
|
||||||
op.nickname should be ("getMeSomeStrings")
|
op.nickname should be ("getMeSomeStrings")
|
||||||
op.parameters.size should be (1)
|
op.parameters.size should be (1)
|
||||||
|
|
||||||
|
op.parameters.foreach(m => {
|
||||||
|
m.name should be ("id")
|
||||||
|
m.description should be ("the id")
|
||||||
|
m.defaultValue should be ("-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")
|
case _ => fail("wrong type returned, should be Operation")
|
||||||
}
|
}
|
||||||
@ -276,6 +304,40 @@ class ErrorResponseSerializersTest extends FlatSpec with ShouldMatchers {
|
|||||||
class ParameterSerializersTest extends FlatSpec with ShouldMatchers {
|
class ParameterSerializersTest extends FlatSpec with ShouldMatchers {
|
||||||
implicit val formats = SwaggerSerializers.formats
|
implicit val formats = SwaggerSerializers.formats
|
||||||
|
|
||||||
|
it should "deserialize another param" in {
|
||||||
|
val jsonString = """
|
||||||
|
{
|
||||||
|
"name":"includeDuplicates",
|
||||||
|
"defaultValue":"false",
|
||||||
|
"description":"Show duplicate examples from different sources",
|
||||||
|
"required":"false",
|
||||||
|
"allowableValues":{
|
||||||
|
"values":[
|
||||||
|
false,
|
||||||
|
true
|
||||||
|
],
|
||||||
|
"valueType":"LIST"
|
||||||
|
},
|
||||||
|
"dataType":"string",
|
||||||
|
"allowMultiple":false,
|
||||||
|
"paramType":"query"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
val json = parse(jsonString)
|
||||||
|
json.extract[Parameter] match {
|
||||||
|
case p: Parameter => {
|
||||||
|
p.name should be ("includeDuplicates")
|
||||||
|
p.description should be ("Show duplicate examples from different sources")
|
||||||
|
p.defaultValue should be ("false")
|
||||||
|
p.required should be (false)
|
||||||
|
p.allowMultiple should be (false)
|
||||||
|
p.dataType should be ("string")
|
||||||
|
p.paramType should be ("query")
|
||||||
|
}
|
||||||
|
case _ => fail("wrong type returned, should be Parameter")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
it should "deserialize a parameter" in {
|
it should "deserialize a parameter" in {
|
||||||
val jsonString = """
|
val jsonString = """
|
||||||
{
|
{
|
||||||
|
Loading…
x
Reference in New Issue
Block a user