Stubby:具有不同主体的相同URLS的存根PUT请求



我想为同一PUT URL匹配不同的正文,但无论正文的内容如何,study4j总是匹配第一种情况。

示例:

- 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"的值是多少,它总是与第一个存根匹配。

对延迟回复表示歉意。

在最近的&study4j(即:7.x.x(的当前版本,可以为相同的PUT/GET/POST/PATCH/etc URL匹配不同的主体。

例如,以下是有效的YAML配置(为了示例起见,我稍微简化了OP提供的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/PATCH的有效负载(如果有效负载太大,则使用file(
  • body密钥只能用于response,而不能用于request
  • CCD_ 13密钥无效&stubby4j不支持

有关request&response:https://stubby4j.com/docs/http_endpoint_configuration_howto.html

尝试将请求主体更改为带有头的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: ...

最新更新