updated 1.2 tests

This commit is contained in:
Tony Tam 2013-08-11 09:26:32 -07:00
parent feb5a2ff3b
commit 5a064d6bad
3 changed files with 12 additions and 22 deletions

View File

@ -107,6 +107,9 @@ object SwaggerSerializers {
class ResourceListingSerializer extends CustomSerializer[ResourceListing](formats => ({ class ResourceListingSerializer extends CustomSerializer[ResourceListing](formats => ({
case json => case json =>
implicit val fmts: Formats = formats implicit val fmts: Formats = formats
val apis = (json \ "apis").extract[List[ApiListingReference]]
ResourceListing( ResourceListing(
(json \ "apiVersion").extractOrElse({ (json \ "apiVersion").extractOrElse({
!!(json, RESOURCE_LISTING, "apiVersion", "missing required field", ERROR) !!(json, RESOURCE_LISTING, "apiVersion", "missing required field", ERROR)
@ -116,11 +119,8 @@ object SwaggerSerializers {
!!(json, RESOURCE_LISTING, "swaggerVersion", "missing required field", ERROR) !!(json, RESOURCE_LISTING, "swaggerVersion", "missing required field", ERROR)
"" ""
}), }),
(json \ "basePath").extractOrElse({ "",
!!(json, RESOURCE_LISTING, "basePath", "missing deprecated field", WARNING) apis.filter(a => a.path != "" && a.path != null)
""
}),
(json \ "apis").extract[List[ApiListingReference]]
) )
}, { }, {
case x: ResourceListing => case x: ResourceListing =>

View File

@ -18,7 +18,7 @@ import scala.collection.mutable.LinkedHashMap
class ResourceListingValidationTest extends FlatSpec with ShouldMatchers { class ResourceListingValidationTest extends FlatSpec with ShouldMatchers {
implicit val formats = SwaggerSerializers.formats("1.2") 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 SwaggerSerializers.validationMessages.clear
val jsonString = """ val jsonString = """
{ {
@ -27,7 +27,7 @@ class ResourceListingValidationTest extends FlatSpec with ShouldMatchers {
} }
""" """
parse(jsonString).extract[ResourceListing] parse(jsonString).extract[ResourceListing]
SwaggerSerializers.validationMessages.size should be (1) SwaggerSerializers.validationMessages.size should be (0)
} }
it should "fail resource listing without apiVersion" in { 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") case _ => fail("didn't parse the underlying apis")
} }
println(SwaggerSerializers.validationMessages)
SwaggerSerializers.validationMessages.size should be (1) SwaggerSerializers.validationMessages.size should be (1)
} }
} }
@ -194,7 +195,7 @@ class ResponseMessageValidationTest extends FlatSpec with ShouldMatchers {
val jsonString = """ val jsonString = """
{ {
"code":101, "code":101,
"reason":"the message" "message":"the message"
} }
""" """
val json = parse(jsonString) val json = parse(jsonString)
@ -398,10 +399,7 @@ class ModelPropertyValidationTest extends FlatSpec with ShouldMatchers {
"type":"string", "type":"string",
"required":false, "required":false,
"description":"nice", "description":"nice",
"allowableValues": { "enum":["1","2","3"],
"valueType":"LIST",
"values":["1","2","3"]
},
"items":{ "items":{
"type":"Foo", "type":"Foo",
"$ref":"Bar" "$ref":"Bar"
@ -441,10 +439,7 @@ class ModelPropertyValidationTest extends FlatSpec with ShouldMatchers {
"type":"string", "type":"string",
"required":false, "required":false,
"description":"nice", "description":"nice",
"allowableValues": { "enum":["1","2","3"]
"valueType":"LIST",
"values":["1","2","3"]
}
} }
""" """
val json = parse(jsonString) val json = parse(jsonString)

View File

@ -22,8 +22,7 @@ class ResourceListingSerializersTest extends FlatSpec with ShouldMatchers {
val jsonString = """ val jsonString = """
{ {
"apiVersion":"1.2.3", "apiVersion":"1.2.3",
"swaggerVersion":"1.2", "swaggerVersion":"1.2"
"basePath":"http://foo/bar"
} }
""" """
val json = parse(jsonString) val json = parse(jsonString)
@ -31,7 +30,6 @@ class ResourceListingSerializersTest extends FlatSpec with ShouldMatchers {
case p: ResourceListing => { case p: ResourceListing => {
p.apiVersion should be ("1.2.3") p.apiVersion should be ("1.2.3")
p.swaggerVersion should be ("1.2") p.swaggerVersion should be ("1.2")
p.basePath should be ("http://foo/bar")
p.apis.size should be (0) p.apis.size should be (0)
} }
case _ => fail("wrong type returned, should be ResourceListing") case _ => fail("wrong type returned, should be ResourceListing")
@ -48,7 +46,6 @@ class ResourceListingSerializersTest extends FlatSpec with ShouldMatchers {
{ {
"apiVersion":"1.2.3", "apiVersion":"1.2.3",
"swaggerVersion":"1.2", "swaggerVersion":"1.2",
"basePath":"http://foo/bar",
"apis":[ "apis":[
{ {
"path":"/a/b", "path":"/a/b",
@ -65,7 +62,6 @@ class ResourceListingSerializersTest extends FlatSpec with ShouldMatchers {
case p: ResourceListing => { case p: ResourceListing => {
p.apiVersion should be ("1.2.3") p.apiVersion should be ("1.2.3")
p.swaggerVersion should be ("1.2") p.swaggerVersion should be ("1.2")
p.basePath should be ("http://foo/bar")
p.apis.size should be (2) p.apis.size should be (2)
} }
case _ => fail("wrong type returned, should be ResourceListing") case _ => fail("wrong type returned, should be ResourceListing")
@ -409,7 +405,6 @@ class ModelSerializationTest extends FlatSpec with ShouldMatchers {
model.id should be ("Foo") model.id should be ("Foo")
model.name should be ("Bar") model.name should be ("Bar")
model.properties should not be (null) model.properties should not be (null)
println(model.properties)
model.properties.size should be (3) model.properties.size should be (3)
model.description should be (Some("nice model")) model.description should be (Some("nice model"))
model.properties("id") match { model.properties("id") match {