docusaurus-plugin-generate-schema-docs 1.2.0 → 1.3.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/README.md +42 -6
- package/__tests__/ExampleDataLayer.test.js +78 -155
- package/__tests__/__fixtures__/static/schemas/add-to-cart-event.json +4 -15
- package/__tests__/__fixtures__/static/schemas/choice-event.json +72 -0
- package/__tests__/__fixtures__/static/schemas/components/dataLayer.json +52 -54
- package/__tests__/__fixtures__/static/schemas/components/product.json +124 -210
- package/__tests__/__fixtures__/static/schemas/nested/child-event.json +10 -0
- package/__tests__/__fixtures__/static/schemas/nested/grandchild-a.json +9 -0
- package/__tests__/__fixtures__/static/schemas/nested/grandchild-b.json +9 -0
- package/__tests__/__fixtures__/static/schemas/nested/parent-event.json +7 -0
- package/__tests__/__fixtures__/static/schemas/root-any-of-event.json +34 -0
- package/__tests__/__fixtures__/static/schemas/root-choice-event.json +36 -0
- package/__tests__/__fixtures__/validateSchemas/circular-schema.json +6 -6
- package/__tests__/__fixtures__/validateSchemas/components/referenced.json +9 -7
- package/__tests__/__fixtures__/validateSchemas/invalid-example-schema.json +7 -7
- package/__tests__/__fixtures__/validateSchemas/main-schema-with-missing-ref.json +7 -7
- package/__tests__/__fixtures__/validateSchemas/main-schema-with-ref.json +7 -7
- package/__tests__/__fixtures__/validateSchemas/no-example-schema.json +11 -11
- package/__tests__/__fixtures__/validateSchemas/schema-A.json +5 -5
- package/__tests__/__fixtures__/validateSchemas/schema-B.json +5 -5
- package/__tests__/__fixtures__/validateSchemas/valid-schema.json +7 -7
- package/__tests__/__fixtures_versioned__/static/schemas/1.1.1/add-to-cart-event.json +44 -0
- package/__tests__/__fixtures_versioned__/static/schemas/1.1.1/components/dataLayer.json +56 -0
- package/__tests__/__fixtures_versioned__/static/schemas/1.1.1/components/product.json +125 -0
- package/__tests__/__fixtures_versioned__/static/schemas/next/add-to-cart-event.json +44 -0
- package/__tests__/__fixtures_versioned__/static/schemas/next/components/dataLayer.json +56 -0
- package/__tests__/__fixtures_versioned__/static/schemas/next/components/product.json +125 -0
- package/__tests__/__fixtures_versioned__/versions.json +1 -0
- package/__tests__/__snapshots__/ExampleDataLayer.test.js.snap +117 -0
- package/__tests__/__snapshots__/generateEventDocs.nested.test.js.snap +92 -0
- package/__tests__/__snapshots__/generateEventDocs.test.js.snap +113 -15
- package/__tests__/__snapshots__/generateEventDocs.versioned.test.js.snap +53 -0
- package/__tests__/components/FoldableRows.test.js +330 -0
- package/__tests__/components/PropertiesTable.test.js +31 -14
- package/__tests__/components/PropertyRow.test.js +471 -51
- package/__tests__/components/SchemaJsonViewer.test.js +23 -19
- package/__tests__/components/SchemaRows.test.js +96 -66
- package/__tests__/components/SchemaViewer.test.js +34 -17
- package/__tests__/components/TableHeader.test.js +12 -12
- package/__tests__/generateEventDocs.nested.test.js +80 -0
- package/__tests__/generateEventDocs.test.js +77 -71
- package/__tests__/generateEventDocs.versioned.test.js +69 -0
- package/__tests__/helpers/buildExampleFromSchema.test.js +160 -160
- package/__tests__/helpers/file-system.test.js +44 -0
- package/__tests__/helpers/getConstraints.test.js +48 -48
- package/__tests__/helpers/loadSchema.test.js +11 -5
- package/__tests__/helpers/path-helpers.test.js +34 -0
- package/__tests__/helpers/processSchema.test.js +42 -22
- package/__tests__/helpers/schema-processing.test.js +82 -0
- package/__tests__/helpers/schemaToExamples.test.js +56 -0
- package/__tests__/helpers/schemaToTableData.filtering.test.js +65 -0
- package/__tests__/helpers/schemaToTableData.hierarchicalLines.test.js +539 -0
- package/__tests__/helpers/schemaToTableData.test.js +222 -0
- package/__tests__/helpers/update-schema-ids.test.js +107 -0
- package/__tests__/update-schema-ids.test.js +39 -0
- package/__tests__/validateSchemas.test.js +125 -88
- package/components/ExampleDataLayer.js +59 -28
- package/components/FoldableRows.js +164 -0
- package/components/PropertiesTable.js +10 -7
- package/components/PropertyRow.js +169 -60
- package/components/SchemaJsonViewer.js +6 -6
- package/components/SchemaRows.css +236 -14
- package/components/SchemaRows.js +24 -41
- package/components/SchemaViewer.js +19 -13
- package/components/TableHeader.js +12 -12
- package/generateEventDocs.js +141 -61
- package/helpers/buildExampleFromSchema.js +58 -72
- package/helpers/choice-index-template.js +22 -0
- package/helpers/file-system.js +32 -0
- package/helpers/getConstraints.js +43 -44
- package/helpers/loadSchema.js +2 -2
- package/helpers/path-helpers.js +22 -0
- package/helpers/processSchema.js +19 -19
- package/helpers/{mdx-template.js → schema-doc-template.js} +12 -12
- package/helpers/schema-processing.js +75 -0
- package/helpers/schemaToExamples.js +99 -0
- package/helpers/schemaToTableData.js +311 -0
- package/helpers/update-schema-ids.js +47 -0
- package/index.js +143 -54
- package/package.json +1 -1
- package/validateSchemas.js +54 -71
package/validateSchemas.js
CHANGED
|
@@ -3,87 +3,70 @@ import path from 'path';
|
|
|
3
3
|
import buildExampleFromSchema from './helpers/buildExampleFromSchema';
|
|
4
4
|
import Ajv2020 from 'ajv/dist/2020.js';
|
|
5
5
|
import addFormats from 'ajv-formats';
|
|
6
|
-
import
|
|
7
|
-
import mergeJsonSchema from "json-schema-merge-allof";
|
|
6
|
+
import processSchema from './helpers/processSchema';
|
|
8
7
|
|
|
9
8
|
const validateSchemas = async (schemaPath) => {
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
9
|
+
const ajv = new Ajv2020();
|
|
10
|
+
addFormats(ajv);
|
|
11
|
+
ajv.addKeyword('x-gtm-clear');
|
|
13
12
|
|
|
14
|
-
|
|
15
|
-
|
|
13
|
+
const getAllFiles = (dir, allFiles = []) => {
|
|
14
|
+
const files = fs.readdirSync(dir);
|
|
16
15
|
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
return allFiles;
|
|
31
|
-
};
|
|
16
|
+
files.forEach((file) => {
|
|
17
|
+
const filePath = path.join(dir, file);
|
|
18
|
+
if (fs.statSync(filePath).isDirectory()) {
|
|
19
|
+
getAllFiles(filePath, allFiles);
|
|
20
|
+
} else {
|
|
21
|
+
if (file.endsWith('.json')) {
|
|
22
|
+
allFiles.push(filePath);
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
});
|
|
26
|
+
return allFiles;
|
|
27
|
+
};
|
|
32
28
|
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
}
|
|
29
|
+
const allSchemaFiles = getAllFiles(schemaPath);
|
|
30
|
+
for (const file of allSchemaFiles) {
|
|
31
|
+
const schemaContent = fs.readFileSync(file, 'utf-8');
|
|
32
|
+
const schema = JSON.parse(schemaContent);
|
|
33
|
+
ajv.addSchema(schema);
|
|
34
|
+
}
|
|
40
35
|
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
36
|
+
const schemaFiles = fs
|
|
37
|
+
.readdirSync(schemaPath)
|
|
38
|
+
.filter((file) => file.endsWith('.json'));
|
|
39
|
+
let allValid = true;
|
|
40
|
+
for (const file of schemaFiles) {
|
|
41
|
+
const filePath = path.join(schemaPath, file);
|
|
46
42
|
|
|
47
|
-
|
|
48
|
-
const clonedSchema = await $RefParser.dereference(filePath, {
|
|
49
|
-
mutateInputSchema: false, dereference: {
|
|
50
|
-
circular: 'ignore'
|
|
51
|
-
}
|
|
52
|
-
});
|
|
53
|
-
const mergedSchema = mergeJsonSchema(clonedSchema, {
|
|
54
|
-
resolvers: {
|
|
55
|
-
defaultResolver: mergeJsonSchema.options.resolvers.title
|
|
56
|
-
}
|
|
57
|
-
});
|
|
43
|
+
const mergedSchema = await processSchema(filePath);
|
|
58
44
|
|
|
59
|
-
|
|
45
|
+
const example_data = buildExampleFromSchema(mergedSchema);
|
|
60
46
|
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
console.error(validate.errors);
|
|
82
|
-
allValid = false;
|
|
83
|
-
}
|
|
84
|
-
}
|
|
47
|
+
if (!example_data) {
|
|
48
|
+
console.error(`x Schema ${file} does not produce a valid example.`);
|
|
49
|
+
allValid = false;
|
|
50
|
+
} else {
|
|
51
|
+
const originalSchema = JSON.parse(fs.readFileSync(filePath, 'utf-8'));
|
|
52
|
+
const validate = ajv.getSchema(originalSchema.$id);
|
|
53
|
+
if (!validate) {
|
|
54
|
+
console.error(
|
|
55
|
+
`x Could not find compiled schema for ${originalSchema.$id}`,
|
|
56
|
+
);
|
|
57
|
+
allValid = false;
|
|
58
|
+
continue;
|
|
59
|
+
}
|
|
60
|
+
if (validate(example_data)) {
|
|
61
|
+
console.log(`OK Schema ${file} produced a valid example.`);
|
|
62
|
+
} else {
|
|
63
|
+
console.error(`x Schema ${file} example data failed validation:`);
|
|
64
|
+
console.error(validate.errors);
|
|
65
|
+
allValid = false;
|
|
66
|
+
}
|
|
85
67
|
}
|
|
86
|
-
|
|
68
|
+
}
|
|
69
|
+
return allValid;
|
|
87
70
|
};
|
|
88
71
|
|
|
89
72
|
export default validateSchemas;
|