Registry / devops / json-schema-merge-allof

json-schema-merge-allof

JSON →
library0.8.1jsnpmunverified

Safely merge JSON Schema allOf compositions into a single, readable schema by resolving logical intersections and conflicts. v0.8.1 supports most JSON Schema core/validation keywords (v6), correctly handles additionalProperties, patternProperties, items, and dependencies. Unlike simple schema merging tools, it throws on logical impossibilities and uses keyword-specific resolution (intersection, union, min/max) to preserve validation semantics. Stable with low release cadence. Suitable for schema authors who want to eliminate allOf from their schemas without changing validation behavior. Supports pluggable resolvers for custom keywords. Node.js >=12.0.0 required.

npm install json-schema-merge-allof
INSTALL
IMPORT
SIG · JSON-SCHEMA-MERGE-
J
json-schema-merge-allof
devopsjavascriptv0.8.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
import mergeAllOf from 'json-schema-merge-allof'
const mergeAllOf = require('json-schema-merge-allof')
ESM default export since v0.7.0. For CommonJS use `const mergeAllOf = require('json-schema-merge-allof').default`.
mergeAllOf
const mergeAllOf = require('json-schema-merge-allof')
const { mergeAllOf } = require('json-schema-merge-allof')
CJS default export, not named. Destructuring will give undefined.
mergeAllOf.Options
import mergeAllOf from 'json-schema-merge-allof'; const options: mergeAllOf.Options = { ignoreAdditionalProperties: true }
import { Options } from 'json-schema-merge-allof'
Options type is exported as a property of the default export; not a separate named export.

Merges an allOf array with a root schema, combining properties and required fields while honoring additionalProperties: false.

import mergeAllOf from 'json-schema-merge-allof'; const schema = { type: 'object', properties: { name: { type: 'string' } }, allOf: [ { properties: { age: { type: 'integer' } }, required: ['age'] }, { additionalProperties: false } ] }; try { const merged = mergeAllOf(schema); console.log(JSON.stringify(merged, null, 2)); } catch (error) { console.error('Merge failed:', error.message); }
Debug
Known issues
breakingDefault export changed from a named function to a default export in v0.7.0. Using require('...') without .default in ESM will fail.
fix
Use `import mergeAllOf from 'json-schema-merge-allof'` or in CJS: `const mergeAllOf = require('json-schema-merge-allof').default`.
affects: >=0.7.0
gotchaMerging schemas with `additionalProperties: false` in one of the allOf members will cause an error by default (logical impossibility). Use `ignoreAdditionalProperties: true` option to override, but be aware the result will be less restrictive.
fix
Call `mergeAllOf(schema, { ignoreAdditionalProperties: true })` to allow merging even when additionalProperties is false.
affects: >=0.1.0
deprecatedOptions object previously accepted `resolvers` as a direct property; in v0.6.0+ it should be passed as `customResolvers`.
fix
Use `mergeAllOf(schema, { customResolvers: { myKeyword: resolverFunction } })` instead of `{ resolvers: ... }`.
affects: >=0.6.0
gotchaThe library assumes all input schemas are valid JSON Schema (draft-06+). Using draft-04 or older keywords like `extends` may not merge correctly.
fix
Ensure your schema is compliant with draft-06 or later, or provide custom resolvers for non-standard keywords.
affects: >=0.1.0
gotchaIf the allOf array contains contradictory constraints (e.g., type: 'string' and type: 'number') the merge will throw an error because no logical intersection exists.
fix
Review your schema for logical contradictions that would yield an empty intersection.
affects: >=0.1.0
Errors
Common errors & fixes
TypeError: mergeAllOf is not a function
Using CommonJS require without .default when the library is ESM-only in newer versions.
fix
Change to `const mergeAllOf = require('json-schema-merge-allof').default;` or switch to ESM `import`.
Error: Can not merge schemas with different additionalProperties values: false vs ...
One allOf member has `additionalProperties: false` while another defines `properties` or `additionalProperties` with object.
fix
Use the `ignoreAdditionalProperties: true` option, or ensure all allOf members have compatible additionalProperties settings.
Error: No intersection found for keyword type between ["object"] and ["array"]
Contradictory type constraints in allOf members (e.g., object vs array).
fix
Remove or adjust the type constraints in the allOf members to have a common type.
mergeAllOf(...) is not a function (TypeError)
Importing as named export `{ mergeAllOf }` instead of default import.
fix
Use default import: `import mergeAllOf from 'json-schema-merge-allof'`.
Upgrade
Version history
0.8.1latest on npm
Audit
Dependencies
json-schema-resolve-allofoptionalUsed internally for resolving allOf references; not required by end users.
Agent activity
10 hits · last 30 days
node
8
Resources
json-schema-merge-allof — npm install json-schema-merge-allof · libregistry