| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
| Name | Name | Last commit date | ||
|---|---|---|---|---|
This repository demonstrates the full Contractual workflow for managing OpenAPI contract versioning, breaking change detection, and changelog generation.
Contractual is a schema contract lifecycle orchestrator that helps you:
Think of it as Changesets for API contracts instead of npm packages.
git clone https://github.com/contractual-dev/example-openapi.git
cd example-openapi
# View the current contract
cat specs/petstore.openapi.yaml
# Check status
npx @contractual/cli@latest statusEdit specs/petstore.openapi.yaml and add a new optional field:
# In the Pet schema, add:
color:
type: string
description: Color of the pet (optional)npx @contractual/cli@latest diffOutput:
petstore: 1 change(s) (1 non-breaking) — suggested bump: minor non-breaking Property added at /components/schemas/Pet/properties/color
npx @contractual/cli@latest changesetThis generates a changeset file in .contractual/changesets/ with the detected changes.
npx @contractual/cli@latest versionThis:
graph LR
A[Edit Spec] --> B[Create PR]
B --> C{PR Check}
C -->|Breaking?| D[Fail]
C -->|No Changeset?| D
C -->|Pass| E[Merge PR]
E --> F{Has Changesets?}
F -->|Yes| G[Release Workflow]
G --> H[Bump Version]
H --> I[Update Changelog]
I --> J[Commit & Push]
When you open a PR with spec changes:
If breaking changes are detected or no changeset exists, the check fails.
The release workflow uses the Changesets pattern with two phases:
When changesets are merged to main:
When the Version PR is merged to main:
These changes require a major version bump (1.0.0 → 2.0.0):
These changes allow a minor version bump (1.0.0 → 1.1.0):
These changes allow a patch version bump (1.0.0 → 1.0.1):
# Initialize Contractual in a repository
npx @contractual/cli init
# Show current contract versions and pending changesets
npx @contractual/cli status
# Lint all contracts
npx @contractual/cli lint
# Show all changes (breaking, non-breaking, patch)
npx @contractual/cli diff
# Check for breaking changes only
npx @contractual/cli breaking
# Create a changeset from detected changes
npx @contractual/cli changeset
# Apply version bumps and generate changelog
npx @contractual/cli version
# List contracts with versions
npx @contractual/cli contract list
# Add a new contract
npx @contractual/cli contract addcontracts:
- name: petstore
type: openapi
path: specs/petstore.openapi.yaml
changeset:
autoDetect: true # Auto-detect breaking/non-breaking changes
requireOnPR: true # Require changeset for spec changes in PRs.contractual/ ├── changesets/ # Pending changesets (Markdown files) │ └── brave-pandas-jump.md ├── snapshots/ # Versioned spec snapshots │ └── petstore.yaml └── versions.json # Version registry
# Add to specs/petstore.openapi.yaml
/pets/{petId}/vaccinations:
get:
summary: Get pet vaccinations
# ...npx @contractual/cli diff
# Output: non-breaking, suggested bump: minor
npx @contractual/cli changeset
# Creates changeset file
npx @contractual/cli version
# Bumps: 1.0.0 → 1.1.0# Remove from specs/petstore.openapi.yaml
# /pets/{petId}:
# delete:
# ...npx @contractual/cli breaking
# Output: Breaking change detected!
npx @contractual/cli changeset
# Creates changeset with major bump
npx @contractual/cli version
# Bumps: 1.1.0 → 2.0.0# Change description in specs/petstore.openapi.yaml
name:
type: string
description: Name of the pet (updated description)npx @contractual/cli diff
# Output: patch, suggested bump: patch
npx @contractual/cli changeset
npx @contractual/cli version
# Bumps: 2.0.0 → 2.0.1The repository includes two workflows:
Runs on every pull request to:
Runs when changesets are merged to main to:
MIT
| Back | FazBrowse Home | New Git URL |