Skip to content

Commit 05cf20f

Browse files
committed
better null support
1 parent 8545b7d commit 05cf20f

File tree

1 file changed

+22
-11
lines changed

1 file changed

+22
-11
lines changed

src/main/scala/com/github/swagger/scala/converter/SwaggerScalaModelConverter.scala

Lines changed: 22 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -98,18 +98,29 @@ class SwaggerScalaModelConverter extends ModelResolver(SwaggerScalaModelConverte
9898
private val AnyClass = classOf[Any]
9999

100100
override def resolve(`type`: AnnotatedType, context: ModelConverterContext, chain: util.Iterator[ModelConverter]): Schema[_] = {
101-
val javaType = _mapper.constructType(`type`.getType)
102-
val subtypes = SubtypeHelper.findSubtypes(javaType.getRawClass)
103-
if (subtypes.isEmpty) {
104-
resolveWithoutSubtypes(javaType, `type`, context, chain)
105-
} else {
106-
val converters = chain.asScala.toSeq
107-
val schema = new ObjectSchema
108-
val subSchemas = subtypes.map { subtype =>
109-
val javaSubType = _mapper.constructType(subtype)
110-
resolveWithoutSubtypes(javaSubType, new AnnotatedType(subtype), context, converters.iterator.asJava)
101+
Option(`type`.getType) match {
102+
case Some(typeType) => {
103+
val javaType = _mapper.constructType(typeType)
104+
val subtypes = SubtypeHelper.findSubtypes(javaType.getRawClass)
105+
if (subtypes.isEmpty) {
106+
resolveWithoutSubtypes(javaType, `type`, context, chain)
107+
} else {
108+
val converters = chain.asScala.toSeq
109+
val schema = new ObjectSchema
110+
val subSchemas = subtypes.map { subtype =>
111+
val javaSubType = _mapper.constructType(subtype)
112+
resolveWithoutSubtypes(javaSubType, new AnnotatedType(subtype), context, converters.iterator.asJava)
113+
}
114+
schema.anyOf(subSchemas.asJava)
115+
}
116+
}
117+
case _ => {
118+
if (chain.hasNext) {
119+
chain.next().resolve(`type`, context, chain)
120+
} else {
121+
None.orNull
122+
}
111123
}
112-
schema.anyOf(subSchemas.asJava)
113124
}
114125
}
115126

0 commit comments

Comments
 (0)