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

OpenAPI - schema annotation in ApiResponse is not used #14

Closed croudet closed 5 years ago

croudet commented 5 years ago

Thanks for reporting an issue for Micronaut, 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 (http://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. Follow up of https://github.com/micronaut-projects/micronaut-core/issues/1181

Expected Behaviour

In a Controller, when you have ApiResponses with Schema annotations, the generated yaml does not use the schema.

    @Override
    @Operation(description = "Returns A dummy", summary = "Returns a Dummy")
    @ApiResponse(responseCode = "200", description = "Returns a dummy", content = @Content(schema = @Schema(implementation = Dummy.class)))
    @ApiResponse(responseCode = "500", description = "Internal Error")
    public Dummy dummyAnnot() {
        return new Dummy();
    }
  /hello/dummyAnnot:
    get:
      summary: Returns a Dummy
      description: Returns A dummy
      operationId: dummyAnnot
      parameters: []
      responses:
        200:
          description: Returns a dummy
          content: 
            application/json:
              schema:
                type: array
                items:
                  $ref: '#/components/schemas/Dummy'
        500:
          description: Internal Error

The content should point to Dummy

Actual Behaviour

  /hello/dummyAnnot:
    get:
      summary: Returns a Dummy
      description: Returns A dummy
      operationId: dummyAnnot
      parameters: []
      responses:
        200:
          description: Returns a dummy
          content: {}
        500:
          description: Internal Error

The content part is empty.

Environment Information

Example Application

See HelloOperations and HelloController in:

puneetbehl commented 5 years ago

@croudet Can you please try with setting mediaType to @Content? For example:

@ApiResponse(responseCode = "200", description = "Returns a dummy", content = @Content(
mediaType = "application/json",
schema = @Schema(implementation = Dummy.class)))
croudet commented 5 years ago

@puneetbehl That did the trick, thanks. But the RequestBody annotation works out of the box without the mediaType attribute.

jacqui932 commented 5 years ago

I have this problem with a Groovy controller. When I add the mediaType as suggested, I am getting this error:

Error reading Swagger Operation for element [io.micronaut.ast.groovy.visitor.GroovyMethodElement@a27e3e0]: Cannot construct instance of io.swagger.v3.oas.models.media.MediaType (although at least one Creator exists): no String-argument constructor/factory method to deserialize from String value ('application/json') at [Source: UNKNOWN; line: -1, column: -1] (through reference chain: io.swagger.v3.oas.models.responses.ApiResponse["content"]->io.swagger.v3.oas.models.media.Content["mediaType"]) (through reference chain: io.swagger.v3.oas.models.Operation["responses"])

And the endpoint does not exist at all in the generated YAML.