diff --git a/src/cli.js b/src/cli.js index 1b69c6d..0360064 100644 --- a/src/cli.js +++ b/src/cli.js @@ -16,16 +16,22 @@ function run(path: string) { } try { + const [indent, width] = [4, 80]; const {types, schema} = collect(path); - const output = yaml.dump(types, null, null, { - indent: 4, - width: 80, + const typesOutput = yaml.dump(types, null, null, { + indent, + width, + }).trimRight(); + + const schemaOutput = stringifyJson(schema, { + indent, + maxLength: width, }); - console.log(output.trimRight()); + console.log(typesOutput); console.log('--------'); - console.log(stringifyJson(schema, {maxLength: 80})); + console.log(schemaOutput); } catch (ex) { console.error(ex.message); console.error(ex.stack); diff --git a/tests/run.js b/tests/run.js index 7bd917a..d5c58f2 100644 --- a/tests/run.js +++ b/tests/run.js @@ -8,12 +8,13 @@ import Ajv from 'ajv'; import collect from '../src'; function run(title) { - let actual, expected; + let actual, expectedTypes, expectedSchema; // Run the collector only if the suite will be checked. before(() => { actual = collect(title + '/source.js'); - expected = yaml.load(fs.readFileSync(title + '/types.yaml', 'utf8')); + expectedTypes = yaml.load(fs.readFileSync(title + '/types.yaml', 'utf8')); + expectedSchema = JSON.parse(fs.readFileSync(title + '/schema.json', 'utf8')); }); it('should not include cycles', () => { @@ -21,7 +22,7 @@ function run(title) { }); it('should provide expected types', () => { - assert.deepEqual(actual.types, expected); + assert.deepEqual(actual.types, expectedTypes); }); it('should generate valid JSON schema', () => { @@ -31,6 +32,10 @@ function run(title) { assert.equal(ajv.errors, null); }); + + it('should provide expected JSON schema', () => { + assert.deepEqual(actual.schema, expectedSchema); + }); } function detectCycles(obj: mixed, cycles: Set = new Set, objs: Set = new Set) { diff --git a/tests/samples/all/schema.json b/tests/samples/all/schema.json new file mode 100644 index 0000000..577af0c --- /dev/null +++ b/tests/samples/all/schema.json @@ -0,0 +1,44 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "all::A": { + "type": "object", + "properties": {"a": {"type": "number"}}, + "required": ["a"] + }, + "all::B": { + "type": "object", + "properties": {"b": {"type": "string"}}, + "required": ["b"] + }, + "all::X": { + "allOf": [ + {"$ref": "#/definitions/all::A"}, + {"$ref": "#/definitions/all::B"} + ] + }, + "all::C": { + "type": "object", + "properties": {"c": {"type": "boolean"}}, + "required": ["c"] + }, + "all::Y": { + "type": "object", + "properties": { + "y": { + "allOf": [ + {"$ref": "#/definitions/all::A"}, + {"$ref": "#/definitions/all::B"}, + {"$ref": "#/definitions/all::C"} + ] + } + }, + "required": ["y"] + }, + "all::Z": { + "type": "object", + "properties": {"z": {"$ref": "#/definitions/all::A"}}, + "required": ["z"] + } + } +} diff --git a/tests/samples/any/schema.json b/tests/samples/any/schema.json new file mode 100644 index 0000000..078c66e --- /dev/null +++ b/tests/samples/any/schema.json @@ -0,0 +1,11 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "any::X": true, + "any::Y": { + "type": "object", + "properties": {"y": true}, + "required": ["y"] + } + } +} diff --git a/tests/samples/arrays/schema.json b/tests/samples/arrays/schema.json new file mode 100644 index 0000000..fba37d7 --- /dev/null +++ b/tests/samples/arrays/schema.json @@ -0,0 +1,32 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "arrays::Type": { + "type": "object", + "properties": { + "a": {"type": "array", "items": {"type": "string"}}, + "b": {"type": "array", "items": {"type": "string"}}, + "c": {"type": "array", "items": {"type": "string"}} + }, + "required": ["a", "b", "c"] + }, + "arrays::Interface": { + "type": "object", + "properties": { + "a": {"type": "array", "items": {"type": "string"}}, + "b": {"type": "array", "items": {"type": "string"}}, + "c": {"type": "array", "items": {"type": "string"}} + }, + "required": ["a", "b", "c"] + }, + "arrays::Class": { + "type": "object", + "properties": { + "a": {"type": "array", "items": {"type": "string"}}, + "b": {"type": "array", "items": {"type": "string"}}, + "c": {"type": "array", "items": {"type": "string"}} + }, + "required": ["a", "b", "c"] + } + } +} diff --git a/tests/samples/declare/schema.json b/tests/samples/declare/schema.json new file mode 100644 index 0000000..a65b7b7 --- /dev/null +++ b/tests/samples/declare/schema.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "declare::Type": { + "type": "object", + "properties": {"a": {"type": "string"}}, + "required": ["a"] + }, + "declare::Interface": { + "type": "object", + "properties": {"a": {"$ref": "#/definitions/declare::Type"}}, + "required": ["a"] + }, + "declare::Class": { + "type": "object", + "properties": {"a": {"$ref": "#/definitions/declare::Interface"}}, + "required": ["a"] + } + } +} diff --git a/tests/samples/diffs/schema.json b/tests/samples/diffs/schema.json new file mode 100644 index 0000000..ead58dc --- /dev/null +++ b/tests/samples/diffs/schema.json @@ -0,0 +1,25 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "diffs::A": { + "type": "object", + "properties": {"x": {"type": "string"}, "y": {"type": "boolean"}}, + "required": ["x", "y"] + }, + "diffs::B": { + "type": "object", + "properties": {"y": {"type": "boolean"}}, + "required": ["y"] + }, + "diffs::X": { + "type": "object", + "properties": {"x": {"type": "string"}}, + "required": ["x"] + }, + "diffs::Y": { + "type": "object", + "properties": {"y": {"type": "boolean"}}, + "required": ["y"] + } + } +} diff --git a/tests/samples/disorder/schema.json b/tests/samples/disorder/schema.json new file mode 100644 index 0000000..a6b1eef --- /dev/null +++ b/tests/samples/disorder/schema.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "disorder::Z": {"type": "string"}, + "disorder::Y": { + "type": "object", + "properties": {"z": {"$ref": "#/definitions/disorder::Z"}}, + "required": ["z"] + }, + "disorder::X": { + "type": "object", + "properties": {"y": {"$ref": "#/definitions/disorder::Y"}}, + "required": ["y"] + } + } +} diff --git a/tests/samples/either/schema.json b/tests/samples/either/schema.json new file mode 100644 index 0000000..94d1ca9 --- /dev/null +++ b/tests/samples/either/schema.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "either::Type": { + "type": "object", + "properties": { + "a": {"anyOf": [{"type": "string"}, {"type": "boolean"}]} + }, + "required": ["a"] + }, + "either::Interface": { + "type": "object", + "properties": { + "a": { + "anyOf": [ + {"type": "string"}, + {"type": "boolean"}, + {"type": "number"} + ] + } + }, + "required": ["a"] + }, + "either::Class": { + "type": "object", + "properties": {"a": {"type": "string"}}, + "required": ["a"] + } + } +} diff --git a/tests/samples/elementType/schema.json b/tests/samples/elementType/schema.json new file mode 100644 index 0000000..78801c2 --- /dev/null +++ b/tests/samples/elementType/schema.json @@ -0,0 +1,22 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "elementType::X::boolean": { + "type": "object", + "properties": { + "x": {"anyOf": [{"type": "boolean"}, {"type": "string"}]} + }, + "required": ["x"] + }, + "elementType::P": {"const": "x"}, + "elementType::Y::x": { + "type": "object", + "properties": { + "y": {"anyOf": [{"type": "boolean"}, {"type": "string"}]}, + "yy": {"anyOf": [{"type": "boolean"}, {"type": "string"}]} + }, + "required": ["y", "yy"] + }, + "elementType::Z": {"anyOf": [{"type": "boolean"}, {"type": "string"}]} + } +} diff --git a/tests/samples/empty/schema.json b/tests/samples/empty/schema.json new file mode 100644 index 0000000..3170a1f --- /dev/null +++ b/tests/samples/empty/schema.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": {} +} diff --git a/tests/samples/enums/schema.json b/tests/samples/enums/schema.json new file mode 100644 index 0000000..6913012 --- /dev/null +++ b/tests/samples/enums/schema.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "enums::Type": { + "type": "object", + "properties": {"a": {"enum": ["one", "two"]}}, + "required": ["a"] + }, + "enums::Interface": { + "type": "object", + "properties": {"a": {"enum": ["one", "two"]}}, + "required": ["a"] + }, + "enums::Class": { + "type": "object", + "properties": {"a": {"enum": ["one", "two"]}}, + "required": ["a"] + } + } +} diff --git a/tests/samples/exact/schema.json b/tests/samples/exact/schema.json new file mode 100644 index 0000000..4c9d72d --- /dev/null +++ b/tests/samples/exact/schema.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "exact::X": { + "type": "object", + "properties": {"x": {"type": "string"}, "y": {"type": "boolean"}}, + "required": ["x", "y"] + }, + "exact::Y": {"$ref": "#/definitions/exact::X"}, + "exact::Z": { + "type": "object", + "properties": {"z": {"type": "string"}}, + "required": ["z"] + } + } +} diff --git a/tests/samples/externals/schema.json b/tests/samples/externals/schema.json new file mode 100644 index 0000000..b428362 --- /dev/null +++ b/tests/samples/externals/schema.json @@ -0,0 +1,65 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "externals::modules::first::A": { + "type": "object", + "properties": {"a": {"type": "boolean"}}, + "required": ["a"] + }, + "externals::modules::first::B": { + "type": "object", + "properties": {"b": {"type": "string"}}, + "required": ["b"] + }, + "externals::modules::first::CC": { + "type": "object", + "properties": {"c": {"type": "number"}}, + "required": ["c"] + }, + "externals::modules::first::D": { + "type": "object", + "properties": {"d": {"type": "number"}}, + "required": ["d"] + }, + "externals::X": { + "type": "object", + "properties": { + "a": {"$ref": "#/definitions/externals::modules::first::A"}, + "b": {"$ref": "#/definitions/externals::modules::first::B"}, + "c": {"$ref": "#/definitions/externals::modules::first::CC"}, + "d": {"$ref": "#/definitions/externals::modules::first::D"} + }, + "required": ["a", "b", "c", "d"] + }, + "externals::modules::second::N": { + "type": "object", + "properties": {"n": {"type": "boolean"}}, + "required": ["n"] + }, + "externals::modules::second::M": { + "type": "object", + "properties": {"m": {"type": "string"}}, + "required": ["m"] + }, + "externals::modules::second::KK": { + "type": "object", + "properties": {"k": {"type": "number"}}, + "required": ["k"] + }, + "externals::modules::second::P": { + "type": "object", + "properties": {"p": {"type": "number"}}, + "required": ["p"] + }, + "externals::Y": { + "type": "object", + "properties": { + "n": {"$ref": "#/definitions/externals::modules::second::N"}, + "m": {"$ref": "#/definitions/externals::modules::second::M"}, + "k": {"$ref": "#/definitions/externals::modules::second::KK"}, + "p": {"$ref": "#/definitions/externals::modules::second::P"} + }, + "required": ["n", "m", "k", "p"] + } + } +} diff --git a/tests/samples/generics/schema.json b/tests/samples/generics/schema.json new file mode 100644 index 0000000..777cec0 --- /dev/null +++ b/tests/samples/generics/schema.json @@ -0,0 +1,30 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "generics::A::string::boolean": { + "type": "object", + "properties": {"t": {"type": "string"}, "k": {"type": "boolean"}}, + "required": ["t", "k"] + }, + "generics::X": { + "type": "object", + "properties": { + "a": {"$ref": "#/definitions/generics::A::string::boolean"} + }, + "required": ["a"] + }, + "generics::A::f64::X": { + "type": "object", + "properties": { + "t": {"type": "number"}, + "k": {"$ref": "#/definitions/generics::X"} + }, + "required": ["t", "k"] + }, + "generics::Y": { + "type": "object", + "properties": {"a": {"$ref": "#/definitions/generics::A::f64::X"}}, + "required": ["a"] + } + } +} diff --git a/tests/samples/inheritance/schema.json b/tests/samples/inheritance/schema.json new file mode 100644 index 0000000..cc88bb2 --- /dev/null +++ b/tests/samples/inheritance/schema.json @@ -0,0 +1,55 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "inheritance::A": { + "type": "object", + "properties": {"a": {"type": "number"}}, + "required": ["a"] + }, + "inheritance::B": { + "allOf": [ + {"$ref": "#/definitions/inheritance::A"}, + { + "type": "object", + "properties": {"b": {"type": "string"}}, + "required": ["b"] + } + ] + }, + "inheritance::C": { + "allOf": [ + {"$ref": "#/definitions/inheritance::B"}, + { + "type": "object", + "properties": {"c": {"type": "boolean"}}, + "required": ["c"] + } + ] + }, + "inheritance::X": { + "type": "object", + "properties": {"x": {"type": "number"}}, + "required": ["x"] + }, + "inheritance::Y": { + "allOf": [ + {"$ref": "#/definitions/inheritance::X"}, + { + "type": "object", + "properties": {"y": {"type": "string"}}, + "required": ["y"] + } + ] + }, + "inheritance::Z": { + "allOf": [ + {"$ref": "#/definitions/inheritance::Y"}, + { + "type": "object", + "properties": {"z": {"type": "boolean"}}, + "required": ["z"] + } + ] + } + } +} diff --git a/tests/samples/intersections/schema.json b/tests/samples/intersections/schema.json new file mode 100644 index 0000000..94c3fa7 --- /dev/null +++ b/tests/samples/intersections/schema.json @@ -0,0 +1,51 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "intersections::A": { + "type": "object", + "properties": {"a": {"type": "number"}}, + "required": ["a"] + }, + "intersections::B": { + "type": "object", + "properties": {"b": {"type": "string"}}, + "required": ["b"] + }, + "intersections::X": { + "allOf": [ + {"$ref": "#/definitions/intersections::A"}, + {"$ref": "#/definitions/intersections::B"} + ] + }, + "intersections::C": { + "type": "object", + "properties": {"c": {"type": "boolean"}}, + "required": ["c"] + }, + "intersections::Y": { + "type": "object", + "properties": { + "y": { + "allOf": [ + {"$ref": "#/definitions/intersections::A"}, + {"$ref": "#/definitions/intersections::B"}, + {"$ref": "#/definitions/intersections::C"} + ] + } + }, + "required": ["y"] + }, + "intersections::Z": { + "type": "object", + "properties": { + "z": { + "allOf": [ + {"$ref": "#/definitions/intersections::A"}, + {"$ref": "#/definitions/intersections::C"} + ] + } + }, + "required": ["z"] + } + } +} diff --git a/tests/samples/keys/schema.json b/tests/samples/keys/schema.json new file mode 100644 index 0000000..06b010f --- /dev/null +++ b/tests/samples/keys/schema.json @@ -0,0 +1,11 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "keys::X": { + "type": "object", + "properties": {"a": {"type": "string"}, "b": {"type": "boolean"}}, + "required": ["a", "b"] + }, + "keys::Y": {"enum": ["a", "b"]} + } +} diff --git a/tests/samples/maps/schema.json b/tests/samples/maps/schema.json new file mode 100644 index 0000000..32cf48a --- /dev/null +++ b/tests/samples/maps/schema.json @@ -0,0 +1,29 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "maps::Type": { + "type": "object", + "additionalProperties": {"type": "boolean"} + }, + "maps::Interface": { + "type": "object", + "additionalProperties": {"type": "boolean"} + }, + "maps::Couple": { + "allOf": [ + {"type": "object", "additionalProperties": {"type": "boolean"}}, + {"type": "object", "additionalProperties": {"type": "string"}} + ] + }, + "maps::Mix": { + "allOf": [ + { + "type": "object", + "properties": {"foo": {"type": "string"}}, + "required": ["foo"] + }, + {"type": "object", "additionalProperties": {"type": "boolean"}} + ] + } + } +} diff --git a/tests/samples/maybe/schema.json b/tests/samples/maybe/schema.json new file mode 100644 index 0000000..bc19eb1 --- /dev/null +++ b/tests/samples/maybe/schema.json @@ -0,0 +1,36 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "maybe::X": { + "type": "object", + "properties": { + "x": {"oneOf": [{"type": "string"}, {"type": "null"}]}, + "xx": {"oneOf": [{"type": "string"}, {"type": "null"}]} + }, + "required": ["x", "xx"] + }, + "maybe::Y": { + "type": "object", + "properties": { + "y": { + "oneOf": [ + {"type": "array", "items": {"type": "string"}}, + {"type": "null"} + ] + }, + "yy": {"oneOf": [{"type": "string"}, {"type": "null"}]} + }, + "required": ["y", "yy"] + }, + "maybe::Z": { + "type": "object", + "properties": { + "z": { + "type": "array", + "items": {"oneOf": [{"type": "string"}, {"type": "null"}]} + } + }, + "required": ["z"] + } + } +} diff --git a/tests/samples/mixed/schema.json b/tests/samples/mixed/schema.json new file mode 100644 index 0000000..d230ad7 --- /dev/null +++ b/tests/samples/mixed/schema.json @@ -0,0 +1,11 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "mixed::X": true, + "mixed::Y": { + "type": "object", + "properties": {"y": true}, + "required": ["y"] + } + } +} diff --git a/tests/samples/nonMaybeType/schema.json b/tests/samples/nonMaybeType/schema.json new file mode 100644 index 0000000..006c91e --- /dev/null +++ b/tests/samples/nonMaybeType/schema.json @@ -0,0 +1,7 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "nonMaybeType::X": {"oneOf": [{"type": "string"}, {"type": "null"}]}, + "nonMaybeType::Y": {"type": "string"} + } +} diff --git a/tests/samples/objects/schema.json b/tests/samples/objects/schema.json new file mode 100644 index 0000000..13c479b --- /dev/null +++ b/tests/samples/objects/schema.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "objects::X": {"type": "object", "additionalProperties": true}, + "objects::Y": { + "type": "object", + "properties": { + "y": {"type": "object", "additionalProperties": true} + }, + "required": ["y"] + }, + "objects::Z": { + "type": "object", + "properties": { + "z": {"type": "object", "additionalProperties": true} + }, + "required": ["z"] + } + } +} diff --git a/tests/samples/optionals/schema.json b/tests/samples/optionals/schema.json new file mode 100644 index 0000000..4e438d2 --- /dev/null +++ b/tests/samples/optionals/schema.json @@ -0,0 +1,13 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "optionals::Type": { + "type": "object", + "properties": {"a": {"type": "string"}} + }, + "optionals::Interface": { + "type": "object", + "properties": {"a": {"type": "boolean"}} + } + } +} diff --git a/tests/samples/pragmas/schema.json b/tests/samples/pragmas/schema.json new file mode 100644 index 0000000..8ebf6b1 --- /dev/null +++ b/tests/samples/pragmas/schema.json @@ -0,0 +1,36 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "pragmas::Type": { + "type": "object", + "properties": { + "a": {"type": "integer"}, + "b": {"type": "integer"}, + "c": {"type": "number"}, + "d": {"type": "number"} + }, + "required": ["a", "b", "c", "d"] + }, + "pragmas::Interface": { + "type": "object", + "properties": { + "a": {"type": "integer"}, + "b": {"type": "integer"}, + "c": {"type": "number"}, + "d": {"type": "number"}, + "e": {"type": "string"} + }, + "required": ["a", "b", "c", "d", "e"] + }, + "pragmas::Class": { + "type": "object", + "properties": { + "a": {"type": "integer"}, + "b": {"type": "integer"}, + "c": {"type": "number"}, + "d": {"type": "number"} + }, + "required": ["a", "b", "c", "d"] + } + } +} diff --git a/tests/samples/primitives/schema.json b/tests/samples/primitives/schema.json new file mode 100644 index 0000000..859fe1c --- /dev/null +++ b/tests/samples/primitives/schema.json @@ -0,0 +1,35 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "primitives::Type": { + "type": "object", + "properties": { + "a": {"type": "string"}, + "b": {"type": "number"}, + "c": {"type": "boolean"}, + "d": {"type": "null"} + }, + "required": ["a", "b", "c", "d"] + }, + "primitives::Interface": { + "type": "object", + "properties": { + "a": {"type": "string"}, + "b": {"type": "number"}, + "c": {"type": "boolean"}, + "d": {"type": "null"} + }, + "required": ["a", "b", "c", "d"] + }, + "primitives::Class": { + "type": "object", + "properties": { + "a": {"type": "string"}, + "b": {"type": "number"}, + "c": {"type": "boolean"}, + "d": {"type": "null"} + }, + "required": ["a", "b", "c", "d"] + } + } +} diff --git a/tests/samples/readOnly/schema.json b/tests/samples/readOnly/schema.json new file mode 100644 index 0000000..f175cd6 --- /dev/null +++ b/tests/samples/readOnly/schema.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "readOnly::X": { + "type": "object", + "properties": {"x": {"type": "string"}, "y": {"type": "boolean"}}, + "required": ["x", "y"] + }, + "readOnly::Y": {"$ref": "#/definitions/readOnly::X"}, + "readOnly::Z": { + "type": "object", + "properties": {"z": {"type": "string"}}, + "required": ["z"] + } + } +} diff --git a/tests/samples/references/schema.json b/tests/samples/references/schema.json new file mode 100644 index 0000000..6a46d0c --- /dev/null +++ b/tests/samples/references/schema.json @@ -0,0 +1,39 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "references::A": {"type": "string"}, + "references::Type": { + "type": "object", + "properties": { + "a": {"$ref": "#/definitions/references::A"}, + "b": { + "type": "array", + "items": {"$ref": "#/definitions/references::A"} + } + }, + "required": ["a", "b"] + }, + "references::Interface": { + "type": "object", + "properties": { + "a": {"$ref": "#/definitions/references::A"}, + "b": { + "type": "array", + "items": {"$ref": "#/definitions/references::A"} + } + }, + "required": ["a", "b"] + }, + "references::Class": { + "type": "object", + "properties": { + "a": {"$ref": "#/definitions/references::A"}, + "b": { + "type": "array", + "items": {"$ref": "#/definitions/references::A"} + } + }, + "required": ["a", "b"] + } + } +} diff --git a/tests/samples/scopes/schema.json b/tests/samples/scopes/schema.json new file mode 100644 index 0000000..861f2a1 --- /dev/null +++ b/tests/samples/scopes/schema.json @@ -0,0 +1,45 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "scopes::2::X": {"type": "boolean"}, + "scopes::1::Z": {"type": "string"}, + "scopes::2::Y": { + "type": "object", + "properties": { + "x": {"$ref": "#/definitions/scopes::2::X"}, + "z": {"$ref": "#/definitions/scopes::1::Z"} + }, + "required": ["x", "z"] + }, + "scopes::3::X": {"type": "number"}, + "scopes::3::Y": { + "type": "object", + "properties": { + "x": {"$ref": "#/definitions/scopes::3::X"}, + "z": {"$ref": "#/definitions/scopes::1::Z"} + }, + "required": ["x", "z"] + }, + "scopes::4::X": {"type": "string"}, + "scopes::4::Y": { + "type": "object", + "properties": { + "x": {"$ref": "#/definitions/scopes::4::X"}, + "z": {"$ref": "#/definitions/scopes::1::Z"} + }, + "required": ["x", "z"] + }, + "scopes::1::X": {"type": "number"}, + "scopes::1::Y": { + "type": "object", + "properties": {"x": {"$ref": "#/definitions/scopes::1::X"}}, + "required": ["x"] + }, + "scopes::X": {"type": "string"}, + "scopes::Y": { + "type": "object", + "properties": {"x": {"$ref": "#/definitions/scopes::X"}}, + "required": ["x"] + } + } +} diff --git a/tests/samples/shadowing/schema.json b/tests/samples/shadowing/schema.json new file mode 100644 index 0000000..af34e20 --- /dev/null +++ b/tests/samples/shadowing/schema.json @@ -0,0 +1,16 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "shadowing::1::Buffer": {"type": "object", "properties": {}}, + "shadowing::1::Y": { + "type": "object", + "properties": {"y": {"$ref": "#/definitions/shadowing::1::Buffer"}}, + "required": ["y"] + }, + "shadowing::X": { + "type": "object", + "properties": {"x": {"$ref": "#/definitions/Buffer"}}, + "required": ["x"] + } + } +} diff --git a/tests/samples/shape/schema.json b/tests/samples/shape/schema.json new file mode 100644 index 0000000..d238c68 --- /dev/null +++ b/tests/samples/shape/schema.json @@ -0,0 +1,14 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "shape::X": { + "type": "object", + "properties": {"x": {"type": "string"}, "y": {"type": "boolean"}}, + "required": ["x", "y"] + }, + "shape::Y": { + "type": "object", + "properties": {"x": {"type": "string"}, "y": {"type": "boolean"}} + } + } +} diff --git a/tests/samples/skipFunctions/schema.json b/tests/samples/skipFunctions/schema.json new file mode 100644 index 0000000..3c798e4 --- /dev/null +++ b/tests/samples/skipFunctions/schema.json @@ -0,0 +1,28 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "skipFunctions::Type": { + "type": "object", + "properties": { + "a": {"type": "string"}, + "b": {"type": "boolean"}, + "c": {"type": "string"} + }, + "required": ["a", "b", "c"] + }, + "skipFunctions::Interface": { + "type": "object", + "properties": { + "a": {"type": "string"}, + "b": {"type": "boolean"}, + "c": {"type": "string"} + }, + "required": ["a", "b", "c"] + }, + "skipFunctions::Class": { + "type": "object", + "properties": {"a": {"type": "string"}, "b": {"type": "boolean"}}, + "required": ["a", "b"] + } + } +} diff --git a/tests/samples/skipStatics/schema.json b/tests/samples/skipStatics/schema.json new file mode 100644 index 0000000..da12a9c --- /dev/null +++ b/tests/samples/skipStatics/schema.json @@ -0,0 +1,10 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "skipStatics::X": { + "type": "object", + "properties": {"xxx": {"type": "string"}}, + "required": ["xxx"] + } + } +} diff --git a/tests/samples/tuples/schema.json b/tests/samples/tuples/schema.json new file mode 100644 index 0000000..8457153 --- /dev/null +++ b/tests/samples/tuples/schema.json @@ -0,0 +1,44 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "tuples::Type": { + "type": "object", + "properties": { + "a": { + "type": "array", + "items": [{"type": "string"}, {"type": "boolean"}] + } + }, + "required": ["a"] + }, + "tuples::Interface": { + "type": "object", + "properties": { + "a": { + "type": "array", + "items": [ + {"type": "string"}, + {"type": "null"}, + {"type": "boolean"} + ] + }, + "b": { + "type": "array", + "items": [ + {"type": "string"}, + {"type": "null"}, + {"type": "boolean"} + ] + } + }, + "required": ["a", "b"] + }, + "tuples::Class": { + "type": "object", + "properties": { + "a": {"type": "array", "items": [{"type": "boolean"}]} + }, + "required": ["a"] + } + } +} diff --git a/tests/samples/typeInMethod/schema.json b/tests/samples/typeInMethod/schema.json new file mode 100644 index 0000000..ef11058 --- /dev/null +++ b/tests/samples/typeInMethod/schema.json @@ -0,0 +1,11 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "typeInMethod::Test": {"type": "object", "properties": {}}, + "typeInMethod::1::X": { + "type": "object", + "properties": {"t": {"$ref": "#/definitions/typeInMethod::Test"}}, + "required": ["t"] + } + } +} diff --git a/tests/samples/unions/schema.json b/tests/samples/unions/schema.json new file mode 100644 index 0000000..fb64e10 --- /dev/null +++ b/tests/samples/unions/schema.json @@ -0,0 +1,32 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "unions::Type": { + "type": "object", + "properties": { + "a": {"anyOf": [{"type": "string"}, {"type": "boolean"}]} + }, + "required": ["a"] + }, + "unions::Interface": { + "type": "object", + "properties": { + "a": { + "anyOf": [ + {"type": "string"}, + {"type": "boolean"}, + {"type": "number"} + ] + } + }, + "required": ["a"] + }, + "unions::Class": { + "type": "object", + "properties": { + "a": {"anyOf": [{"type": "string"}, {"type": "boolean"}]} + }, + "required": ["a"] + } + } +} diff --git a/tests/samples/unionsAndEnums/schema.json b/tests/samples/unionsAndEnums/schema.json new file mode 100644 index 0000000..a3382b2 --- /dev/null +++ b/tests/samples/unionsAndEnums/schema.json @@ -0,0 +1,26 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "unionsAndEnums::Type": { + "type": "object", + "properties": { + "a": {"anyOf": [{"type": "string"}, {"enum": ["one", "two"]}]} + }, + "required": ["a"] + }, + "unionsAndEnums::Interface": { + "type": "object", + "properties": { + "a": {"anyOf": [{"type": "string"}, {"enum": ["one", "two"]}]} + }, + "required": ["a"] + }, + "unionsAndEnums::Class": { + "type": "object", + "properties": { + "a": {"anyOf": [{"type": "string"}, {"enum": ["one", "two"]}]} + }, + "required": ["a"] + } + } +} diff --git a/tests/samples/unused/schema.json b/tests/samples/unused/schema.json new file mode 100644 index 0000000..3170a1f --- /dev/null +++ b/tests/samples/unused/schema.json @@ -0,0 +1,4 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": {} +} diff --git a/tests/samples/valueAsType/schema.json b/tests/samples/valueAsType/schema.json new file mode 100644 index 0000000..c3e7a2c --- /dev/null +++ b/tests/samples/valueAsType/schema.json @@ -0,0 +1,20 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "valueAsType::Type": { + "type": "object", + "properties": {"a": {"const": "one"}}, + "required": ["a"] + }, + "valueAsType::Interface": { + "type": "object", + "properties": {"a": {"const": "one"}}, + "required": ["a"] + }, + "valueAsType::Class": { + "type": "object", + "properties": {"a": {"const": "one"}}, + "required": ["a"] + } + } +} diff --git a/tests/samples/values/schema.json b/tests/samples/values/schema.json new file mode 100644 index 0000000..02e47ae --- /dev/null +++ b/tests/samples/values/schema.json @@ -0,0 +1,11 @@ +{ + "$schema": "http://json-schema.org/draft-06/schema#", + "definitions": { + "values::X": { + "type": "object", + "properties": {"a": {"type": "string"}, "b": {"type": "boolean"}}, + "required": ["a", "b"] + }, + "values::Y": {"anyOf": [{"type": "string"}, {"type": "boolean"}]} + } +}