1

as I wrote in this issue: https://github.com/spring-cloud/spring-cloud-openfeign/issues/375 and in this SO question: Spring data Pageable does not work with feign client

I have some problems sending a Pageable object in a POST request containing a @requestbody element.

First I tried sending the Pageable embedded in my RequestBody since it was generated as example when using springdoc-openapi-webmvc-core.

Example:

@PostMapping("/search") public Page<HelloDto> searchHellos(@RequestBody HelloDto example, Pageable pageable)

{ "example": { "message": "string" }, "pageable": { "pageNumber": 0, "pageSize": 50, "offset": 10, "sort": { "sorted": false, }, "paged": true, } }

No I learned, that I can send it via Query parameter aswell and it will be parsed. The annotation that extracts the pageable into QueryParams is called org.springdoc.api.annotations.ParameterObject in SpringDoc.

@PostMapping("/search") public Page<HelloDto> searchHellos(@RequestBody HelloDto example, @ParameterObject Pageable pageable) { return helloCallerService.callHelloServiceClient(example, pageable); }

When I try to call a similar controller interface via feign like this client interface:

@PostMapping("/search") public Page<HelloDto> searchHellos(@RequestHeader("apiKey") String apiKey, @RequestBody HelloDto example, Pageable pageable);

The application won't start since the method "has too many body params". I tried to annotate Pageable with @RequestParam but it won't be recognized / parsed.

My question is:

Can we use a custom AnnotatedParameterProcessor for e.g. @ParameterObject that flats out the ParameterObject and encodes it into the url query parameters?

How would you do that? Or is the AnnotatedParameterProcessor the wrong way? Do I maybe need an expander or anything?

Manuel Waltschek
  • 515
  • 1
  • 6
  • 23
  • did you manage to get this working? I've seen your answer about using @SpringQueryMap but in my case I need to modify some of the pageable queryparams. Ex: sortField: DESC should become -sortField – Gvg Jul 29 '20 at 14:12
  • Sorry, I just felt lucky that it parsed my Pageable correctly (at least it seems like it). I don't know how you get more control over this. Maybe look for a solution using Expander, Param annotation and RequestLine like in this example: https://stackoverflow.com/questions/43868680/feign-client-does-not-resolve-query-parameter I'd also prefer a more generic solution which comes with confiuration options. Let me please know if you could resolve your issue. – Manuel Waltschek Jul 29 '20 at 14:16
  • Hmm, was looking into the custom AnnotatedParameterProcessor too but didn't have success yet. I'm also using the reactive-feign implementation and added a ticket there: https://github.com/Playtika/feign-reactive/issues/271 – Gvg Jul 29 '20 at 14:22
  • 1
    I've ended up with creating own object which extends from HashMap. It can be used as a normal @RequestParam then. I've added a constructor which accepts a Pageable and puts the correct information into the map – Gvg Jul 30 '20 at 09:01

1 Answers1

2

Your question is more related to feign usage than springdoc-openapi. Using using org.springframework.cloud.openfeign.SpringQueryMap, solves your problem.

brianbro
  • 4,141
  • 2
  • 24
  • 37