diff --git a/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/JsonSchema.scala b/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/JsonSchema.scala index 22cd74e241..f9b957b244 100644 --- a/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/JsonSchema.scala +++ b/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/JsonSchema.scala @@ -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, _) => diff --git a/zio-http/shared/src/test/scala/zio/http/endpoint/openapi/OpenAPISpec.scala b/zio-http/shared/src/test/scala/zio/http/endpoint/openapi/OpenAPISpec.scala index da3ab41a08..e3ec7d73be 100644 --- a/zio-http/shared/src/test/scala/zio/http/endpoint/openapi/OpenAPISpec.scala +++ b/zio-http/shared/src/test/scala/zio/http/endpoint/openapi/OpenAPISpec.scala @@ -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 { @@ -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) + }, ) }