-
-
Notifications
You must be signed in to change notification settings - Fork 32
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Allow LinkVariables to support multiple values with the same key #421
Comments
Thanks for the nice words! Ah interesting. What would the URI Template look like for these? |
This is an example from my "clients" link. Page,size,projection are single values, whereas sort can be a collection/multiple. Spring documents it here: https://docs.spring.io/spring-data/rest/docs/current/reference/html/#repository-resources.collection-resource.supported-methods.get : "A collection of sort directives in the format ($propertyname,)+[asc|desc]?." |
I wonder if we could just type LinkVariables as: /**
* A key->value map of variables to place in a templated link
*/
export type LinkVariables = {
[key: string]: string | number | (string|number)[]
}; |
Ok, interesting rabbit hole, just delved into the URI template RFC. I think your suggested change is needed and will work. The issue is that Spring data expects multivalues for sort to be "expanded" by duplicating the key for each entry. (see https://docs.spring.io/spring-data/jpa/docs/current/reference/html/#core.web.basic, Table 1). If i use the template provided by Spring, i get the following: const templ = uriTemplate.parse("http://localhost:8080/api/clients{?page,size,sort,projection}");
const expanded = templ.expand({sort : ["id,asc", "lastModifiedDate,desc"]});
// http://localhost:8080/api/clients?sort=id%2Casc,lastModifiedDate%2Cdesc Spring doesn't parse this properly and the sort direction for the params isn't handled properly (they both end up with a sort direction of "DESC"). If i modify the template to include the expansion modifier (*) for sort in the URI template, i get what Spring expects: const templ = uriTemplate.parse("http://localhost:8080/api/clients{?page,size,sort*,projection}");
const expanded = templ.expand({sort : ["id,asc", "lastModifiedDate,desc"]});
// http://localhost:8080/api/clients?sort=id%2Casc&sort=lastModifiedDate%2Cdesc This works great and Spring is happy, all is good with the world. So given your suggested change, and the proper template i should be able to generate the URL Spring expects. I still need to follow up to see why Spring isn't providing the expansion modifier on the sort variable which i think it should be, but for this issue if your change is made that should do it. |
For reference, anyone else dealing with this issue when using your spectacularly amazing stupendous library and the lack of an explosion modifier for the sort parameter generated by Spring, i've opened an issue here: |
Yes, it works ! |
Hi Evert, i don't see this commit in any releases, it's not in 7.5.1. Did it get overlooked ? |
Really enjoying building a client side data access layer using Ketting, thank you for making it !
Have an issue at the moment supporting sort using multiple fields. My backend is a Spring Data Rest, and the method for sorting by multiple fields is to repeat the "sort" parameter for each field (e.g. ?sort=name,asc&sort=created,desc).
I'm using the LinkVariables param on the follow() method in Resource, but it is defined as a map and doesn't permit duplicate keys.
Since there doesn't look to be anything in the RFC for query params that disallows multiple values, i'm thinking LinkVariables should be redefined to support this.
Looking at the API, I don't see any workarounds that would allow me to make this happen... unless you have any suggestions ?
The text was updated successfully, but these errors were encountered: