From 027edbd1d851d729ca8f4d2ead0e1fc107e20280 Mon Sep 17 00:00:00 2001 From: Vamshi Maskuri <117595548+varshith257@users.noreply.github.com> Date: Fri, 2 Aug 2024 12:50:11 +0530 Subject: [PATCH] fix openapi generation --- .../endpoint/openapi/OpenAPIGenSpec.scala | 20 +++++++------------ .../http/endpoint/openapi/JsonSchema.scala | 2 +- 2 files changed, 8 insertions(+), 14 deletions(-) diff --git a/zio-http/jvm/src/test/scala/zio/http/endpoint/openapi/OpenAPIGenSpec.scala b/zio-http/jvm/src/test/scala/zio/http/endpoint/openapi/OpenAPIGenSpec.scala index 823930f926..a5cec11430 100644 --- a/zio-http/jvm/src/test/scala/zio/http/endpoint/openapi/OpenAPIGenSpec.scala +++ b/zio-http/jvm/src/test/scala/zio/http/endpoint/openapi/OpenAPIGenSpec.scala @@ -2460,21 +2460,15 @@ object OpenAPIGenSpec extends ZIOSpecDefault { SwaggerUI.routes("docs/openapi", OpenAPIGen.fromEndpoints(endpoint)) assertCompletes }, - // test("Ensure OpenAPI generation succeeds for Map[String, List[String]]") { - // val schema = Schema.map[String, List[String]] - // val openAPISchema = JsonSchema.fromZSchemaMulti(schema, SchemaStyle.Reference) - // assertTrue(openAPISchema != null) - // }, + test("Ensure OpenAPI generation succeeds for Map[String, List[String]]") { + val schema = Schema.map[String, List[String]] + val openAPISchema = JsonSchema.fromZSchemaMulti(schema, SchemaStyle.Reference) + assertTrue(openAPISchema != null) + }, test("Failing test case for Map[String, List[String]] schema generation") { val schema = Schema.map[String, List[String]] - val result = - try { - JsonSchema.fromZSchemaMulti(schema, SchemaStyle.Reference) - true - } catch { - case _: NoSuchElementException => false - } - assertTrue(result == false) + val result = scala.util.Try(JsonSchema.fromZSchemaMulti(schema, SchemaStyle.Reference)) + assertTrue(result.isFailure) }, test("Recursive schema") { val endpoint = Endpoint(RoutePattern.POST / "folder") 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, _) =>