File tree Expand file tree Collapse file tree 2 files changed +23
-1
lines changed
com/github/swagger/scala/converter Expand file tree Collapse file tree 2 files changed +23
-1
lines changed Original file line number Diff line number Diff line change @@ -36,6 +36,18 @@ class ScalaModelTest extends AnyFlatSpec with Matchers {
3636 sp.getEnum().asScala.toSet shouldEqual Set (" TALL" , " GRANDE" , " VENTI" )
3737 }
3838
39+ it should " extract a scala enum with custom value names (jackson annotated)" in {
40+ val schemas = ModelConverters .getInstance().readAll(classOf [ModelWithTestEnum ]).asScala
41+ val userSchema = schemas(" ModelWithTestEnum" )
42+
43+ val orderSize = userSchema.getProperties().get(" enum" )
44+ orderSize should not be null
45+ orderSize shouldBe a [StringSchema ]
46+ val sp = orderSize.asInstanceOf [StringSchema ]
47+ Option (sp.getEnum) shouldBe defined
48+ sp.getEnum().asScala.toSet shouldEqual Set (" a" , " b" )
49+ }
50+
3951 it should " read a scala case class with properties" in {
4052 val schemas = ModelConverters .getInstance().readAll(classOf [SimpleUser ]).asScala
4153 val userSchema = schemas(" SimpleUser" )
Original file line number Diff line number Diff line change @@ -4,6 +4,7 @@ import com.fasterxml.jackson.core.`type`.TypeReference
44import com .fasterxml .jackson .module .scala .JsonScalaEnumeration
55import io .swagger .v3 .oas .annotations .media .Schema
66import models .OrderSize .OrderSize
7+ import models .TestEnum .TestEnum
78
89import scala .annotation .meta .field
910
@@ -20,4 +21,13 @@ case object OrderSize extends Enumeration {
2021 val TALL = Value (" TALL" )
2122 val GRANDE = Value (" GRANDE" )
2223 val VENTI = Value (" VENTI" )
23- }
24+ }
25+
26+ class TestEnumTypeClass extends TypeReference [TestEnum .type ]
27+ case class ModelWithTestEnum (@ JsonScalaEnumeration (classOf [TestEnumTypeClass ]) enum : TestEnum = TestEnum .AEnum )
28+
29+ object TestEnum extends Enumeration {
30+ type TestEnum = Value
31+ val AEnum = Value (" a" )
32+ val BEnum = Value (" b" )
33+ }
You can’t perform that action at this time.
0 commit comments