jsonschema-v54-constant
Downgrade json-schema v5 string and number constants to v4 constructs
Usage
var constant54 = ;obj = type: "object" items: "constant": "1" ; // Modifies **in-place**!console;// {"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