From f73633f1801f628fa04524be2ae60e09a9ad5497 Mon Sep 17 00:00:00 2001 From: Gilad Hoch Date: Tue, 6 Aug 2024 23:47:12 +0300 Subject: [PATCH] test for #2652 (issue already fixed in #2935) (#3004) --- .../endpoint/openapi/OpenAPIGenSpec.scala | 79 +++++++++++++++++++ 1 file changed, 79 insertions(+) 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 fc7d3d82a1..ddfd2500d8 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 @@ -138,6 +138,15 @@ object OpenAPIGenSpec extends ZIOSpecDefault { implicit val schema: Schema[Payload] = DeriveSchema.gen[Payload] } + object Lazy { + case class A(b: B) + + object A { + implicit val schema: Schema[A] = DeriveSchema.gen + } + case class B(i: Int) + } + private val simpleEndpoint = Endpoint( (GET / "static" / int("id") / uuid("uuid") ?? Doc.p("user id") / string("name")) ?? Doc.p("get path"), @@ -2551,6 +2560,76 @@ object OpenAPIGenSpec extends ZIOSpecDefault { |""".stripMargin assertTrue(json == toJsonAst(expectedJson)) }, + test("Lazy schema") { + val endpoint = Endpoint(RoutePattern.POST / "lazy") + .in[Lazy.A] + .out[Unit] + val openApi = OpenAPIGen.fromEndpoints(endpoint) + val json = toJsonAst(openApi) + val expectedJson = """{ + | "openapi" : "3.1.0", + | "info": { + | "title": "", + | "version": "" + | }, + | "paths" : { + | "/lazy" : { + | "post" : { + | "requestBody" : { + | "content" : { + | "application/json" : { + | "schema" : { + | "$ref" : "#/components/schemas/A" + | } + | } + | }, + | "required" : true + | }, + | "responses" : { + | "200" : { + | "content" : { + | "application/json" : { + | "schema": { + | "type" : "null" + | } + | } + | } + | } + | } + | } + | } + | }, + | "components" : { + | "schemas" : { + | "A" : { + | "type" : "object", + | "properties" : { + | "b" : { + | "$ref" : "#/components/schemas/B" + | } + | }, + | "required" : [ + | "b" + | ] + | }, + | "B" : { + | "type" : "object", + | "properties" : { + | "i" : { + | "type" : "integer", + | "format" : "int32" + | } + | }, + | "required" : [ + | "i" + | ] + | } + | } + | } + |}""".stripMargin + val expected = toJsonAst(expectedJson) + assertTrue(json == expected) + }, ) }