@@ -2,7 +2,17 @@ package com.github.swagger.enumeratum.converter
22
33import io .swagger .v3 .core .converter ._
44import io .swagger .v3 .oas .models .media ._
5- import models .{Ctx , ModelWCtxEnum , ModelWCtxEnumAndAnnotation , ModelWEnum , ModelWEnumAnnotated , ModelWEnumSet , ModelWOptionalEnum , OrderSize }
5+ import models .{
6+ Animal ,
7+ Ctx ,
8+ ModelWCtxEnum ,
9+ ModelWCtxEnumAndAnnotation ,
10+ ModelWEnum ,
11+ ModelWEnumAnnotated ,
12+ ModelWEnumSet ,
13+ ModelWOptionalEnum ,
14+ OrderSize
15+ }
616import org .scalatest .OptionValues
717import org .scalatest .flatspec .AnyFlatSpec
818import org .scalatest .matchers .should .Matchers
@@ -14,32 +24,32 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
1424 val converter = ModelConverters .getInstance()
1525 val schemas = converter.readAll(classOf [ModelWEnum ]).asScala.toMap
1626 val model = findModel(schemas, " ModelWEnum" )
17- model should be (defined)
27+ model should be(defined)
1828 model.get.getProperties should not be (null )
1929 val field = model.value.getProperties.get(" field" )
20- field shouldBe a [StringSchema ]
30+ field shouldBe a[StringSchema ]
2131 field.asInstanceOf [StringSchema ].getEnum.asScala shouldEqual OrderSize .values.map(_.entryName)
2232 nullSafeList(model.value.getRequired) shouldBe Seq (" field" )
2333 }
2434 it should " process Model with Optional Enumeratum Enum" in {
2535 val converter = ModelConverters .getInstance()
2636 val schemas = converter.readAll(classOf [ModelWOptionalEnum ]).asScala.toMap
2737 val model = findModel(schemas, " ModelWOptionalEnum" )
28- model should be (defined)
38+ model should be(defined)
2939 model.get.getProperties should not be (null )
3040 val field = model.value.getProperties.get(" field" )
31- field shouldBe a [StringSchema ]
41+ field shouldBe a[StringSchema ]
3242 field.asInstanceOf [StringSchema ].getEnum.asScala shouldEqual OrderSize .values.map(_.entryName)
3343 nullSafeList(model.value.getRequired) shouldBe empty
3444 }
3545 it should " process Model with Enumeratum Set" in {
3646 val converter = ModelConverters .getInstance()
3747 val schemas = converter.readAll(classOf [ModelWEnumSet ]).asScala.toMap
3848 val model = findModel(schemas, " ModelWEnumSet" )
39- model should be (defined)
49+ model should be(defined)
4050 model.get.getProperties should not be (null )
4151 val field = model.value.getProperties.get(" sizes" )
42- field shouldBe a [ArraySchema ]
52+ field shouldBe a[ArraySchema ]
4353 val arraySchema = field.asInstanceOf [ArraySchema ]
4454 arraySchema.getItems.getEnum.asScala shouldEqual OrderSize .values.map(_.entryName)
4555 nullSafeList(model.value.getRequired) shouldEqual List (" sizes" )
@@ -48,10 +58,10 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
4858 val converter = ModelConverters .getInstance()
4959 val schemas = converter.readAll(classOf [ModelWEnumAnnotated ]).asScala.toMap
5060 val model = findModel(schemas, " ModelWEnumAnnotated" )
51- model should be (defined)
61+ model should be(defined)
5262 model.get.getProperties should not be (null )
5363 val field = model.value.getProperties.get(" field" )
54- field shouldBe a [StringSchema ]
64+ field shouldBe a[StringSchema ]
5565 val schema = field.asInstanceOf [StringSchema ]
5666 schema.getDescription shouldEqual " enum value"
5767 schema.getEnum.asScala shouldEqual OrderSize .values.map(_.entryName)
@@ -62,17 +72,40 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
6272 val schemas = converter.readAll(classOf [ModelWCtxEnum ]).asScala.toMap
6373 schemas.keys should have size 1
6474 val model = findModel(schemas, " ModelWCtxEnum" )
65- model should be (defined)
75+ model should be(defined)
6676 model.get.getProperties should not be (null )
77+
6778 val field = model.value.getProperties.get(" field" )
68- field shouldBe a [StringSchema ]
79+ field shouldBe a[StringSchema ]
80+ field.asInstanceOf [StringSchema ].getRequired shouldBe null
81+
6982 val schema = field.asInstanceOf [StringSchema ]
7083 schema.getDescription shouldEqual (null )
71- schema.getDefault should be (null )
84+ schema.getDefault should be(null )
7285 schema.getEnum.asScala shouldEqual Ctx .Color .values.map(_.entryName)
7386 nullSafeList(model.value.getRequired) shouldBe Seq (" field" )
7487 }
7588
89+ it should " process sealed abstract class" in {
90+ val converter = ModelConverters .getInstance()
91+ val schemas = converter.readAll(classOf [Animal ]).asScala.toMap
92+ val catModel = findModel(schemas, " Cat" )
93+ catModel should be(defined)
94+ val catProps = catModel.value.getProperties
95+ catProps should have size 3
96+ catProps.get(" name" ) shouldBe a[StringSchema ]
97+ catProps.get(" age" ) shouldBe a[IntegerSchema ]
98+ catProps.get(" animalType" ) shouldBe a[StringSchema ]
99+ catModel.value.getRequired.asScala shouldEqual Seq (" age" , " animalType" , " name" )
100+ val dogModel = findModel(schemas, " Dog" )
101+ dogModel should be(defined)
102+ val dogProps = dogModel.value.getProperties
103+ dogProps should have size 2
104+ dogProps.get(" name" ) shouldBe a[StringSchema ]
105+ dogProps.get(" animalType" ) shouldBe a[StringSchema ]
106+ dogModel.value.getRequired.asScala shouldEqual Seq (" animalType" , " name" )
107+ }
108+
76109 it should " not add additional model when enum field is annotated" in {
77110 val converter = ModelConverters .getInstance()
78111 val schemas = converter.readAll(classOf [ModelWCtxEnumAndAnnotation ]).asScala.toMap
@@ -86,8 +119,8 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
86119 val schema = field.asInstanceOf [StringSchema ]
87120 schema.getDescription shouldEqual " An annotated field"
88121 schema.getName shouldEqual " field"
89- schema.getDefault should be (null )
90- schema.getDeprecated should be (null )
122+ schema.getDefault should be(null )
123+ schema.getDeprecated should be(null )
91124 schema.getEnum.asScala shouldEqual Ctx .Color .values.map(_.entryName)
92125 nullSafeList(model.value.getRequired) shouldBe Seq (" field" )
93126 }
0 commit comments