0.1.0 • Published 9 months ago

json-schema-intersect v0.1.0

Weekly downloads
-
License
MIT
Repository
github
Last release
9 months ago

JSON Schema Intersect

Build Status Coverage Dependency Status Supported Node Version Version on NPM

A library to combine multiple JSON Schemas into a single schema which matches instances which are valid for all of the combined schemas. This is useful for supporting older JSON Schema versions which lack support for allOf, such as JSON Schema Draft 4 used by Swagger/OpenAPI 2. The combined schema behaves as closely as possible to a schema with allOf. containing each of the input schemas.

!IMPORTANT Use allOf to create a combined schema when possible.

Introductory Example

import assert from 'node:assert/strict';
import jsonSchemaIntersect from 'json-schema-intersect';

assert.deepEqual(
  jsonSchemaIntersect(
    {
      type: 'number',
      minimum: 5,
      maximum: 15,
    },
    {
      type: 'number',
      minimum: 0,
      maximum: 10,
    },
  ),
  {
    type: 'number',
    minimum: 5,
    maximum: 10,
  },
);

Features

Installation

This package can be installed using npm, either globally or locally, by running:

npm install json-schema-intersect

Recipes

More examples can be found in the test specifications.

API Docs

To use this module as a library, see the API Documentation.

Contributing

Contributions are appreciated. Contributors agree to abide by the Contributor Covenant Code of Conduct. If this is your first time contributing to a Free and Open Source Software project, consider reading How to Contribute to Open Source in the Open Source Guides.

If the desired change is large, complex, backwards-incompatible, can have significantly differing implementations, or may not be in scope for this project, opening an issue before writing the code can avoid frustration and save a lot of time and effort.

License

This project is available under the terms of the MIT License. See the summary at TLDRLegal.

0.1.0

9 months ago