SpringMvcContract support parse params#1016
Conversation
|
@Puppy4C Please sign the Contributor License Agreement! Click here to manually synchronize the status of this Pull Request. See the FAQ for frequently asked questions. |
|
@Puppy4C Thank you for signing the Contributor License Agreement! |
OlgaMaciaszek
left a comment
There was a problem hiding this comment.
Thanks for the PR, @Puppy4C. Have added some comments - please take a look.
| } | ||
| } | ||
|
|
||
| private void parseParams(MethodMetadata data, Method method, RequestMapping methodMapping) { |
There was a problem hiding this comment.
Please add documentation for this feature in spring-cloud-openfeign.adoc.
| NameValueResolver(String expression) { | ||
| int separator = expression.indexOf('='); | ||
| if (separator == -1) { | ||
| this.isNegated = expression.startsWith("!"); |
There was a problem hiding this comment.
Please remove unnecessary this. keywords.
| } | ||
|
|
||
| @Test | ||
| void testProcessAnnotations_ParseParams_SingleParam() throws Exception { |
There was a problem hiding this comment.
Please add a tests to verify behaviour when both params= and @RequestParam annotation present.
| } | ||
| for (String param : params) { | ||
| NameValueResolver nameValueResolver = new NameValueResolver(param); | ||
| if (!nameValueResolver.isNegated()) { |
There was a problem hiding this comment.
I know it was handled for headers, but it actually does not make much sense to have negated values on client side; I think we should not handle them at all (i.e. throw an exception), because adding them on client side indicates the client-side API has not been thought through.
There was a problem hiding this comment.
I think it's good. Fixed
There was a problem hiding this comment.
I know it was handled for headers, but it actually does not make much sense to have negated values on client side; I think we should not handle them at all (i.e. throw an exception), because adding them on client side indicates the client-side API has not been thought through.
Hi @OlgaMaciaszek ,
Is it possible to change the access modifier of the parseParams method (and other parse* methods) in this Contract from private to protected? This would allow for greater accessibility and potential subclassing, enabling us to enrich the Contract.
Note: We use generated APIs from the same OpenAPI specifications for intercommunication between our Spring-based applications, which use the same interfaces for both the Feign client and REST controller.
Thank you!
ca111e1 to
c26d64e
Compare
OlgaMaciaszek
left a comment
There was a problem hiding this comment.
Thanks @Puppy4C. The implementation looks good, but the documentation should be slightly more robust. I have added a comment. Please address.
| Page<Store> getStores(Pageable pageable); | ||
|
|
||
| @PostMapping(value = "/stores/{storeId}", consumes = "application/json") | ||
| @PostMapping(value = "/stores/{storeId}", consumes = "application/json", params = "mode=upsert") |
There was a problem hiding this comment.
Please add a description of the feature, including information on what syntax is allowed and to what resulting query params it will be resolved.
OlgaMaciaszek
left a comment
There was a problem hiding this comment.
Thanks @Puppy4C. LGTM.
|
@Buzzardo could you please review the documentation changes? |
| [[spring-requestmapping-support]] | ||
| === Spring @RequestMapping Support | ||
|
|
||
| Spring Cloud OpenFeign provides support for the Spring `@RequestMapping` annotation and its derived annotations (such as `@GetMapping`, `@PostMapping`, etc.) support. |
| === Spring @RequestMapping Support | ||
|
|
||
| Spring Cloud OpenFeign provides support for the Spring `@RequestMapping` annotation and its derived annotations (such as `@GetMapping`, `@PostMapping`, etc.) support. | ||
| The attributes on the `@RequestMapping` annotation (including `value`, `method`, `params`, `headers`, `consumes`, and `produces`) will be parsed by `SpringMvcContract` as the content of the request. |
| The attributes on the `@RequestMapping` annotation (including `value`, `method`, `params`, `headers`, `consumes`, and `produces`) will be parsed by `SpringMvcContract` as the content of the request. | ||
|
|
||
|
|
||
| For example: |
There was a problem hiding this comment.
Change to Consider the following example:
| } | ||
| ---- | ||
|
|
||
| In the above example, the request url will be resolved to `/stores/{storeId}?mode=upsert`. + |
| ---- | ||
|
|
||
| In the above example, the request url will be resolved to `/stores/{storeId}?mode=upsert`. + | ||
| The params attribute also supports the use of multiple `key=value` or only one `key`. For example: + |
| In the above example, the request url will be resolved to `/stores/{storeId}?mode=upsert`. + | ||
| The params attribute also supports the use of multiple `key=value` or only one `key`. For example: + | ||
|
|
||
| - When `params = { "key1=v1", "key2=v2" }`, the request url will be parsed as `/stores/{storeId}?key1=v1&key2=v2`. |
| The params attribute also supports the use of multiple `key=value` or only one `key`. For example: + | ||
|
|
||
| - When `params = { "key1=v1", "key2=v2" }`, the request url will be parsed as `/stores/{storeId}?key1=v1&key2=v2`. | ||
| - When `params = "key"`, the request url will be parsed as `/stores/{storeId}?key`. |
|
Hi @OlgaMaciaszek,Done |
OlgaMaciaszek
left a comment
There was a problem hiding this comment.
Thanks @Puppy4C. LGTM.
Previously, SpringMvcContract did not support parsing the
paramsparameter of@RequestMapping.Example:
paramsparameter:When sending this request, the request path will be resolved to
/userinstead of/user?action=disable, resulting in 400 errors.Therefore, this PR provides the ability to parse
paramsparameter.