Use minItems/maxItems in collection JSON schemas

To make your collection JSON schemas more reilable use minItems and maxItems so that you can trust your API.

{
  "type": "array",
  "minItems": 1,
  "items": {
    "$ref": "subscription_notification.json"
  }
}


instead of

{
  "type": "array",
  "items": {
    "$ref": "subscription_notification.json"
  }
}


If your API returns [] empty array that last one would pass if you make an assertion in your specs.

expect(response).to match_response_schema(:subscription_notifications)


But not the first one

The property '#/' did not contain a minimum number of items 1 in schema


https://json-schema.org/understanding-json-schema/reference/array.html

Ali

Get our stories delivered

From us to your inbox weekly.