Shallow clone a old repo

If you don't need the full git history for a repo you will be working on you can supply a clone depth to only clone x revisions of the repo.

git clone --depth=1 https://github.com/my/repo.git

829
Joe

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


Understanding JSON Schema Arrays


JSON Schema arrays are essential for defining the structure and constraints of arrays in JSON data. An array in JSON is an ordered collection of values, and a JSON Schema array is used to specify the characteristics and restrictions of these arrays. By using a JSON Schema array, you can validate the length, contents, and uniqueness of an array, ensuring that the data adheres to the expected format. This is particularly useful when you need to enforce specific rules on the data structure, such as requiring a certain number of items or ensuring that all items are of a particular type.

Validation Keywords for Arrays


JSON Schema provides several validation keywords that can be used to constrain arrays. These keywords include:

  • items: Specifies the schema for each item in the array.

  • additionalItems: Specifies the schema for any additional items in the array beyond the first items schema.

  • minItems and maxItems: Specify the minimum and maximum number of items in the array.

  • uniqueItems: Specifies whether the items in the array must be unique.

  • contains: Specifies a schema that at least one item in the array must match.

  • minContains and maxContains: Specify the minimum and maximum number of items in the array that must match the contains schema.

These keywords allow you to define precise constraints on the array, ensuring that the data meets the required criteria.

Constraining Array Length


JSON Schema provides several ways to constrain the length of an array. The minItems and maxItems keywords can be used to specify the minimum and maximum number of items in the array. For example: { "type": "array", "minItems": 2, "maxItems": 5 } This schema specifies that the array must have at least 2 items and at most 5 items. By using these keywords, you can ensure that the array length falls within the desired range, preventing issues with too few or too many items.

Best Practices for Array Validation


When validating arrays with JSON Schema, it’s a good idea to use a combination of validation keywords to ensure that the array meets the required constraints. For example, you might use items to specify the schema for each item in the array, and minItems and maxItems to specify the minimum and maximum number of items in the array.

It’s also a good idea to use the uniqueItems keyword to ensure that the items in the array are unique, if that’s a requirement for your data. By combining these keywords, you can create a robust schema that thoroughly validates the array structure and contents.

Example Use Cases


Here are a few example use cases for JSON Schema arrays:

  • Validating a list of user IDs: You might use a schema like this to validate a list of user IDs:

{ "type": "array", 
"items": {"type": "integer"}, 
"minItems": 1, "maxItems": 10 } 

  • Validating a list of product names: You might use a schema like this to validate a list of product names:

{ "type": "array", "items": {"type": "string"}, "minItems": 1, "maxItems": 5, "uniqueItems": true } 

  • Validating a list of addresses: You might use a schema like this to validate a list of addresses:

{ "type": "array", "items": { "type": "object", "properties": { "street": {"type": "string"}, "city": {"type": "string"}, "state": {"type": "string"}, "zip": {"type": "string"} }, "required": ["street", "city", "state", "zip"] }, "minItems": 1, "maxItems": 10 } 

These examples illustrate how to apply JSON Schema arrays to different types of data, ensuring that the arrays meet the specified constraints and requirements.



Ali