micronaut-projects / micronaut-openapi

Generates OpenAPI / Swagger Documentation for Micronaut projects
https://micronaut-projects.github.io/micronaut-openapi/latest/guide/index.html
Apache License 2.0
80 stars 94 forks source link

Micronaut 2.2.0 adds requestBody as a required parameters to Put/Post requests #402

Closed andyndang closed 3 years ago

andyndang commented 3 years ago

Thanks for reporting an issue, please review the task list below before submitting the issue. Your issue report will be closed if the issue is incomplete and the below tasks not completed.

NOTE: If you are unsure about something and the issue is more of a question a better place to ask questions is on Stack Overflow (https://stackoverflow.com/tags/micronaut) or Gitter (https://gitter.im/micronautfw/). DO NOT use the issue tracker to ask questions.

Task List

Steps to Reproduce

  1. Create a Post API with a single parameter and without any request body

    @Post(
            uri = "/upload/{id}",
            produces = [MediaType.APPLICATION_JSON]
    )
    fun upload(
            id: String,
    
    ) {
        print("Do nothing")
    }
  2. Generate the OpenAPI YAML

Expected Behaviour

API should look like this:

  /v1/repro/upload/{id}:
    post:
      tags:
        - 'ReproController '
      summary: summary
      description: desc
      operationId: id2
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string

Actual Behaviour

requestBody is added

  /v1/repro/upload/{id}:
    post:
      tags:
        - 'ReproController '
      summary: summary
      description: desc
      operationId: id2
      parameters:
        - name: id
          in: path
          required: true
          schema:
            type: string
      requestBody:
        content:
          application/json:
            schema:
              type: object
        required: true

Environment Information

Example Application

https://github.com/andyndang/micronaut-swagger-yml-bug/tree/89b20c9451f333e8fb17678cff0ca6ac063a415f

2.1.0 YAML: https://github.com/andyndang/micronaut-swagger-yml-bug/blob/89b20c9451f333e8fb17678cff0ca6ac063a415f/schema_2.1.0.yml

2.2.0 YAML: https://github.com/andyndang/micronaut-swagger-yml-bug/blob/89b20c9451f333e8fb17678cff0ca6ac063a415f/schema_2.2.0.yml

ivanmartinvalle commented 3 years ago

As a workaround, I was able to redundantly add a path parameter annotation to remove the extra body parameter.

@Post("/nouns/{noun_id}/link")
// Parameter is redundant, but cannot remove until the below bug is fixed
// https://github.com/micronaut-projects/micronaut-openapi/issues/402
fun linkNoun(@Parameter(`in` = ParameterIn.PATH) @PathVariable("noun_id") nounId: String): HttpResponse<Unit> {
  return HttpResponse.ok()
}