This is a complete example of API contract validation in k6 using the expect library.
Contracts are stored in ./api_contracts folder as .js
files.
Contracts can also be standard .json
files if there's no need to compose complex contracts from multiple objects.
API contracts follow the JSON Schema format. Under the hood, the expect library is using Ajv JSON schema validator developed by Mozilla.
The example script validates API contracts of selected services from https://test-api.k6.io/.