docusaurus-plugin-generate-schema-docs 1.7.0 → 1.8.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.
@@ -125,6 +125,7 @@ export default function PropertyRow({ row, isLastInGroup, bracketEnds }) {
125
125
  rowSpan={rowSpan}
126
126
  style={{ ...indentStyle, ...continuingLinesStyle }}
127
127
  className={clsx(
128
+ 'property-cell',
128
129
  level > 0 && `level-${level}`,
129
130
  isLastInGroup && 'is-last',
130
131
  hasChildren && 'has-children',
@@ -143,7 +144,7 @@ export default function PropertyRow({ row, isLastInGroup, bracketEnds }) {
143
144
  </td>
144
145
 
145
146
  {/* The first constraint cell */}
146
- <td>
147
+ <td className="constraint-cell">
147
148
  {firstConstraint && (
148
149
  <code
149
150
  className={clsx(
@@ -181,7 +182,7 @@ export default function PropertyRow({ row, isLastInGroup, bracketEnds }) {
181
182
  {/* Render subsequent constraints in their own rows */}
182
183
  {remainingConstraints.map((constraint) => (
183
184
  <tr className={clsx(required && 'required-row')} key={constraint}>
184
- <td>
185
+ <td className="constraint-cell">
185
186
  <code
186
187
  className={clsx(
187
188
  'constraint-code',
@@ -63,10 +63,19 @@
63
63
  }
64
64
 
65
65
  .schema-table th:first-child,
66
- .schema-table td:first-child {
66
+ .schema-table td.property-cell {
67
67
  border-left: none;
68
68
  }
69
69
 
70
+ /*
71
+ * Constraint-only continuation rows render a single cell; in those rows that
72
+ * cell is also :first-child, but it still needs the separator before the
73
+ * "Constraints" column.
74
+ */
75
+ .schema-table td.constraint-cell {
76
+ border-left: 1px solid var(--ifm-table-border-color);
77
+ }
78
+
70
79
  .schema-table thead th {
71
80
  border-bottom: 2px solid var(--ifm-table-border-color);
72
81
  }
@@ -0,0 +1,70 @@
1
+ import { schemaToExamples } from './schemaToExamples';
2
+ import {
3
+ DEFAULT_SNIPPET_TARGET_ID,
4
+ findClearableProperties,
5
+ generateSnippetForTarget,
6
+ getSnippetTarget,
7
+ } from './snippetTargets';
8
+
9
+ export function resolveExampleTargets(schema) {
10
+ const configured = schema?.['x-tracking-targets'];
11
+ const targetIds =
12
+ Array.isArray(configured) && configured.length > 0
13
+ ? configured
14
+ : [DEFAULT_SNIPPET_TARGET_ID];
15
+
16
+ const targets = targetIds
17
+ .map((id) => {
18
+ try {
19
+ return getSnippetTarget(id);
20
+ } catch {
21
+ return null;
22
+ }
23
+ })
24
+ .filter(Boolean);
25
+
26
+ if (targets.length > 0) return targets;
27
+ return [getSnippetTarget(DEFAULT_SNIPPET_TARGET_ID)];
28
+ }
29
+
30
+ export function buildExampleModel(schema, { dataLayerName } = {}) {
31
+ const exampleGroups = schemaToExamples(schema);
32
+ const targets = resolveExampleTargets(schema);
33
+
34
+ if (!exampleGroups || exampleGroups.length === 0) {
35
+ return {
36
+ targets,
37
+ variantGroups: [],
38
+ isSimpleDefault: false,
39
+ };
40
+ }
41
+
42
+ const variantGroups = exampleGroups.map((group) => ({
43
+ property: group.property,
44
+ options: group.options.map((option, index) => ({
45
+ id: `${group.property}-${index}`,
46
+ title: option.title,
47
+ example: option.example,
48
+ snippets: Object.fromEntries(
49
+ targets.map((target) => [
50
+ target.id,
51
+ generateSnippetForTarget({
52
+ targetId: target.id,
53
+ example: option.example,
54
+ schema,
55
+ dataLayerName,
56
+ }),
57
+ ]),
58
+ ),
59
+ })),
60
+ }));
61
+
62
+ return {
63
+ targets,
64
+ variantGroups,
65
+ isSimpleDefault:
66
+ variantGroups.length === 1 && variantGroups[0].property === 'default',
67
+ };
68
+ }
69
+
70
+ export { findClearableProperties };
@@ -1,5 +1,33 @@
1
1
  import path from 'path';
2
+ import fs from 'fs';
2
3
  import processSchema from './processSchema.js';
4
+ import mergeJsonSchema from 'json-schema-merge-allof';
5
+
6
+ function mergePropertySchemas(baseProperties = {}, optionProperties = {}) {
7
+ const mergedProperties = {
8
+ ...baseProperties,
9
+ ...optionProperties,
10
+ };
11
+
12
+ for (const key of Object.keys(baseProperties)) {
13
+ if (!Object.prototype.hasOwnProperty.call(optionProperties, key)) {
14
+ continue;
15
+ }
16
+
17
+ mergedProperties[key] = mergeJsonSchema(
18
+ {
19
+ allOf: [baseProperties[key], optionProperties[key]],
20
+ },
21
+ {
22
+ resolvers: {
23
+ defaultResolver: mergeJsonSchema.options.resolvers.title,
24
+ },
25
+ },
26
+ );
27
+ }
28
+
29
+ return mergedProperties;
30
+ }
3
31
 
4
32
  export function slugify(text) {
5
33
  if (!text) {
@@ -20,7 +48,15 @@ export async function processOneOfSchema(schema, filePath) {
20
48
  const choiceType = schema.oneOf ? 'oneOf' : null;
21
49
 
22
50
  if (choiceType) {
23
- const parentWithoutChoice = { ...schema };
51
+ let parentSchema = schema;
52
+
53
+ // When the root schema is loaded from disk, use its processed form so
54
+ // parent-level allOf refs (e.g. shared dataLayer metadata) are preserved.
55
+ if (filePath && fs.existsSync(filePath)) {
56
+ parentSchema = await processSchema(filePath);
57
+ }
58
+
59
+ const parentWithoutChoice = { ...parentSchema };
24
60
  delete parentWithoutChoice[choiceType];
25
61
 
26
62
  for (const option of schema[choiceType]) {
@@ -34,10 +70,10 @@ export async function processOneOfSchema(schema, filePath) {
34
70
 
35
71
  // Merge the parent schema with the resolved option schema
36
72
  const newSchema = { ...parentWithoutChoice, ...resolvedOption };
37
- newSchema.properties = {
38
- ...parentWithoutChoice.properties,
39
- ...resolvedOption.properties,
40
- };
73
+ newSchema.properties = mergePropertySchemas(
74
+ parentWithoutChoice.properties,
75
+ resolvedOption.properties,
76
+ );
41
77
 
42
78
  let slug;
43
79
  const hadId = resolvedOption.$id && resolvedOption.$id.endsWith('.json');