Skip to content

Commit

Permalink
more deeply nested types
Browse files Browse the repository at this point in the history
  • Loading branch information
pjfanning committed Aug 8, 2022
1 parent 9bb35ac commit 60dbce2
Show file tree
Hide file tree
Showing 3 changed files with 16 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package com.github.swagger.scala.converter

import org.slf4j.LoggerFactory

import scala.annotation.tailrec
import scala.reflect.runtime.universe
import scala.util.Try
import scala.util.control.NonFatal
Expand All @@ -27,7 +28,7 @@ private[converter] object ErasureHelper {
val maybeClass: Option[Class[_]] = prop.typeSignature.typeArgs.headOption.flatMap { signature =>
if (signature.typeSymbol.isClass) {
signature.typeArgs.headOption match {
case Some(typeArg) => Option(mirror.runtimeClass(typeArg))
case Some(typeArg) => Option(mirror.runtimeClass(nestedTypeArg(typeArg)))
case _ => Option(mirror.runtimeClass(signature))
}
} else {
Expand All @@ -48,4 +49,12 @@ private[converter] object ErasureHelper {
}
}
}

@tailrec
private def nestedTypeArg(typeArg: universe.Type): universe.Type = {
typeArg.typeArgs.headOption match {
case Some(innerArg) => nestedTypeArg(innerArg)
case _ => typeArg
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -21,4 +21,8 @@ class ErasureHelperTest extends AnyFlatSpec with Matchers {
val expected = if (RuntimeUtil.isScala3()) Map.empty[String, Class[_]] else Map("values" -> classOf[Long])
ErasureHelper.erasedOptionalPrimitives(classOf[SeqOptionLong]) shouldBe expected
}
it should "handle OptionSeqOptionLong" in {
val expected = if (RuntimeUtil.isScala3()) Map.empty[String, Class[_]] else Map("values" -> classOf[Long])
ErasureHelper.erasedOptionalPrimitives(classOf[OptionSeqOptionLong]) shouldBe expected
}
}
Original file line number Diff line number Diff line change
@@ -1,3 +1,5 @@
package com.github.swagger.scala.converter

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

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

0 comments on commit 60dbce2

Please sign in to comment.