Skip to content

Commit ff3a38d

Browse files
authored
try to fix issue with Option[Iterable] type (#310)
1 parent 74e1a49 commit ff3a38d

File tree

2 files changed

+14
-8
lines changed

2 files changed

+14
-8
lines changed

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

Lines changed: 8 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,13 @@ import io.swagger.v3.core.jackson.ModelResolver
1010
import io.swagger.v3.core.util.{Json, PrimitiveType}
1111
import io.swagger.v3.oas.annotations.Parameter
1212
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode
13-
import io.swagger.v3.oas.annotations.media.{ArraySchema, Schema => SchemaAnnotation}
14-
import io.swagger.v3.oas.models.media.{MapSchema, ObjectSchema, Schema}
13+
import io.swagger.v3.oas.annotations.media.{ArraySchema => ArraySchemaAnnotation, Schema => SchemaAnnotation}
14+
import io.swagger.v3.oas.models.media.{ArraySchema, MapSchema, ObjectSchema, Schema}
1515
import org.slf4j.LoggerFactory
1616

1717
import java.lang.annotation.Annotation
1818
import java.lang.reflect.ParameterizedType
1919
import java.util
20-
import java.util.List
2120
import scala.collection.JavaConverters._
2221
import scala.util.Try
2322
import scala.util.control.NonFatal
@@ -109,7 +108,7 @@ object SwaggerScalaModelConverter {
109108
s.requiredMode()
110109
}
111110
}
112-
case a: ArraySchema => {
111+
case a: ArraySchemaAnnotation => {
113112
if (a.arraySchema().requiredMode() == RequiredMode.AUTO) {
114113
if (a.arraySchema().required()) {
115114
RequiredMode.REQUIRED
@@ -350,6 +349,11 @@ class SwaggerScalaModelConverter extends ModelResolver(SwaggerScalaModelConverte
350349
private[converter] def tryCorrectSchema(itemSchema: Schema[_], primitiveType: PrimitiveType): Schema[_] = {
351350
itemSchema match {
352351
case ms: MapSchema => ms
352+
case as: ArraySchema => {
353+
val correctedSchema = tryCorrectSchema(as.getItems, primitiveType)
354+
as.setItems(correctedSchema)
355+
as
356+
}
353357
case _ => {
354358
Try {
355359
val primitiveProperty = primitiveType.createProperty()

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

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,17 +73,19 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
7373
it should "process Option[Set[String]] as string" in new PropertiesScope[OptionSetString] {
7474
val values = model.value.getProperties().get("values")
7575
values should not be (null)
76-
// TODO fix broken assertion
77-
//values shouldBe an[ArraySchema]
76+
values shouldBe an[ArraySchema]
7877
values.getRequired shouldBe null
78+
values.asInstanceOf[ArraySchema].getItems shouldBe a[StringSchema]
7979
}
8080

8181
it should "process Option[Seq[Long]] as string" in new PropertiesScope[OptionSeqLong] {
8282
val values = model.value.getProperties().get("values")
8383
values should not be (null)
84-
// TODO fix broken assertion
85-
// values shouldBe an[ArraySchema]
84+
values shouldBe an[ArraySchema]
8685
values.getRequired shouldBe null
86+
val itemSchema = values.asInstanceOf[ArraySchema].getItems
87+
itemSchema shouldBe an[IntegerSchema]
88+
itemSchema.asInstanceOf[IntegerSchema].getFormat shouldBe "int64"
8789
}
8890

8991
it should "process Option[Model] as Model" in new PropertiesScope[ModelWOptionModel] {

0 commit comments

Comments
 (0)