-
Notifications
You must be signed in to change notification settings - Fork 371
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
OpenAPI Generator missing endpoints #2541
Labels
bug
Something isn't working
Comments
I narrowed it down to the following line:
Where the two Endpoint s share the same path, and since the paths is of type Map[OpenAPI.Path, OpenAPI.PathItem] only one PathItem survives the concatenation of the two.
So no matter how many methods one has for a given path, only one will make it out to the OpenAPI AST. |
Rather than the example application I posted above, it might be easier to start with the following failing test: diff --git a/zio-http/src/test/scala/zio/http/endpoint/openapi/OpenAPIGenSpec.scala b/zio-http/src/test/scala/zio/http/endpoint/openapi/OpenAPIGenSpec.scala
index 7c0b25db..919f9089 100644
--- a/zio-http/src/test/scala/zio/http/endpoint/openapi/OpenAPIGenSpec.scala
+++ b/zio-http/src/test/scala/zio/http/endpoint/openapi/OpenAPIGenSpec.scala
@@ -9,7 +9,7 @@ import zio.schema.annotation.{caseName, discriminatorName, noDiscriminator, opti
import zio.schema.codec.JsonCodec
import zio.schema.{DeriveSchema, Schema}
-import zio.http.Method.GET
+import zio.http.Method.{GET, POST}
import zio.http._
import zio.http.codec.{Doc, HttpCodec, QueryCodec}
import zio.http.endpoint._
@@ -2228,6 +2228,80 @@ object OpenAPIGenSpec extends ZIOSpecDefault {
|}""".stripMargin
assertTrue(json == toJsonAst(expectedJson))
},
+ test("multiple endpoints to same path") {
+ val getEndpoint = Endpoint(GET / "test")
+ .out[String](MediaType.text.`plain`)
+ val postEndpoint = Endpoint(POST / "test")
+ .in[String]
+ .out[String](Status.Created, MediaType.text.`plain`)
+ val generated = OpenAPIGen.fromEndpoints("Multiple Endpoints - Same Path", "1.0", getEndpoint, postEndpoint)
+ val json = toJsonAst(generated)
+ val expectedJson =
+ """{
+ | "openapi": "3.1.0",
+ | "info": {
+ | "title": "Multiple Endpoints - Same Path",
+ | "version": "1.0"
+ | },
+ | "paths": {
+ | "/test": {
+ | "get": {
+ | "requestBody": {
+ | "content": {
+ | "application/json": {
+ | "schema": {
+ | "type": "null"
+ | }
+ | }
+ | },
+ | "required": false
+ | },
+ | "responses": {
+ | "200": {
+ | "description": "",
+ | "content": {
+ | "text/plain": {
+ | "schema": {
+ | "type": "string"
+ | }
+ | }
+ | }
+ | }
+ | },
+ | "deprecated": false
+ | },
+ | "post": {
+ | "requestBody": {
+ | "content": {
+ | "application/json": {
+ | "schema": {
+ | "type": "string"
+ | }
+ | }
+ | },
+ | "required": true
+ | },
+ | "responses": {
+ | "201": {
+ | "description": "",
+ | "content": {
+ | "text/plain": {
+ | "schema": {
+ | "type": "string"
+ | }
+ | }
+ | }
+ | }
+ | },
+ | "deprecated": false
+ | }
+ | }
+ | },
+ | "components": {}
+ |}
+ |""".stripMargin
+ assertTrue(json == toJsonAst(expectedJson))
+ },
)
} |
daharon
added a commit
to daharon/zio-http
that referenced
this issue
Dec 4, 2023
…le methods for the same path.
daharon
added a commit
to daharon/zio-http
that referenced
this issue
Dec 5, 2023
…le methods for the same path.
daharon
added a commit
to daharon/zio-http
that referenced
this issue
Dec 5, 2023
…le methods for the same path.
daharon
added a commit
to daharon/zio-http
that referenced
this issue
Dec 5, 2023
…le methods for the same path.
daharon
added a commit
to daharon/zio-http
that referenced
this issue
Dec 5, 2023
…le methods for the same path.
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
I'm testing the new
OpenAPIGen
functionality, and I'm getting output that doesn't match my expectations.I have two endpoints, one
GET
and onePOST
to the path/books
.The
POST
request is the only one that shows up in the generated OpenAPI document.If I remove the
POST
endpoint, then I do see theGET
endpoint in the generated OpenAPI document.To Reproduce
Here is an example:
And here is the resulting OpenAPI document:
As can be seen, the
GET /books
endpoint is missing.The text was updated successfully, but these errors were encountered: