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.
Files changed (62) hide show
  1. package/README.md +12 -0
  2. package/__tests__/__fixtures__/validateSchemas/main-schema-with-not-allof.json +11 -0
  3. package/__tests__/__fixtures__/validateSchemas/schema-with-not-anyof-multi.json +12 -0
  4. package/__tests__/__fixtures__/validateSchemas/schema-with-not-anyof.json +30 -0
  5. package/__tests__/__fixtures__/validateSchemas/schema-with-not-edge-cases.json +24 -0
  6. package/__tests__/__fixtures__/validateSchemas/schema-with-not-non-object.json +15 -0
  7. package/__tests__/__snapshots__/generateEventDocs.anchor.test.js.snap +6 -0
  8. package/__tests__/__snapshots__/generateEventDocs.nested.test.js.snap +6 -0
  9. package/__tests__/__snapshots__/generateEventDocs.test.js.snap +15 -0
  10. package/__tests__/__snapshots__/generateEventDocs.versioned.test.js.snap +6 -0
  11. package/__tests__/components/PropertiesTable.test.js +66 -0
  12. package/__tests__/components/PropertyRow.test.js +85 -4
  13. package/__tests__/components/SchemaJsonViewer.test.js +118 -0
  14. package/__tests__/generateEventDocs.anchor.test.js +1 -1
  15. package/__tests__/generateEventDocs.nested.test.js +1 -1
  16. package/__tests__/generateEventDocs.partials.test.js +1 -1
  17. package/__tests__/generateEventDocs.test.js +506 -1
  18. package/__tests__/generateEventDocs.versioned.test.js +1 -1
  19. package/__tests__/helpers/buildExampleFromSchema.test.js +240 -0
  20. package/__tests__/helpers/constraintSchemaPaths.test.js +208 -0
  21. package/__tests__/helpers/continuingLinesStyle.test.js +492 -0
  22. package/__tests__/helpers/example-helper.test.js +12 -0
  23. package/__tests__/helpers/exampleModel.test.js +209 -0
  24. package/__tests__/helpers/file-system.test.js +73 -1
  25. package/__tests__/helpers/getConstraints.test.js +43 -0
  26. package/__tests__/helpers/mergeSchema.test.js +94 -0
  27. package/__tests__/helpers/processSchema.test.js +309 -1
  28. package/__tests__/helpers/schema-doc-template.test.js +54 -0
  29. package/__tests__/helpers/schema-processing.test.js +122 -2
  30. package/__tests__/helpers/schemaToExamples.test.js +1007 -0
  31. package/__tests__/helpers/schemaToTableData.mutations.test.js +970 -0
  32. package/__tests__/helpers/schemaToTableData.test.js +157 -0
  33. package/__tests__/helpers/schemaTraversal.test.js +110 -0
  34. package/__tests__/helpers/snippetTargets.test.js +432 -0
  35. package/__tests__/helpers/trackingTargets.test.js +319 -0
  36. package/__tests__/helpers/validator.test.js +385 -1
  37. package/__tests__/index.test.js +436 -0
  38. package/__tests__/syncGtm.test.js +366 -6
  39. package/__tests__/update-schema-ids.test.js +70 -1
  40. package/__tests__/validateSchemas-integration.test.js +2 -2
  41. package/__tests__/validateSchemas.test.js +192 -1
  42. package/components/PropertiesTable.js +32 -2
  43. package/components/PropertyRow.js +29 -2
  44. package/components/SchemaJsonViewer.js +234 -131
  45. package/components/SchemaRows.css +40 -0
  46. package/components/SchemaViewer.js +11 -2
  47. package/generateEventDocs.js +21 -1
  48. package/helpers/constraintSchemaPaths.js +10 -14
  49. package/helpers/example-helper.js +2 -2
  50. package/helpers/getConstraints.js +20 -0
  51. package/helpers/processSchema.js +32 -1
  52. package/helpers/schema-doc-template.js +4 -0
  53. package/helpers/schemaToExamples.js +29 -35
  54. package/helpers/schemaToTableData.js +538 -492
  55. package/helpers/schemaTraversal.cjs +148 -0
  56. package/helpers/trackingTargets.js +26 -3
  57. package/helpers/validator.js +18 -4
  58. package/index.js +1 -2
  59. package/package.json +1 -1
  60. package/scripts/sync-gtm.js +65 -34
  61. package/test-data/payloadContracts.js +35 -0
  62. 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 findChoicePoints = (subSchema, path = []) => {
5
- if (!subSchema) {
6
- return [];
7
- }
5
+ const { visitSchemaNodes } = traversalHelpers;
8
6
 
9
- const choiceType = subSchema.oneOf
10
- ? 'oneOf'
11
- : subSchema.anyOf
12
- ? 'anyOf'
13
- : null;
14
- const currentChoice = choiceType ? [{ path, schema: subSchema }] : [];
7
+ const findChoicePoints = (schema) => {
8
+ const choicePoints = [];
15
9
 
16
- const nestedChoices = subSchema.properties
17
- ? Object.entries(subSchema.properties).flatMap(([key, propSchema]) =>
18
- findChoicePoints(propSchema, [...path, 'properties', key]),
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 [...currentChoice, ...nestedChoices];
16
+ return choicePoints;
23
17
  };
24
18
 
25
- const findConditionalPoints = (subSchema, path = []) => {
26
- if (!subSchema) {
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
- const nestedConditionals = subSchema.properties
36
- ? Object.entries(subSchema.properties).flatMap(([key, propSchema]) =>
37
- findConditionalPoints(propSchema, [...path, 'properties', key]),
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 [...currentConditional, ...nestedConditionals];
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 (example && Object.keys(example).length > 0) {
155
- return [
156
- { property: 'default', options: [{ title: 'Example', example }] },
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
  }