Skip to main content

CLI Reference

What is the CVT CLI?

The CVT CLI lets you validate contracts locally without running a server. Use it for:

  • Quick one-off validations during development
  • CI/CD pipelines that need schema comparison
  • Generating test fixtures from OpenAPI schemas
  • Starting a CVT server for remote validation

Installation

# Build from source
go build -o cvt ./cmd/cvt

# Or install globally
go install github.com/sahina/cvt/cmd/cvt@latest

Commands Overview

CommandDescription
validateValidate an interaction against a schema
compareCompare schemas for breaking changes
generateGenerate test fixtures from schemas
can-i-deployCheck deployment safety against registered consumers
waitWait for CVT server to become ready
register-schemaRegister an OpenAPI schema with the server
serveStart the server
versionShow version information

validate

Validate an HTTP request/response interaction against an OpenAPI schema.

Usage

cvt validate --schema <path> [options]

Options

FlagShortDescriptionRequired
--schema-sPath or URL to OpenAPI schema (JSON/YAML)Yes
--interaction-iPath to combined interaction JSON fileNo (alternative to request/response)
--requestPath to request JSON fileNo (use with --response)
--responsePath to response JSON fileNo (use with --request)
--method-mHTTP method (GET, POST, etc.)No (alternative to files)
--path-pRequest path (e.g., /pets/123)No (use with --method)
--request-bodyRequest body as JSON stringNo
--status-codeResponse status code (default: 200)No
--response-bodyResponse body as JSON stringNo
--jsonOutput results as JSONNo

Input Methods

You can provide interaction data in three ways:

1. Combined interaction file:

cvt validate --schema ./openapi.json --interaction interaction.json

2. Separate request/response files:

cvt validate --schema ./openapi.json --request req.json --response resp.json

3. Command-line flags (for simple cases):

cvt validate --schema ./openapi.json \
--method GET --path /pets/123 \
--status-code 200 --response-body '{"id": 123, "name": "doggie"}'

4. Using a URL for the schema:

cvt validate --schema https://petstore3.swagger.io/api/v3/openapi.json \
--interaction interaction.json

Request File Format

{
"method": "GET",
"path": "/pets/123",
"headers": {
"Accept": "application/json"
},
"body": null
}

Response File Format

{
"status_code": 200,
"headers": {
"Content-Type": "application/json"
},
"body": "{\"id\": 123, \"name\": \"doggie\"}"
}

Interaction File Format

{
"request": {
"method": "GET",
"path": "/pets/123",
"headers": { "Accept": "application/json" }
},
"response": {
"statusCode": 200,
"headers": { "Content-Type": "application/json" },
"body": { "id": 123, "name": "doggie" }
}
}

Exit Codes

CodeMeaning
0Validation passed
1Validation failed (errors printed)

compare

Compare two OpenAPI schema versions to detect breaking changes.

Usage

cvt compare --old <path> --new <path> [options]

Options

FlagDescriptionRequired
--oldPath or URL to old/previous schemaYes
--newPath or URL to new schemaYes
--jsonOutput results as JSONNo

Examples

# Compare schemas
cvt compare --old ./v1/openapi.json --new ./v2/openapi.json

# JSON output for CI/CD integration
cvt compare --old ./v1/openapi.json --new ./v2/openapi.json --json

# Compare local schema against a remote URL
cvt compare --old ./local-schema.json --new https://api.example.com/openapi.json

Output

✗ Found 2 breaking change(s):

[ENDPOINT_REMOVED] DELETE /users/{id} was removed
Old: DELETE /users/{id}

[REQUIRED_FIELD_ADDED] Required field 'phone' added to POST /users request
New: phone (required)

Exit Codes

CodeMeaning
0Schemas are compatible
1Breaking changes detected

generate

Generate test fixtures from an OpenAPI schema.

Usage

cvt generate --schema <path> [options]

Options

FlagShortDescriptionDefault
--schema-sPath or URL to OpenAPI schema(required)
--list-lList all available endpoints and exitfalse
--method-mHTTP method (GET, POST, PUT, DELETE, etc.)(required for gen)
--path-pAPI path (e.g., /users, /users/{id})(required for gen)
--output-type-tWhat to generate: fixture, request, responsefixture
--status-codeResponse status code (0 = first successful)0
--use-examplesUse schema examples when availabletrue
--content-typeContent type for request/responseapplication/json
--output-oOutput file path (default: stdout)stdout

Examples

# List all endpoints in the schema
cvt generate --schema ./openapi.json --list

# List endpoints from a remote URL
cvt generate --schema https://petstore3.swagger.io/api/v3/openapi.json --list

# Generate complete request/response fixture
cvt generate --schema ./openapi.json --method GET --path /pets/{petId}

# Generate only request body
cvt generate --schema ./openapi.json --method POST --path /pets --output-type request

# Generate response with specific status code
cvt generate --schema ./openapi.json --method GET --path /pets --output-type response --status-code 200

# Save output to file
cvt generate --schema ./openapi.json --method GET --path /pets/{petId} -o fixture.json

Output (Fixture)

{
"request": {
"method": "GET",
"path": "/pets/123",
"headers": {
"Accept": "application/json"
}
},
"response": {
"statusCode": 200,
"headers": {
"Content-Type": "application/json"
},
"body": {
"id": 123,
"name": "doggie",
"status": "available"
}
}
}

Endpoint List Output

Available endpoints:
GET /pets
GET /pets/{petId}
POST /pets
PUT /pets/{petId}
DELETE /pets/{petId}

can-i-deploy

Check if a schema version can be safely deployed without breaking registered consumers.

Usage

cvt can-i-deploy --schema <id> --version <version> --env <environment> [options]

Options

FlagDescriptionRequiredDefault
--schemaSchema ID to checkYes
--versionNew version to deployYes
--envTarget environment (dev, staging, prod)Yes
--serverCVT server addressNolocalhost:9550
--jsonOutput results as JSONNofalse
--timeoutConnection timeout in secondsNo30

Examples

# Check deployment safety against local server
cvt can-i-deploy --schema petstore --version 2.0.0 --env prod

# Check against a remote server
cvt can-i-deploy --schema petstore --version 2.0.0 --env prod --server cvt.internal:9550

# JSON output for CI/CD
cvt can-i-deploy --schema petstore --version 2.0.0 --env prod --json

# Custom timeout
cvt can-i-deploy --schema petstore --version 2.0.0 --env prod --timeout 60

Output (Safe)

Deployment Safety Check
=======================
Schema: petstore
Version: 2.0.0
Environment: prod

✅ SAFE TO DEPLOY

No breaking changes detected that would affect registered consumers.

Output (Unsafe)

Deployment Safety Check
=======================
Schema: petstore
Version: 2.0.0
Environment: prod

❌ UNSAFE TO DEPLOY

Breaking changes in v2.0.0:
- ENDPOINT_REMOVED: DELETE /pets/{petId}
Endpoint was removed from the API

Affected consumers in prod:
├── order-service v2.1.0
│ Schema version: 1.0.0
│ Impact: BREAKING
│ Affected by:
│ - DELETE /pets/{petId}

└── billing-service v1.0.0
Schema version: 1.0.0
Impact: None

Safe consumers: 1/2
Affected consumers: 1/2

Recommendation: Coordinate with order-service team before deploying.

Exit Codes

CodeMeaning
0Safe to deploy
1Unsafe to deploy (breaking changes affect consumers)

wait

Wait for the CVT server to become ready. Useful for CI/CD pipelines and startup scripts.

Usage

cvt wait [options]

Options

FlagShortDescriptionDefault
--server-SCVT server addresslocalhost:9550
--timeout-tTimeout in seconds60
--interval-iPolling interval in seconds2
--json-jOutput results as JSONfalse
--quiet-qSuppress output except errorsfalse

Examples

# Wait with defaults (60s timeout, 2s interval)
cvt wait

# Wait for specific server with custom timeout
cvt wait --server cvt.internal:9550 --timeout 120

# Custom polling interval
cvt wait --server localhost:9550 --timeout 120 --interval 1

# Short flags
cvt wait -S localhost:9550 -t 120 -i 1

# Quiet mode for CI/CD
cvt wait -q

# JSON output for scripting
cvt wait --json

Exit Codes

CodeMeaning
0Server is ready
1Timeout waiting for server

register-schema

Register an OpenAPI schema with the CVT server. Supports both local files and URLs, and can check for breaking changes before registering.

Usage

cvt register-schema <schema-id> <schema-file> [options]

Arguments

ArgumentDescriptionRequired
schema-idUnique identifier for the schemaYes
schema-filePath or URL to OpenAPI schema (JSON/YAML)Yes

Options

FlagShortDescriptionDefault
--version-vSchema version (e.g., "2.0.0")
--server-SCVT server addresslocalhost:9550
--check-compatibilityCheck for breaking changesfalse
--fail-on-breakingExit with error if breaking changesfalse
--ownerSchema owner name
--teamTeam name
--json-jOutput results as JSONfalse
--quiet-qSuppress output except errorsfalse
--timeout-tConnection timeout in seconds30

Examples

# Basic registration from file
cvt register-schema my-api ./openapi.yaml

# Register from URL
cvt register-schema my-api https://api.example.com/openapi.json

# Register with version
cvt register-schema my-api ./openapi.yaml --version 2.0.0

# Short flag for version
cvt register-schema my-api ./openapi.yaml -v 2.0.0

# Check for breaking changes before registering
cvt register-schema my-api ./openapi.yaml --check-compatibility

# Fail CI if breaking changes detected
cvt register-schema my-api ./openapi.yaml --check-compatibility --fail-on-breaking

# With ownership metadata
cvt register-schema my-api ./openapi.yaml --owner "Jane Doe" --team "Platform"

# JSON output for scripting
cvt register-schema my-api ./openapi.yaml --json

# Quiet mode
cvt register-schema my-api ./openapi.yaml -q

Exit Codes

CodeMeaning
0Schema registered successfully
1Registration failed or breaking changes found

serve

Start the CVT gRPC server.

Usage

cvt serve [options]

Options

FlagShortDescriptionDefault
--port-pgRPC server port9550
--metrics-portPrometheus metrics port9551
--tlsEnable TLSfalse
--certPath to TLS certificate
--keyPath to TLS private key
--api-key-authEnable API key authenticationfalse

Examples

# Start with defaults
cvt serve

# Custom ports
cvt serve --port 9550 --metrics-port 9551

# Enable TLS
cvt serve --tls --cert ./certs/server.crt --key ./certs/server.key

# Enable API key authentication
cvt serve --api-key-auth

Environment Variables

The serve command also respects environment variables. See Configuration Reference for the complete list.


version

Display version information.

Usage

cvt version

Output

CVT version 1.0.0
Commit: abc1234
Built: 2024-01-15T10:30:00Z

Global Options

These options work with all commands:

FlagDescription
--help, -hShow help for command

CI/CD Integration

GitHub Actions

- name: Check for breaking changes
run: |
cvt compare --old ./main-schema.json --new ./pr-schema.json --json
if [ $? -ne 0 ]; then
echo "Breaking changes detected!"
exit 1
fi

- name: Check deployment safety
run: |
cvt can-i-deploy \
--schema my-api \
--version ${{ github.sha }} \
--env prod \
--server ${{ secrets.CVT_SERVER }} \
--json > deploy-check.json

if [ "$(jq '.safe_to_deploy' deploy-check.json)" != "true" ]; then
echo "Unsafe to deploy!"
jq '.affected_consumers' deploy-check.json
exit 1
fi

GitLab CI

check-breaking-changes:
script:
- cvt compare --old $CI_MERGE_REQUEST_TARGET_BRANCH_SHA:openapi.json --new ./openapi.json --json
allow_failure: false
rules:
- if: $CI_PIPELINE_SOURCE == "merge_request_event"
changes:
- openapi.json

deployment-safety:
script:
- cvt can-i-deploy --schema $SCHEMA_ID --version $CI_COMMIT_SHA --env prod --json
allow_failure: false