JSPM

json-schema-specificity

1.0.0
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 5
  • Score
    100M100P100Q30636F
  • License ISC

A library for comparing JSON Schema specificity

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-specificity

Usage

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 schema
  • extension (Object): The extension JSON schema to compare

Returns

  • boolean: Returns true if the extension schema is more specific than the original schema, false otherwise.

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' }
); // true

Numeric Constraints

isMoreSpecific(
  { type: 'number', minimum: 0, maximum: 100 },
  { type: 'number', minimum: 10, maximum: 50 }
); // true

Array Constraints

isMoreSpecific(
  { type: 'array', items: { type: 'string' }, maxItems: 5 },
  { type: 'array', items: { type: 'string' }, minItems: 1, maxItems: 3 }
); // true

License

ISC

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.