Skip to content

Commit

Permalink
Fix fromZSchemaMulti (#2996)
Browse files Browse the repository at this point in the history
  • Loading branch information
pawelsadlo authored Aug 2, 2024
1 parent a68c33b commit 0392228
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -387,7 +387,7 @@ object JsonSchema {
Chunk.empty,
),
ref,
nested.children + (nested.rootRef.get -> nested.root),
nested.children ++ (nested.rootRef.map(_ -> nested.root)),
)
}
case Schema.Set(elementSchema, _) =>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,9 @@ import scala.collection.immutable.ListMap
import zio.json.ast.Json
import zio.test._

import zio.schema.Schema

import zio.http.endpoint.openapi.JsonSchema.SchemaStyle
import zio.http.endpoint.openapi.OpenAPI.SecurityScheme._

object OpenAPISpec extends ZIOSpecDefault {
Expand Down Expand Up @@ -60,5 +63,20 @@ object OpenAPISpec extends ZIOSpecDefault {

assertTrue(toJsonAst(json) == toJsonAst(expected))
},
test("JsonSchema.fromZSchemaMulti correctly handles Map schema with List as Value") {
val schema = Schema.map[String, List[String]]
val sch: JsonSchemas = JsonSchema.fromZSchemaMulti(schema, SchemaStyle.Reference)

val isSchemaProperlyGenerated = if (sch.root.isCollection) sch.root match {
case JsonSchema.Object(_, additionalProperties, _) =>
additionalProperties match {
case Right(JsonSchema.ArrayType(items)) => items.exists(_.isInstanceOf[JsonSchema.String])
case _ => false
}
case _ => false
}
else false
assertTrue(isSchemaProperlyGenerated)
},
)
}

0 comments on commit 0392228

Please sign in to comment.