Is there any way to create a JSON request mapping on WireMock to match a list of two different items having n number of elements?

614 Views Asked by At

I have create a Wiremock JSON mapping file as follows:

 {
    "request": {
        "method": "POST",
        "url": "/some/thing",
        "bodyPatterns": [
            {
                "equalToJson": {
                    "items": [
                        {
                            "name": "${json-unit.any-string}",
                            "phone": "${json-unit.regex}(^[0-9]{10}$)"
                        },
                        {
                            "address": "${json-unit.any-string}"
                        }
                    ]
                },
                "ignoreArrayOrder": true
            }
        ]
    },
    "response": {
        "status": 200,
        "body": "Hello world!"
    }
}

Now when I send a JSON request where the number of elements in the items list is more than two, it does not match the above mapping.

Is there any way to change the above mapping in such way that it matches JSON requests having two or more elements in its items list?

1

There are 1 best solutions below

0
rasklaad On

ignoreExtraElements param should do the job

"equalToJson": {
    "items": [
        {
            "name": "${json-unit.any-string}",
            "phone": "${json-unit.regex}(^[0-9]{10}$)"
        },
        {
            "address": "${json-unit.any-string}"
        }
        ]
},
"ignoreArrayOrder": true,
"ignoreExtraElements": true