Skip to content

Commit 6673ba8

Browse files
author
PJ Fanning
committed
add tests
1 parent 60163fd commit 6673ba8

File tree

2 files changed

+32
-0
lines changed

2 files changed

+32
-0
lines changed

src/test/scala/com/github/swagger/scala/converter/ModelPropertyParserTest.scala

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -293,6 +293,34 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
293293
nullSafeList(arraySchema.getRequired()) shouldBe empty
294294
}
295295

296+
it should "process Model with Scala Map" in {
297+
val converter = ModelConverters.getInstance()
298+
val schemas = converter.readAll(classOf[ModelWMapString]).asScala.toMap
299+
val model = findModel(schemas, "ModelWMapString")
300+
model should be (defined)
301+
model.value.getProperties should not be (null)
302+
val stringsField = model.value.getProperties.get("strings")
303+
stringsField shouldBe a [MapSchema]
304+
val mapSchema = stringsField.asInstanceOf[MapSchema]
305+
mapSchema.getUniqueItems() shouldBe (null)
306+
nullSafeMap(mapSchema.getProperties()) shouldBe empty
307+
nullSafeList(mapSchema.getRequired()) shouldBe empty
308+
}
309+
310+
it should "process Model with Java Map" in {
311+
val converter = ModelConverters.getInstance()
312+
val schemas = converter.readAll(classOf[ModelWJavaMapString]).asScala.toMap
313+
val model = findModel(schemas, "ModelWJavaMapString")
314+
model should be (defined)
315+
model.value.getProperties should not be (null)
316+
val stringsField = model.value.getProperties.get("strings")
317+
stringsField shouldBe a [MapSchema]
318+
val mapSchema = stringsField.asInstanceOf[MapSchema]
319+
mapSchema.getUniqueItems() shouldBe (null)
320+
nullSafeMap(mapSchema.getProperties()) shouldBe empty
321+
nullSafeList(mapSchema.getRequired()) shouldBe empty
322+
}
323+
296324
private def findModel(schemas: Map[String, Schema[_]], name: String): Option[Schema[_]] = {
297325
schemas.get(name) match {
298326
case Some(m) => Some(m)

src/test/scala/models/ModelWSeqString.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -5,3 +5,7 @@ case class ModelWSeqString(strings: Seq[String])
55
case class ModelWSetString(strings: Set[String])
66

77
case class ModelWJavaListString(strings: java.util.List[String])
8+
9+
case class ModelWMapString(strings: Map[String, String])
10+
11+
case class ModelWJavaMapString(strings: java.util.Map[String, String])

0 commit comments

Comments
 (0)