Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

try to fix issue with Option[Iterable] type #310

Merged
merged 1 commit into from
Feb 1, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,14 +10,13 @@ import io.swagger.v3.core.jackson.ModelResolver
import io.swagger.v3.core.util.{Json, PrimitiveType}
import io.swagger.v3.oas.annotations.Parameter
import io.swagger.v3.oas.annotations.media.Schema.RequiredMode
import io.swagger.v3.oas.annotations.media.{ArraySchema, Schema => SchemaAnnotation}
import io.swagger.v3.oas.models.media.{MapSchema, ObjectSchema, Schema}
import io.swagger.v3.oas.annotations.media.{ArraySchema => ArraySchemaAnnotation, Schema => SchemaAnnotation}
import io.swagger.v3.oas.models.media.{ArraySchema, MapSchema, ObjectSchema, Schema}
import org.slf4j.LoggerFactory

import java.lang.annotation.Annotation
import java.lang.reflect.ParameterizedType
import java.util
import java.util.List
import scala.collection.JavaConverters._
import scala.util.Try
import scala.util.control.NonFatal
Expand Down Expand Up @@ -109,7 +108,7 @@ object SwaggerScalaModelConverter {
s.requiredMode()
}
}
case a: ArraySchema => {
case a: ArraySchemaAnnotation => {
if (a.arraySchema().requiredMode() == RequiredMode.AUTO) {
if (a.arraySchema().required()) {
RequiredMode.REQUIRED
Expand Down Expand Up @@ -350,6 +349,11 @@ class SwaggerScalaModelConverter extends ModelResolver(SwaggerScalaModelConverte
private[converter] def tryCorrectSchema(itemSchema: Schema[_], primitiveType: PrimitiveType): Schema[_] = {
itemSchema match {
case ms: MapSchema => ms
case as: ArraySchema => {
val correctedSchema = tryCorrectSchema(as.getItems, primitiveType)
as.setItems(correctedSchema)
as
}
case _ => {
Try {
val primitiveProperty = primitiveType.createProperty()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,17 +73,19 @@ class ModelPropertyParserTest extends AnyFlatSpec with BeforeAndAfterEach with M
it should "process Option[Set[String]] as string" in new PropertiesScope[OptionSetString] {
val values = model.value.getProperties().get("values")
values should not be (null)
// TODO fix broken assertion
//values shouldBe an[ArraySchema]
values shouldBe an[ArraySchema]
values.getRequired shouldBe null
values.asInstanceOf[ArraySchema].getItems shouldBe a[StringSchema]
}

it should "process Option[Seq[Long]] as string" in new PropertiesScope[OptionSeqLong] {
val values = model.value.getProperties().get("values")
values should not be (null)
// TODO fix broken assertion
// values shouldBe an[ArraySchema]
values shouldBe an[ArraySchema]
values.getRequired shouldBe null
val itemSchema = values.asInstanceOf[ArraySchema].getItems
itemSchema shouldBe an[IntegerSchema]
itemSchema.asInstanceOf[IntegerSchema].getFormat shouldBe "int64"
}

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