mirror of
https://github.com/valitydev/openapi-generator.git
synced 2024-11-07 19:08:52 +00:00
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 toModelName(name: String): String
|
||||
def toApiName(name: String): String
|
||||
|
||||
|
||||
def toModelFilename(name: String) = name
|
||||
def toApiFilename(name: String) = toApiName(name)
|
||||
def apiNameFromPath(apiPath: String): String
|
||||
|
@ -167,8 +167,18 @@ object SwaggerSerializers {
|
||||
Parameter(
|
||||
(json \ "name").extractOrElse(""),
|
||||
(json \ "description").extract[String],
|
||||
(json \ "defaultValue").extractOrElse(""),
|
||||
(json \ "required").extractOrElse(false),
|
||||
(json \ "defaultValue") match {
|
||||
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 \ "dataType").extract[String],
|
||||
(json \ "allowableValues").extract[AllowableValues],
|
||||
@ -232,7 +242,11 @@ object SwaggerSerializers {
|
||||
implicit val fmts: Formats = formats
|
||||
ModelProperty(
|
||||
`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],
|
||||
allowableValues = (json \ "allowableValues").extract[AllowableValues],
|
||||
items = {
|
||||
|
@ -251,7 +251,7 @@ class BasicScalaGeneratorTest extends FlatSpec with ShouldMatchers {
|
||||
queryParam("swaggerDataType") should be ("string")
|
||||
queryParam("allowMultiple") should be ("true")
|
||||
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 {
|
||||
|
@ -167,6 +167,24 @@ class ApiDescriptionSerializersTest extends FlatSpec with ShouldMatchers {
|
||||
p.path should be ("/foo/bar")
|
||||
p.description should be ("the description")
|
||||
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")
|
||||
}
|
||||
@ -227,6 +245,16 @@ class OperationSerializersTest extends FlatSpec with ShouldMatchers {
|
||||
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 Operation")
|
||||
}
|
||||
@ -276,6 +304,40 @@ class ErrorResponseSerializersTest extends FlatSpec with ShouldMatchers {
|
||||
class ParameterSerializersTest extends FlatSpec with ShouldMatchers {
|
||||
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 {
|
||||
val jsonString = """
|
||||
{
|
||||
|
Loading…
Reference in New Issue
Block a user