0

我想为同一个 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”的值是什么,它总是与第一个存根匹配。

4

2 回答 2

1

为迟到的回应道歉。

在最近和当前版本的 stubby4j(即:)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
  • 密钥无效且 stubby4jjson支持

request有关&的 YAML 配置的更多信息,请参阅 stubby4j 用户手册responsehttps ://stubby4j.com/docs/http_endpoint_configuration_howto.html

于 2021-02-24T15:57:33.663 回答
0

尝试将请求正文更改为带有标头的 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: ...
于 2018-12-06T22:17:14.540 回答