spring-cloud-contract icon indicating copy to clipboard operation
spring-cloud-contract copied to clipboard

Validating all parameters of an array

Open KanikaDeka opened this issue 5 years ago • 2 comments

In contract, if we have two array items and we are trying to validate both with same regex in our request, as of now, if any of the two gets validated successfully then whole contract is validated. But we want it to pass when both of them are matching the given regex pattern. e,g:

Producer

name: Validating Customer
request:
  method: POST
  url: /ValidateMO
  body:
    address:
      - zipCode: "{zip_val}"
  headers:
    Content-Type: application/json
  matchers:
    body:
      - path: $.address.*.zipCode
        type: by_regex
        value: "[0-9]{5}"
response:
  status: 200
  body: 
    "status": "OK"
  headers: 
    Content-Type: application/json;charset=UTF-8

Consumer json:

{
  "address": [{
    "zipCode": "12345"
  },
  {
    "zipCode": "123456"
  }]
} 

In this scenario, even if second zip code is wrong, the contract is validating successfully. We want it to fail and we don't want to use indexing in contract.

KanikaDeka avatar Dec 24 '18 12:12 KanikaDeka

Until WireMock 2.20.0 (I have to double check that) this will not be possible (I think) due to JSONPath limitations. You have to use indexing for now.

marcingrzejszczak avatar Dec 24 '18 12:12 marcingrzejszczak

When WireMock 2.20.0 version will be available? Actually I am working on big json where I need to validate many fields with many combinations. Now due to some limitations in spring cloud, we are not able to validate it properly.

KanikaDeka avatar Dec 26 '18 05:12 KanikaDeka