docusaurus-plugin-generate-schema-docs 1.8.3 → 1.8.5
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 +12 -0
- package/__tests__/__fixtures__/validateSchemas/main-schema-with-not-allof.json +11 -0
- package/__tests__/__fixtures__/validateSchemas/schema-with-not-anyof-multi.json +12 -0
- package/__tests__/__fixtures__/validateSchemas/schema-with-not-anyof.json +30 -0
- package/__tests__/__fixtures__/validateSchemas/schema-with-not-edge-cases.json +24 -0
- package/__tests__/__fixtures__/validateSchemas/schema-with-not-non-object.json +15 -0
- package/__tests__/__snapshots__/generateEventDocs.anchor.test.js.snap +6 -0
- package/__tests__/__snapshots__/generateEventDocs.nested.test.js.snap +6 -0
- package/__tests__/__snapshots__/generateEventDocs.test.js.snap +15 -0
- package/__tests__/__snapshots__/generateEventDocs.versioned.test.js.snap +6 -0
- package/__tests__/components/PropertiesTable.test.js +66 -0
- package/__tests__/components/PropertyRow.test.js +85 -4
- package/__tests__/components/SchemaJsonViewer.test.js +118 -0
- package/__tests__/generateEventDocs.anchor.test.js +1 -1
- package/__tests__/generateEventDocs.nested.test.js +1 -1
- package/__tests__/generateEventDocs.partials.test.js +1 -1
- package/__tests__/generateEventDocs.test.js +506 -1
- package/__tests__/generateEventDocs.versioned.test.js +1 -1
- package/__tests__/helpers/buildExampleFromSchema.test.js +240 -0
- package/__tests__/helpers/constraintSchemaPaths.test.js +208 -0
- package/__tests__/helpers/continuingLinesStyle.test.js +492 -0
- package/__tests__/helpers/example-helper.test.js +12 -0
- package/__tests__/helpers/exampleModel.test.js +209 -0
- package/__tests__/helpers/file-system.test.js +73 -1
- package/__tests__/helpers/getConstraints.test.js +43 -0
- package/__tests__/helpers/mergeSchema.test.js +94 -0
- package/__tests__/helpers/processSchema.test.js +309 -1
- package/__tests__/helpers/schema-doc-template.test.js +54 -0
- package/__tests__/helpers/schema-processing.test.js +122 -2
- package/__tests__/helpers/schemaToExamples.test.js +1007 -0
- package/__tests__/helpers/schemaToTableData.mutations.test.js +970 -0
- package/__tests__/helpers/schemaToTableData.test.js +157 -0
- package/__tests__/helpers/schemaTraversal.test.js +110 -0
- package/__tests__/helpers/snippetTargets.test.js +432 -0
- package/__tests__/helpers/trackingTargets.test.js +319 -0
- package/__tests__/helpers/validator.test.js +385 -1
- package/__tests__/index.test.js +436 -0
- package/__tests__/syncGtm.test.js +366 -6
- package/__tests__/update-schema-ids.test.js +70 -1
- package/__tests__/validateSchemas-integration.test.js +2 -2
- package/__tests__/validateSchemas.test.js +192 -1
- package/components/PropertiesTable.js +32 -2
- package/components/PropertyRow.js +29 -2
- package/components/SchemaJsonViewer.js +234 -131
- package/components/SchemaRows.css +40 -0
- package/components/SchemaViewer.js +11 -2
- package/generateEventDocs.js +21 -1
- package/helpers/constraintSchemaPaths.js +10 -14
- package/helpers/example-helper.js +2 -2
- package/helpers/getConstraints.js +20 -0
- package/helpers/processSchema.js +32 -1
- package/helpers/schema-doc-template.js +4 -0
- package/helpers/schemaToExamples.js +29 -35
- package/helpers/schemaToTableData.js +538 -492
- package/helpers/schemaTraversal.cjs +148 -0
- package/helpers/trackingTargets.js +26 -3
- package/helpers/validator.js +18 -4
- package/index.js +1 -2
- package/package.json +1 -1
- package/scripts/sync-gtm.js +65 -34
- package/test-data/payloadContracts.js +35 -0
- package/validateSchemas.js +1 -1
|
@@ -12,6 +12,7 @@ export default function MdxTemplate(data) {
|
|
|
12
12
|
sourcePath,
|
|
13
13
|
schemaSources,
|
|
14
14
|
} = data;
|
|
15
|
+
const sourceSchema = schemaSources?.[sourcePath] || schema;
|
|
15
16
|
|
|
16
17
|
return `---
|
|
17
18
|
title: ${schema.title}
|
|
@@ -33,6 +34,9 @@ ${topPartialComponent}
|
|
|
33
34
|
|
|
34
35
|
<SchemaViewer
|
|
35
36
|
schema={${JSON.stringify(mergedSchema)}}
|
|
37
|
+
sourceSchema={${JSON.stringify(sourceSchema)}}
|
|
38
|
+
sourcePath={${JSON.stringify(sourcePath)}}
|
|
39
|
+
schemaSources={${JSON.stringify(schemaSources)}}
|
|
36
40
|
${dataLayerName ? ` dataLayerName={'${dataLayerName}'}` : ''}
|
|
37
41
|
/>
|
|
38
42
|
<SchemaJsonViewer
|
|
@@ -1,44 +1,31 @@
|
|
|
1
1
|
import buildExampleFromSchema from './buildExampleFromSchema';
|
|
2
2
|
import { mergeSchema } from './mergeSchema.js';
|
|
3
|
+
import traversalHelpers from './schemaTraversal.cjs';
|
|
3
4
|
|
|
4
|
-
const
|
|
5
|
-
if (!subSchema) {
|
|
6
|
-
return [];
|
|
7
|
-
}
|
|
5
|
+
const { visitSchemaNodes } = traversalHelpers;
|
|
8
6
|
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
: subSchema.anyOf
|
|
12
|
-
? 'anyOf'
|
|
13
|
-
: null;
|
|
14
|
-
const currentChoice = choiceType ? [{ path, schema: subSchema }] : [];
|
|
7
|
+
const findChoicePoints = (schema) => {
|
|
8
|
+
const choicePoints = [];
|
|
15
9
|
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
10
|
+
visitSchemaNodes(schema, (subSchema, context) => {
|
|
11
|
+
if (subSchema.oneOf || subSchema.anyOf) {
|
|
12
|
+
choicePoints.push({ path: context.path, schema: subSchema });
|
|
13
|
+
}
|
|
14
|
+
});
|
|
21
15
|
|
|
22
|
-
return
|
|
16
|
+
return choicePoints;
|
|
23
17
|
};
|
|
24
18
|
|
|
25
|
-
const findConditionalPoints = (
|
|
26
|
-
|
|
27
|
-
return [];
|
|
28
|
-
}
|
|
29
|
-
|
|
30
|
-
const currentConditional =
|
|
31
|
-
subSchema.if && (subSchema.then || subSchema.else)
|
|
32
|
-
? [{ path, schema: subSchema }]
|
|
33
|
-
: [];
|
|
19
|
+
const findConditionalPoints = (schema) => {
|
|
20
|
+
const conditionalPoints = [];
|
|
34
21
|
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
22
|
+
visitSchemaNodes(schema, (subSchema, context) => {
|
|
23
|
+
if (subSchema.if && (subSchema.then || subSchema.else)) {
|
|
24
|
+
conditionalPoints.push({ path: context.path, schema: subSchema });
|
|
25
|
+
}
|
|
26
|
+
});
|
|
40
27
|
|
|
41
|
-
return
|
|
28
|
+
return conditionalPoints;
|
|
42
29
|
};
|
|
43
30
|
|
|
44
31
|
const generateExampleForChoice = (rootSchema, path, option) => {
|
|
@@ -151,10 +138,17 @@ export function schemaToExamples(rootSchema) {
|
|
|
151
138
|
|
|
152
139
|
if (choicePoints.length === 0 && conditionalPoints.length === 0) {
|
|
153
140
|
const example = buildExampleFromSchema(rootSchema);
|
|
154
|
-
if (
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
141
|
+
if (typeof example !== 'undefined') {
|
|
142
|
+
const shouldIncludeObjectExample =
|
|
143
|
+
typeof example !== 'object' ||
|
|
144
|
+
example === null ||
|
|
145
|
+
Object.keys(example).length > 0;
|
|
146
|
+
|
|
147
|
+
if (shouldIncludeObjectExample) {
|
|
148
|
+
return [
|
|
149
|
+
{ property: 'default', options: [{ title: 'Example', example }] },
|
|
150
|
+
];
|
|
151
|
+
}
|
|
158
152
|
}
|
|
159
153
|
return [];
|
|
160
154
|
}
|