Contract Verification with Schemas
Validate complex microservice structures against strict JSON Schema contracts with a single assertion line.
📝 The Scenario
scenario: Verify User List Contract
tags:
- contract
- users
steps:
- request:
method: GET
url: /v1/users
headers:
Authorization: "Bearer ${adminToken}"
expect:
status: 200
# Validates the response body against the target schema
schema: users/list-response
📐 The Schema File: .gherkio/schemas/users/list-response.yaml
Define your structural contracts inside .gherkio/schemas/:
type: object
required:
- users
- pageInfo
properties:
users:
type: array
items:
type: object
required:
- id
- name
- email
properties:
id:
type: string
format: uuid
name:
type: string
email:
type: string
format: email
pageInfo:
type: object
required:
- page
- totalPages
properties:
page:
type: integer
totalPages:
type: integer
💡 Key Design Patterns Used
- Zero-Boilerplate Checks: Validating deep collection trees, formats, and required field lists with one simple
schema:declaration. - Schema Reuse: The schema file can be referenced by multiple scenarios, ensuring changes to contracts are updated in one central location.