Skip to content

Commit 0553501

Browse files
authored
ignore string type in erasure helper (#311)
* ignore string type in erasure helper * try to fix test failure
1 parent 4d9b1b8 commit 0553501

File tree

3 files changed

+14
-4
lines changed

3 files changed

+14
-4
lines changed

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

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,11 @@ private[converter] object ErasureHelper {
2727
val maybeClass: Option[Class[_]] = prop.typeSignature.typeArgs.headOption.flatMap { signature =>
2828
if (signature.typeSymbol.isClass) {
2929
signature.typeArgs.headOption match {
30-
case Some(typeArg) => Option(mirror.runtimeClass(nestedTypeArg(typeArg)))
30+
case Some(typeArg) => {
31+
val resultType: universe.Type = nestedTypeArg(typeArg)
32+
val resultClass = mirror.runtimeClass(resultType)
33+
if (resultClass.isPrimitive) Option(resultClass) else None
34+
}
3135
case _ => Option(mirror.runtimeClass(signature))
3236
}
3337
} else {

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,11 +19,14 @@ private[converter] object ErasureHelper {
1919
val results = classInfo.fields.flatMap { fieldInfo =>
2020
fieldInfo.fieldType match {
2121
case optionInfo: ScalaOptionInfo =>
22-
Some(fieldInfo.name -> getInnerType(optionInfo.optionParamType).infoClass)
22+
val innerClass = getInnerType(optionInfo.optionParamType).infoClass
23+
if (innerClass.isPrimitive) Some(fieldInfo.name -> innerClass) else None
2324
case mapInfo: MapLikeInfo =>
24-
Some(fieldInfo.name -> getInnerType(mapInfo.elementType2).infoClass)
25+
val innerClass = getInnerType(mapInfo.elementType2).infoClass
26+
if (innerClass.isPrimitive) Some(fieldInfo.name -> innerClass) else None
2527
case seqInfo: CollectionRType =>
26-
Some(fieldInfo.name -> getInnerType(seqInfo.elementType).infoClass)
28+
val innerClass = getInnerType(seqInfo.elementType).infoClass
29+
if (innerClass.isPrimitive) Some(fieldInfo.name -> innerClass) else None
2730
case _ =>
2831
None
2932
}

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,4 +29,7 @@ class ErasureHelperTest extends AnyFlatSpec with Matchers {
2929
it should "handle OptionSeqOptionLong" in {
3030
ErasureHelper.erasedOptionalPrimitives(classOf[OptionSeqOptionLong]) shouldBe Map("values" -> classOf[Long])
3131
}
32+
it should "handle OptionSetString" in {
33+
ErasureHelper.erasedOptionalPrimitives(classOf[OptionSetString]) shouldBe Map.empty
34+
}
3235
}

0 commit comments

Comments
 (0)