Skip to content

Contract Management

Manage contracts in your project using the contract subcommands.


Add a new contract to the project.

Terminal window
contractual contract add [options]
OptionAliasRequiredDescription
--name-nInteractive: noContract name (unique identifier)
--type-tInteractive: noContract type: openapi or json-schema
--path-pInteractive: noPath to spec file
--version-VNoInitial version (default: 0.0.0)
--skip-validationNoSkip spec file validation
terminal
$ contractual contract add

? Contract name: user-api
? Contract type: openapi
? Path to spec file: ./specs/user.openapi.yaml
Validating...  Valid OpenAPI 3.0.3
? Initial version: (0.0.0)

Added user-api (openapi) at v0.0.0
Updated: contractual.yaml
Created: .contractual/snapshots/user-api.yaml
Terminal window
contractual contract add \
--name user-api \
--type openapi \
--path ./specs/user.openapi.yaml \
--version 1.0.0 \
--yes

The command validates:

  • File exists
  • File is valid spec of declared type (unless --skip-validation)
  • Name is unique
terminal
$ contractual contract add --name orders-api --type openapi --path ./missing.yaml

Error: Spec file not found: ./missing.yaml
terminal
$ contractual contract add --name orders-api --type json-schema --path ./specs/orders.openapi.yaml

Warning: File appears to be OpenAPI, not JSON Schema. Continue? (y/N)

List all contracts in the project.

Terminal window
contractual contract list [options]
OptionDescription
--jsonOutput as JSON
terminal
$ contractual contract list

Contracts (3):

Name           Type          Version   Path
─────────────────────────────────────────────────────────
orders-api     openapi       1.2.0     ./specs/orders.openapi.yaml
order-schema   json-schema   1.0.0     ./schemas/order.schema.json
terminal
$ contractual contract list --json

{
"contracts": [
  {
    "name": "orders-api",
    "type": "openapi",
    "version": "1.2.0",
    "path": "./specs/orders.openapi.yaml"
  }
]
}

Remove a contract from the project.

Terminal window
contractual contract remove <name> [options]
OptionDescription
--keep-historyKeep version history and snapshots
terminal
$ contractual contract remove user-api

? Remove contract "user-api"? This will delete:
  - Entry in contractual.yaml
  - Version history (.contractual/snapshots/user-api.yaml)
  - Pending changesets mentioning user-api

Continue? (y/N)

Requires --yes flag:

Terminal window
contractual contract remove user-api --yes

To remove from config but preserve snapshots:

Terminal window
contractual contract remove user-api --keep-history --yes