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.
Files changed (81) hide show
  1. package/README.md +42 -6
  2. package/__tests__/ExampleDataLayer.test.js +78 -155
  3. package/__tests__/__fixtures__/static/schemas/add-to-cart-event.json +4 -15
  4. package/__tests__/__fixtures__/static/schemas/choice-event.json +72 -0
  5. package/__tests__/__fixtures__/static/schemas/components/dataLayer.json +52 -54
  6. package/__tests__/__fixtures__/static/schemas/components/product.json +124 -210
  7. package/__tests__/__fixtures__/static/schemas/nested/child-event.json +10 -0
  8. package/__tests__/__fixtures__/static/schemas/nested/grandchild-a.json +9 -0
  9. package/__tests__/__fixtures__/static/schemas/nested/grandchild-b.json +9 -0
  10. package/__tests__/__fixtures__/static/schemas/nested/parent-event.json +7 -0
  11. package/__tests__/__fixtures__/static/schemas/root-any-of-event.json +34 -0
  12. package/__tests__/__fixtures__/static/schemas/root-choice-event.json +36 -0
  13. package/__tests__/__fixtures__/validateSchemas/circular-schema.json +6 -6
  14. package/__tests__/__fixtures__/validateSchemas/components/referenced.json +9 -7
  15. package/__tests__/__fixtures__/validateSchemas/invalid-example-schema.json +7 -7
  16. package/__tests__/__fixtures__/validateSchemas/main-schema-with-missing-ref.json +7 -7
  17. package/__tests__/__fixtures__/validateSchemas/main-schema-with-ref.json +7 -7
  18. package/__tests__/__fixtures__/validateSchemas/no-example-schema.json +11 -11
  19. package/__tests__/__fixtures__/validateSchemas/schema-A.json +5 -5
  20. package/__tests__/__fixtures__/validateSchemas/schema-B.json +5 -5
  21. package/__tests__/__fixtures__/validateSchemas/valid-schema.json +7 -7
  22. package/__tests__/__fixtures_versioned__/static/schemas/1.1.1/add-to-cart-event.json +44 -0
  23. package/__tests__/__fixtures_versioned__/static/schemas/1.1.1/components/dataLayer.json +56 -0
  24. package/__tests__/__fixtures_versioned__/static/schemas/1.1.1/components/product.json +125 -0
  25. package/__tests__/__fixtures_versioned__/static/schemas/next/add-to-cart-event.json +44 -0
  26. package/__tests__/__fixtures_versioned__/static/schemas/next/components/dataLayer.json +56 -0
  27. package/__tests__/__fixtures_versioned__/static/schemas/next/components/product.json +125 -0
  28. package/__tests__/__fixtures_versioned__/versions.json +1 -0
  29. package/__tests__/__snapshots__/ExampleDataLayer.test.js.snap +117 -0
  30. package/__tests__/__snapshots__/generateEventDocs.nested.test.js.snap +92 -0
  31. package/__tests__/__snapshots__/generateEventDocs.test.js.snap +113 -15
  32. package/__tests__/__snapshots__/generateEventDocs.versioned.test.js.snap +53 -0
  33. package/__tests__/components/FoldableRows.test.js +330 -0
  34. package/__tests__/components/PropertiesTable.test.js +31 -14
  35. package/__tests__/components/PropertyRow.test.js +471 -51
  36. package/__tests__/components/SchemaJsonViewer.test.js +23 -19
  37. package/__tests__/components/SchemaRows.test.js +96 -66
  38. package/__tests__/components/SchemaViewer.test.js +34 -17
  39. package/__tests__/components/TableHeader.test.js +12 -12
  40. package/__tests__/generateEventDocs.nested.test.js +80 -0
  41. package/__tests__/generateEventDocs.test.js +77 -71
  42. package/__tests__/generateEventDocs.versioned.test.js +69 -0
  43. package/__tests__/helpers/buildExampleFromSchema.test.js +160 -160
  44. package/__tests__/helpers/file-system.test.js +44 -0
  45. package/__tests__/helpers/getConstraints.test.js +48 -48
  46. package/__tests__/helpers/loadSchema.test.js +11 -5
  47. package/__tests__/helpers/path-helpers.test.js +34 -0
  48. package/__tests__/helpers/processSchema.test.js +42 -22
  49. package/__tests__/helpers/schema-processing.test.js +82 -0
  50. package/__tests__/helpers/schemaToExamples.test.js +56 -0
  51. package/__tests__/helpers/schemaToTableData.filtering.test.js +65 -0
  52. package/__tests__/helpers/schemaToTableData.hierarchicalLines.test.js +539 -0
  53. package/__tests__/helpers/schemaToTableData.test.js +222 -0
  54. package/__tests__/helpers/update-schema-ids.test.js +107 -0
  55. package/__tests__/update-schema-ids.test.js +39 -0
  56. package/__tests__/validateSchemas.test.js +125 -88
  57. package/components/ExampleDataLayer.js +59 -28
  58. package/components/FoldableRows.js +164 -0
  59. package/components/PropertiesTable.js +10 -7
  60. package/components/PropertyRow.js +169 -60
  61. package/components/SchemaJsonViewer.js +6 -6
  62. package/components/SchemaRows.css +236 -14
  63. package/components/SchemaRows.js +24 -41
  64. package/components/SchemaViewer.js +19 -13
  65. package/components/TableHeader.js +12 -12
  66. package/generateEventDocs.js +141 -61
  67. package/helpers/buildExampleFromSchema.js +58 -72
  68. package/helpers/choice-index-template.js +22 -0
  69. package/helpers/file-system.js +32 -0
  70. package/helpers/getConstraints.js +43 -44
  71. package/helpers/loadSchema.js +2 -2
  72. package/helpers/path-helpers.js +22 -0
  73. package/helpers/processSchema.js +19 -19
  74. package/helpers/{mdx-template.js → schema-doc-template.js} +12 -12
  75. package/helpers/schema-processing.js +75 -0
  76. package/helpers/schemaToExamples.js +99 -0
  77. package/helpers/schemaToTableData.js +311 -0
  78. package/helpers/update-schema-ids.js +47 -0
  79. package/index.js +143 -54
  80. package/package.json +1 -1
  81. package/validateSchemas.js +54 -71
@@ -1,28 +1,250 @@
1
1
  .required-row {
2
- background-color: rgba(255, 0, 0, 0.05);
2
+ background-color: rgba(var(--ifm-color-danger-rgb), 0.05);
3
3
  }
4
4
 
5
5
  .constraint-code {
6
- white-space: pre-wrap;
7
- margin-right: 4px;
8
- display: inline-block;
9
- margin-bottom: 4px;
6
+ white-space: pre-wrap;
7
+ margin-right: 4px;
8
+ display: inline-block;
9
+ margin-bottom: 4px;
10
10
  }
11
11
 
12
12
  .constraint-code.required {
13
- font-weight: bold;
14
- color: #c7254e;
15
- /* A reddish color */
16
- background-color: #f9f2f4;
17
- padding: 2px 4px;
18
- border-radius: 4px;
13
+ font-weight: bold;
14
+ color: var(--ifm-color-danger-dark);
15
+ background-color: var(--ifm-color-danger-lightest);
16
+ padding: 2px 4px;
17
+ border-radius: 4px;
19
18
  }
20
19
 
21
20
  .nested-table-container {
22
- padding-left: 20px;
23
- border-left: 4px solid #eee;
21
+ padding-left: 1.25rem;
22
+ border-left: 0.25rem solid var(--ifm-table-border-color);
24
23
  }
25
24
 
26
25
  .schema-json-viewer {
27
- margin-bottom: 1em;
26
+ margin-bottom: 1em;
27
+ }
28
+
29
+ /* --- Property Name and Container Symbol Styles --- */
30
+
31
+ .property-name {
32
+ display: inline-flex;
33
+ align-items: baseline;
34
+ gap: 4px;
35
+ }
36
+
37
+ .container-symbol {
38
+ font-family: var(--ifm-font-family-monospace);
39
+ font-size: 0.9em;
40
+ color: var(--ifm-color-emphasis-600);
41
+ font-weight: bold;
42
+ margin-left: -0.55em;
43
+ }
44
+
45
+ /* --- Organigram Connector Line Styles --- */
46
+
47
+ /*
48
+ * Strategy:
49
+ * - ::before = vertical line from parent (top to bottom, or top to 50% for last items)
50
+ * - ::after = horizontal connector (from vertical line to property name)
51
+ * - background-image = parent-to-child lines (from 50% down) + continuing ancestor lines
52
+ */
53
+
54
+ /* Base positioning */
55
+ td[class*='level-'],
56
+ td.has-children {
57
+ position: relative;
58
+ }
59
+
60
+ /*
61
+ * VERTICAL LINE (::before)
62
+ * Connects this row to its parent and siblings.
63
+ * Runs from top to bottom (or to 50% for last items in group).
64
+ */
65
+ td[class*='level-']::before {
66
+ content: '';
67
+ position: absolute;
68
+ top: 0;
69
+ bottom: 0;
70
+ width: 0;
71
+ border-left: 1px solid var(--ifm-table-border-color);
72
+ }
73
+
74
+ /* Last items: stop vertical line at middle */
75
+ td.is-last[class*='level-']::before {
76
+ bottom: 50%;
77
+ }
78
+
79
+ /*
80
+ * HORIZONTAL CONNECTOR (::after)
81
+ * Connects vertical line to the property name.
82
+ */
83
+ td[class*='level-']::after {
84
+ content: '';
85
+ position: absolute;
86
+ top: 50%;
87
+ height: 0;
88
+ width: 0.75rem;
89
+ border-bottom: 1px solid var(--ifm-table-border-color);
90
+ }
91
+
92
+ /* --- Level-based positioning --- */
93
+
94
+ td.level-1::before,
95
+ td.level-1::after {
96
+ left: 0.5rem;
97
+ }
98
+
99
+ td.level-2::before,
100
+ td.level-2::after {
101
+ left: 1.75rem;
102
+ }
103
+
104
+ td.level-3::before,
105
+ td.level-3::after {
106
+ left: 3rem;
107
+ }
108
+
109
+ td.level-4::before,
110
+ td.level-4::after {
111
+ left: 4.25rem;
112
+ }
113
+
114
+ td.level-5::before,
115
+ td.level-5::after {
116
+ left: 5.5rem;
117
+ }
118
+
119
+ td.level-6::before,
120
+ td.level-6::after {
121
+ left: 6.75rem;
122
+ }
123
+
124
+ /*
125
+ * Note: Parent-to-child lines and continuing ancestor lines are now
126
+ * handled via inline styles in PropertyRow.js using background gradients.
127
+ * This allows dynamic combination of multiple line levels.
128
+ */
129
+
130
+ /* --- Choice Row Styles --- */
131
+
132
+ .choice-row {
133
+ background-color: var(--ifm-table-stripe-background);
134
+ }
135
+
136
+ .choice-row:hover {
137
+ background-color: var(--ifm-hover-overlay);
138
+ }
139
+
140
+ .choice-row-header {
141
+ position: relative;
142
+ display: flex;
143
+ align-items: center;
144
+ cursor: pointer;
145
+ }
146
+
147
+ .choice-row-header input {
148
+ position: absolute;
149
+ opacity: 0;
150
+ width: 100%;
151
+ height: 100%;
152
+ cursor: pointer;
153
+ }
154
+
155
+ .choice-row-description {
156
+ margin-left: 28px;
157
+ font-size: 0.9em;
158
+ color: var(--ifm-color-secondary-darkest);
159
+ }
160
+ .choice-row-header-description {
161
+ font-size: 0.9em;
162
+ color: var(--ifm-color-secondary-darkest);
163
+ }
164
+
165
+ .choice-row-header-headline {
166
+ margin-bottom: 0px;
167
+ }
168
+
169
+ .choice-row-toggle {
170
+ display: inline-block;
171
+ width: 1rem;
172
+ height: 1rem;
173
+ margin-right: 0.75rem;
174
+ border: 1px solid var(--ifm-color-emphasis-400);
175
+ flex-shrink: 0;
176
+ position: relative;
177
+ }
178
+
179
+ .choice-row-toggle.radio {
180
+ border-radius: 50%;
181
+ }
182
+
183
+ .choice-row-toggle.checkbox {
184
+ border-radius: 0.25rem;
185
+ }
186
+
187
+ .choice-row-toggle.checkbox::after {
188
+ content: '';
189
+ position: absolute;
190
+ display: none;
191
+ }
192
+
193
+ .choice-row-header input:checked + .choice-row-toggle.radio {
194
+ border-color: var(--ifm-color-primary-dark);
195
+ }
196
+
197
+ .choice-row-toggle.radio::after {
198
+ content: '';
199
+ position: absolute;
200
+ display: none;
201
+ border-radius: 50%;
202
+ background-color: var(--ifm-color-primary);
203
+ width: 0.5em;
204
+ height: 0.5em;
205
+ left: 22%;
206
+ top: 22%;
207
+ }
208
+
209
+ .choice-row-header input:checked + .choice-row-toggle.radio::after {
210
+ display: block;
211
+ }
212
+
213
+ .choice-row-header input:checked + .choice-row-toggle.checkbox {
214
+ border-color: var(--ifm-color-primary-dark);
215
+ }
216
+
217
+ .choice-row-header input:checked + .choice-row-toggle.checkbox::after {
218
+ display: block;
219
+ left: 0.29em;
220
+ top: 0.125rem;
221
+ width: 0.1875rem;
222
+ height: 0.4375rem;
223
+ border: solid var(--ifm-color-primary);
224
+ border-width: 0 0.125rem 0.125rem 0;
225
+ transform: rotate(45deg);
226
+ }
227
+
228
+ /* --- Example CodeBlock Styles --- */
229
+
230
+ .schema-examples {
231
+ margin: 0;
232
+ font-size: 0.85em;
233
+ white-space: pre-wrap;
234
+ /* Override theme defaults to make it blend into the table cell */
235
+ background-color: transparent !important;
236
+ box-shadow: none !important;
237
+ border: none !important;
238
+ }
239
+
240
+ .schema-examples pre,
241
+ .schema-examples code {
242
+ margin: 0 !important;
243
+ padding: 0 !important;
244
+ background-color: transparent !important;
245
+ }
246
+
247
+ /* Hide the copy button within the examples code block */
248
+ .schema-examples button {
249
+ display: none;
28
250
  }
@@ -1,47 +1,30 @@
1
1
  import React from 'react';
2
2
  import './SchemaRows.css';
3
3
  import PropertyRow from './PropertyRow';
4
- import TableHeader from './TableHeader';
4
+ import FoldableRows from './FoldableRows';
5
5
 
6
- const SchemaRows = ({ properties, requiredList = [], level = 0, getConstraints }) => {
7
- return (
8
- <>
9
- {Object.entries(properties).map(([key, prop]) => {
10
- const childProperties = prop.properties || (prop.items && prop.items.properties);
11
- const hasChildren = childProperties && Object.keys(childProperties).length > 0;
6
+ /**
7
+ * Renders the rows of the schema table from a flat `tableData` array.
8
+ * It maps over the array and renders the appropriate component for each row.
9
+ */
10
+ export default function SchemaRows({ tableData }) {
11
+ if (!tableData) {
12
+ return null;
13
+ }
12
14
 
13
- return (
14
- <React.Fragment key={key}>
15
- <PropertyRow
16
- propertyKey={key}
17
- prop={prop}
18
- requiredList={requiredList}
19
- level={level}
20
- getConstraints={getConstraints}
21
- />
22
- {hasChildren && (
23
- <tr key={`${key}-nested`}>
24
- <td colSpan="5" className="nested-table-container">
25
- <strong>{prop.type === 'array' ? `${key} [ ]` : `${key} { }`}</strong>
26
- <table style={{ width: '100%', marginTop: '5px' }}>
27
- <TableHeader />
28
- <tbody>
29
- <SchemaRows
30
- properties={prop.type === 'object' ? prop.properties : prop.items.properties}
31
- requiredList={prop.type === 'object' ? prop.required || [] : prop.items.required || []}
32
- level={level + 1}
33
- getConstraints={getConstraints}
34
- />
35
- </tbody>
36
- </table>
37
- </td>
38
- </tr>
39
- )}
40
- </React.Fragment>
41
- );
42
- })}
43
- </>
44
- );
45
- };
15
+ return tableData.map((row) => {
16
+ const key = row.path.join('.');
46
17
 
47
- export default SchemaRows;
18
+ if (row.type === 'choice') {
19
+ return <FoldableRows key={key} row={row} />;
20
+ }
21
+
22
+ if (row.type === 'property') {
23
+ return (
24
+ <PropertyRow key={key} row={row} isLastInGroup={row.isLastInGroup} />
25
+ );
26
+ }
27
+
28
+ return null;
29
+ });
30
+ }
@@ -3,19 +3,25 @@ import Heading from '@theme/Heading';
3
3
  import ExampleDataLayer from './ExampleDataLayer';
4
4
  import PropertiesTable from './PropertiesTable';
5
5
 
6
- // --- Main Exported Component ---
7
- // Helper: Build an example payload from per-property `examples` or other hints
8
-
9
-
10
6
  export default function SchemaViewer({ schema }) {
7
+ const hasOneOfAnyOf =
8
+ schema.oneOf ||
9
+ schema.anyOf ||
10
+ (schema.properties &&
11
+ Object.values(schema.properties).some(
12
+ (prop) => prop.oneOf || prop.anyOf,
13
+ ));
14
+ const exampleTitle = hasOneOfAnyOf
15
+ ? 'DataLayer Examples'
16
+ : 'DataLayer Example';
11
17
 
12
- return (
13
- <div>
14
- <Heading as="h2">DataLayer Example</Heading>
15
- <ExampleDataLayer schema={schema} />
18
+ return (
19
+ <div>
20
+ <Heading as="h2">{exampleTitle}</Heading>
21
+ <ExampleDataLayer schema={schema} />
16
22
 
17
- <Heading as="h2">Event Properties</Heading>
18
- <PropertiesTable schema={schema} />
19
- </div>
20
- );
21
- }
23
+ <Heading as="h2">Event Properties</Heading>
24
+ <PropertiesTable schema={schema} />
25
+ </div>
26
+ );
27
+ }
@@ -1,15 +1,15 @@
1
1
  import React from 'react';
2
2
 
3
3
  export default function TableHeader() {
4
- return (
5
- <thead>
6
- <tr>
7
- <th width="20%">Property</th>
8
- <th width="15%">Type</th>
9
- <th width="25%">Constraints</th>
10
- <th width="15%">Examples</th>
11
- <th>Description</th>
12
- </tr>
13
- </thead>
14
- );
15
- }
4
+ return (
5
+ <thead>
6
+ <tr>
7
+ <th>Property</th>
8
+ <th>Type</th>
9
+ <th>Constraints</th>
10
+ <th>Examples</th>
11
+ <th>Description</th>
12
+ </tr>
13
+ </thead>
14
+ );
15
+ }
@@ -1,69 +1,149 @@
1
- import fs from 'fs';
2
1
  import path from 'path';
3
- import loadSchema from './helpers/loadSchema';
4
- import processSchema from './helpers/processSchema';
5
- import MdxTemplate from './helpers/mdx-template.js';
2
+ import fs from 'fs';
3
+ import { getPathsForVersion } from './helpers/path-helpers.js';
4
+ import { readSchemas, writeDoc, createDir } from './helpers/file-system.js';
5
+ import { processOneOfSchema, slugify } from './helpers/schema-processing.js';
6
+ import SchemaDocTemplate from './helpers/schema-doc-template.js';
7
+ import ChoiceIndexTemplate from './helpers/choice-index-template.js';
8
+ import processSchema from './helpers/processSchema.js';
9
+
10
+ async function generateAndWriteDoc(
11
+ filePath,
12
+ schema,
13
+ eventName,
14
+ outputDir,
15
+ options,
16
+ alreadyMergedSchema = null,
17
+ ) {
18
+ const { organizationName, projectName, siteDir } = options;
19
+ const baseEditUrl = `https://github.com/${organizationName}/${projectName}/edit/main`;
20
+ const PARTIALS_DIR = path.join(siteDir, 'docs/partials');
21
+
22
+ const mergedSchema = alreadyMergedSchema || (await processSchema(filePath));
23
+
24
+ // Check for partials
25
+ const topPartialPath = path.join(PARTIALS_DIR, `${eventName}.mdx`);
26
+ const bottomPartialPath = path.join(PARTIALS_DIR, `${eventName}_bottom.mdx`);
27
+
28
+ let topPartialImport = '';
29
+ let topPartialComponent = '';
30
+ if (fs.existsSync(topPartialPath)) {
31
+ topPartialImport = `import TopPartial from '@site/docs/partials/${eventName}.mdx';`;
32
+ topPartialComponent = '<TopPartial />';
33
+ }
34
+
35
+ let bottomPartialImport = '';
36
+ let bottomPartialComponent = '';
37
+ if (fs.existsSync(bottomPartialPath)) {
38
+ bottomPartialImport = `import BottomPartial from '@site/docs/partials/${eventName}_bottom.mdx';`;
39
+ bottomPartialComponent = '<BottomPartial />';
40
+ }
41
+
42
+ const editUrl = `${baseEditUrl}/${path.relative(
43
+ path.join(siteDir, '..'),
44
+ filePath,
45
+ )}`;
46
+
47
+ const mdxContent = SchemaDocTemplate({
48
+ schema,
49
+ mergedSchema,
50
+ editUrl,
51
+ file: path.basename(filePath),
52
+ topPartialImport,
53
+ bottomPartialImport,
54
+ topPartialComponent,
55
+ bottomPartialComponent,
56
+ });
57
+
58
+ const outputFilename = path.basename(filePath).replace('.json', '.mdx');
59
+ writeDoc(outputDir, outputFilename, mdxContent);
60
+ }
61
+
62
+ async function generateOneOfDocs(
63
+ eventName,
64
+ schema,
65
+ filePath,
66
+ outputDir,
67
+ options,
68
+ ) {
69
+ const eventOutputDir = path.join(outputDir, eventName);
70
+ createDir(eventOutputDir);
71
+
72
+ const processed = await processOneOfSchema(schema, filePath);
73
+
74
+ const indexPageContent = ChoiceIndexTemplate({
75
+ schema,
76
+ processedOptions: processed,
77
+ });
78
+ writeDoc(eventOutputDir, 'index.mdx', indexPageContent);
79
+
80
+ for (const [
81
+ index,
82
+ { slug, schema: processedSchema },
83
+ ] of processed.entries()) {
84
+ const subChoiceType = processedSchema.oneOf ? 'oneOf' : null;
85
+ const prefixedSlug = `${(index + 1).toString().padStart(2, '0')}-${slug}`;
86
+
87
+ if (subChoiceType) {
88
+ const tempFilePath = path.join(eventOutputDir, `${slug}.json`);
89
+ fs.writeFileSync(tempFilePath, JSON.stringify(processedSchema, null, 2));
90
+ await generateOneOfDocs(
91
+ prefixedSlug,
92
+ processedSchema,
93
+ tempFilePath,
94
+ eventOutputDir,
95
+ options,
96
+ );
97
+ fs.unlinkSync(tempFilePath);
98
+ } else {
99
+ const tempFilePath = path.join(eventOutputDir, `${prefixedSlug}.json`);
100
+ fs.writeFileSync(tempFilePath, JSON.stringify(processedSchema, null, 2));
101
+ await generateAndWriteDoc(
102
+ tempFilePath,
103
+ processedSchema,
104
+ slug,
105
+ eventOutputDir,
106
+ options,
107
+ processedSchema,
108
+ );
109
+ fs.unlinkSync(tempFilePath);
110
+ }
111
+ }
112
+ }
6
113
 
7
114
  export default async function generateEventDocs(options) {
8
- const { organizationName, projectName, siteDir } = options || {};
9
- const baseEditUrl = `https://github.com/${organizationName}/${projectName}/edit/main`;
10
- // CONFIGURATION
11
- const SCHEMA_DIR = path.join(siteDir, 'static/schemas'); // Where your JSON files are
12
- const OUTPUT_DIR = path.join(siteDir, 'docs/events'); // Where MDX goes
13
- const PARTIALS_DIR = path.join(siteDir, 'docs/partials'); // Where your partials are
14
-
15
- // Ensure output dir exists
16
- if (!fs.existsSync(OUTPUT_DIR))
17
- {
18
- fs.mkdirSync(OUTPUT_DIR, { recursive: true });
115
+ const { siteDir, version, url } = options || {};
116
+ const { schemaDir, outputDir } = getPathsForVersion(version, siteDir);
117
+
118
+ createDir(outputDir);
119
+ const schemas = readSchemas(schemaDir);
120
+
121
+ console.log(`🚀 Generating documentation for ${schemas.length} schemas...`);
122
+
123
+ for (const { fileName, filePath, schema } of schemas) {
124
+ const eventName = fileName.replace('.json', '');
125
+
126
+ if (version) {
127
+ const baseUrl = url.endsWith('/') ? url.slice(0, -1) : url;
128
+ if (version !== 'current') {
129
+ schema.$id = `${baseUrl}/schemas/${version}/${fileName}`;
130
+ } else {
131
+ schema.$id = `${baseUrl}/schemas/next/${fileName}`;
132
+ }
19
133
  }
20
134
 
21
- // Read all JSON files
22
- const files = fs.readdirSync(SCHEMA_DIR).filter(file => file.endsWith('.json'));
23
-
24
- console.log(`🚀 Generating documentation for ${files.length} schemas...`);
25
-
26
- for (const file of files)
27
- {
28
- const filePath = path.join(SCHEMA_DIR, file);
29
- const schema = loadSchema(filePath);
30
- const mergedSchema = await processSchema(filePath);
31
- const eventName = file.replace('.json', '');
32
-
33
- // Check for partials
34
- const topPartialPath = path.join(PARTIALS_DIR, `${eventName}.mdx`);
35
- const bottomPartialPath = path.join(PARTIALS_DIR, `${eventName}_bottom.mdx`);
36
-
37
- let topPartialImport = '';
38
- let topPartialComponent = '';
39
- if (fs.existsSync(topPartialPath)) {
40
- topPartialImport = `import TopPartial from '@site/docs/partials/${eventName}.mdx';`;
41
- topPartialComponent = '<TopPartial />';
42
- }
43
-
44
- let bottomPartialImport = '';
45
- let bottomPartialComponent = '';
46
- if (fs.existsSync(bottomPartialPath)) {
47
- bottomPartialImport = `import BottomPartial from '@site/docs/partials/${eventName}_bottom.mdx';`;
48
- bottomPartialComponent = '<BottomPartial />';
49
- }
50
-
51
- const mdxContent = MdxTemplate({
52
- schema,
53
- mergedSchema,
54
- baseEditUrl,
55
- file,
56
- topPartialImport,
57
- bottomPartialImport,
58
- topPartialComponent,
59
- bottomPartialComponent
60
- });
61
-
62
- // Write the .mdx file
63
- const outputFilename = file.replace('.json', '.mdx');
64
- fs.writeFileSync(path.join(OUTPUT_DIR, outputFilename), mdxContent);
65
- console.log(`✅ Generated docs/events/${outputFilename}`);
135
+ if (schema.oneOf) {
136
+ await generateOneOfDocs(eventName, schema, filePath, outputDir, options);
137
+ } else {
138
+ await generateAndWriteDoc(
139
+ filePath,
140
+ schema,
141
+ eventName,
142
+ outputDir,
143
+ options,
144
+ );
66
145
  }
146
+ }
67
147
 
68
- console.log('🎉 Documentation generation complete!');
148
+ console.log('🎉 Documentation generation complete!');
69
149
  }