Skip to content

Linting

Linting ensures specs are structurally valid and follow best practices before breaking change detection or changeset generation. Contractual ships with sensible defaults for every supported format.


CategoryExamples
Structural errorsMissing required fields, invalid types, malformed YAML/JSON
Reference errorsBroken $ref pointers, missing schema definitions
Style violationsMissing descriptions, operations without tags, undocumented parameters
Best practice issuesNo servers defined, missing error responses, deprecated patterns

Linting runs independently from breaking change detection. A spec can be structurally valid (passes lint) but still contain breaking changes compared to the previous snapshot.


Contractual ships with built-in linter defaults for each supported spec format:

Spec typeDefault linterWhat it checks
OpenAPISpectralOpenAPI spec compliance, style rules
JSON SchemaBuilt-in validatorDraft-07 compliance, schema validity

Any default can be overridden with a custom command. See Usage for configuration.


Run linting at these points in the workflow:

WhenWhy
Local developmentCatch errors before committing
Pre-commit hookPrevent invalid specs from entering the repo
Pull request CIBlock merges with lint violations
Before breaking checkEnsure valid spec before diffing

These two commands serve different purposes:

CommandPurposeCompares against
contractual lintValidate spec structure and styleFormat specification (OpenAPI, JSON Schema)
contractual breakingDetect API contract changesPrevious snapshot

A valid spec can still contain breaking changes. A spec with lint errors might have no breaking changes. Run both in the CI pipeline.


  • Usage: Command options, custom linters, CI integration