docusaurus-plugin-generate-schema-docs 1.8.1 → 1.8.3

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 (37) hide show
  1. package/README.md +17 -7
  2. package/__tests__/__fixtures__/validateSchemas/main-schema-with-constraints-ref.json +20 -0
  3. package/__tests__/__snapshots__/generateEventDocs.anchor.test.js.snap +15 -3
  4. package/__tests__/__snapshots__/generateEventDocs.nested.test.js.snap +20 -4
  5. package/__tests__/__snapshots__/generateEventDocs.test.js.snap +30 -6
  6. package/__tests__/__snapshots__/generateEventDocs.versioned.test.js.snap +10 -2
  7. package/__tests__/components/ConditionalRows.test.js +28 -0
  8. package/__tests__/components/FoldableRows.test.js +31 -290
  9. package/__tests__/components/PropertyRow.test.js +216 -0
  10. package/__tests__/components/SchemaJsonViewer.test.js +76 -10
  11. package/__tests__/components/SchemaRows.test.js +62 -12
  12. package/__tests__/components/__snapshots__/ConnectorLines.visualRegression.test.js.snap +3 -3
  13. package/__tests__/generateEventDocs.partials.test.js +95 -0
  14. package/__tests__/generateEventDocs.test.js +3 -0
  15. package/__tests__/helpers/processSchema.test.js +29 -0
  16. package/__tests__/helpers/schemaToTableData.test.js +112 -0
  17. package/__tests__/helpers/validator.test.js +32 -0
  18. package/components/ConditionalRows.js +6 -3
  19. package/components/FoldableRows.js +9 -3
  20. package/components/PropertiesTable.js +2 -1
  21. package/components/PropertyRow.js +90 -5
  22. package/components/SchemaJsonViewer.js +221 -4
  23. package/components/SchemaRows.css +98 -7
  24. package/components/SchemaRows.js +11 -1
  25. package/generateEventDocs.js +184 -18
  26. package/helpers/buildExampleFromSchema.js +3 -3
  27. package/helpers/choice-index-template.js +6 -2
  28. package/helpers/constraintSchemaPaths.js +46 -0
  29. package/helpers/file-system.js +28 -0
  30. package/helpers/mergeSchema.js +16 -0
  31. package/helpers/processSchema.js +19 -6
  32. package/helpers/schema-doc-template.js +7 -1
  33. package/helpers/schema-processing.js +4 -11
  34. package/helpers/schemaToExamples.js +4 -4
  35. package/helpers/schemaToTableData.js +68 -7
  36. package/helpers/validator.js +7 -0
  37. package/package.json +1 -1
@@ -41,6 +41,36 @@ function materializeConditionalBranchSchema(branchSchema, parentSchema) {
41
41
  };
42
42
  }
43
43
 
44
+ function hasRenderableAdditionalProperties(schemaNode) {
45
+ return !!(
46
+ schemaNode &&
47
+ schemaNode.additionalProperties &&
48
+ typeof schemaNode.additionalProperties === 'object' &&
49
+ !Array.isArray(schemaNode.additionalProperties)
50
+ );
51
+ }
52
+
53
+ function getRenderablePatternProperties(schemaNode) {
54
+ if (!schemaNode?.patternProperties) {
55
+ return [];
56
+ }
57
+
58
+ return Object.entries(schemaNode.patternProperties)
59
+ .filter(
60
+ ([, patternSchema]) =>
61
+ patternSchema &&
62
+ typeof patternSchema === 'object' &&
63
+ !Array.isArray(patternSchema),
64
+ )
65
+ .map(([pattern, patternSchema]) => [
66
+ `patternProperties /${pattern}/`,
67
+ {
68
+ ...patternSchema,
69
+ 'x-schema-keyword-row': true,
70
+ },
71
+ ]);
72
+ }
73
+
44
74
  function processOptions(
45
75
  choices,
46
76
  level,
@@ -247,8 +277,26 @@ export function schemaToTableData(
247
277
  ) {
248
278
  if (!subSchema) return;
249
279
 
250
- if (subSchema.properties) {
251
- const propKeys = Object.keys(subSchema.properties);
280
+ const patternPropertyEntries = getRenderablePatternProperties(subSchema);
281
+
282
+ if (
283
+ subSchema.properties ||
284
+ hasRenderableAdditionalProperties(subSchema) ||
285
+ patternPropertyEntries.length > 0
286
+ ) {
287
+ const propEntries = subSchema.properties
288
+ ? Object.entries(subSchema.properties)
289
+ : [];
290
+ if (hasRenderableAdditionalProperties(subSchema)) {
291
+ propEntries.push([
292
+ 'additionalProperties',
293
+ {
294
+ ...subSchema.additionalProperties,
295
+ 'x-schema-keyword-row': true,
296
+ },
297
+ ]);
298
+ }
299
+ propEntries.push(...patternPropertyEntries);
252
300
  const hasSiblingChoices = !!(
253
301
  subSchema.oneOf ||
254
302
  subSchema.anyOf ||
@@ -256,19 +304,17 @@ export function schemaToTableData(
256
304
  );
257
305
 
258
306
  // Filter out properties that should be skipped to get accurate count
259
- const visiblePropKeys = propKeys.filter((name) => {
260
- const propSchema = subSchema.properties[name];
307
+ const visiblePropEntries = propEntries.filter(([name, propSchema]) => {
261
308
  return !(
262
309
  propSchema['x-gtm-clear'] === true && isEffectivelyEmpty(propSchema)
263
310
  );
264
311
  });
265
312
 
266
- visiblePropKeys.forEach((name, index) => {
267
- const propSchema = subSchema.properties[name];
313
+ visiblePropEntries.forEach(([name, propSchema], index) => {
268
314
  const newPath = [...currentPath, name];
269
315
 
270
316
  const isLastProp =
271
- index === visiblePropKeys.length - 1 && !hasSiblingChoices;
317
+ index === visiblePropEntries.length - 1 && !hasSiblingChoices;
272
318
 
273
319
  // Updated Logic:
274
320
  // A property is visually "last" only if it is the last property
@@ -283,6 +329,8 @@ export function schemaToTableData(
283
329
 
284
330
  // Determine if this property has children and what type
285
331
  const hasNestedProperties = !!propSchema.properties;
332
+ const hasAdditionalProperties =
333
+ hasRenderableAdditionalProperties(propSchema);
286
334
  const hasArrayItems =
287
335
  propSchema.type === 'array' &&
288
336
  !!(propSchema.items?.properties || propSchema.items?.if);
@@ -290,6 +338,7 @@ export function schemaToTableData(
290
338
  const hasNestedConditional = isConditionalWrapper;
291
339
  const hasChildren =
292
340
  hasNestedProperties ||
341
+ hasAdditionalProperties ||
293
342
  hasArrayItems ||
294
343
  hasNestedChoice ||
295
344
  hasNestedConditional;
@@ -302,6 +351,7 @@ export function schemaToTableData(
302
351
  choiceOptions.some((opt) => opt.type === 'object' || opt.properties);
303
352
  if (
304
353
  hasNestedProperties ||
354
+ hasAdditionalProperties ||
305
355
  (isChoiceWrapper && propSchema.type === 'object') ||
306
356
  (isConditionalWrapper && propSchema.type === 'object') ||
307
357
  choiceOptionsAreObjects
@@ -388,6 +438,8 @@ export function schemaToTableData(
388
438
  containerType,
389
439
  continuingLevels: [...continuingLevels],
390
440
  groupBrackets: [...currentGroupBrackets],
441
+ isSchemaKeywordRow: propSchema['x-schema-keyword-row'] === true,
442
+ keepConnectorOpen: propSchema['x-keep-connector-open'] === true,
391
443
  });
392
444
 
393
445
  if (propSchema.properties) {
@@ -399,6 +451,15 @@ export function schemaToTableData(
399
451
  childContinuingLevels,
400
452
  currentGroupBrackets,
401
453
  );
454
+ } else if (propSchema.type === 'object' && hasAdditionalProperties) {
455
+ buildRows(
456
+ propSchema,
457
+ currentLevel + 1,
458
+ newPath,
459
+ [],
460
+ childContinuingLevels,
461
+ currentGroupBrackets,
462
+ );
402
463
  } else if (
403
464
  propSchema.type === 'array' &&
404
465
  (propSchema.items?.properties || propSchema.items?.if)
@@ -7,11 +7,18 @@ import ajvKeywords from 'ajv-keywords';
7
7
  import path from 'path';
8
8
  import { promises as fs } from 'fs';
9
9
  import { URL } from 'url';
10
+ import { resolveConstraintSchemaPath } from './constraintSchemaPaths.js';
10
11
 
11
12
  function createAjvInstance(schemas, mainSchema, schemaPath) {
12
13
  const schemaVersion = mainSchema?.$schema;
13
14
 
14
15
  const loadSchema = async (uri) => {
16
+ const constraintPath = resolveConstraintSchemaPath(uri);
17
+ if (constraintPath) {
18
+ const schemaContent = await fs.readFile(constraintPath, 'utf-8');
19
+ return JSON.parse(schemaContent);
20
+ }
21
+
15
22
  let localPath;
16
23
  if (uri.startsWith('http')) {
17
24
  const url = new URL(uri);
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "docusaurus-plugin-generate-schema-docs",
3
- "version": "1.8.1",
3
+ "version": "1.8.3",
4
4
  "description": "Docusaurus plugin to generate documentation from JSON schemas.",
5
5
  "main": "index.js",
6
6
  "license": "MIT",