0.0.1 • Published 8 years ago
jsonschema-v54-constant v0.0.1
jsonschema-v54-constant
Downgrade json-schema v5 string and number constants to v4 constructs
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- schemaType defaults to
typeof value
- If schemaType is
object
- throw Exception Unsupported
- If schemaType is
string
- If schemaType is
number
- schemaType defaults to
- sibling is
- If key is
String constant
{constant: "foo"}
==>
{type: "string", enum: ["foo"]}
Number constant
{constant: 42}
==>
{type: "number", min: 42, max: 42}
0.0.1
8 years ago