Skip to content

Commit df6efa6

Browse files
Copilothawkeyexl
andcommitted
Improve array schema references to properly link to referenced schemas
Co-authored-by: hawkeyexl <[email protected]>
1 parent 6243266 commit df6efa6

File tree

5 files changed

+55
-16
lines changed

5 files changed

+55
-16
lines changed

.scripts/buildSchemaReferencesV3.js

Lines changed: 49 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -481,18 +481,35 @@ function generatePropertyRow(name, property, options = {}) {
481481
if (property.items && property.items.type) {
482482
typeDetails.type = `${typeDetails.type} of ${property.items.type}`;
483483
}
484+
// Check if items have a title (schema reference)
485+
else if (property.items && property.items.title) {
486+
typeDetails.type = `${typeDetails.type} of object([${property.items.title}](/docs/references/schemas/${property.items.title}))`;
487+
}
484488
// Check if items have multiple possible types
485489
else if (property.items && (property.items.anyOf || property.items.oneOf)) {
486490
const itemVariants = property.items.anyOf || property.items.oneOf;
487-
if (itemVariants.length === 1 && itemVariants[0].type) {
488-
typeDetails.type = `${typeDetails.type} of ${itemVariants[0].type}`;
489-
} else {
490-
const types = itemVariants
491-
.filter(v => v.type)
492-
.map(v => v.type)
493-
.join(', ');
494-
if (types) {
495-
typeDetails.type = `${typeDetails.type} of ${types}`;
491+
// Handle single variant with title or type
492+
if (itemVariants.length === 1) {
493+
if (itemVariants[0].title) {
494+
typeDetails.type = `${typeDetails.type} of object([${itemVariants[0].title}](/docs/references/schemas/${itemVariants[0].title}))`;
495+
} else if (itemVariants[0].type) {
496+
typeDetails.type = `${typeDetails.type} of ${itemVariants[0].type}`;
497+
}
498+
}
499+
// Handle multiple variants
500+
else {
501+
const typesList = itemVariants.map(v => {
502+
if (v.title) {
503+
return `object([${v.title}](/docs/references/schemas/${v.title}))`;
504+
} else if (v.type) {
505+
return v.type;
506+
} else {
507+
return "unknown";
508+
}
509+
});
510+
511+
if (typesList.length > 0) {
512+
typeDetails.type = `${typeDetails.type} of one of: ${typesList.join(', ')}`;
496513
}
497514
}
498515
}
@@ -608,7 +625,15 @@ function getItems(property, typeFilter) {
608625

609626
// Apply type filter if specified
610627
if (typeFilter && items.length > 0) {
611-
items = items.filter((item) => item.type === typeFilter);
628+
items = items.filter((item) => {
629+
// If item has explicit type that matches
630+
if (item.type === typeFilter) return true;
631+
632+
// For object filter, also include items with title (schema references)
633+
if (typeFilter === 'object' && item.title) return true;
634+
635+
return false;
636+
});
612637
}
613638

614639
return items;
@@ -718,6 +743,9 @@ function getArraySubTypes(property, depth) {
718743
.map(variant => {
719744
if (variant.type === "object" && variant.title) {
720745
return `${variant.type}([${variant.title}](/docs/references/schemas/${variant.title}))`;
746+
} else if (variant.title) {
747+
// Handle case where title exists but type might be undefined
748+
return `object([${variant.title}](/docs/references/schemas/${variant.title}))`;
721749
} else if (variant.type) {
722750
return variant.type;
723751
} else {
@@ -731,6 +759,10 @@ function getArraySubTypes(property, depth) {
731759
else if (item.type) {
732760
subTypes = `${subTypes}<br/>${spaces}- ${item.type}`;
733761
}
762+
// Check for title on the item directly (handles schema references in array items)
763+
else if (item.title) {
764+
subTypes = `${subTypes}<br/>${spaces}-&nbsp;object([${item.title}](/docs/references/schemas/${item.title}))`;
765+
}
734766
// Handle unknown types
735767
else {
736768
subTypes = `${subTypes}<br/>${spaces}- unknown`;
@@ -751,6 +783,9 @@ function getArraySubTypes(property, depth) {
751783
const variantTypes = variants.map(variant => {
752784
if (variant.type === "object" && variant.title) {
753785
return `${variant.type}([${variant.title}](/docs/references/schemas/${variant.title}))`;
786+
} else if (variant.title) {
787+
// Handle case where title exists but type might be undefined
788+
return `object([${variant.title}](/docs/references/schemas/${variant.title}))`;
754789
} else if (variant.type) {
755790
return variant.type;
756791
} else {
@@ -759,6 +794,10 @@ function getArraySubTypes(property, depth) {
759794
}).join(", ");
760795
subTypes += variantTypes;
761796
}
797+
// Check for title on the item directly (handles schema references in array items)
798+
else if (item.title) {
799+
subTypes = `${subTypes}object([${item.title}](/docs/references/schemas/${item.title}))`;
800+
}
762801
// Handle regular types
763802
else if (item.type) {
764803
subTypes += item.type;

docs/references/schemas/config.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@ afterAll | string | Optional. Path(s) to test specifications to perform after th
2222
afterAll | array of string | Optional. Path(s) to test specifications to perform after those specified by `input`. Useful for cleaning up testing environments. |
2323
detectSteps | boolean | Optional. Whether or not to detect steps in input files based on defined markup. | `true`
2424
logLevel | string | Optional. Amount of detail to output when performing an operation.<br/><br/>Accepted values: `silent`, `error`, `warning`, `info`, `debug` | `info`
25-
runOn | array of object | Optional. Contexts to run the test in. Overrides contexts defined at the config and spec levels. |
26-
fileTypes | array of string, object, object | Optional. Configuration for file types and their markup detection. |
25+
runOn | array of object([context](/docs/references/schemas/context)) | Optional. Contexts to run the test in. Overrides contexts defined at the config and spec levels. |
26+
fileTypes | array of one of: object([Predefined](/docs/references/schemas/Predefined)), object([Custom](/docs/references/schemas/Custom)), object([Executable](/docs/references/schemas/Executable)) | Optional. Configuration for file types and their markup detection. |
2727
integrations | object | Optional. Options for connecting to external services. |
2828
integrations.openApi | array of unknown | Optional. No description provided. |
2929
telemetry | object | Optional. Options around sending telemetry for Doc Detective usage. | ``{"send":true}``

docs/references/schemas/context.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ browsers.window.height | integer | Optional. Height of the browser window in pix
2020
browsers.viewport | object | Optional. Viewport dimensions. |
2121
browsers.viewport.width | integer | Optional. Width of the viewport in pixels. |
2222
browsers.viewport.height | integer | Optional. Height of the viewport in pixels. |
23-
browsers | array of string, object | Optional. Browsers to run tests on. |
23+
browsers | array of one of: string, object | Optional. Browsers to run tests on. |
2424
browsers[].name | string | Required. Name of the browser.<br/><br/>Accepted values: `chrome`, `firefox`, `safari`, `webkit` |
2525
browsers[].headless | boolean | Optional. If `true`, runs the browser in headless mode. | `true`
2626
browsers[].window | object | Optional. Browser dimensions. |

docs/references/schemas/specification.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ specId | string | Optional. Unique identifier for the test specification. |
1111
description | string | Optional. Description of the test specification. |
1212
specPath | string | Optional. Path to the test specification. |
1313
contentPath | string | Optional. Path to the content that the specification is associated with. |
14-
runOn | array of object | Optional. Contexts to run the test in. Overrides contexts defined at the config and spec levels. |
14+
runOn | array of object([context](/docs/references/schemas/context)) | Optional. Contexts to run the test in. Overrides contexts defined at the config and spec levels. |
1515
openApi | array of unknown | Optional. No description provided. |
16-
tests | array of object | Required. [Tests](test) to perform. |
16+
tests | array of object([test](/docs/references/schemas/test)) | Required. [Tests](test) to perform. |
1717

1818
## Examples
1919

docs/references/schemas/test.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@ testId | string | Optional. Unique identifier for the test. |
1515
description | string | Optional. Description of the test. |
1616
contentPath | string | Optional. Path to the content that the test is associated with. |
1717
detectSteps | boolean | Optional. Whether or not to detect steps in input files based on markup regex. | `true`
18-
runOn | array of object | Optional. Contexts to run the test in. Overrides contexts defined at the config and spec levels. |
18+
runOn | array of object([context](/docs/references/schemas/context)) | Optional. Contexts to run the test in. Overrides contexts defined at the config and spec levels. |
1919
openApi | array of unknown | Optional. No description provided. |
2020
before | string | Optional. Path to a test specification to perform before this test, while maintaining this test's context. Useful for setting up testing environments. Only the `steps` property is used from the first test in the setup spec. |
2121
after | string | Optional. Path to a test specification to perform after this test, while maintaining this test's context. Useful for cleaning up testing environments. Only the `steps` property is used from the first test in the cleanup spec. |

0 commit comments

Comments
 (0)