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
Set request parameter templates with [] inside do not pass Expressions matching check #928
Comments
Thanks for bringing this to our attention. Looking over RFC 6570 again, it looks like brackets This is also similar to #922 and #924, where certain Contract implementations are generating template expressions that are not compliant. My first thoughts were to pct-encode them to make them compliant, but I need more time to vet that out. I'm open to any other suggestions you may have. |
@kdavisk6 Thanks for the quick reply. I understand the principle to comply with the RFC. However, the issue is that our users might currently be consuming APIs containing endpoints where the set parameters should be passed and query params such as ("ids[]") are expected. As we are providing tools for the clients and the issue is on the server side, it's difficult to request our users to fix it according to the RFC, as it might well not be their app that needs the changes. Wdyt? If there's anything we could do or change in our Contract implementation in order to make fixing it easier, please let me know. |
I completely agree that we should do what we can to support our users and I don't want to force these concerns into other areas that are not directly in Feign's space. With regards to pct-encoding, For this particular issue, I think we may be able to solve it by allowing users to specify which @RequestLine("/path", collectionFormat=CollectionFormat.CSV)
public Response request(@Param("collection") Set<String> collection); Result:
An updated version could look like this: /* feign core */
@RequestLine("/path")
public Response request(@Param("collection", collectionFormat=CollectionFormat.SET) Set<String> collection);
/* jaxrs / Spring with Collection autodetection in the Contract */
@Path("/path")
public Response request(@QueryParam Set<String> collection); Result:
Would something like this work? Assuming we can update |
@kdavisk6 yes, sounds good to me. If that would produce the following result |
Would it be ok if the brackets were pct-encoded as |
@kdavisk6 Yes, that'll probably be the best solution. |
Fixes OpenFeign#928 Relaxed the regular expression that is used to determine if a given value is an Expression per the URI Template Spec RFC 6570. We already deviated by allowing dashes to exist without pct-encoding, this change adds braces `[]` to this list.
Fixes OpenFeign#928 Relaxed the regular expression that is used to determine if a given value is an Expression per the URI Template Spec RFC 6570. We already deviated by allowing dashes to exist without pct-encoding, this change adds braces `[]` to this list. Also included is the ability to set Collection Format per Query, overriding the Template default. This allows for mixed Collection formats in the same template and provides a way for Contract extensions to determine which expansion type they want when parsing a contract.
#939 is ready for your review. Let me know if this meets your needs. |
Thanks a lot, @kdavisk6 Sorry for not getting back to you earlier - I was traveling; will take a look at it soon. |
Hello @kdavisk6 have verified that. Looks good. Thanks :). When do you think a version containing this change could be released? |
* Updated Expression Patterns to allow brackets Fixes #928 Relaxed the regular expression that is used to determine if a given value is an Expression per the URI Template Spec RFC 6570. We already deviated by allowing dashes to exist without pct-encoding, this change adds braces `[]` to this list. Also included is the ability to set Collection Format per Query, overriding the Template default. This allows for mixed Collection formats in the same template and provides a way for Contract extensions to determine which expansion type they want when parsing a contract. * Fixing Formatting
I'll check with the others, but I think we can release a patched 10.2.1 sometime in the next week. |
Hello, I have the feign client endpoint declaration:
I have a test which fails with the below message (I have paraphrased):
What's the least I can do to make my test pass, while still using feign? Many thanks, Rob |
When adding a
Set
query param template using thefeign.RequestTemplate#query(java.lang.String, java.lang.Iterable<java.lang.String>)
method, we pass a query with a name containing[]
and a corresponding template value, for examplename = "ids[]"
and then aList
containing{ids[]}
value. This causes an issue as a template containing[]
does not pass theentry -> entry.getKey().matcher(expression).matches()
filter infeign.template.Expressions#create
method against theSimpleExpression
pattern, created as follows:Pattern.compile("(\\w[-\\w.]*[ ]*)(:(.+))?"), SimpleExpression.class;
As an http call to
[requestUrl]?ids[]=1,2,3
would work, it should probably work via Feign as well.This issue causes the following issue in Spring Cloud OpenFeign: spring-cloud/spring-cloud-openfeign#143 that has been reported to us by the users.
The text was updated successfully, but these errors were encountered: