Skip to content

Commit dd91e3e

Browse files
committed
chore: update documentation generation workflow and improve links in documentation
- Added pull request trigger to the documentation generation workflow for better automation. - Updated links in PAGE_TEMPLATES.md to use absolute paths for consistency and clarity. - Enhanced the generate-schema-docs test suite with additional cases for handling schemas with array items and single items.
1 parent 419d0bd commit dd91e3e

3 files changed

Lines changed: 112 additions & 8 deletions

File tree

.github/workflows/documentation-generation.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
11
name: Documentation Generation
22

33
on:
4+
pull_request:
45
push:
5-
branches:
6-
- main
76

87
permissions:
98
contents: read

docs/features/configuration-based/PAGE_TEMPLATES.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -155,8 +155,8 @@ Full example of the minified and escaped component, which can be appended to [th
155155

156156
## Providing your own filters
157157

158-
Whilst DXT offers some out of the box filters, teams using the plugin have the capability to provide their own. See [PLUGIN_OPTIONS.md](../../PLUGIN_OPTIONS.md#custom-filters) for more information.
158+
Whilst DXT offers some out of the box filters, teams using the plugin have the capability to provide their own. See [PLUGIN_OPTIONS.md](/PLUGIN_OPTIONS) for more information.
159159

160160
## Using page templates with data from your own API
161161

162-
Page templates have access to``{{ context.data }}` , which is an attribute made available when a page event is triggered. It represents the entire response body from your API. To learn more about this, [see our guidance on page events](./PAGE_EVENTS.md).
162+
Page templates have access to``{{ context.data }}` , which is an attribute made available when a page event is triggered. It represents the entire response body from your API. To learn more about this, [see our guidance on page events](/features/configuration-based/PAGE_EVENTS).

scripts/generate-schema-docs.test.js

Lines changed: 109 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -73,19 +73,27 @@ jest.mock('path', () => {
7373

7474
if (typeof args[0] === 'string') {
7575
if (args[0] === '/mock/schemas/dir' && args[1]) {
76-
return `/mock/schemas/dir/${args[1]}`
76+
const arg1String =
77+
typeof args[1] === 'string' ? args[1] : JSON.stringify(args[1])
78+
return `/mock/schemas/dir/${arg1String}`
7779
}
7880

7981
if (args[0] === '/mock/docs/dir' && args[1]) {
80-
return `/mock/docs/dir/${args[1]}`
82+
const arg1String =
83+
typeof args[1] === 'string' ? args[1] : JSON.stringify(args[1])
84+
return `/mock/docs/dir/${arg1String}`
8185
}
8286

8387
if (args[0] === '/mock/temp/dir' && args[1]) {
84-
return `/mock/temp/dir/${args[1]}`
88+
const arg1String =
89+
typeof args[1] === 'string' ? args[1] : JSON.stringify(args[1])
90+
return `/mock/temp/dir/${arg1String}`
8591
}
8692

8793
if (args[0].includes('/docs/dir') && args[1]) {
88-
return `/mock/docs/dir/${args[1]}`
94+
const arg1String =
95+
typeof args[1] === 'string' ? args[1] : JSON.stringify(args[1])
96+
return `/mock/docs/dir/${arg1String}`
8997
}
9098
}
9199

@@ -365,6 +373,42 @@ describe('Schema Documentation Generator', () => {
365373
expect(capturedContent).toContain('* [schema1](schema1.md)')
366374
expect(capturedContent).toContain('* [schema2](schema2.md)')
367375
})
376+
377+
it('categorizes schemas correctly into core and advanced', () => {
378+
path.basename.mockImplementation((filename) =>
379+
filename.replace('.json', '')
380+
)
381+
let capturedContent = ''
382+
fs.writeFileSync.mockImplementation((path, content) => {
383+
capturedContent = content
384+
})
385+
386+
const schemaFiles = [
387+
'component-schema-v2.json', // core
388+
'form-metadata-author-schema.json', // advanced
389+
'uncategorized-schema.json' // neither
390+
]
391+
392+
const consoleSpy = jest.spyOn(console, 'log').mockImplementation()
393+
394+
createIndexFile(schemaFiles)
395+
396+
expect(capturedContent).toContain(
397+
'* [component-schema-v2](component-schema-v2.md)'
398+
)
399+
400+
expect(capturedContent).toContain(
401+
'* [form-metadata-author-schema](form-metadata-author-schema.md)'
402+
)
403+
404+
expect(consoleSpy).toHaveBeenCalledWith(
405+
expect.stringContaining(
406+
"Schema 'uncategorized-schema' is not categorised"
407+
)
408+
)
409+
410+
consoleSpy.mockRestore()
411+
})
368412
})
369413

370414
describe('cleanupFiles', () => {
@@ -566,6 +610,67 @@ describe('Schema Documentation Generator', () => {
566610
'Display Component Name'
567611
)
568612
})
613+
614+
it('handles array items in schema', () => {
615+
const schemaWithArrayItems = {
616+
title: 'Array Items Schema',
617+
items: [
618+
{
619+
title: 'First Item',
620+
properties: { prop: { title: 'Property' } }
621+
},
622+
{
623+
type: 'string'
624+
}
625+
]
626+
}
627+
628+
const titleMap = {}
629+
buildTitleMap(schemaWithArrayItems, 'array-items', titleMap)
630+
631+
expect(titleMap['array-items']).toBe('Array Items Schema')
632+
expect(titleMap['array-items/items/0']).toBe('First Item')
633+
expect(titleMap['array-items/items/1']).toBe('Item 2')
634+
expect(titleMap['array-items/items/0/properties/prop']).toBe('Property')
635+
})
636+
637+
it('handles single item schema', () => {
638+
const schemaWithSingleItem = {
639+
title: 'Single Item Schema',
640+
items: {
641+
title: 'The Item',
642+
properties: {
643+
name: { title: 'Name Property' },
644+
age: { type: 'number' }
645+
}
646+
}
647+
}
648+
649+
const titleMap = {}
650+
buildTitleMap(schemaWithSingleItem, 'single-item', titleMap)
651+
652+
expect(titleMap['single-item']).toBe('Single Item Schema')
653+
expect(titleMap['single-item/items']).toBe('The Item')
654+
expect(titleMap['single-item/items/properties/name']).toBe(
655+
'Name Property'
656+
)
657+
expect(titleMap['single-item/items/properties/age']).toBe('Age')
658+
})
659+
660+
it('handles item without a title', () => {
661+
const schemaWithoutItemTitle = {
662+
title: 'No Item Title Schema',
663+
items: {
664+
type: 'string',
665+
properties: { prop: { type: 'string' } }
666+
}
667+
}
668+
669+
const titleMap = {}
670+
buildTitleMap(schemaWithoutItemTitle, 'no-item-title', titleMap)
671+
672+
expect(titleMap['no-item-title/items']).toBe('Item')
673+
})
569674
})
570675

571676
describe('formatPropertyName', () => {

0 commit comments

Comments
 (0)