@philiprehberger/ts-schema-diff
v0.1.4
Published
Compare JSON schemas and detect breaking changes
Readme
@philiprehberger/ts-schema-diff
Compare JSON schemas and detect breaking changes.
Installation
npm install @philiprehberger/ts-schema-diffUsage
import { diffSchemas } from '@philiprehberger/ts-schema-diff';
const changes = diffSchemas(
{ name: { type: 'string' }, email: { type: 'string' } },
{ name: { type: 'string' }, age: { type: 'number' } },
);
// [
// { path: 'email', type: 'removed', breaking: true, message: 'Removed "email"' },
// { path: 'age', type: 'added', breaking: false, message: 'Added "age"' },
// ]
const hasBreaking = changes.some(c => c.breaking);API
| Export | Description |
|--------|-------------|
| diffSchemas(before, after) | Deep-compare two schemas, returns SchemaChange[] |
SchemaChange
| Property | Type | Description |
|----------|------|-------------|
| path | string | Dot-separated path |
| type | 'added' \| 'removed' \| 'changed' | Change type |
| breaking | boolean | Whether the change is breaking |
| before | unknown | Previous value |
| after | unknown | New value |
| message | string | Human-readable description |
Development
npm install
npm run build
npm testLicense
MIT
