forked from loafle/openapi-generator-original
updated 1.2 tests
This commit is contained in:
parent
feb5a2ff3b
commit
5a064d6bad
@ -107,6 +107,9 @@ object SwaggerSerializers {
|
||||
class ResourceListingSerializer extends CustomSerializer[ResourceListing](formats => ({
|
||||
case json =>
|
||||
implicit val fmts: Formats = formats
|
||||
|
||||
val apis = (json \ "apis").extract[List[ApiListingReference]]
|
||||
|
||||
ResourceListing(
|
||||
(json \ "apiVersion").extractOrElse({
|
||||
!!(json, RESOURCE_LISTING, "apiVersion", "missing required field", ERROR)
|
||||
@ -116,11 +119,8 @@ object SwaggerSerializers {
|
||||
!!(json, RESOURCE_LISTING, "swaggerVersion", "missing required field", ERROR)
|
||||
""
|
||||
}),
|
||||
(json \ "basePath").extractOrElse({
|
||||
!!(json, RESOURCE_LISTING, "basePath", "missing deprecated field", WARNING)
|
||||
""
|
||||
}),
|
||||
(json \ "apis").extract[List[ApiListingReference]]
|
||||
"",
|
||||
apis.filter(a => a.path != "" && a.path != null)
|
||||
)
|
||||
}, {
|
||||
case x: ResourceListing =>
|
||||
|
@ -18,7 +18,7 @@ import scala.collection.mutable.LinkedHashMap
|
||||
class ResourceListingValidationTest extends FlatSpec with ShouldMatchers {
|
||||
implicit val formats = SwaggerSerializers.formats("1.2")
|
||||
|
||||
it should "fail resource listing without base path" in {
|
||||
it should "not have base path" in {
|
||||
SwaggerSerializers.validationMessages.clear
|
||||
val jsonString = """
|
||||
{
|
||||
@ -27,7 +27,7 @@ class ResourceListingValidationTest extends FlatSpec with ShouldMatchers {
|
||||
}
|
||||
"""
|
||||
parse(jsonString).extract[ResourceListing]
|
||||
SwaggerSerializers.validationMessages.size should be (1)
|
||||
SwaggerSerializers.validationMessages.size should be (0)
|
||||
}
|
||||
|
||||
it should "fail resource listing without apiVersion" in {
|
||||
@ -64,6 +64,7 @@ class ResourceListingValidationTest extends FlatSpec with ShouldMatchers {
|
||||
}
|
||||
case _ => fail("didn't parse the underlying apis")
|
||||
}
|
||||
println(SwaggerSerializers.validationMessages)
|
||||
SwaggerSerializers.validationMessages.size should be (1)
|
||||
}
|
||||
}
|
||||
@ -194,7 +195,7 @@ class ResponseMessageValidationTest extends FlatSpec with ShouldMatchers {
|
||||
val jsonString = """
|
||||
{
|
||||
"code":101,
|
||||
"reason":"the message"
|
||||
"message":"the message"
|
||||
}
|
||||
"""
|
||||
val json = parse(jsonString)
|
||||
@ -398,10 +399,7 @@ class ModelPropertyValidationTest extends FlatSpec with ShouldMatchers {
|
||||
"type":"string",
|
||||
"required":false,
|
||||
"description":"nice",
|
||||
"allowableValues": {
|
||||
"valueType":"LIST",
|
||||
"values":["1","2","3"]
|
||||
},
|
||||
"enum":["1","2","3"],
|
||||
"items":{
|
||||
"type":"Foo",
|
||||
"$ref":"Bar"
|
||||
@ -441,10 +439,7 @@ class ModelPropertyValidationTest extends FlatSpec with ShouldMatchers {
|
||||
"type":"string",
|
||||
"required":false,
|
||||
"description":"nice",
|
||||
"allowableValues": {
|
||||
"valueType":"LIST",
|
||||
"values":["1","2","3"]
|
||||
}
|
||||
"enum":["1","2","3"]
|
||||
}
|
||||
"""
|
||||
val json = parse(jsonString)
|
||||
|
@ -22,8 +22,7 @@ class ResourceListingSerializersTest extends FlatSpec with ShouldMatchers {
|
||||
val jsonString = """
|
||||
{
|
||||
"apiVersion":"1.2.3",
|
||||
"swaggerVersion":"1.2",
|
||||
"basePath":"http://foo/bar"
|
||||
"swaggerVersion":"1.2"
|
||||
}
|
||||
"""
|
||||
val json = parse(jsonString)
|
||||
@ -31,7 +30,6 @@ class ResourceListingSerializersTest extends FlatSpec with ShouldMatchers {
|
||||
case p: ResourceListing => {
|
||||
p.apiVersion should be ("1.2.3")
|
||||
p.swaggerVersion should be ("1.2")
|
||||
p.basePath should be ("http://foo/bar")
|
||||
p.apis.size should be (0)
|
||||
}
|
||||
case _ => fail("wrong type returned, should be ResourceListing")
|
||||
@ -48,7 +46,6 @@ class ResourceListingSerializersTest extends FlatSpec with ShouldMatchers {
|
||||
{
|
||||
"apiVersion":"1.2.3",
|
||||
"swaggerVersion":"1.2",
|
||||
"basePath":"http://foo/bar",
|
||||
"apis":[
|
||||
{
|
||||
"path":"/a/b",
|
||||
@ -65,7 +62,6 @@ class ResourceListingSerializersTest extends FlatSpec with ShouldMatchers {
|
||||
case p: ResourceListing => {
|
||||
p.apiVersion should be ("1.2.3")
|
||||
p.swaggerVersion should be ("1.2")
|
||||
p.basePath should be ("http://foo/bar")
|
||||
p.apis.size should be (2)
|
||||
}
|
||||
case _ => fail("wrong type returned, should be ResourceListing")
|
||||
@ -409,7 +405,6 @@ class ModelSerializationTest extends FlatSpec with ShouldMatchers {
|
||||
model.id should be ("Foo")
|
||||
model.name should be ("Bar")
|
||||
model.properties should not be (null)
|
||||
println(model.properties)
|
||||
model.properties.size should be (3)
|
||||
model.description should be (Some("nice model"))
|
||||
model.properties("id") match {
|
||||
|
Loading…
x
Reference in New Issue
Block a user