Package Exports
- json-schema-specificity
- json-schema-specificity/dist/index.js
This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (json-schema-specificity) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.
Readme
json-schema-specificity
A JavaScript library for comparing JSON Schema specificity. This library helps determine if one JSON schema is more specific than another, meaning that any JSON document that would be validated by the extension schema would also be validated by the original schema.
Installation
npm install json-schema-specificityUsage
import { isMoreSpecific } from 'json-schema-specificity';
const original = {
type: 'object',
properties: {
name: { type: 'string' }
}
};
const extension = {
type: 'object',
properties: {
name: { type: 'string', minLength: 1 }
}
};
const result = isMoreSpecific(original, extension);
// result: true (because extension is more specific than original)API
isMoreSpecific(original, extension)
Determines if the extension schema is more specific than the original schema.
Parameters
original(Object): The original JSON schemaextension(Object): The extension JSON schema to compare
Returns
boolean: Returnstrueif the extension schema is more specific than the original schema,falseotherwise.
Features
- Supports JSON Schema Draft-07
- Handles various schema keywords:
- Type compatibility (including number/integer relationships)
- Required properties
- Property constraints
- Numeric constraints (minimum, maximum, multipleOf)
- String constraints (minLength, maxLength, pattern)
- Array constraints (minItems, maxItems, uniqueItems)
- Enum values
- Const values
- Additional properties
Examples
Type Compatibility
isMoreSpecific(
{ type: 'number' },
{ type: 'integer' }
); // trueNumeric Constraints
isMoreSpecific(
{ type: 'number', minimum: 0, maximum: 100 },
{ type: 'number', minimum: 10, maximum: 50 }
); // trueArray Constraints
isMoreSpecific(
{ type: 'array', items: { type: 'string' }, maxItems: 5 },
{ type: 'array', items: { type: 'string' }, minItems: 1, maxItems: 3 }
); // trueLicense
ISC
Contributing
Contributions are welcome! Please feel free to submit a Pull Request.