1

我正在使用 Spring Boot (v2.1.3 RELEASE) 和 SpringDoc。我已经浏览过https://springdoc.org/springdoc-properties.htmlhttps://springdoc.org/,但看起来 SpringDoc 会自动按字母顺序对参数进行排序。我们怎样才能防止这种情况发生?

@Operation(summary = "Find Students")
@Parameter(in=ParameterIn.QUERY, name="page", description="Results page you want to retrieve (0..N)", schema=@Schema(defaultValue = 0))
@Parameter(in=ParameterIn.QUERY, name="size", description="Number of records per page.", schema=@Schema(defaultValue =50))
@Parameter(in=ParameterIn.QUERY, name="search_type", description=AppConstants.SEARCH_TYPE, schema=@Schema(allowableValues= {"Starts", "Contains"},defaultValue = "Starts"))
@ApiCountryHeader
@GetMapping(value = "/students")
public ResponseEntity<List<Students>> findStudentss(
        @Parameter(description  = "") @RequestParam(required = false) String studentCd,
        @Parameter(description  = "") @RequestParam(required = false) String studentName,
        @Parameter(hidden=true) String search_type){

    ....
    ....
    ...
    return new ResponseEntity<>(studentts, HttpStatus.OK);
}
4

1 回答 1

0

字段不按字母顺序排序,但保留声明的顺序。

您可以使用不同的可用定制器更改字段顺序:

  • OpenApiCustomiser:自定义 OpenAPI 对象
  • OperationCustomizer:根据HandlerMethod自定义操作

例如:

@RestController
public class HelloController {

    @GetMapping(value = "/persons")
    public String getPerson(String b, String a) {
        return null;
    }

    @Bean
    OperationCustomizer operationCustomizer() {
        return (Operation operation, HandlerMethod handlerMethod) -> {
            if ("getPerson".equals(handlerMethod.getMethod().getName())) {
                List<Parameter> parameterList = operation.getParameters();
                if (!CollectionUtils.isEmpty(parameterList))
                    Collections.reverse(parameterList);
            }
            return operation;
        };
    }

}
于 2020-06-09T12:49:27.497 回答