diff --git a/build.sbt b/build.sbt index 960c258c2c6..e3fe4896955 100644 --- a/build.sbt +++ b/build.sbt @@ -5,7 +5,7 @@ organization := "com.wordnik" name := "swagger-codegen" -version := "2.0.9-WN9" +version := "2.0.9-WN11" scalaVersion := "2.10.0" diff --git a/src/main/scala/com/wordnik/swagger/model/SwaggerModelSerializer.scala b/src/main/scala/com/wordnik/swagger/model/SwaggerModelSerializer.scala index dad526acf0d..f5a6638ecea 100644 --- a/src/main/scala/com/wordnik/swagger/model/SwaggerModelSerializer.scala +++ b/src/main/scala/com/wordnik/swagger/model/SwaggerModelSerializer.scala @@ -421,9 +421,8 @@ object SwaggerSerializers { val required = (json \ "required").extract[Set[String]] json \ "properties" match { case JObject(entries) => { - entries.map({ - case (key, value) => { - val prop = value.extract[ModelProperty] + entries.map(kv => kv._1 -> kv._2.extract[ModelProperty]).sortBy(_._2.position).map({ + case (key, prop) => { if(required.contains(key)) output += key -> prop.copy(required = true) else @@ -514,6 +513,7 @@ object SwaggerSerializers { case e:JBool => e.value case _ => false }, + position = (json \ "position").extractOrElse(0), description = (json \ "description").extractOpt[String], allowableValues = allowableValues, items = { @@ -527,7 +527,8 @@ object SwaggerSerializers { case x: ModelProperty => val output = toJsonSchema("type", x.`type`) ~ ("description" -> x.description) ~ - ("items" -> Extraction.decompose(x.items)) + ("items" -> Extraction.decompose(x.items)) ~ + ("position" -> x.position) x.allowableValues match { case AllowableListValues(values, "LIST") => diff --git a/src/test/scala/swaggerSpec1_2/ModelSerializerValidations.scala b/src/test/scala/swaggerSpec1_2/ModelSerializerValidations.scala index aeeecb9bf74..0d321d1990c 100644 --- a/src/test/scala/swaggerSpec1_2/ModelSerializerValidations.scala +++ b/src/test/scala/swaggerSpec1_2/ModelSerializerValidations.scala @@ -354,7 +354,7 @@ class ModelValidationTest extends FlatSpec with ShouldMatchers { it should "serialize a model" in { val ref = Model("Foo", "Bar", "Bar", (LinkedHashMap("s" -> ModelProperty("string", "string", 0, true, Some("a string"))))) - write(ref) should be ("""{"id":"Foo","name":"Bar","required":["s"],"properties":{"s":{"type":"string","description":"a string"}}}""") + write(ref) should be ("""{"id":"Foo","name":"Bar","required":["s"],"properties":{"s":{"type":"string","description":"a string","position":0}}}""") } } @@ -426,7 +426,7 @@ class ModelPropertyValidationTest extends FlatSpec with ShouldMatchers { it should "serialize a model property with allowable values and ref" in { val p = ModelProperty("string", "string", 0, false, Some("nice"), AllowableListValues(List("a","b")),Some(ModelRef("Foo",Some("Bar")))) - write(p) should be ("""{"type":"string","description":"nice","items":{"type":"Foo","$ref":"Bar"},"enum":["a","b"]}""") + write(p) should be ("""{"type":"string","description":"nice","items":{"type":"Foo","$ref":"Bar"},"position":0,"enum":["a","b"]}""") } it should "deserialize a model property with allowable values" in { @@ -455,7 +455,7 @@ class ModelPropertyValidationTest extends FlatSpec with ShouldMatchers { it should "serialize a model property with allowable values" in { val p = ModelProperty("string", "string", 0, false, Some("nice"), AllowableListValues(List("a","b"))) - write(p) should be ("""{"type":"string","description":"nice","enum":["a","b"]}""") + write(p) should be ("""{"type":"string","description":"nice","position":0,"enum":["a","b"]}""") } it should "deserialize a model property" in { @@ -479,7 +479,7 @@ class ModelPropertyValidationTest extends FlatSpec with ShouldMatchers { it should "serialize a model property" in { val p = ModelProperty("string", "string", 0, false, Some("nice")) - write(p) should be ("""{"type":"string","description":"nice"}""") + write(p) should be ("""{"type":"string","description":"nice","position":0}""") } } diff --git a/src/test/scala/swaggerSpec1_2/ModelSerializersTest.scala b/src/test/scala/swaggerSpec1_2/ModelSerializersTest.scala index 398443accf9..01490cf5947 100644 --- a/src/test/scala/swaggerSpec1_2/ModelSerializersTest.scala +++ b/src/test/scala/swaggerSpec1_2/ModelSerializersTest.scala @@ -537,7 +537,7 @@ class ModelSerializationTest extends FlatSpec with ShouldMatchers { it should "serialize a model" in { val ref = Model("Foo", "Bar", "Bar", (LinkedHashMap("s" -> ModelProperty("string", "string", 0, true, Some("a string"))))) - write(ref) should be ("""{"id":"Foo","name":"Bar","required":["s"],"properties":{"s":{"type":"string","description":"a string"}}}""") + write(ref) should be ("""{"id":"Foo","name":"Bar","required":["s"],"properties":{"s":{"type":"string","description":"a string","position":0}}}""") } } @@ -609,7 +609,7 @@ class ModelPropertySerializationTest extends FlatSpec with ShouldMatchers { it should "serialize a model property with allowable values and ref" in { val p = ModelProperty("string", "string", 0, false, Some("nice"), AllowableListValues(List("a","b")),Some(ModelRef("Foo",Some("Bar")))) - write(p) should be ("""{"type":"string","description":"nice","items":{"type":"Foo","$ref":"Bar"},"enum":["a","b"]}""") + write(p) should be ("""{"type":"string","description":"nice","items":{"type":"Foo","$ref":"Bar"},"position":0,"enum":["a","b"]}""") } it should "deserialize a model property with allowable values" in { @@ -638,7 +638,7 @@ class ModelPropertySerializationTest extends FlatSpec with ShouldMatchers { it should "serialize a model property with allowable values" in { val p = ModelProperty("string", "string", 0, false, Some("nice"), AllowableListValues(List("a","b"))) - write(p) should be ("""{"type":"string","description":"nice","enum":["a","b"]}""") + write(p) should be ("""{"type":"string","description":"nice","position":0,"enum":["a","b"]}""") } it should "deserialize a model property" in { @@ -662,7 +662,7 @@ class ModelPropertySerializationTest extends FlatSpec with ShouldMatchers { it should "serialize a model property" in { val p = ModelProperty("string", "string", 0, false, Some("nice")) - write(p) should be ("""{"type":"string","description":"nice"}""") + write(p) should be ("""{"type":"string","description":"nice","position":0}""") } it should "extract model properties" in {