@scalar/json-diff
v0.0.4
Published
Diffing and conflict resolution tool for JSON objects
Downloads
26,326
Maintainers
Keywords
Readme
Scalar JSON Diff
This package provides a way to compare two OpenAPI definitions and get the differences, resolve conflicts and return conflicts that need to be resolved manually.
Quickstart
import { apply, diff, merge } from '@scalar/json-diff'
const baseDocument = {
openapi: '3.0.0',
info: {
title: 'Simple API',
description: 'A small OpenAPI specification example',
version: '1.0.0',
},
}
const documentV1 = {
openapi: '3.0.0',
info: {
title: 'Simple API',
description: 'A small OpenAPI specification example',
version: '1.0.0',
},
change: 'This is a new property',
}
const documentV2 = {
openapi: '3.0.0',
info: {
title: 'Simple API',
description: 'A small OpenAPI specification example',
version: '1.0.1',
},
}
// Merge the changes of both versions with the same parent document
const { diffs, conflicts } = merge(
diff(baseDocument, documentV1),
diff(baseDocument, documentV2),
)
// Apply changes from v1 and v2 to the parent document to get the final document
const finalDocument = apply(baseDocument, diffs)Community
We are API nerds. You too? Let's chat on Discord: https://discord.gg/scalar
License
The source code in this repository is licensed under MIT.
