docusaurus-plugin-generate-schema-docs 1.6.0 → 1.7.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.
- package/__tests__/__fixtures__/static/schemas/battle-test-event.json +771 -0
- package/__tests__/__fixtures__/static/schemas/conditional-event.json +52 -0
- package/__tests__/__fixtures__/static/schemas/nested-conditional-event.json +50 -0
- package/__tests__/components/ConditionalRows.test.js +150 -0
- package/__tests__/components/ConnectorLines.visualRegression.test.js +93 -0
- package/__tests__/components/FoldableRows.test.js +7 -4
- package/__tests__/components/SchemaRows.test.js +31 -0
- package/__tests__/components/__snapshots__/ConnectorLines.visualRegression.test.js.snap +7 -0
- package/__tests__/generateEventDocs.partials.test.js +134 -0
- package/__tests__/helpers/buildExampleFromSchema.test.js +49 -0
- package/__tests__/helpers/schemaToExamples.test.js +75 -0
- package/__tests__/helpers/schemaToTableData.battleTest.test.js +704 -0
- package/__tests__/helpers/schemaToTableData.hierarchicalLines.test.js +190 -7
- package/__tests__/helpers/schemaToTableData.test.js +263 -2
- package/__tests__/helpers/validator.test.js +6 -6
- package/components/ConditionalRows.js +156 -0
- package/components/FoldableRows.js +88 -61
- package/components/PropertiesTable.js +1 -1
- package/components/PropertyRow.js +24 -8
- package/components/SchemaRows.css +115 -0
- package/components/SchemaRows.js +31 -4
- package/generateEventDocs.js +41 -34
- package/helpers/buildExampleFromSchema.js +11 -0
- package/helpers/continuingLinesStyle.js +169 -0
- package/helpers/schema-doc-template.js +2 -5
- package/helpers/schemaToExamples.js +75 -2
- package/helpers/schemaToTableData.js +252 -26
- package/helpers/update-schema-ids.js +3 -3
- package/helpers/validator.js +7 -19
- package/package.json +1 -1
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
import { schemaToExamples } from '../../helpers/schemaToExamples';
|
|
2
2
|
import choiceEventSchema from '../__fixtures__/static/schemas/choice-event.json';
|
|
3
|
+
import conditionalEventSchema from '../__fixtures__/static/schemas/conditional-event.json';
|
|
4
|
+
import nestedConditionalEventSchema from '../__fixtures__/static/schemas/nested-conditional-event.json';
|
|
3
5
|
|
|
4
6
|
describe('schemaToExamples', () => {
|
|
5
7
|
it('should generate examples for all options in a complex schema', () => {
|
|
@@ -53,4 +55,77 @@ describe('schemaToExamples', () => {
|
|
|
53
55
|
expect(userIdIntegerOption).toBeDefined();
|
|
54
56
|
expect(userIdIntegerOption.example).toHaveProperty('payment_method');
|
|
55
57
|
});
|
|
58
|
+
|
|
59
|
+
describe('if/then/else conditional examples', () => {
|
|
60
|
+
it('generates two examples for schema with if/then/else', () => {
|
|
61
|
+
const groups = schemaToExamples(conditionalEventSchema);
|
|
62
|
+
const conditionalGroup = groups.find((g) => g.property === 'conditional');
|
|
63
|
+
expect(conditionalGroup).toBeDefined();
|
|
64
|
+
expect(conditionalGroup.options).toHaveLength(2);
|
|
65
|
+
});
|
|
66
|
+
|
|
67
|
+
it('then example includes then properties merged with base', () => {
|
|
68
|
+
const groups = schemaToExamples(conditionalEventSchema);
|
|
69
|
+
const conditionalGroup = groups.find((g) => g.property === 'conditional');
|
|
70
|
+
const thenOption = conditionalGroup.options.find(
|
|
71
|
+
(o) => o.title === 'When condition is met',
|
|
72
|
+
);
|
|
73
|
+
expect(thenOption).toBeDefined();
|
|
74
|
+
expect(thenOption.example).toHaveProperty('event');
|
|
75
|
+
expect(thenOption.example).toHaveProperty('postal_code', '90210');
|
|
76
|
+
expect(thenOption.example).toHaveProperty('state', 'CA');
|
|
77
|
+
});
|
|
78
|
+
|
|
79
|
+
it('else example includes else properties merged with base', () => {
|
|
80
|
+
const groups = schemaToExamples(conditionalEventSchema);
|
|
81
|
+
const conditionalGroup = groups.find((g) => g.property === 'conditional');
|
|
82
|
+
const elseOption = conditionalGroup.options.find(
|
|
83
|
+
(o) => o.title === 'When condition is not met',
|
|
84
|
+
);
|
|
85
|
+
expect(elseOption).toBeDefined();
|
|
86
|
+
expect(elseOption.example).toHaveProperty('event');
|
|
87
|
+
expect(elseOption.example).toHaveProperty('postal_code', 'K1A 0B1');
|
|
88
|
+
expect(elseOption.example).not.toHaveProperty('state');
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
it('generates only one example when else is absent', () => {
|
|
92
|
+
const schema = {
|
|
93
|
+
type: 'object',
|
|
94
|
+
properties: {
|
|
95
|
+
status: { type: 'string', examples: ['active'] },
|
|
96
|
+
},
|
|
97
|
+
if: { properties: { status: { const: 'active' } } },
|
|
98
|
+
then: {
|
|
99
|
+
properties: {
|
|
100
|
+
active_since: { type: 'string', examples: ['2024-01-01'] },
|
|
101
|
+
},
|
|
102
|
+
},
|
|
103
|
+
};
|
|
104
|
+
const groups = schemaToExamples(schema);
|
|
105
|
+
const conditionalGroup = groups.find((g) => g.property === 'conditional');
|
|
106
|
+
expect(conditionalGroup).toBeDefined();
|
|
107
|
+
expect(conditionalGroup.options).toHaveLength(1);
|
|
108
|
+
expect(conditionalGroup.options[0].title).toBe('When condition is met');
|
|
109
|
+
});
|
|
110
|
+
|
|
111
|
+
it('detects nested conditional points inside properties', () => {
|
|
112
|
+
const groups = schemaToExamples(nestedConditionalEventSchema);
|
|
113
|
+
const conditionalGroup = groups.find((g) => g.property === 'conditional');
|
|
114
|
+
expect(conditionalGroup).toBeDefined();
|
|
115
|
+
expect(conditionalGroup.options).toHaveLength(2);
|
|
116
|
+
|
|
117
|
+
const thenOption = conditionalGroup.options.find(
|
|
118
|
+
(o) => o.title === 'When condition is met',
|
|
119
|
+
);
|
|
120
|
+
expect(thenOption.example.shipping).toHaveProperty(
|
|
121
|
+
'priority_level',
|
|
122
|
+
'high',
|
|
123
|
+
);
|
|
124
|
+
|
|
125
|
+
const elseOption = conditionalGroup.options.find(
|
|
126
|
+
(o) => o.title === 'When condition is not met',
|
|
127
|
+
);
|
|
128
|
+
expect(elseOption.example.shipping).toHaveProperty('estimated_days', 5);
|
|
129
|
+
});
|
|
130
|
+
});
|
|
56
131
|
});
|