我试图弄清楚如何指示SpringDoc
OpenApi
正在生成一个自定义对象,使用HandlerMethodArgumentResolver
它拦截一些传入的请求参数并从中创建一个对象。这个概念实际上与 Spring 对@Pageable
.
这是我的自定义对象的一部分:
class FlightRequestHandlerMethodArgumentResolver implements HandlerMethodArgumentResolver {
FlightRequestHandlerMethodArgumentResolver() {
}
@Override
boolean supportsParameter(final MethodParameter parameter) {
return FlightRequest.class.equals(parameter.getParameterType());
}
@Override
Object resolveArgument(
final MethodParameter parameter,
final ModelAndViewContainer mavContainer,
final NativeWebRequest webRequest, final WebDataBinderFactory binderFactory) throws Exception {
final Map<String, String[]> parameterMap = webRequest.getParameterMap()
// query param names are configurable
// implementation about finding query param names is ommited
return new FlightRequest(parameterMap)
}
FlightRequest
班级:
public class FlightRequest {
@Parameter(name = "startDate")
private final LocalDate startDate;
@Parameter(name = "endDate")
private final LocalDate endDate;
FlightRequest (LocalDate startDate, LocalDate endDate) {
this.submissionStartDate = submissionStartDate;
this.submissionEndDate = submissionEndDate;
}
FlightRequest
使用默认查询参数名称的控制器:
@RequestMapping(value = "/flights", method = RequestMethod.GET)
Flights flights(FlightRequest flightRequest, HttpServletResponse response) {
return flightSearchService.retrieveFlights(flightRequest);
}
FlightRequest
与自定义查询参数名称一起使用的控制器:
@RequestMapping(value = "/current-flights", method = RequestMethod.GET)
Flights flights(@FlightRequestParams(fromDateParamName="current-flights-from", toDateParamName="current-flights-till) FlightRequest flightRequest, HttpServletResponse response) {
return flightSearchService.retrieveFlights(flightRequest);
}
就像您在上面的示例中看到的那样,每个端点都可以覆盖默认查询参数名称。
我怎样才能表明这一点Spring Doc
?