Skip to content

Commit 60dbce2

Browse files
committed
more deeply nested types
1 parent 9bb35ac commit 60dbce2

File tree

3 files changed

+16
-1
lines changed

3 files changed

+16
-1
lines changed

src/main/scala-2/com/github/swagger/scala/converter/ErasureHelper.scala

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ package com.github.swagger.scala.converter
22

33
import org.slf4j.LoggerFactory
44

5+
import scala.annotation.tailrec
56
import scala.reflect.runtime.universe
67
import scala.util.Try
78
import scala.util.control.NonFatal
@@ -27,7 +28,7 @@ private[converter] object ErasureHelper {
2728
val maybeClass: Option[Class[_]] = prop.typeSignature.typeArgs.headOption.flatMap { signature =>
2829
if (signature.typeSymbol.isClass) {
2930
signature.typeArgs.headOption match {
30-
case Some(typeArg) => Option(mirror.runtimeClass(typeArg))
31+
case Some(typeArg) => Option(mirror.runtimeClass(nestedTypeArg(typeArg)))
3132
case _ => Option(mirror.runtimeClass(signature))
3233
}
3334
} else {
@@ -48,4 +49,12 @@ private[converter] object ErasureHelper {
4849
}
4950
}
5051
}
52+
53+
@tailrec
54+
private def nestedTypeArg(typeArg: universe.Type): universe.Type = {
55+
typeArg.typeArgs.headOption match {
56+
case Some(innerArg) => nestedTypeArg(innerArg)
57+
case _ => typeArg
58+
}
59+
}
5160
}

src/test/scala/com/github/swagger/scala/converter/ErasureHelperTest.scala

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,4 +21,8 @@ class ErasureHelperTest extends AnyFlatSpec with Matchers {
2121
val expected = if (RuntimeUtil.isScala3()) Map.empty[String, Class[_]] else Map("values" -> classOf[Long])
2222
ErasureHelper.erasedOptionalPrimitives(classOf[SeqOptionLong]) shouldBe expected
2323
}
24+
it should "handle OptionSeqOptionLong" in {
25+
val expected = if (RuntimeUtil.isScala3()) Map.empty[String, Class[_]] else Map("values" -> classOf[Long])
26+
ErasureHelper.erasedOptionalPrimitives(classOf[OptionSeqOptionLong]) shouldBe expected
27+
}
2428
}
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
package com.github.swagger.scala.converter
22

33
case class SeqOptionLong(values: Seq[Option[Long]])
4+
5+
case class OptionSeqOptionLong(values: Option[Seq[Option[Long]]])

0 commit comments

Comments
 (0)