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

@Parameter annotation not working in method level #416

Closed hyunrealshadow closed 3 years ago

hyunrealshadow 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.

We have a custom paging object for DynamoDB, and we write a converter for it. I hope to generate the swagger document correctly.

Task List

Steps to Reproduce

  1. Define an annotation interface
    @Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
    @Retention(RetentionPolicy.RUNTIME)
    @Parameter(name = "page", in = ParameterIn.QUERY)
    @Parameter(name = "pageSize", in = ParameterIn.QUERY)
    public @interface PageParam {
    }
  2. Define a simple controller method
    @Get("/test")
    @PageParam
    public String test(@Parameter(hidden = true) Page page) {
        return "test";
    }
  3. Compiling with maven

Expected Behaviour

The swagger definition is generated correctly, like this

  /test:
    get:
      operationId: test
      parameters:
      - name: page
        in: query
        required: true
        schema:
          type: integer
          format: int32
      - name: pageSize
        in: query
        required: true
        schema:
          type: integer
          format: int32
      responses:
        default:
          description: test default response
          content:
            application/json:
              schema:
                type: string

Actual Behaviour

It's generated something like this

/test:
    get:
      operationId: test
      parameters: []
      responses:
        default:
          description: test default response
          content:
            application/json:
              schema:
                type: string

Environment Information

Example Application

preyest1300 commented 3 years ago

Hey @hyunrealshadow ! I have been trying to solve this issue, but i need to know the Page class definiton in order to be able to reproduce the bug.

hyunrealshadow commented 3 years ago

@preyest1300 Sorry, I didn't reply in time It's like this

public class Page {
    private String page;
    private String pageSize;

    public String getPage() {
        return page;
    }

    public void setPage(String page) {
        this.page = page;
    }

    public String getPageSize() {
        return pageSize;
    }

    public void setPageSize(String pageSize) {
        this.pageSize = pageSize;
    }
}
nathanwang-ops commented 3 years ago

@preyest1300 I have same issue, I am trying to add @Parameter annotation at method level, the output of Parameters[] is empty. Thanks!