micronaut-projects / micronaut-projects/micronaut-data
Invalid query parameters when using Pageable as argument to declarative http client
- Dominant language
- Java
- Stars
- 482
- Forks
- 229
- Avg merge
- 1d 7h
- Merged PRs (30d)
- 32
Description
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
1. Create Controller with Pageable as argument
```java
@Controller("/pets")
class PetController {
@Get("/{?pageable*}") // No really needed but for symmetrical
List all(Pageable pageable) {
return petRepository.list(pageable);
}
}
```
2. Create corresponding declarative http client
```java
@Client("/pets")
public interface PetClient {
@Get("/{?pageable*}")
List all(Pageable pageable);
}
```
3. Use client to invoke controller.
```java
List results = petClient.all(Pageable.from(1,1).order("name", DESC));
```
### 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:
```java
21:23:05.541 [pool-2-thread-2] ERROR i.m.h.s.netty.RoutingInBoundHandler - Unexpected error occurred: Cannot sort on non-existent property path: io.micronaut.data.model.DefaultSort@f331e9d7
java.lang.IllegalArgumentException: Cannot sort on non-existent property path: io.micronaut.data.model.DefaultSort@f331e9d7
at io.micronaut.data.model.query.builder.AbstractSqlLikeQueryBuilder.lambda$buildOrderBy$35(AbstractSqlLikeQueryBuilder.java:1310)
at java.util.Optional.orElseThrow(Optional.java:290)
at io.micronaut.data.model.query.builder.AbstractSqlLikeQueryBuilder.buildOrderBy(AbstractSqlLikeQueryBuilder.java:1310)
at io.micronaut.data.hibernate.operations.HibernateJpaOperations.lambda$findAll$6(HibernateJpaOperations.java:252)
at io.micronaut.transaction.support.AbstractSynchronousTransactionManager.executeRead(AbstractSynchronousTransactionManager.java:157)
at io.micronaut.data.hibernate.operations.HibernateJpaOperations.findAll(HibernateJpaOperations.java:245)
at io.micronaut.data.runtime.intercept.DefaultFindAllInterceptor.intercept(DefaultFindAllInterceptor.java:52)
at io.micronaut.data.runtime.intercept.DefaultFindAllInterceptor.intercept(DefaultFindAllInterceptor.java:36)
at io.micronaut.data.intercept.DataIntroductionAdvice.intercept(DataIntroductionAdvice.java:78)
at io.micronaut.aop.chain.MethodInterceptorChain.proceed(MethodInterceptorChain.java:69)
at example.repositories.PetRepository$Intercepted.list(Unknown Source)
at example.controllers.PetController.all(PetController.java:24)
...
```
### Environment Information
- **Operating System**: Mac OS 10.14.3
- **Micronaut Version:** 1.2.3
- **Micronaut Data Version:** 1.0.0.M3
- **JDK Version:** 8.0.222
### Example Application
- See https://github.com/Uniqen/micronaut-predator/tree/pageable_as_query_parameter
- Or just the relevant commit https://github.com/Uniqen/micronaut-predator/commit/619bcf54d4061cf4b4658cc96da297f3c8670a1f
Contributor guide
Research direction
Start with the PetClient and PetController examples in the issue, then reproduce the request using the linked micronaut-predator example application. Trace how Pageable arguments become declarative client query parameters; done means the client sends only page, size, and sort in the expected format without breaking existing parameter handling.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- java
- Domain
- api, backend
- Issue type
- Feature
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 52/100