Open Uniqen opened 4 years ago
This would be nice. Currently the client implementation is not flexible enough to allow custom encoding of arguments. So we would need an improvement in Micronaut Core first to implement this.
I've duplicated the Pageable (and DefaultPageable, Sort, DefaultSort) as a workaround until it is resolved. This still blocks sharing interface between Client and Controller but at least makes it easy to use in tests and api gateway.
@Controller("/pets")
class PetGatewayController {
@Get("/{?pageable*}")
List<NameDTO> all(Pageable pageable) {
return petClient.all(PageableQuery.from(pageable));
}
}
@Client("/pets")
public interface PetClient {
@Get("/{?pageable*}")
List<NameDTO> all(PageableQuery pageable);
}
//Usage in tests is the same as Pageable
PageableQuery pageable = PageableQuery.from(1, 1)
.order("name", DESC);
List<NameDTO> results = petClient.all(pageable);
If anyone else is interested in the workaround see commit: https://github.com/Uniqen/micronaut-predator/commit/37147347b4e1c6d59d2816e658c3ba9d6ed623d0
Another option is to pass to the @Client the values of the Pageable like this:
@QueryValue("size") int size,
@QueryValue("number") int number
And the @Controller can still declare the
@QueryValue("pageable") Pageable page
Any updates on this? Would be terrific to be able to share interface between controllers and clients.
In Micronaut 4 we added support for custom message writers so maybe it is possible now
Bumping this - any updates for Pageable
parameters within @Controller
methods?
It would be very usable if Pageable was converted to the correct query parameters when used with the declarative http client. For example for an API-gateway that should just forward the request or when writing tests. This would also make it possible to share a common interface between Controller and Client.
The problem as I see it is to make it a non breaking change or is there a way to configure how the query parameters is resolved that I don't know about?
Steps to Reproduce
Expected Behaviour
The pageable should be sent using the query parameters page, size and sort:
GET /parent/?size=1&sort=name%2CDESC&page=1
Actual Behaviour
The query string is invalid (both page (sent as number) and sort) plus som additional irrelevant parameters.
GET /pets/?sort=io.micronaut.data.model.DefaultSort%40f331e9d7&sorted=true&number=1&orderBy=io.micronaut.data.model.Sort%24Order%40f331e999&offset=1&size=1
And then an exception is raised on the server side since the sorting is invalid:
Environment Information
Example Application