docusaurus-plugin-generate-schema-docs 1.5.4 → 1.6.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.
@@ -4,6 +4,7 @@ exports[`generateEventDocs (oneOf with $anchor) should generate documentation us
4
4
  "---
5
5
  title: Parent Event Anchor
6
6
  description: "This is a parent event with oneOf."
7
+ custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_anchor__/static/schemas/parent-event-anchor.json
7
8
  ---
8
9
  import SchemaJsonViewer from '@theme/SchemaJsonViewer';
9
10
 
@@ -25,7 +26,7 @@ exports[`generateEventDocs (oneOf with $anchor) should generate documentation us
25
26
  title: Child Event Anchor
26
27
  description: "This is a child event with an anchor."
27
28
  sidebar_label: Child Event Anchor
28
- custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_anchor__/docs/parent-event-anchor/01-child-event-with-anchor.json
29
+ custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_anchor__/static/schemas/parent-event-anchor.json
29
30
  ---
30
31
 
31
32
  import SchemaViewer from '@theme/SchemaViewer';
@@ -54,7 +55,7 @@ exports[`generateEventDocs (oneOf with $anchor) should generate documentation us
54
55
  title: Child Event Title
55
56
  description: "This is a child event with only a title."
56
57
  sidebar_label: Child Event Title
57
- custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_anchor__/docs/parent-event-anchor/02-child-event-title.json
58
+ custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_anchor__/static/schemas/parent-event-anchor.json
58
59
  ---
59
60
 
60
61
  import SchemaViewer from '@theme/SchemaViewer';
@@ -4,6 +4,7 @@ exports[`generateEventDocs (nested oneOf) should generate nested documentation c
4
4
  "---
5
5
  title: Parent Event
6
6
  description: "undefined"
7
+ custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_nested__/static/schemas/parent-event.json
7
8
  ---
8
9
  import SchemaJsonViewer from '@theme/SchemaJsonViewer';
9
10
 
@@ -23,6 +24,7 @@ exports[`generateEventDocs (nested oneOf) should generate nested documentation c
23
24
  "---
24
25
  title: Child Event
25
26
  description: "undefined"
27
+ custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_nested__/static/schemas/child-event.json
26
28
  ---
27
29
  import SchemaJsonViewer from '@theme/SchemaJsonViewer';
28
30
 
@@ -44,7 +46,7 @@ exports[`generateEventDocs (nested oneOf) should generate nested documentation c
44
46
  title: Grandchild A
45
47
  description: undefined
46
48
  sidebar_label: Grandchild A
47
- custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_nested__/docs/parent-event/01-child-event/01-grandchild-a.json
49
+ custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_nested__/static/schemas/child-event.json
48
50
  ---
49
51
 
50
52
  import SchemaViewer from '@theme/SchemaViewer';
@@ -73,7 +75,7 @@ exports[`generateEventDocs (nested oneOf) should generate nested documentation c
73
75
  title: Grandchild B
74
76
  description: undefined
75
77
  sidebar_label: Grandchild B
76
- custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_nested__/docs/parent-event/01-child-event/02-grandchild-b.json
78
+ custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_nested__/static/schemas/child-event.json
77
79
  ---
78
80
 
79
81
  import SchemaViewer from '@theme/SchemaViewer';
@@ -91,6 +91,7 @@ exports[`generateEventDocs (non-versioned) should generate documentation correct
91
91
  "---
92
92
  title: Root Choice Event
93
93
  description: "An example event that has oneOf at the root level."
94
+ custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures__/static/schemas/root-choice-event.json
94
95
  ---
95
96
  import SchemaJsonViewer from '@theme/SchemaJsonViewer';
96
97
 
@@ -112,7 +113,7 @@ exports[`generateEventDocs (non-versioned) should generate documentation correct
112
113
  title: Option A
113
114
  description: "An example event that has oneOf at the root level."
114
115
  sidebar_label: Option A
115
- custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures__/docs/root-choice-event/01-option-a.json
116
+ custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures__/static/schemas/root-choice-event.json
116
117
  ---
117
118
 
118
119
  import SchemaViewer from '@theme/SchemaViewer';
@@ -141,7 +142,7 @@ exports[`generateEventDocs (non-versioned) should generate documentation correct
141
142
  title: Option B
142
143
  description: "An example event that has oneOf at the root level."
143
144
  sidebar_label: Option B
144
- custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures__/docs/root-choice-event/02-option-b.json
145
+ custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures__/static/schemas/root-choice-event.json
145
146
  ---
146
147
 
147
148
  import SchemaViewer from '@theme/SchemaViewer';
@@ -61,11 +61,18 @@ describe('generateEventDocs (oneOf with $anchor)', () => {
61
61
  'utf-8',
62
62
  );
63
63
  expect(childWithAnchor).toMatchSnapshot();
64
+ // Inline oneOf options (using $anchor for slug) must link to the parent schema file
65
+ expect(childWithAnchor).toContain(
66
+ 'custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_anchor__/static/schemas/parent-event-anchor.json',
67
+ );
64
68
 
65
69
  const childWithTitle = fs.readFileSync(
66
70
  path.join(parentDir, '02-child-event-title.mdx'),
67
71
  'utf-8',
68
72
  );
69
73
  expect(childWithTitle).toMatchSnapshot();
74
+ expect(childWithTitle).toContain(
75
+ 'custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_anchor__/static/schemas/parent-event-anchor.json',
76
+ );
70
77
  });
71
78
  });
@@ -70,11 +70,18 @@ describe('generateEventDocs (nested oneOf)', () => {
70
70
  'utf-8',
71
71
  );
72
72
  expect(grandchildA).toMatchSnapshot();
73
+ // Nested $ref-based oneOf options must link to the resolved source schema file
74
+ expect(grandchildA).toContain(
75
+ 'custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_nested__/static/schemas/child-event.json',
76
+ );
73
77
 
74
78
  const grandchildB = fs.readFileSync(
75
79
  path.join(childDir, '02-grandchild-b.mdx'),
76
80
  'utf-8',
77
81
  );
78
82
  expect(grandchildB).toMatchSnapshot();
83
+ expect(grandchildB).toContain(
84
+ 'custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures_nested__/static/schemas/child-event.json',
85
+ );
79
86
  });
80
87
  });
@@ -80,11 +80,18 @@ describe('generateEventDocs (non-versioned)', () => {
80
80
  'utf-8',
81
81
  );
82
82
  expect(rootChoiceA).toMatchSnapshot();
83
+ // Inline oneOf options must link to the parent schema file, not a temp output file
84
+ expect(rootChoiceA).toContain(
85
+ 'custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures__/static/schemas/root-choice-event.json',
86
+ );
83
87
 
84
88
  const rootChoiceB = fs.readFileSync(
85
89
  path.join(choiceEventDir, '02-option-b.mdx'),
86
90
  'utf-8',
87
91
  );
88
92
  expect(rootChoiceB).toMatchSnapshot();
93
+ expect(rootChoiceB).toContain(
94
+ 'custom_edit_url: https://github.com/test-org/test-project/edit/main/__fixtures__/static/schemas/root-choice-event.json',
95
+ );
89
96
  });
90
97
  });
@@ -14,34 +14,39 @@ async function generateAndWriteDoc(
14
14
  outputDir,
15
15
  options,
16
16
  alreadyMergedSchema = null,
17
+ editFilePath = null,
17
18
  ) {
18
- const { organizationName, projectName, siteDir, dataLayerName } = options;
19
+ const { organizationName, projectName, siteDir, dataLayerName, version } =
20
+ options;
19
21
  const baseEditUrl = `https://github.com/${organizationName}/${projectName}/edit/main`;
20
- const PARTIALS_DIR = path.join(siteDir, 'docs/partials');
22
+
23
+ const { outputDir: versionOutputDir } = getPathsForVersion(version, siteDir);
24
+ const PARTIALS_DIR = path.join(versionOutputDir, 'partials');
25
+ const relativePartialsDir = path.relative(siteDir, PARTIALS_DIR);
21
26
 
22
27
  const mergedSchema = alreadyMergedSchema || (await processSchema(filePath));
23
28
 
24
29
  // Check for partials
25
- const topPartialPath = path.join(PARTIALS_DIR, `${eventName}.mdx`);
26
- const bottomPartialPath = path.join(PARTIALS_DIR, `${eventName}_bottom.mdx`);
30
+ const topPartialPath = path.join(PARTIALS_DIR, `_${eventName}.mdx`);
31
+ const bottomPartialPath = path.join(PARTIALS_DIR, `_${eventName}_bottom.mdx`);
27
32
 
28
33
  let topPartialImport = '';
29
34
  let topPartialComponent = '';
30
35
  if (fs.existsSync(topPartialPath)) {
31
- topPartialImport = `import TopPartial from '@site/docs/partials/${eventName}.mdx';`;
36
+ topPartialImport = `import TopPartial from '@site/${relativePartialsDir}/_${eventName}.mdx';`;
32
37
  topPartialComponent = '<TopPartial />';
33
38
  }
34
39
 
35
40
  let bottomPartialImport = '';
36
41
  let bottomPartialComponent = '';
37
42
  if (fs.existsSync(bottomPartialPath)) {
38
- bottomPartialImport = `import BottomPartial from '@site/docs/partials/${eventName}_bottom.mdx';`;
43
+ bottomPartialImport = `import BottomPartial from '@site/${relativePartialsDir}/_${eventName}_bottom.mdx';`;
39
44
  bottomPartialComponent = '<BottomPartial />';
40
45
  }
41
46
 
42
47
  const editUrl = `${baseEditUrl}/${path.relative(
43
48
  path.join(siteDir, '..'),
44
- filePath,
49
+ editFilePath || filePath,
45
50
  )}`;
46
51
 
47
52
  const mdxContent = SchemaDocTemplate({
@@ -67,6 +72,10 @@ async function generateOneOfDocs(
67
72
  outputDir,
68
73
  options,
69
74
  ) {
75
+ const { organizationName, projectName, siteDir } = options;
76
+ const baseEditUrl = `https://github.com/${organizationName}/${projectName}/edit/main`;
77
+ const editUrl = `${baseEditUrl}/${path.relative(path.join(siteDir, '..'), filePath)}`;
78
+
70
79
  const eventOutputDir = path.join(outputDir, eventName);
71
80
  createDir(eventOutputDir);
72
81
 
@@ -75,12 +84,13 @@ async function generateOneOfDocs(
75
84
  const indexPageContent = ChoiceIndexTemplate({
76
85
  schema,
77
86
  processedOptions: processed,
87
+ editUrl,
78
88
  });
79
89
  writeDoc(eventOutputDir, 'index.mdx', indexPageContent);
80
90
 
81
91
  for (const [
82
92
  index,
83
- { slug, schema: processedSchema },
93
+ { slug, schema: processedSchema, sourceFilePath },
84
94
  ] of processed.entries()) {
85
95
  const subChoiceType = processedSchema.oneOf ? 'oneOf' : null;
86
96
  const prefixedSlug = `${(index + 1).toString().padStart(2, '0')}-${slug}`;
@@ -91,7 +101,7 @@ async function generateOneOfDocs(
91
101
  await generateOneOfDocs(
92
102
  prefixedSlug,
93
103
  processedSchema,
94
- tempFilePath,
104
+ sourceFilePath || filePath,
95
105
  eventOutputDir,
96
106
  options,
97
107
  );
@@ -106,6 +116,7 @@ async function generateOneOfDocs(
106
116
  eventOutputDir,
107
117
  options,
108
118
  processedSchema,
119
+ sourceFilePath || filePath,
109
120
  );
110
121
  fs.unlinkSync(tempFilePath);
111
122
  }
@@ -1,9 +1,10 @@
1
1
  export default function ChoiceIndexTemplate(data) {
2
- const { schema, processedOptions } = data;
2
+ const { schema, processedOptions, editUrl } = data;
3
3
 
4
4
  return `---
5
5
  title: ${schema.title}
6
6
  description: "${schema.description}"
7
+ custom_edit_url: ${editUrl}
7
8
  ---
8
9
  import SchemaJsonViewer from '@theme/SchemaJsonViewer';
9
10
 
@@ -25,8 +25,10 @@ export async function processOneOfSchema(schema, filePath) {
25
25
 
26
26
  for (const option of schema[choiceType]) {
27
27
  let resolvedOption = option;
28
+ let sourceFilePath = null;
28
29
  if (option.$ref && !option.$ref.startsWith('#')) {
29
30
  const refPath = path.resolve(path.dirname(filePath), option.$ref);
31
+ sourceFilePath = refPath;
30
32
  resolvedOption = await processSchema(refPath);
31
33
  }
32
34
 
@@ -54,6 +56,7 @@ export async function processOneOfSchema(schema, filePath) {
54
56
  processedSchemas.push({
55
57
  slug,
56
58
  schema: newSchema,
59
+ sourceFilePath,
57
60
  });
58
61
  }
59
62
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-generate-schema-docs",
3
- "version": "1.5.4",
3
+ "version": "1.6.0",
4
4
  "description": "Docusaurus plugin to generate documentation from JSON schemas.",
5
5
  "main": "index.js",
6
6
  "license": "MIT",
@@ -12,7 +12,8 @@
12
12
  "@apidevtools/json-schema-ref-parser": "^15.1.3",
13
13
  "json-schema-merge-allof": "^0.8.1",
14
14
  "ajv": "^8.17.1",
15
- "ajv-draft-04": "^1.0.0"
15
+ "ajv-draft-04": "^1.0.0",
16
+ "ajv-keywords": "^5.1.0"
16
17
  },
17
18
  "publishConfig": {
18
19
  "access": "public",