mirror of
https://github.com/OpenAPITools/openapi-generator.git
synced 2025-07-04 06:30:52 +00:00
fix for jsonschema format in model property with array
This commit is contained in:
parent
5483ba5ae7
commit
01dc29d789
@ -567,8 +567,22 @@ object SwaggerSerializers {
|
|||||||
class ModelRefSerializer extends CustomSerializer[ModelRef](formats => ({
|
class ModelRefSerializer extends CustomSerializer[ModelRef](formats => ({
|
||||||
case json =>
|
case json =>
|
||||||
implicit val fmts: Formats = formats
|
implicit val fmts: Formats = formats
|
||||||
|
|
||||||
|
val `type` = (json \ "type") match {
|
||||||
|
case e: JString => e.s
|
||||||
|
case _ => ""
|
||||||
|
}
|
||||||
|
val format = (json \ "format") match {
|
||||||
|
case e: JString => e.s
|
||||||
|
case _ => ""
|
||||||
|
}
|
||||||
|
val jsonSchemaType = jsonSchemaTypeMap.getOrElse((`type`, format), `type`)
|
||||||
|
|
||||||
ModelRef(
|
ModelRef(
|
||||||
(json \ "type").extractOrElse(null: String),
|
jsonSchemaType match {
|
||||||
|
case e: String if(e != "") => e
|
||||||
|
case _ => null
|
||||||
|
},
|
||||||
(json \ "$ref").extractOpt[String]
|
(json \ "$ref").extractOpt[String]
|
||||||
)
|
)
|
||||||
}, {
|
}, {
|
||||||
|
@ -569,6 +569,59 @@ class ModelPropertySerializationTest extends FlatSpec with ShouldMatchers {
|
|||||||
val p = ModelProperty("string", "string", 0, false, Some("nice"))
|
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"}""")
|
||||||
}
|
}
|
||||||
|
|
||||||
|
it should "extract model properties" in {
|
||||||
|
val jsonString = """
|
||||||
|
{
|
||||||
|
"type":"integer",
|
||||||
|
"format":"int64",
|
||||||
|
"required":true,
|
||||||
|
"description":"nice"
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
val json = parse(jsonString)
|
||||||
|
json.extract[ModelProperty] match {
|
||||||
|
case p: ModelProperty => {
|
||||||
|
p.`type` should be ("long")
|
||||||
|
p.required should be (true)
|
||||||
|
p.description should be (Some("nice"))
|
||||||
|
}
|
||||||
|
case _ => fail("expected type ModelProperty")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
it should "extract model properties with arrays" in {
|
||||||
|
val jsonString = """
|
||||||
|
{
|
||||||
|
"id": "DocIdList",
|
||||||
|
"name": "DocIdList",
|
||||||
|
"properties": {
|
||||||
|
"docIds": {
|
||||||
|
"items": {
|
||||||
|
"format": "int64",
|
||||||
|
"type": "integer"
|
||||||
|
},
|
||||||
|
"type": "array"
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
"""
|
||||||
|
val json = parse(jsonString)
|
||||||
|
json.extract[Model] match {
|
||||||
|
case p: Model => {
|
||||||
|
p.properties should not be (null)
|
||||||
|
p.properties.size should be (1)
|
||||||
|
p.properties.keys.size should be (1)
|
||||||
|
for(key <- p.properties.keys) {
|
||||||
|
val property = p.properties(key)
|
||||||
|
property.`type` should be ("Array")
|
||||||
|
property.items should not be (None)
|
||||||
|
property.items.get.`type` should be ("long")
|
||||||
|
}
|
||||||
|
}
|
||||||
|
case _ => fail("expected type ModelProperty")
|
||||||
|
}
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@RunWith(classOf[JUnitRunner])
|
@RunWith(classOf[JUnitRunner])
|
||||||
|
Loading…
x
Reference in New Issue
Block a user