Skip to content

Check to see if input of one JSON schema will be valid according to another schema

License

Notifications You must be signed in to change notification settings

haggholm/is-json-schema-subset

Repository files navigation

Build Status Greenkeeper badge Coverage Status

is-json-schema-subset

Check if a JSON schema is a subset of another

Given a schema defining the output of some process A, and a second schema defining the input of some process B, will the output from A be valid input for process B?

Uses ajv and json-schema-merge-allof.

Usage

import isJsonSchemaSubset from 'is-json-schema-subset';

import inputSchema from './input-schema.json';
import outputSchema from './output-schema.json';

async function check() {
	if (await isJsonSchemaSubset(inputSchema, outputSchema)) {
		console.log('OK');
	} else {
		console.log('Fail');
	}
}

API

import isJsonSchemaSubset from 'is-json-schema-subset';

isJsonSchemaSubset(subset: JSONSchema, superset: JSONSchema[, allowPartial: boolean = false])

Returns a promise resolving to true if subset is a compatible subset of superset, else false.

If allowPartial is false, subset must provide all required properties for superset.

Install

$ yarn add is-json-schema-subset

Debugging

DEBUG=is-json-schema-subset ...

License

MIT

About

Check to see if input of one JSON schema will be valid according to another schema

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Contributors 4

  •  
  •  
  •  
  •