1

I am trying to validate an API response schema with this structure in Karate:

{
  "payoutQuotes": [ //could be empty or not but when not empty must have the required object structure inside
    {
      "customerDomain": {
        "financialAccountData": { 
          "payoutQuoteId": "#number",
          "payoutQuoteExpiryDate": "#? isValidDate(_)",
          "totalAmountOfPayoutQuote": "#number",
          "payoutQuoteCreateDate": "#? isValidDate(_)",
          "payoutRequestedBy": "#string"
        }
      }
    }
  ]
}

Now if the response returns an empty "payoutQuotes" array then it is acceptable but when it also contains the object(s) inside, I want to check they have the proper required key-value combinations. Please note that I have this schema saved as a separate file in my data folder of the project to be used for my schema validation.

1 Answer 1

1

Here's the approach, it should be simple. You can read the value of quote from a single file.

* def quote = { foo: '#string' }
* def response1 = { payout: [] }
* def response2 = { payout: [{ foo: 'bar' }] }
* match response1 == { payout: '#[] quote' }
* match response2 == { payout: '#[] quote' }
Sign up to request clarification or add additional context in comments.

1 Comment

As you suggested I have updated my schema Json file to be a subschema that validates the object inside the array and wrote my evaluation line as: And match response == {"payoutQuotes": '#[] PayoutQuoteHistorySuccessSchema'} And it worked... thank you @peter

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.