Skip to content

preserve order of @Parameters not working for spring-boot 2.2 #289

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

Closed
ny-currenxie opened this issue Dec 23, 2019 · 1 comment
Closed

preserve order of @Parameters not working for spring-boot 2.2 #289

ny-currenxie opened this issue Dec 23, 2019 · 1 comment
Labels
enhancement New feature or request

Comments

@ny-currenxie
Copy link

ny-currenxie commented Dec 23, 2019

The previous fix on #274 works nicely while testing with spring-boot 2.1.x but not working in spring-boot 2.2.

Likely due to the changed annotation handling (https://github.com/spring-projects/spring-framework/wiki/Upgrading-to-Spring-Framework-5.x#upgrading-to-version-52), the method AbstractRequestBuilder.getApiParameters can now only dig out @Parameter annotations in the third call to AnnotatedElementUtils.findAllMergedAnnotations(method, io.swagger.v3.oas.annotations.Parameter.class) even though they are wrapped in @Parameters.

Suggest all 4 Collectors.toMap in the method AbstractRequestBuilder.getApiParameters be changed to collect the results in LinkedHashMap

Sample code:

@Target({ElementType.METHOD, ElementType.ANNOTATION_TYPE})
@Retention(RetentionPolicy.RUNTIME)
@Parameters({
  @Parameter(
      in = ParameterIn.QUERY,
      description = "Page you want to retrieve (0..N)",
      name = "page",
      content = @Content(schema = @Schema(type = "integer", defaultValue = "0"))),
  @Parameter(
      in = ParameterIn.QUERY,
      description = "Number of records per page.",
      name = "size",
      content = @Content(schema = @Schema(type = "integer", defaultValue = "20"))),
  @Parameter(
      in = ParameterIn.QUERY,
      description =
          "Sorting criteria in the format: property(,asc|desc). "
              + "Default sort order is ascending. "
              + "Multiple sort criteria are supported.",
      name = "sort",
      content = @Content(array = @ArraySchema(schema = @Schema(type = "string")))),
  @Parameter(in = ParameterIn.QUERY, name = "pageable", hidden = true),
})
public @interface PageableParameter {}
@PageableParameter
public void someController(Pageable pageable){
   ...
}

Generated api-doc On spring-boot 2.2

 {"name": "size",...},
 {"name": "page",...},
 {"name": "sort",...}

Generated api-doc On spring-boot 2.1.x

 {"name": "page",...},
 {"name": "size",...},
 {"name": "sort",...}
@springdoc
Copy link
Collaborator

springdoc commented Dec 23, 2019

Hi @ny-currenxie,

Finally, able to reproduce the behaviour you describe.

@ny-currenxie ny-currenxie removed their assignment Dec 23, 2019
@springdoc springdoc removed their assignment Dec 29, 2019
@bnasslahsen bnasslahsen added the enhancement New feature or request label Jan 10, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants