Skip to content

Commit 3bf85c4

Browse files
committed
Ensure sealed traits keep working as expected
1 parent 0c8e766 commit 3bf85c4

File tree

3 files changed

+34
-2
lines changed

3 files changed

+34
-2
lines changed

build.sbt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ pomIncludeRepository := { x => false }
2020

2121
libraryDependencies ++= Seq(
2222
"io.swagger.core.v3" % "swagger-core-jakarta" % "2.2.4",
23-
"com.github.swagger-akka-http" %% "swagger-scala-module" % "2.7.7",
23+
"com.github.swagger-akka-http" %% "swagger-scala-module" % "2.7.8",
2424
"com.fasterxml.jackson.module" %% "jackson-module-scala" % "2.13.4",
2525
"com.beachape" %% "enumeratum" % "1.7.0",
2626
"org.scalatest" %% "scalatest" % "3.2.14" % Test,

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

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@ package com.github.swagger.enumeratum.converter
33
import io.swagger.v3.core.converter._
44
import io.swagger.v3.oas.models.media._
55
import models.{
6+
Animal,
67
Ctx,
78
ModelWCtxEnum,
89
ModelWCtxEnumAndAnnotation,
@@ -76,7 +77,7 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
7677

7778
val field = model.value.getProperties.get("field")
7879
field shouldBe a[StringSchema]
79-
field.asInstanceOf[StringSchema].getRequired shouldBe Seq.empty
80+
field.asInstanceOf[StringSchema].getRequired shouldBe null
8081

8182
val schema = field.asInstanceOf[StringSchema]
8283
schema.getDescription shouldEqual (null)
@@ -85,6 +86,26 @@ class ModelPropertyParserTest extends AnyFlatSpec with Matchers with OptionValue
8586
nullSafeList(model.value.getRequired) shouldBe Seq("field")
8687
}
8788

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+
88109
it should "not add additional model when enum field is annotated" in {
89110
val converter = ModelConverters.getInstance()
90111
val schemas = converter.readAll(classOf[ModelWCtxEnumAndAnnotation]).asScala.toMap
Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,11 @@
1+
package models
2+
3+
sealed abstract class Animal(val animalType: String) {
4+
val name: String
5+
}
6+
7+
class Dog(val name: String) extends Animal("Dog")
8+
9+
class Cat(val name: String, val age: Int) extends Animal("Cat")
10+
11+
case class PetOwner(owner: String, pet: Animal)

0 commit comments

Comments
 (0)