smallrye-open-api icon indicating copy to clipboard operation
smallrye-open-api copied to clipboard

QueryParams merged when using kotlin suspend

Open judomu opened this issue 3 years ago • 0 comments

When using quarkus, smallrye-open-api and kotlin-suspend functions, the generated openapi file contains all @QueryParam definitions (from suspend functions) on every path level.

The issue disappears when removing allOpen { annotation("javax.ws.rs.Path") }.

Example

The following resource definition:

@Path("/hello")
class GreetingResource {

    @Path("foo")
    @GET
    @Produces(MediaType.TEXT_PLAIN)
    suspend fun foo(
        @QueryParam("foo") foo: String
    ) = "Hello from RESTEasy Reactive"

    @Path("bla")
    @POST
    @Produces(MediaType.TEXT_PLAIN)
    suspend fun bla(
        @QueryParam("bla") bla: String
    ) = "Hello from RESTEasy Reactive"

    @Path("foobla")
    @DELETE
    @Produces(MediaType.TEXT_PLAIN)
    suspend fun foobla(
        @QueryParam("foobla") bla: String
    ) = "Hello from RESTEasy Reactive"

    @Path("blafoo")
    @PATCH
    @Produces(MediaType.TEXT_PLAIN)
    fun blafoo(
        @QueryParam("blafoo") bla: String
    ) = "Hello from RESTEasy Reactive"
}

leads to

---
openapi: 3.0.3
info:
  title: rest-kotlin-quickstart API
  version: 1.0.0-SNAPSHOT
paths:
  /hello/bla:
    post:
      tags:
      - Greeting Resource
      parameters:
      - name: bla # correct!
        in: query
        schema:
          type: string
      responses:
        "200":
          description: OK
          content:
            text/plain:
              schema:
                type: string
    parameters:
    - name: bla # failure: query parameter from bla-function 
      in: query
      schema:
        type: string
    - name: foo # failure: query parameter from foo-function
      in: query
      schema:
        type: string
    - name: foobla # failure: query parameter from foobla-function
      in: query
      schema:
        type: string
# ...

I've created a minimal showcase repo at https://github.com/judomu/smallrye-open-api-issue-suspend-merging to see the issue in action.

Similar issues

https://github.com/smallrye/smallrye-open-api/issues/895 https://github.com/smallrye/smallrye-open-api/issues/893

judomu avatar Oct 20 '22 13:10 judomu