step.expect

Summary

Expect are the validations to be done on the response.

Fields

code

type: int
required: no
description: The expected HTTP status code

body

body.type

type: string
required: no
default: plaintext
description: This affects how some other fields are interpreted, such as body.exact. See below for details. Currently only json and plaintext are supported.

body.content

type: string
required: no
description: A string with the expected response body. See body.exact for more details

body.exact

type: bool
required: no
default: true
description: Whether or not to strictly validate the response body. If false and body.type=json, just the fields are recursively validated, but not scalar (ints, strings, etc.); for arrays, the fields of each element of the response array are validated recursively against the first element in the array in expect. If false and body.type=plaintext, the the response needs to contain the body.content, but doesn't have to fully match it.

Examples

Exact JSON

expect:
  code: 200
  body:
    type: "json"
    exact: true
    content: |
      {
        "first_name": "Bobby",
        "last_name": "Hounslow",
        "address": {
            "postcode": "TW4 7AE"
        }
      }

In this case an API response below on the left will pass validation, but the one of the right will not ("Boris" != "Bobby")

    {
      "first_name": "Bobby",
      "last_name": "Hounslow",
      "address": {
        "postcode": "TW4 7AE"
      }
    }
    {
      "first_name": "Boris",
      "last_name": "Hounslow",
      "address": {
        "postcode": "TW4 7AE"
      }
    }

Non-exact JSON

expect:
  code: 200
  body:
    type: "json"
    exact: false
    content: |
      {
        "first_name": "Bobby",
        "last_name": "Hounslow",
        "address": {
            "postcode": "TW4 7AE"
        }
      }

In this case an API response below on the left will pass validation, but the one of the right won't ("code" != "postcode")

    {
      "first_name": "John",
      "last_name": "Leicester",
      "address": {
        "postcode": "LE9 6HF"
      }
    }
    {
      "first_name": "John",
      "last_name": "Leicester",
      "address": {
        "code": "LE9 6HF"
      }
    }

Non-exact JSON Array

expect:
  code: 200
  body:
    type: "json"
    exact: false
    content: |
      {
        "people": [
          {
            "first_name": "Bobby",
            "last_name": "Hounslow"
          }
        ]
      }

In this case an API response below on the left will pass validation, but the one of the right won't

    {
      "people": [
        {
           "first_name": "John",
           "last_name": "Leicester"
        },
        {
           "first_name": "John",
           "last_name": "Leicester"
        }
      ]
    }
     {
       "people": [
         {
           "first_name": "John",
           "last_name": "Leicester"
         },
         {
            "first_name": "John"

         }
       ]
     }

Didn't find what you were looking for?

You can head over to our FAQ page