我想为相同的PUT URL匹配不同的体,但是stubby4j总是匹配第一种情况,不管主体的内容是什么。
示例:
- request:
url: /individuals/.*/address$
method: PUT
body: >
{
"type": "MOBILE",
(other input fields)
}
response:
status: 400
body: >
{
"type": "BAD_REQUEST",
"message": "Validation error on request."
}
- request:
url: /individuals/.*/address$
method: PUT
body: >
{
"type": "HOME",
(other input fields)
}
response:
status: 200在这种情况下,无论我的请求中参数"type“的值是什么,它总是与第一个存根匹配。
发布于 2021-02-24 15:57:33
对迟来的回应表示歉意。
在最近和当前版本的PUT/GET/POST/PATCH/etc (即:7.x.x)中,可以为相同的stubby4j URL匹配不同的主体。
例如,下面是一个有效的YAML配置,它可以工作(为了示例起见,我简化了OP提供的tad YAML配置):
- request:
url: /individuals/.*/address$
method: PUT
post: >
{"type": "MOBILE"}
response:
status: 400
body: >
{"type": "BAD_REQUEST"}
- request:
url: /individuals/.*/address$
method: PUT
post: >
{"type": "HOME"}
response:
body: OK
status: 200请注意:
request没有得到body键,使用post键代替POST/PUT/修补程序的有效负载(如果有效负载太大,则使用file )。body键只应在response中使用,而不应用于request中。json键无效& stubby4j不支持有关request & response:howto.html的YAML配置的更多信息,请参阅request用户手册
发布于 2018-12-06 22:17:14
尝试将请求体更改为带有标头的json数据。
- request:
url: /individuals/.*/address$
method: PUT
headers:
content-type: application/json
json: '{"type": "MOBILE"}'
response: ...
- request:
url: /individuals/.*/address$
method: PUT
headers:
content-type: application/json
json: '{"type": "HOME"}'
response: ...https://stackoverflow.com/questions/53162912
复制相似问题