Spring @ModelAttribute parameters don't respect parametrized types
DoctorAlpaca opened this issue · 0 comments
DoctorAlpaca commented
Extending the GreetingController in the sample-maven-spring project with the following endpoint
public static class GreetingsParams {
private List<String> names;
public void setNames(List<String> names) {
this.names = names;
}
}
@RequestMapping("/greetings")
public List<Greeting> greetings(@ModelAttribute GreetingsParams params) {
return params.names.stream().map(name -> greeting(name)).collect(Collectors.toList());
}
generates this typescript definition greetings(queryParams?: { names?: any[]; }, options?: O): RestResponse<Greeting[]> [...]
which sadly just contains the type any[]
instead of string[]
.
After looking at the responsible code (SpringApplicationParser.java:330), it appears that the unparametrized type from the bean PropertyDescriptor is used. It might be possible to instead get a parametrized type from the writeMethod (that is being fetched anyways) instead. If this seems like a good solution I can gladly open a pull request.