0.0.1 • Published 8 years ago

jsonschema-v54-constant v0.0.1

Weekly downloads
1
License
MIT
Repository
github
Last release
8 years ago

jsonschema-v54-constant

Downgrade json-schema v5 string and number constants to v4 constructs

See constant (v5 proposal).

Usage

var constant54 = require('jsonschema-v54-constant');
obj = { type: "object", items: { "constant": "1" } }
constant54(obj); // Modifies **in-place**!
console.log(JSON.stringify(obj));
// {"type":"object","items":{"type":"string","enum":["1"]}}

Algorithm

Matching

  • Walk an object
    • If key is constant and
      • sibling is type (schemaType) or
      • parent is one of items, additionalItems, not or
      • grandParent is one of properties, additionalProperties then

String constant

{constant: "foo"}
==>
{type: "string", enum: ["foo"]}

Number constant

{constant: 42}
==>
{type: "number", min: 42, max: 42}