使用Feign @RequestLine添加解码器斜线 [英] Adding decodeSlash using Feign @RequestLine
问题描述
我当前正在使用YAML文件通过swagger插件生成模型和API客户端,并且正在使用Feign OkHttpClient向API发出请求,这里的问题是客户端对URL进行了编码,但忽略了斜杠( ),API调用将失败.有没有一种方法可以在客户端中添加decodeSlash
参数?还是可以使用拦截器来实现?
I am currently using a YAML file to generate the models and the API clients using the swagger plugin and I am using Feign OkHttpClient to make requests to the API, the problem here is the client encodes the URL but ignores the Slash(es) with this the API call fails. Is there a way to add decodeSlash
parameter in the client? Or can this be achieved using an interceptor?
这是我遇到此问题的示例路径参数. QgKuK2DU/0%3D
应该在QgKuK2DU%2F0%3D
Here is the sample path param where I am running into this issue. QgKuK2DU/0%3D
where as it should be QgKuK2DU%2F0%3D
推荐答案
如果使用 openapi-generator 您可以此处)自己添加decodeSlash
参数:
If you use the openapi-generator you can modify the templates (also described here) yourself to add the decodeSlash
Parameter:
git clone https://github.com/openapitools/openapi-generator
cd openapi-generator
git checkout v4.2.0 # The Version Tag you are actually using
cd modules/openapi-generator/src/main/resources/Java/libraries/feign/
cp api.mustache <your_local_project>/src/main/resources/Java/libraries/feign
在api.mustache
中更改@RequestLine
的2种外观:
- @RequestLine("{{httpMethod}} {{{path}}}{{#hasQueryParams}}?{{/hasQueryParams}}{{#queryParams}}{{baseName}}={{=<% %>=}}{<%paramName%>}<%={{ }}=%>{{#hasMore}}&{{/hasMore}}{{/queryParams}}")
+ @RequestLine(value="{{httpMethod}} {{{path}}}{{#hasQueryParams}}?{{/hasQueryParams}}{{#queryParams}}{{baseName}}={{=<% %>=}}{<%paramName%>}<%={{ }}=%>{{#hasMore}}&{{/hasMore}}{{/queryParams}}", decodeSlash = false)
- @RequestLine("{{httpMethod}} {{{path}}}?{{#queryParams}}{{baseName}}={{=<% %>=}}{<%paramName%>}<%={{ }}=%>{{#hasMore}}&{{/hasMore}}{{/queryParams}}")
+ @RequestLine(value="{{httpMethod}} {{{path}}}?{{#queryParams}}{{baseName}}={{=<% %>=}}{<%paramName%>}<%={{ }}=%>{{#hasMore}}&{{/hasMore}}{{/queryParams}}", decodeSlash = false)
使用openapi-generator-maven-plugin
将templateDirectory
添加到<configuration>
块:
<templateDirectory>src/main/resources/Java/libraries/feign</templateDirectory>
这篇关于使用Feign @RequestLine添加解码器斜线的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!