I'm getting the following error. Couldn't figure o...
# help
j
I'm getting the following error. Couldn't figure out where I'm wrong. Been stuck at this for the last 3 hrs. Signed up on wiremock slack to get help.
Copy code
Request was not matched
                                               =======================

-----------------------------------------------------------------------------------------------------------------------
| Closest stub                                             | Request                                                  |
-----------------------------------------------------------------------------------------------------------------------
                                                           |
get-aadhaar-details-success-teen                           |
                                                           |
POST                                                       | POST
[path regex] /okyc/v1/digio/init                           | /okyc/v1/digio/init
                                                           |
$.things[?(@ =~ /Required.*/i)]                            |                                                     <<<<< Body does not match
                                                           |     { "things":  "Required"  }
                                                           |
-----------------------------------------------------------------------------------------------------------------------
entire mock
Copy code
{
            "name": "get-aadhaar-details-success-teen",
            "request": {
                "method": "POST",
                "urlPathPattern": "/okyc/v1/digio/init",
                "bodyPatterns": [
                    {
                        "matchesJsonPath" : "$.things[?(@ =~ /Required.*/i)]"
                    }
                ]
            },
            "response": {
                "status": 200,
                "headers": {
                    "Content-Type": "application/json"
                },
                "jsonBody": {
                    "success": true,
                }
            }
curl:
Copy code
curl --location 'localhost:8080/okyc/v1/digio/init' \
--header 'Content-Type: application/json' \
--data '
    { "things":  "Required"  }

'
f
Copy code
{
  "request": {
    ...
    "queryParameters" : {
      "search_term" : {
        "matches" : "^(.*)wiremock([A-Za-z]+)$"
      }
    }
    ...
  },
  ...
}
this seems to be the json syntax for that kind of check
I don't see a case insensitive capability though
j
I am using it for request body match
f
I mean sure, wrap key matches regex in that
j
My POST request body is specifically like
Copy code
{
  "things": "Required_thing"
}
I'm trying to match
things
key for values starting with
Required
The queryParameters is specifically for query params, no?
f
yes
sorry, I didn't edit the example
use bodyPatterns instead of that
j
I have used exactly that. but it doesn't work. It does work though when there's nesting. But not when there's no nesting https://wiremock.org/docs/request-matching/#equality-matching
For example the below works
Copy code
{
  "request": {
    ...
    "bodyPatterns" : [ {
      "matchesJsonPath" : "$.things[?(@.name == 'RequiredThing')]"
    } ]
    ...
  },
  ...
}
where I'm matching things.name == RequiredThing
But not
Copy code
{
  "request": {
    ...
    "bodyPatterns" : [ {
      "matchesJsonPath" : "$.things[?(@ == 'RequiredThing')]"
    } ]
    ...
  },
  ...
}
where I'm trying to match things with RequiredThing
f
I see it now
j
Thank you! Been at it for quick sometime now..
still couldn't make it work
f
so you're matching {"things": {"RequiredThing"}} I think
the $.things is the structure outside
maybe $. would be appropriate?
or just $
sorry I'm still learning too
j
let me try
f
and you want the field name inside, so @.things =~ ...
it's just $
so
Copy code
"$[?(@.things =~ /Required.*/i)]"
I think
l
Hi, did you get this sorted or are you still struggling ?