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 73ceede3a0..4851af366d 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 @@ -250,6 +250,28 @@ object OpenAPIGenSpec extends ZIOSpecDefault { |}""".stripMargin assertTrue(json == toJsonAst(expectedJson)) }, + test("endpoint documentation") { + val genericEndpoint = Endpoint(GET / "users") ?? Doc.p("Get all users") + val generated = OpenAPIGen.fromEndpoints("Generic Endpoint", "1.0", genericEndpoint) + val json = toJsonAst(generated) + val expectedJson = """{ + | "openapi" : "3.1.0", + | "info" : { + | "title" : "Generic Endpoint", + | "version" : "1.0" + | }, + | "paths" : { + | "/users" : { + | "description" : "Get all users\n\n", + | "get" : { + | "description" : "Get all users\n\n" + | } + | } + | }, + | "components" : {} + |}""".stripMargin + assertTrue(json == toJsonAst(expectedJson)) + }, test("simple endpoint to OpenAPI") { val generated = OpenAPIGen.fromEndpoints( "Simple Endpoint", @@ -271,7 +293,7 @@ object OpenAPIGenSpec extends ZIOSpecDefault { | "simple", | "endpoint" | ], - | "description" : "get path\n\n", + | "description" : "some extra doc\n\nget path\n\n- simple\n- endpoint\n", | "parameters" : [ | { | "name" : "id", diff --git a/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/OpenAPIGen.scala b/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/OpenAPIGen.scala index 64ba057807..19727820ae 100644 --- a/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/OpenAPIGen.scala +++ b/zio-http/shared/src/main/scala/zio/http/endpoint/openapi/OpenAPIGen.scala @@ -538,7 +538,8 @@ object OpenAPIGen { val path = buildPath(endpoint.input) val method0 = method(inAtoms.method) // Endpoint has only one doc. But open api has a summery and a description - val pathItem = OpenAPI.PathItem.empty.copy(description = Some(endpoint.documentation).filter(!_.isEmpty)) + val pathItem = OpenAPI.PathItem.empty + .copy(description = Some(endpoint.documentation + endpoint.input.doc.getOrElse(Doc.empty)).filter(!_.isEmpty)) val pathItemWithOp = method0 match { case Method.OPTIONS => pathItem.addOptions(operation(endpoint)) case Method.GET => pathItem.addGet(operation(endpoint)) @@ -580,7 +581,7 @@ object OpenAPIGen { } def operation(endpoint: Endpoint[_, _, _, _, _]): OpenAPI.Operation = { - val maybeDoc = Some(pathDoc).filter(!_.isEmpty) + val maybeDoc = Some(endpoint.documentation + pathDoc).filter(!_.isEmpty) OpenAPI.Operation( tags = endpoint.tags, summary = None,