Hi, I am trying to get something to work but dont ...
# help
b
Hi, I am trying to get something to work but dont know how, or if its even possible I want to combine multiple body patterns with logical 'OR' operation in wiremock like in the below example, the request is matched when both product.group or appointment.id is absent but is it possible to match the request when either of these parameters are absent
Copy code
{
  "request": {
    "urlPath": "/somePath",
    "method": "POST",
    "bodyPatterns": [
      {
        "matchesJsonPath": "[?(!(@.appointment.id))]"
      }
    ]
  },
  "response": {
    "status": 400,
    "jsonBody": [
      {
        "code": 400,
        "detail": "Missing Required Parameter",
        "field": "product.group, title, id, contact.name, contact.number",
        "message": "The request is missing a required parameter."
      }
    ],
    "headers": {
      "Content-Type": "application/json"
    }
  }
}
Any help is appreciated. Thanks 🙂
t
Hi @Biswajit Shaw, If you want logical OR you need something along the lines of:
Copy code
"bodyPatterns": [
    {
      "or": [
        {
          "matchesJsonPath": "[?(!(@.product.group))]"
        },
        {
          "matchesJsonPath": "[?(!(@.appointment.id))]"
        }
      ]
    }
  ]
b
Oh thank you 🙂 works like a charm do you need help with adding this to the documentation ? maybe i can submit a pull request
t
It’s documented here, albeit fairly briefly: https://wiremock.org/docs/request-matching/#logical-and-and-or
b
is it possible to have a logical AND/OR operator inside query parameter like match the request if any of the query parameter is present
Copy code
"queryParameters": {
      "or": {
        "limit": {
          "and": [
            {
              "matches": "^.+$"
            },
            {
              "doesNotMatch": "[0-9]+"
            }
          ]
        },
        "offset": {
          "and": [
            {
              "matches": "^.+$"
            },
            {
              "doesNotMatch": "[0-9]+"
            }
          ]
        }
t
Unfortunately not, the query parameter names must come directly under
queryParameters
, then under each of those you can nest matchers as deeply as you like.