Skip to content

Commit dff802f

Browse files
authored
Merge pull request #384 from RafalSumislawski/fix-model-of-enums
Fix a regression causing enum properties to be modeled as RefProperty
2 parents 757368e + ef548ee commit dff802f

File tree

2 files changed

+6
-2
lines changed

2 files changed

+6
-2
lines changed

swagger/src/main/scala/org/http4s/rho/swagger/TypeBuilder.scala

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -196,7 +196,7 @@ object TypeBuilder {
196196
typeToProperty(tpe.typeArgs.head, sfs).withRequired(false)
197197
else if (tpe.isAnyVal && !tpe.isPrimitive)
198198
typeToProperty(ptSym.asClass.primaryConstructor.asMethod.paramLists.flatten.head.typeSignature, sfs)
199-
else if (isCaseClass(ptSym) || isSumType(ptSym))
199+
else if (isCaseClass(ptSym) || (isSumType(ptSym) && !isObjectEnum(ptSym)))
200200
RefProperty(tpe.simpleName)
201201
else
202202
DataType.fromType(tpe) match {

swagger/src/test/scala/org/http4s/rho/swagger/TypeBuilderSpec.scala

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ import java.util.Date
66
import cats.effect.IO
77
import cats.syntax.all._
88
import fs2.Stream
9-
import org.http4s.rho.swagger.models.AbstractProperty
9+
import org.http4s.rho.swagger.models.{AbstractProperty, StringProperty}
1010
import org.specs2.execute.Result
1111
import org.specs2.mutable.Specification
1212
import shapeless.{:+:, CNil}
@@ -415,6 +415,10 @@ class TypeBuilderSpec extends Specification {
415415
"Build a model for a case class containing a sealed enum" in {
416416
val ms = modelOf[SealedEnumContainer]
417417
ms.size must_== 1
418+
val sealedEnumContainerModel = ms.head
419+
val e = sealedEnumContainerModel.properties("e")
420+
val enumProperty = e.asInstanceOf[StringProperty]
421+
enumProperty.enums should_== Set("FooEnum", "BarEnum")
418422
}
419423

420424
"Build a model for a type recursive through sealed trait" in {

0 commit comments

Comments
 (0)