Skip to content

Commit

Permalink
handle value types like Option[Seq[T]] (#174)
Browse files Browse the repository at this point in the history
* handle value types like Option[Seq[T]]

* Update ErasureHelperTest.scala
  • Loading branch information
pjfanning committed Aug 8, 2022
1 parent 4c1bc86 commit 9bb35ac
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,13 @@ private[converter] object ErasureHelper {
properties.flatMap { prop: universe.Symbol =>
val maybeClass: Option[Class[_]] = prop.typeSignature.typeArgs.headOption.flatMap { signature =>
if (signature.typeSymbol.isClass) {
Option(mirror.runtimeClass(signature.typeSymbol.asClass))
} else None
signature.typeArgs.headOption match {
case Some(typeArg) => Option(mirror.runtimeClass(typeArg))
case _ => Option(mirror.runtimeClass(signature))
}
} else {
None
}
}
maybeClass.map(prop.name.toString.trim -> _)
}.toMap
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,4 +13,12 @@ class ErasureHelperTest extends AnyFlatSpec with Matchers {
"ErasureHelper" should "handle MyTrait" in {
ErasureHelper.erasedOptionalPrimitives(classOf[ErasureHelperTest.SuperType]) shouldBe empty
}
it should "handle OptionSeqLong" in {
val expected = if (RuntimeUtil.isScala3()) Map.empty[String, Class[_]] else Map("values" -> classOf[Long])
ErasureHelper.erasedOptionalPrimitives(classOf[OptionSeqLong]) shouldBe expected
}
it should "handle SeqOptionLong" in {
val expected = if (RuntimeUtil.isScala3()) Map.empty[String, Class[_]] else Map("values" -> classOf[Long])
ErasureHelper.erasedOptionalPrimitives(classOf[SeqOptionLong]) shouldBe expected
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.github.swagger.scala.converter

case class OptionSeqLong(values: Option[Seq[Long]])
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
package com.github.swagger.scala.converter

case class SeqOptionLong(values: Seq[Option[Long]])

0 comments on commit 9bb35ac

Please sign in to comment.