1

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 Answers1

0

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
rasklaad
  • 151
  • 1
  • 6