forked from loafle/openapi-generator-original
use position property in json to preserve ordering across generations
This commit is contained in:
parent
450b3c7ed5
commit
9ee361df5b
@ -5,7 +5,7 @@ organization := "com.wordnik"
|
||||
|
||||
name := "swagger-codegen"
|
||||
|
||||
version := "2.0.9-WN9"
|
||||
version := "2.0.9-WN11"
|
||||
|
||||
scalaVersion := "2.10.0"
|
||||
|
||||
|
@ -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") =>
|
||||
|
@ -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}""")
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -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 {
|
||||
|
Loading…
x
Reference in New Issue
Block a user