@adobe/jsonschema2md 6.1.4 → 7.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/{.eslintrc.js → .eslintrc.cjs} +3 -17
- package/{.releaserc.js → .releaserc.cjs} +0 -0
- package/CHANGELOG.md +41 -0
- package/README.md +1 -1
- package/cli.js +1 -1
- package/lib/formatInfo.js +17 -19
- package/lib/formattingTools.js +6 -8
- package/lib/index.js +176 -81
- package/lib/keywords.js +2 -4
- package/lib/locales/nl-NL.json +182 -0
- package/lib/locales/update.js +2 -2
- package/lib/markdownBuilder.js +62 -44
- package/lib/readmeBuilder.js +15 -15
- package/lib/schemaProxy.js +32 -26
- package/lib/symbols.js +14 -2
- package/lib/traverseSchema.js +5 -5
- package/lib/writeMarkdown.js +87 -41
- package/lib/writeSchema.js +46 -21
- package/package.json +41 -30
- package/types/api.d.ts +72 -0
- package/types/formatInfo.d.ts +19 -0
- package/types/formattingTools.d.ts +2 -0
- package/types/index.d.ts +75 -0
- package/types/keywords.d.ts +2 -0
- package/types/markdownBuilder.d.ts +8 -0
- package/types/readmeBuilder.d.ts +5 -0
- package/types/schemaProxy.d.ts +1 -0
- package/types/symbols.d.ts +11 -0
- package/types/traverseSchema.d.ts +6 -0
- package/types/writeMarkdown.d.ts +56 -0
- package/types/writeSchema.d.ts +19 -0
- package/.circleci/config.yml +0 -83
- package/.github/ISSUE_TEMPLATE/bug_report.md +0 -23
- package/.github/workflows/semantic-release.yaml +0 -55
- package/.github/workflows/semver-check.yaml +0 -16
- package/.renovaterc.json +0 -3
- package/.tidelift.yml +0 -32
- package/crowdin.yml +0 -4
- package/examples/abstract.md +0 -3
- package/examples/docs/README.md +0 -121
- package/examples/docs/abstract-definitions-first-properties-foo.md +0 -15
- package/examples/docs/abstract-definitions-first-properties-nonfoo.md +0 -23
- package/examples/docs/abstract-definitions-first.md +0 -66
- package/examples/docs/abstract-definitions-second-properties-bar.md +0 -15
- package/examples/docs/abstract-definitions-second.md +0 -39
- package/examples/docs/abstract-definitions.md +0 -15
- package/examples/docs/abstract.md +0 -104
- package/examples/docs/arrays-properties-boollist-items.md +0 -15
- package/examples/docs/arrays-properties-boollist.md +0 -19
- package/examples/docs/arrays-properties-coordinatelist-items-items.md +0 -21
- package/examples/docs/arrays-properties-coordinatelist-items.md +0 -21
- package/examples/docs/arrays-properties-coordinatelist.md +0 -19
- package/examples/docs/arrays-properties-intlist-items.md +0 -15
- package/examples/docs/arrays-properties-intlist.md +0 -21
- package/examples/docs/arrays-properties-jointypelist-items-oneof-0-properties-foo.md +0 -21
- package/examples/docs/arrays-properties-jointypelist-items-oneof-0.md +0 -45
- package/examples/docs/arrays-properties-jointypelist-items-oneof-1-properties-bar.md +0 -21
- package/examples/docs/arrays-properties-jointypelist-items-oneof-1.md +0 -45
- package/examples/docs/arrays-properties-jointypelist-items.md +0 -21
- package/examples/docs/arrays-properties-jointypelist.md +0 -15
- package/examples/docs/arrays-properties-list-items.md +0 -15
- package/examples/docs/arrays-properties-list.md +0 -15
- package/examples/docs/arrays-properties-listlist-items.md +0 -15
- package/examples/docs/arrays-properties-listlist.md +0 -15
- package/examples/docs/arrays-properties-numlist-items.md +0 -19
- package/examples/docs/arrays-properties-numlist.md +0 -19
- package/examples/docs/arrays-properties-objectlist-items-properties-a.md +0 -15
- package/examples/docs/arrays-properties-objectlist-items-properties-b.md +0 -15
- package/examples/docs/arrays-properties-objectlist-items.md +0 -58
- package/examples/docs/arrays-properties-objectlist.md +0 -15
- package/examples/docs/arrays-properties-stringlistlist-items-items.md +0 -15
- package/examples/docs/arrays-properties-stringlistlist-items.md +0 -15
- package/examples/docs/arrays-properties-stringlistlist.md +0 -15
- package/examples/docs/arrays-properties-tuple-items-negative-integer.md +0 -19
- package/examples/docs/arrays-properties-tuple-items-positive-integer.md +0 -19
- package/examples/docs/arrays-properties-tuple-zero.md +0 -23
- package/examples/docs/arrays-properties-tuple.md +0 -21
- package/examples/docs/arrays.md +0 -240
- package/examples/docs/complex-additionalproperties.md +0 -15
- package/examples/docs/complex-patternproperties-int.md +0 -15
- package/examples/docs/complex-patternproperties-str.md +0 -15
- package/examples/docs/complex-patternproperties.md +0 -15
- package/examples/docs/complex-properties-and-allof-0.md +0 -19
- package/examples/docs/complex-properties-and-allof-1.md +0 -19
- package/examples/docs/complex-properties-and.md +0 -21
- package/examples/docs/complex-properties-or-anyof-0.md +0 -15
- package/examples/docs/complex-properties-or-anyof-1.md +0 -19
- package/examples/docs/complex-properties-or.md +0 -21
- package/examples/docs/complex-properties-reflocalfiledef.md +0 -39
- package/examples/docs/complex-properties-refnestedobj-properties-refobj.md +0 -39
- package/examples/docs/complex-properties-refnestedobj.md +0 -39
- package/examples/docs/complex-properties-refobj.md +0 -39
- package/examples/docs/complex-properties-xor-oneof-0.md +0 -19
- package/examples/docs/complex-properties-xor-oneof-1.md +0 -19
- package/examples/docs/complex-properties-xor.md +0 -21
- package/examples/docs/complex.md +0 -285
- package/examples/docs/constants-properties-hello.md +0 -23
- package/examples/docs/constants.md +0 -47
- package/examples/docs/custom-allof-0.md +0 -15
- package/examples/docs/custom-allof-1.md +0 -39
- package/examples/docs/custom-allof-2.md +0 -39
- package/examples/docs/custom-definitions-first-properties-foo.md +0 -15
- package/examples/docs/custom-definitions-first-properties.md +0 -15
- package/examples/docs/custom-definitions-first.md +0 -39
- package/examples/docs/custom-definitions-second-properties-bar.md +0 -15
- package/examples/docs/custom-definitions-second-properties.md +0 -15
- package/examples/docs/custom-definitions-second.md +0 -39
- package/examples/docs/custom-definitions.md +0 -15
- package/examples/docs/custom.md +0 -85
- package/examples/docs/deepextending-allof-0.md +0 -49
- package/examples/docs/deepextending-allof-1.md +0 -89
- package/examples/docs/deepextending-allof-3.md +0 -39
- package/examples/docs/deepextending-definitions-fourth-properties-hey.md +0 -15
- package/examples/docs/deepextending-definitions-fourth-properties.md +0 -15
- package/examples/docs/deepextending-definitions-fourth.md +0 -39
- package/examples/docs/deepextending-definitions.md +0 -15
- package/examples/docs/deepextending.md +0 -57
- package/examples/docs/definitions-definitions-myid-properties-id-1.md +0 -19
- package/examples/docs/definitions-definitions-myid-properties-id.md +0 -19
- package/examples/docs/definitions-definitions-myid-properties-metaid.md +0 -19
- package/examples/docs/definitions-definitions-myid-properties.md +0 -15
- package/examples/docs/definitions-definitions-myid.md +0 -89
- package/examples/docs/definitions-definitions.md +0 -15
- package/examples/docs/definitions.md +0 -117
- package/examples/docs/enums-properties-enumerated-nested-properties-test.md +0 -25
- package/examples/docs/enums-properties-enumerated-nested.md +0 -49
- package/examples/docs/enums-properties-hello.md +0 -24
- package/examples/docs/enums.md +0 -67
- package/examples/docs/example-properties-bar.md +0 -25
- package/examples/docs/example-properties-foo.md +0 -21
- package/examples/docs/example.md +0 -83
- package/examples/docs/examples-properties-bar.md +0 -25
- package/examples/docs/examples-properties-foo.md +0 -21
- package/examples/docs/examples.md +0 -90
- package/examples/docs/extending-definitions-third-properties-baaaz.md +0 -21
- package/examples/docs/extending-definitions-third.md +0 -45
- package/examples/docs/extending-definitions.md +0 -15
- package/examples/docs/extending.md +0 -61
- package/examples/docs/extensible-definitions-first-properties-foo.md +0 -21
- package/examples/docs/extensible-definitions-first-properties.md +0 -15
- package/examples/docs/extensible-definitions-first.md +0 -45
- package/examples/docs/extensible-definitions-second-properties-bar.md +0 -25
- package/examples/docs/extensible-definitions-second-properties.md +0 -15
- package/examples/docs/extensible-definitions-second.md +0 -49
- package/examples/docs/extensible-definitions.md +0 -15
- package/examples/docs/extensible.md +0 -93
- package/examples/docs/identifiable-properties-id.md +0 -19
- package/examples/docs/identifiable.md +0 -43
- package/examples/docs/join-oneof-0-not-oneof-0-properties-foo.md +0 -21
- package/examples/docs/join-oneof-0-not-oneof-0.md +0 -45
- package/examples/docs/join-oneof-0-not-oneof-1-properties-bar.md +0 -21
- package/examples/docs/join-oneof-0-not-oneof-1.md +0 -45
- package/examples/docs/join-oneof-0-not.md +0 -21
- package/examples/docs/join-oneof-0.md +0 -23
- package/examples/docs/join-oneof-1-allof-0-properties-foo.md +0 -21
- package/examples/docs/join-oneof-1-allof-0.md +0 -45
- package/examples/docs/join-oneof-1.md +0 -19
- package/examples/docs/join-oneof-2-anyof-0-properties-bar.md +0 -21
- package/examples/docs/join-oneof-2-anyof-0.md +0 -45
- package/examples/docs/join-oneof-2.md +0 -19
- package/examples/docs/join.md +0 -33
- package/examples/docs/nestedobj-properties-settings-properties-collaborators-patternproperties-.md +0 -15
- package/examples/docs/nestedobj-properties-settings-properties-collaborators-patternproperties.md +0 -15
- package/examples/docs/nestedobj-properties-settings-properties-collaborators-properties-id.md +0 -15
- package/examples/docs/nestedobj-properties-settings-properties-collaborators.md +0 -58
- package/examples/docs/nestedobj-properties-settings.md +0 -39
- package/examples/docs/nestedobj.md +0 -39
- package/examples/docs/pattern-patternproperties-0-9.md +0 -21
- package/examples/docs/pattern-patternproperties.md +0 -15
- package/examples/docs/pattern.md +0 -45
- package/examples/docs/simple-properties-id.md +0 -19
- package/examples/docs/simple.md +0 -43
- package/examples/docs/simpletypes-properties-integer_threes.md +0 -23
- package/examples/docs/simpletypes-properties-interger_constrained.md +0 -19
- package/examples/docs/simpletypes-properties-interger_unconstrained.md +0 -15
- package/examples/docs/simpletypes-properties-number_constrained.md +0 -19
- package/examples/docs/simpletypes-properties-number_unconstrained.md +0 -15
- package/examples/docs/simpletypes-properties-string_date.md +0 -19
- package/examples/docs/simpletypes-properties-string_email.md +0 -19
- package/examples/docs/simpletypes-properties-string_hostname.md +0 -19
- package/examples/docs/simpletypes-properties-string_ipv4.md +0 -19
- package/examples/docs/simpletypes-properties-string_ipv6.md +0 -19
- package/examples/docs/simpletypes-properties-string_length.md +0 -31
- package/examples/docs/simpletypes-properties-string_pattern-metaenum.md +0 -15
- package/examples/docs/simpletypes-properties-string_pattern.md +0 -39
- package/examples/docs/simpletypes-properties-string_pattern_noexample.md +0 -25
- package/examples/docs/simpletypes-properties-string_pattern_singleexample.md +0 -31
- package/examples/docs/simpletypes-properties-string_unconstrained.md +0 -21
- package/examples/docs/simpletypes-properties-string_uri.md +0 -19
- package/examples/docs/simpletypes-properties-yesno.md +0 -15
- package/examples/docs/simpletypes.md +0 -455
- package/examples/docs/stabilizing-properties-id.md +0 -19
- package/examples/docs/stabilizing.md +0 -43
- package/examples/docs/subdir-allof-0.md +0 -43
- package/examples/docs/subdir-definitions-content-properties-id.md +0 -19
- package/examples/docs/subdir-definitions-content-properties.md +0 -15
- package/examples/docs/subdir-definitions-content.md +0 -43
- package/examples/docs/subdir-definitions.md +0 -15
- package/examples/docs/subdir.md +0 -55
- package/examples/docs/typearrays-properties-null.md +0 -15
- package/examples/docs/typearrays-properties-string-or-null.md +0 -15
- package/examples/docs/typearrays-properties-string-or-number-null.md +0 -15
- package/examples/docs/typearrays-properties-string-or-number.md +0 -15
- package/examples/docs/typearrays.md +0 -96
- package/examples/docsWithoutHeader/arrays.schema.md +0 -254
- package/examples/generated-schemas/abstract.schema.json +0 -1
- package/examples/generated-schemas/arrays.schema.json +0 -1
- package/examples/generated-schemas/complex.schema.json +0 -1
- package/examples/generated-schemas/constants.schema.json +0 -1
- package/examples/generated-schemas/custom.schema.json +0 -1
- package/examples/generated-schemas/deepextending.schema.json +0 -1
- package/examples/generated-schemas/definitions.schema.json +0 -1
- package/examples/generated-schemas/enums.schema.json +0 -1
- package/examples/generated-schemas/example.schema.json +0 -1
- package/examples/generated-schemas/examples.schema.json +0 -1
- package/examples/generated-schemas/extending.schema.json +0 -1
- package/examples/generated-schemas/extensible.schema.json +0 -1
- package/examples/generated-schemas/identifiable.schema.json +0 -1
- package/examples/generated-schemas/join.schema.json +0 -1
- package/examples/generated-schemas/nestedobj.schema.json +0 -1
- package/examples/generated-schemas/pattern.schema.json +0 -1
- package/examples/generated-schemas/simple.schema.json +0 -1
- package/examples/generated-schemas/simpletypes.schema.json +0 -1
- package/examples/generated-schemas/stabilizing.schema.json +0 -1
- package/examples/generated-schemas/subdir/subdir.schema.json +0 -1
- package/examples/generated-schemas/typearrays.schema.json +0 -1
- package/examples/schemas/abstract.schema.json +0 -44
- package/examples/schemas/arrays.schema.json +0 -185
- package/examples/schemas/complex.schema.json +0 -123
- package/examples/schemas/constants.schema.json +0 -25
- package/examples/schemas/custom.schema.json +0 -41
- package/examples/schemas/deepextending.schema.json +0 -37
- package/examples/schemas/definitions.description.md +0 -17
- package/examples/schemas/definitions.schema.json +0 -46
- package/examples/schemas/enums.schema.json +0 -42
- package/examples/schemas/example.example.1.json +0 -4
- package/examples/schemas/example.schema.json +0 -29
- package/examples/schemas/examples.example.1.json +0 -4
- package/examples/schemas/examples.example.2.json +0 -4
- package/examples/schemas/examples.schema.json +0 -32
- package/examples/schemas/extending.schema.json +0 -38
- package/examples/schemas/extensible.schema.json +0 -38
- package/examples/schemas/identifiable.schema.json +0 -22
- package/examples/schemas/join.schema.json +0 -88
- package/examples/schemas/nestedobj.schema.json +0 -35
- package/examples/schemas/pattern.schema.json +0 -21
- package/examples/schemas/simple.schema.json +0 -22
- package/examples/schemas/simpletypes.schema.json +0 -151
- package/examples/schemas/stabilizing.schema.json +0 -23
- package/examples/schemas/subdir/subdir.schema.json +0 -29
- package/examples/schemas/typearrays.schema.json +0 -39
- package/examples/status.md +0 -3
- package/test/api.test.js +0 -55
- package/test/cyclicSchemaIntegration.test.js +0 -87
- package/test/fixtures/additionalprops/additionalprops.schema.json +0 -6
- package/test/fixtures/additionalprops/arrays.schema.json +0 -9
- package/test/fixtures/arrays/arrays.schema.json +0 -201
- package/test/fixtures/arrays/tuple.schema.json +0 -35
- package/test/fixtures/content/html.schema.json +0 -5
- package/test/fixtures/content/jwt.schema.json +0 -26
- package/test/fixtures/content/png.schema.json +0 -6
- package/test/fixtures/cyclic/one.description.md +0 -1
- package/test/fixtures/cyclic/one.example.1.json +0 -1
- package/test/fixtures/cyclic/one.schema.json +0 -17
- package/test/fixtures/cyclic/three.schema.json +0 -17
- package/test/fixtures/cyclic/two.schema.json +0 -17
- package/test/fixtures/deadref/deadref.schema.json +0 -6
- package/test/fixtures/enums/arrayenums.schema.json +0 -29
- package/test/fixtures/enums/enums.schema.json +0 -29
- package/test/fixtures/example/example.schema.json +0 -52
- package/test/fixtures/format/format.schema.json +0 -25
- package/test/fixtures/identifiable/identifiable.schema.json +0 -22
- package/test/fixtures/not/not.schema.json +0 -7
- package/test/fixtures/null/null.schema.json +0 -14
- package/test/fixtures/nullable/array.schema.json +0 -17
- package/test/fixtures/readme-1/abstract.schema.json +0 -50
- package/test/fixtures/readme-1/complex.schema.json +0 -118
- package/test/fixtures/readme-1/simple.schema.json +0 -30
- package/test/fixtures/skipproperties/complete.schema.json +0 -29
- package/test/fixtures/stringformats/simpletypes.schema.json +0 -211
- package/test/fixtures/title/meta.schema.json +0 -53
- package/test/fixtures/type/button.schema.json +0 -28
- package/test/fixtures/type/type.schema.json +0 -20
- package/test/fixtures/types/merged.schema.json +0 -10
- package/test/fixtures/types/object.schema.json +0 -3
- package/test/fixtures/types/objectorarray.schema.json +0 -3
- package/test/fixtures/types/undefined.schema.json +0 -3
- package/test/fixtures/types/wrong.schema.json +0 -6
- package/test/formatting.test.js +0 -59
- package/test/markdownBuilder.test.js +0 -441
- package/test/readmeBuilder.test.js +0 -106
- package/test/schemaProxy.test.js +0 -187
- package/test/testUtils.js +0 -88
- package/test/testintegration.test.js +0 -65
- package/test/traverseSchema.test.js +0 -111
- package/test/zSchemaCoverage.test.js +0 -186
package/test/schemaProxy.test.js
DELETED
|
@@ -1,187 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2019 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
/* eslint-env mocha */
|
|
13
|
-
|
|
14
|
-
const assert = require('assert');
|
|
15
|
-
const path = require('path');
|
|
16
|
-
const {
|
|
17
|
-
loader, pointer, filename, id, titles, resolve, slug, meta,
|
|
18
|
-
} = require('../lib/schemaProxy');
|
|
19
|
-
|
|
20
|
-
const example = require('./fixtures/example/example.schema.json');
|
|
21
|
-
|
|
22
|
-
const referencing = {
|
|
23
|
-
$schema: 'http://json-schema.org/draft-06/schema#',
|
|
24
|
-
$id: 'https://example.com/schemas/referencing',
|
|
25
|
-
title: 'Referencing',
|
|
26
|
-
properties: {
|
|
27
|
-
$ref: 'https://example.com/schemas/example#/properties',
|
|
28
|
-
zap: {
|
|
29
|
-
type: 'boolean',
|
|
30
|
-
},
|
|
31
|
-
},
|
|
32
|
-
};
|
|
33
|
-
|
|
34
|
-
describe('Testing Schema Proxy', () => {
|
|
35
|
-
it('Schema Proxy creates a JSON schema', () => {
|
|
36
|
-
const proxied = loader()(example, 'example.schema.json');
|
|
37
|
-
|
|
38
|
-
assert.equal(proxied.title, 'Example');
|
|
39
|
-
assert.equal(proxied.properties.foo.type, 'string');
|
|
40
|
-
});
|
|
41
|
-
|
|
42
|
-
it('Schema Proxy loads multiple JSON schemas', () => {
|
|
43
|
-
const myloader = loader();
|
|
44
|
-
const proxied1 = myloader(example, 'example.schema.json');
|
|
45
|
-
const proxied2 = myloader(referencing, 'referencing.schema.json');
|
|
46
|
-
|
|
47
|
-
assert.equal(proxied1.title, 'Example');
|
|
48
|
-
assert.equal(proxied2.$id, 'https://example.com/schemas/referencing');
|
|
49
|
-
});
|
|
50
|
-
|
|
51
|
-
it('Schema Proxy creates a JSON schema with Pointers', () => {
|
|
52
|
-
const proxied = loader()(example, 'example.schema.json');
|
|
53
|
-
|
|
54
|
-
assert.equal(proxied[pointer], '');
|
|
55
|
-
assert.equal(proxied.properties[pointer], '/properties');
|
|
56
|
-
assert.equal(proxied.properties.foo[pointer], '/properties/foo');
|
|
57
|
-
assert.equal(proxied['meta:license'][pointer], '/meta:license');
|
|
58
|
-
assert.equal(proxied.properties.baz.anyOf[0][pointer], '/properties/baz/anyOf/0');
|
|
59
|
-
});
|
|
60
|
-
|
|
61
|
-
it('Schema Proxy creates a JSON schema with ID References', () => {
|
|
62
|
-
const proxied = loader()(example, 'example.schema.json');
|
|
63
|
-
|
|
64
|
-
assert.equal(proxied[id], 'https://example.com/schemas/example');
|
|
65
|
-
assert.equal(proxied.properties[pointer], '/properties');
|
|
66
|
-
|
|
67
|
-
assert.equal(proxied.properties[id], 'https://example.com/schemas/example');
|
|
68
|
-
assert.equal(proxied.properties[pointer], '/properties');
|
|
69
|
-
|
|
70
|
-
assert.equal(proxied.properties.foo[id], 'https://example.com/schemas/example');
|
|
71
|
-
assert.equal(proxied['meta:license'][id], 'https://example.com/schemas/example');
|
|
72
|
-
assert.equal(proxied.properties.baz.anyOf[0][id], 'https://example.com/schemas/example');
|
|
73
|
-
});
|
|
74
|
-
|
|
75
|
-
it('Schema Proxy creates a JSON schema with Filename References', () => {
|
|
76
|
-
const proxied = loader()(example, 'example.schema.json');
|
|
77
|
-
|
|
78
|
-
assert.equal(proxied[filename], 'example.schema.json');
|
|
79
|
-
assert.equal(proxied.properties[filename], 'example.schema.json');
|
|
80
|
-
assert.equal(proxied.properties.foo[filename], 'example.schema.json');
|
|
81
|
-
assert.equal(proxied['meta:license'][filename], 'example.schema.json');
|
|
82
|
-
assert.equal(proxied.properties.baz.anyOf[0][filename], 'example.schema.json');
|
|
83
|
-
});
|
|
84
|
-
|
|
85
|
-
it('Schema Proxy creates a JSON schema with title References', () => {
|
|
86
|
-
const proxied = loader()(example, 'example.schema.json');
|
|
87
|
-
|
|
88
|
-
assert.deepStrictEqual(proxied[titles], ['Example']);
|
|
89
|
-
assert.deepStrictEqual(proxied.properties.zip[titles], ['Example', undefined, 'An object']);
|
|
90
|
-
});
|
|
91
|
-
|
|
92
|
-
it('Schema proxy resolves JSON Pointers', () => {
|
|
93
|
-
const myloader = loader();
|
|
94
|
-
const proxied1 = myloader(example, 'example.schema.json');
|
|
95
|
-
|
|
96
|
-
assert.deepStrictEqual(proxied1.properties, proxied1[resolve]('/properties'));
|
|
97
|
-
assert.deepStrictEqual(proxied1.properties.foo, proxied1[resolve]('/properties/foo'));
|
|
98
|
-
assert.deepStrictEqual(proxied1.properties.foo, proxied1.properties[resolve]('/foo'));
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
it('Schema proxy resolves Reference Pointers', () => {
|
|
102
|
-
const myloader = loader();
|
|
103
|
-
myloader(example, 'example.schema.json');
|
|
104
|
-
const proxied2 = myloader(referencing, 'referencing.schema.json');
|
|
105
|
-
|
|
106
|
-
assert.deepStrictEqual(new Set(Object.keys(proxied2.properties)), new Set([
|
|
107
|
-
'$ref', 'zap', // the two properties from the original declaration
|
|
108
|
-
'foo', 'bar', 'zip', 'zup', 'baz', // plus all the referenced properties
|
|
109
|
-
]));
|
|
110
|
-
});
|
|
111
|
-
|
|
112
|
-
it('Schema proxy generates unique names', () => {
|
|
113
|
-
const myloader = loader();
|
|
114
|
-
const proxied1 = myloader(example, 'example.schema.json');
|
|
115
|
-
const proxied2 = myloader(referencing, 'referencing.schema.json');
|
|
116
|
-
const proxied3 = myloader({
|
|
117
|
-
title: 'Referencing',
|
|
118
|
-
}, 'anotherreference.schema.json');
|
|
119
|
-
|
|
120
|
-
assert.equal(proxied1[slug], 'example');
|
|
121
|
-
|
|
122
|
-
assert.equal(proxied1.properties.zip[slug], 'example-properties-an-object');
|
|
123
|
-
assert.equal(proxied1.properties.zup[slug], 'example-properties-an-object-1'); // avoid duplicates
|
|
124
|
-
|
|
125
|
-
assert.equal(proxied2[slug], 'referencing');
|
|
126
|
-
assert.equal(proxied2[slug], 'referencing'); // make sure the slug stays stable
|
|
127
|
-
assert.equal(proxied3[slug], 'anotherreference');
|
|
128
|
-
});
|
|
129
|
-
|
|
130
|
-
it('Schema proxy loads actual schemas with meta information', () => {
|
|
131
|
-
const myloader = loader();
|
|
132
|
-
|
|
133
|
-
const examplefile = path.resolve(__dirname, '..', 'examples', 'schemas', 'definitions.schema.json');
|
|
134
|
-
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
135
|
-
const exampleschema = myloader(require(examplefile), examplefile);
|
|
136
|
-
|
|
137
|
-
assert.equal(exampleschema[meta].shortdescription, 'This is an example of using a definitions object within a schema');
|
|
138
|
-
});
|
|
139
|
-
|
|
140
|
-
it('Schema proxy loads complex schemas with meta information', () => {
|
|
141
|
-
const myloader = loader();
|
|
142
|
-
|
|
143
|
-
const files = [
|
|
144
|
-
'abstract.schema.json',
|
|
145
|
-
'simple.schema.json',
|
|
146
|
-
'complex.schema.json',
|
|
147
|
-
'custom.schema.json',
|
|
148
|
-
'examples.schema.json',
|
|
149
|
-
'extending.schema.json',
|
|
150
|
-
];
|
|
151
|
-
|
|
152
|
-
const schemas = files.map((file) => {
|
|
153
|
-
const fname = path.resolve(__dirname, '..', 'examples', 'schemas', file);
|
|
154
|
-
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
155
|
-
return myloader(require(fname), fname);
|
|
156
|
-
});
|
|
157
|
-
|
|
158
|
-
assert.equal(schemas[0][slug], 'abstract');
|
|
159
|
-
|
|
160
|
-
assert.deepEqual(schemas[2].title, 'Complex References');
|
|
161
|
-
assert.equal(schemas[2].properties.refnamed.title, 'Simple');
|
|
162
|
-
assert.equal(schemas[2].properties.refrefed.title, 'Simple');
|
|
163
|
-
assert.equal(schemas[2].properties.reflocalfile.title, 'Simple');
|
|
164
|
-
assert.equal(schemas[2].properties.reflocalfiledef.properties.third.properties.baz.title, 'BAAAZ!');
|
|
165
|
-
|
|
166
|
-
assert.equal(schemas[3].allOf[2].properties.bar.type, 'string');
|
|
167
|
-
|
|
168
|
-
assert.equal(schemas[4].examples.length, 2);
|
|
169
|
-
});
|
|
170
|
-
|
|
171
|
-
it('Schema proxy loads complex schemas with meta information', () => {
|
|
172
|
-
const myloader = loader();
|
|
173
|
-
|
|
174
|
-
const files = [
|
|
175
|
-
'deadref.schema.json',
|
|
176
|
-
];
|
|
177
|
-
|
|
178
|
-
const schemas = files.map((file) => {
|
|
179
|
-
const fname = path.resolve(__dirname, 'fixtures', 'deadref', file);
|
|
180
|
-
// eslint-disable-next-line import/no-dynamic-require, global-require
|
|
181
|
-
return myloader(require(fname), fname);
|
|
182
|
-
});
|
|
183
|
-
|
|
184
|
-
assert.equal(schemas[0][slug], 'deadref');
|
|
185
|
-
assert.deepEqual(schemas[0].properties.foo, { $ref: 'http://unknown-ref' });
|
|
186
|
-
});
|
|
187
|
-
});
|
package/test/testUtils.js
DELETED
|
@@ -1,88 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2019 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
const assert = require('assert');
|
|
13
|
-
const unified = require('unified');
|
|
14
|
-
const stringify = require('remark-stringify');
|
|
15
|
-
const inspect = require('unist-util-inspect');
|
|
16
|
-
const select = require('unist-util-select');
|
|
17
|
-
const path = require('path');
|
|
18
|
-
const gfm = require('remark-gfm');
|
|
19
|
-
const readdirp = require('readdirp');
|
|
20
|
-
const { loader } = require('../lib/schemaProxy');
|
|
21
|
-
const traverse = require('../lib/traverseSchema');
|
|
22
|
-
|
|
23
|
-
function assertMarkdown(node) {
|
|
24
|
-
const processor = unified()
|
|
25
|
-
.use(gfm)
|
|
26
|
-
.use(stringify);
|
|
27
|
-
try {
|
|
28
|
-
const result = processor.stringify(node);
|
|
29
|
-
const tester = {};
|
|
30
|
-
tester.contains = (str) => {
|
|
31
|
-
assert.ok(result.indexOf(str) >= 0, `Markdown output does not contain search string "${str}"
|
|
32
|
-
${result}`);
|
|
33
|
-
return tester;
|
|
34
|
-
};
|
|
35
|
-
tester.doesNotContain = (str) => {
|
|
36
|
-
assert.ok(result.indexOf(str) < 0, `Markdown output contains search string "${str}"
|
|
37
|
-
${result}`);
|
|
38
|
-
return tester;
|
|
39
|
-
};
|
|
40
|
-
tester.matches = (re) => {
|
|
41
|
-
assert.ok(result.match(re), `Markdown output does not match regex "${String(re)}"
|
|
42
|
-
${result}`);
|
|
43
|
-
return tester;
|
|
44
|
-
};
|
|
45
|
-
tester.inspect = () => {
|
|
46
|
-
console.log(inspect(node));
|
|
47
|
-
return tester;
|
|
48
|
-
};
|
|
49
|
-
tester.print = () => {
|
|
50
|
-
console.log(result);
|
|
51
|
-
return tester;
|
|
52
|
-
};
|
|
53
|
-
tester.has = (selector) => {
|
|
54
|
-
assert.ok(select.select(selector, node), `Markdown AST does not include node matching selector "${selector}"
|
|
55
|
-
${inspect(node)}`);
|
|
56
|
-
return tester;
|
|
57
|
-
};
|
|
58
|
-
tester.equals = (selector, value) => {
|
|
59
|
-
assert.deepStrictEqual(select.select(selector, node), value);
|
|
60
|
-
return tester;
|
|
61
|
-
};
|
|
62
|
-
tester.fuzzy = (expr) => {
|
|
63
|
-
const matches = expr.filter((line) => result.indexOf(line) >= 0);
|
|
64
|
-
if (matches.length < expr.length) {
|
|
65
|
-
assert.equal(result, expr.join(''));
|
|
66
|
-
}
|
|
67
|
-
return tester;
|
|
68
|
-
};
|
|
69
|
-
return tester;
|
|
70
|
-
} catch (e) {
|
|
71
|
-
assert.fail(`Invalid Markdown:\n${inspect(node)}\n${e}\n${JSON.stringify(node, undefined, 2)}`);
|
|
72
|
-
}
|
|
73
|
-
return null;
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
async function loadschemas(dir) {
|
|
77
|
-
const schemaloader = loader();
|
|
78
|
-
const schemadir = path.resolve(__dirname, 'fixtures', dir);
|
|
79
|
-
const schemas = await readdirp.promise(schemadir, { fileFilter: '*.schema.json' });
|
|
80
|
-
|
|
81
|
-
return traverse(schemas
|
|
82
|
-
.map(({ fullPath }) => schemaloader(
|
|
83
|
-
// eslint-disable-next-line global-require, import/no-dynamic-require
|
|
84
|
-
require(fullPath), fullPath,
|
|
85
|
-
)));
|
|
86
|
-
}
|
|
87
|
-
|
|
88
|
-
module.exports = { assertMarkdown, loadschemas };
|
|
@@ -1,65 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2019 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
/* eslint-env mocha */
|
|
13
|
-
const assert = require('assert');
|
|
14
|
-
const { AssertionError } = require('assert');
|
|
15
|
-
const fs = require('fs-extra');
|
|
16
|
-
const path = require('path');
|
|
17
|
-
const { main } = require('../lib/index');
|
|
18
|
-
|
|
19
|
-
describe('Integration Test', () => {
|
|
20
|
-
let oldargs = [];
|
|
21
|
-
let oldexit;
|
|
22
|
-
|
|
23
|
-
beforeEach(async () => {
|
|
24
|
-
oldargs = process.argv;
|
|
25
|
-
oldexit = process.exit;
|
|
26
|
-
await fs.remove(path.resolve(__dirname, '..', 'tmp'));
|
|
27
|
-
});
|
|
28
|
-
|
|
29
|
-
afterEach(async () => {
|
|
30
|
-
process.argv = oldargs;
|
|
31
|
-
process.exit = oldexit;
|
|
32
|
-
await fs.remove(path.resolve(__dirname, '..', 'tmp'));
|
|
33
|
-
});
|
|
34
|
-
|
|
35
|
-
it('CLI needs arguments to run', async (done) => {
|
|
36
|
-
process.exit = () => {
|
|
37
|
-
done();
|
|
38
|
-
throw new Error('Intercepted Exit');
|
|
39
|
-
};
|
|
40
|
-
|
|
41
|
-
try {
|
|
42
|
-
await main();
|
|
43
|
-
assert.fail('CLI called without args should exit');
|
|
44
|
-
} catch (e) {
|
|
45
|
-
if (e instanceof AssertionError) {
|
|
46
|
-
throw e;
|
|
47
|
-
}
|
|
48
|
-
assert.equal(e.message, 'Intercepted Exit');
|
|
49
|
-
}
|
|
50
|
-
});
|
|
51
|
-
|
|
52
|
-
['arrays', 'cyclic'].forEach((dir) => it(`CLI processes ${dir} directory`, async () => {
|
|
53
|
-
const res = await main((`jsonschema2md -d test/fixtures/${dir} -o tmp -x tmp`).split(' '));
|
|
54
|
-
console.log('done!', res);
|
|
55
|
-
const readme = await fs.stat(path.resolve(__dirname, '..', 'tmp', 'README.md'));
|
|
56
|
-
assert.ok(readme.isFile());
|
|
57
|
-
}));
|
|
58
|
-
|
|
59
|
-
['json-logic-js/schemas'].forEach((dir) => it(`CLI processes ${dir} directory`, async () => {
|
|
60
|
-
const res = await main((`jsonschema2md -d node_modules/${dir} -o tmp -x tmp -e json`).split(' '));
|
|
61
|
-
console.log('done!', res);
|
|
62
|
-
const readme = await fs.stat(path.resolve(__dirname, '..', 'tmp', 'README.md'));
|
|
63
|
-
assert.ok(readme.isFile());
|
|
64
|
-
}));
|
|
65
|
-
});
|
|
@@ -1,111 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2019 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
/* eslint-env mocha */
|
|
13
|
-
|
|
14
|
-
const assert = require('assert');
|
|
15
|
-
const fs = require('fs-extra');
|
|
16
|
-
const path = require('path');
|
|
17
|
-
const {
|
|
18
|
-
loader, filename,
|
|
19
|
-
} = require('../lib/schemaProxy');
|
|
20
|
-
|
|
21
|
-
const traverse = require('../lib/traverseSchema');
|
|
22
|
-
|
|
23
|
-
const example = {
|
|
24
|
-
'meta:license': [
|
|
25
|
-
'Copyright 2017 Adobe Systems Incorporated. All rights reserved.',
|
|
26
|
-
"This file is licensed to you under the Apache License, Version 2.0 (the 'License');",
|
|
27
|
-
'you may not use this file except in compliance with the License. You may obtain a copy',
|
|
28
|
-
'of the License at http://www.apache.org/licenses/LICENSE-2.0',
|
|
29
|
-
],
|
|
30
|
-
$schema: 'http://json-schema.org/draft-06/schema#',
|
|
31
|
-
$id: 'https://example.com/schemas/example',
|
|
32
|
-
title: 'Example',
|
|
33
|
-
type: 'object',
|
|
34
|
-
description:
|
|
35
|
-
'This is an example schema with examples. Too many examples? There can never be too many examples!',
|
|
36
|
-
properties: {
|
|
37
|
-
foo: {
|
|
38
|
-
type: 'string',
|
|
39
|
-
description: 'A simple string.',
|
|
40
|
-
examples: ['bar'],
|
|
41
|
-
version: '1.0.0',
|
|
42
|
-
testProperty: 'test',
|
|
43
|
-
},
|
|
44
|
-
bar: {
|
|
45
|
-
type: 'string',
|
|
46
|
-
description: 'A simple string.',
|
|
47
|
-
examples: ['bar', 'baz'],
|
|
48
|
-
version: '1.0.0',
|
|
49
|
-
testProperty: 'test',
|
|
50
|
-
},
|
|
51
|
-
zip: {
|
|
52
|
-
type: 'object',
|
|
53
|
-
title: 'An object',
|
|
54
|
-
},
|
|
55
|
-
zup: {
|
|
56
|
-
type: 'object',
|
|
57
|
-
title: 'An object',
|
|
58
|
-
},
|
|
59
|
-
baz: {
|
|
60
|
-
anyOf: [
|
|
61
|
-
{ $ref: '#/properties/foo' },
|
|
62
|
-
{ $ref: '#/properties/bar' },
|
|
63
|
-
],
|
|
64
|
-
},
|
|
65
|
-
properties: {
|
|
66
|
-
type: 'object',
|
|
67
|
-
description: 'properties witin properties',
|
|
68
|
-
},
|
|
69
|
-
required: {
|
|
70
|
-
type: 'array',
|
|
71
|
-
examples: [
|
|
72
|
-
[
|
|
73
|
-
{
|
|
74
|
-
properies: [],
|
|
75
|
-
},
|
|
76
|
-
],
|
|
77
|
-
],
|
|
78
|
-
},
|
|
79
|
-
examples: {
|
|
80
|
-
type: 'number',
|
|
81
|
-
examples: [1, 2, 3],
|
|
82
|
-
},
|
|
83
|
-
},
|
|
84
|
-
};
|
|
85
|
-
|
|
86
|
-
describe('Testing Schema Traversal', () => {
|
|
87
|
-
it('Schema Traversal generates a list', () => {
|
|
88
|
-
const proxied = loader()(example, 'example.schema.json');
|
|
89
|
-
const schemas = traverse([proxied]);
|
|
90
|
-
|
|
91
|
-
assert.equal(schemas.length, 11);
|
|
92
|
-
assert.equal(schemas[7][filename], 'example.schema.json');
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it('Cyclic Schema Traversal generates a list', async () => {
|
|
96
|
-
const one = await fs.readJson(path.resolve(__dirname, 'fixtures', 'cyclic', 'one.schema.json'));
|
|
97
|
-
const two = await fs.readJson(path.resolve(__dirname, 'fixtures', 'cyclic', 'two.schema.json'));
|
|
98
|
-
const three = await fs.readJson(path.resolve(__dirname, 'fixtures', 'cyclic', 'three.schema.json'));
|
|
99
|
-
|
|
100
|
-
const myloader = loader();
|
|
101
|
-
const proxiedone = myloader(one, path.resolve(__dirname, 'fixtures', 'cyclic', 'one.schema.json'));
|
|
102
|
-
const proxiedtwo = myloader(two, path.resolve(__dirname, 'fixtures', 'cyclic', 'two.schema.json'));
|
|
103
|
-
const proxiedthree = myloader(three, path.resolve(__dirname, 'fixtures', 'cyclic', 'three.schema.json'));
|
|
104
|
-
|
|
105
|
-
const schemas = traverse([proxiedone, proxiedtwo, proxiedthree]);
|
|
106
|
-
|
|
107
|
-
assert.equal(schemas[0].$id, 'http://example.com/schemas/one');
|
|
108
|
-
assert.equal(schemas[3].$id, 'http://example.com/schemas/three');
|
|
109
|
-
assert.equal(schemas[6].$id, 'http://example.com/schemas/two');
|
|
110
|
-
});
|
|
111
|
-
});
|
|
@@ -1,186 +0,0 @@
|
|
|
1
|
-
/*
|
|
2
|
-
* Copyright 2019 Adobe. All rights reserved.
|
|
3
|
-
* This file is licensed to you under the Apache License, Version 2.0 (the "License");
|
|
4
|
-
* you may not use this file except in compliance with the License. You may obtain a copy
|
|
5
|
-
* of the License at http://www.apache.org/licenses/LICENSE-2.0
|
|
6
|
-
*
|
|
7
|
-
* Unless required by applicable law or agreed to in writing, software distributed under
|
|
8
|
-
* the License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR REPRESENTATIONS
|
|
9
|
-
* OF ANY KIND, either express or implied. See the License for the specific language
|
|
10
|
-
* governing permissions and limitations under the License.
|
|
11
|
-
*/
|
|
12
|
-
const assert = require('assert');
|
|
13
|
-
const {
|
|
14
|
-
root, heading, paragraph, text, link, table, tableRow, tableCell, inlineCode,
|
|
15
|
-
} = require('mdast-builder');
|
|
16
|
-
const unified = require('unified');
|
|
17
|
-
const stringify = require('remark-stringify');
|
|
18
|
-
const gfm = require('remark-gfm');
|
|
19
|
-
const fs = require('fs-extra');
|
|
20
|
-
const { report } = require('../lib/keywords');
|
|
21
|
-
/* eslint-env mocha */
|
|
22
|
-
const expected = [
|
|
23
|
-
'examples',
|
|
24
|
-
'allOf',
|
|
25
|
-
'json-pointer',
|
|
26
|
-
'relative-json-pointer',
|
|
27
|
-
'regex',
|
|
28
|
-
'uri-template',
|
|
29
|
-
'default',
|
|
30
|
-
];
|
|
31
|
-
|
|
32
|
-
const allkeywords = {
|
|
33
|
-
'The JSON Schema Core Vocabulary, https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.8.1': [
|
|
34
|
-
'$schema',
|
|
35
|
-
'$vocabulary',
|
|
36
|
-
'$id',
|
|
37
|
-
'$anchor',
|
|
38
|
-
'$ref',
|
|
39
|
-
'$recursiveRef',
|
|
40
|
-
'$recursiveAnchor',
|
|
41
|
-
'$defs',
|
|
42
|
-
'$comment',
|
|
43
|
-
],
|
|
44
|
-
'A Vocabulary for Applying Subschemas, https://json-schema.org/draft/2019-09/json-schema-core.html#rfc.section.9': [
|
|
45
|
-
'additionalProperties',
|
|
46
|
-
'properties',
|
|
47
|
-
'patternProperties',
|
|
48
|
-
'unevaluatedProperties',
|
|
49
|
-
'additionalItems',
|
|
50
|
-
'items',
|
|
51
|
-
'unevaluatedItems',
|
|
52
|
-
'allOf',
|
|
53
|
-
'anyOf',
|
|
54
|
-
'oneOf',
|
|
55
|
-
'not',
|
|
56
|
-
'if',
|
|
57
|
-
'then',
|
|
58
|
-
'else',
|
|
59
|
-
'dependentSchemas',
|
|
60
|
-
'contains',
|
|
61
|
-
'propertyNames',
|
|
62
|
-
],
|
|
63
|
-
'Validation Keywords for Any Instance Type, https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.1': [
|
|
64
|
-
'type',
|
|
65
|
-
'enum',
|
|
66
|
-
'const',
|
|
67
|
-
],
|
|
68
|
-
'Validation Keywords for Numeric Instances, https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.2': [
|
|
69
|
-
'multipleOf',
|
|
70
|
-
'maximum',
|
|
71
|
-
'exclusiveMaximum',
|
|
72
|
-
'minimum',
|
|
73
|
-
'exclusiveMinimum',
|
|
74
|
-
],
|
|
75
|
-
'Validation Keywords for Strings, https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.3': [
|
|
76
|
-
'maxLength',
|
|
77
|
-
'minLength',
|
|
78
|
-
'pattern',
|
|
79
|
-
],
|
|
80
|
-
'Validation Keywords for Arrays, https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.4': [
|
|
81
|
-
'maxItems',
|
|
82
|
-
'minItems',
|
|
83
|
-
'uniqueItems',
|
|
84
|
-
'maxContains',
|
|
85
|
-
'minContains',
|
|
86
|
-
],
|
|
87
|
-
'Validation Keywords for Objects, https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.6.5': [
|
|
88
|
-
'maxProperties',
|
|
89
|
-
'minProperties',
|
|
90
|
-
'required',
|
|
91
|
-
'dependentRequired',
|
|
92
|
-
],
|
|
93
|
-
'Defined Formats, https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.7.3': [
|
|
94
|
-
'date-time',
|
|
95
|
-
'date',
|
|
96
|
-
'time',
|
|
97
|
-
'duration',
|
|
98
|
-
'email',
|
|
99
|
-
'idn-email',
|
|
100
|
-
'hostname',
|
|
101
|
-
'idn-hostname',
|
|
102
|
-
'ipv4',
|
|
103
|
-
'ipv6',
|
|
104
|
-
'uri',
|
|
105
|
-
'uri-reference',
|
|
106
|
-
'iri',
|
|
107
|
-
'iri-reference',
|
|
108
|
-
'uuid',
|
|
109
|
-
'uri-template',
|
|
110
|
-
'json-pointer',
|
|
111
|
-
'relative-json-pointer',
|
|
112
|
-
'regex',
|
|
113
|
-
],
|
|
114
|
-
'A Vocabulary for the Contents of String-Encoded Data, https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.8': [
|
|
115
|
-
'contentEncoding',
|
|
116
|
-
'contentMediaType',
|
|
117
|
-
'contentSchema',
|
|
118
|
-
],
|
|
119
|
-
'A Vocabulary for Basic Meta-Data Annotations, https://json-schema.org/draft/2019-09/json-schema-validation.html#rfc.section.9': [
|
|
120
|
-
'title',
|
|
121
|
-
'description',
|
|
122
|
-
'default',
|
|
123
|
-
'deprecated',
|
|
124
|
-
'readOnly',
|
|
125
|
-
'writeOnly',
|
|
126
|
-
'examples',
|
|
127
|
-
],
|
|
128
|
-
};
|
|
129
|
-
|
|
130
|
-
after('Generating Schema Coverage Report', () => {
|
|
131
|
-
const allkeywordsplain = Array.from(new Set(Object
|
|
132
|
-
.values(allkeywords)
|
|
133
|
-
.reduce((p, v) => [...p, ...v], [])));
|
|
134
|
-
const allkeywordssupported = allkeywordsplain
|
|
135
|
-
.filter((keyword) => report().has(keyword));
|
|
136
|
-
|
|
137
|
-
const overall = Math.floor((100 * allkeywordssupported.length) / allkeywordsplain.length);
|
|
138
|
-
|
|
139
|
-
const sections = Object.entries(allkeywords).map(([name, keywords]) => {
|
|
140
|
-
const [label, url] = name.split(', ');
|
|
141
|
-
const coverage = Math.floor(
|
|
142
|
-
(100
|
|
143
|
-
* keywords.filter((keyword) => report().has(keyword)).length)
|
|
144
|
-
/ keywords.length,
|
|
145
|
-
);
|
|
146
|
-
return [
|
|
147
|
-
heading(2, text(label)),
|
|
148
|
-
paragraph([text('Coverage for '), link(url, '', text(label)), text(` is ${coverage}%.`)]),
|
|
149
|
-
table('left', [
|
|
150
|
-
tableRow([
|
|
151
|
-
tableCell(text('Keyword')),
|
|
152
|
-
tableCell(text('Supported')),
|
|
153
|
-
]),
|
|
154
|
-
...keywords.sort().map((keyword) => tableRow([
|
|
155
|
-
tableCell(inlineCode(keyword)),
|
|
156
|
-
tableCell(text(report().has(keyword) ? 'Yes' : 'No')),
|
|
157
|
-
])),
|
|
158
|
-
]),
|
|
159
|
-
];
|
|
160
|
-
}).reduce((p, v) => [...p, ...v], []);
|
|
161
|
-
|
|
162
|
-
const mdast = root([
|
|
163
|
-
heading(1, text('JSON Schema Spec Coverage Report')),
|
|
164
|
-
paragraph(text(`This report lists the keywords of the JSON Schema spec that are covered in the tests. The overall coverage is ${overall}%`)),
|
|
165
|
-
...sections,
|
|
166
|
-
]);
|
|
167
|
-
|
|
168
|
-
const processor = unified()
|
|
169
|
-
.use(gfm)
|
|
170
|
-
.use(stringify);
|
|
171
|
-
|
|
172
|
-
const output = processor.stringify(mdast);
|
|
173
|
-
|
|
174
|
-
fs.writeFileSync('schemasupport.md', output);
|
|
175
|
-
|
|
176
|
-
const lowerlimit = 50;
|
|
177
|
-
assert.ok(overall > lowerlimit, `Expected minumum spec coverage of ${lowerlimit}%, got only ${overall}%`);
|
|
178
|
-
});
|
|
179
|
-
|
|
180
|
-
describe('Checking JSON Schema Spec coverage', () => {
|
|
181
|
-
expected.forEach((keyword) => {
|
|
182
|
-
it(`keyword ${keyword}`, () => {
|
|
183
|
-
assert.ok(report().has(keyword), `keyword ${keyword} not used in tests`);
|
|
184
|
-
});
|
|
185
|
-
});
|
|
186
|
-
});
|