https://linen.dev logo
#help
Title
# help
b

Biswajit Shaw

06/27/2023, 8:26 PM
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

Tom

06/27/2023, 8:33 PM
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

Biswajit Shaw

06/27/2023, 8:43 PM
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

Tom

06/27/2023, 9:26 PM
It’s documented here, albeit fairly briefly: https://wiremock.org/docs/request-matching/#logical-and-and-or
b

Biswajit Shaw

06/28/2023, 3:26 PM
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

Tom

06/28/2023, 7:35 PM
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.