-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdocs.js
More file actions
99 lines (85 loc) · 3.96 KB
/
Copy pathdocs.js
File metadata and controls
99 lines (85 loc) · 3.96 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
const lib = require('./lib');
const fs = require('fs');
(async() => {
try {
const schemas = await lib.parseEntities();
let markdown = '# API Reference\n\n';
markdown += 'This reference shows all available schemas and their component names for use in path definitions.\n\n';
// Separate schemas by type
const writeSchemas = [];
const objectSchemas = [];
const commonSchemas = [];
Object.keys(schemas).forEach(key => {
if (key.startsWith('write')) {
writeSchemas.push(key);
} else if (key.endsWith('Object')) {
objectSchemas.push(key);
} else {
commonSchemas.push(key);
}
});
// Write Schemas Section
markdown += '## Write Schemas (Input Objects)\n\n';
markdown += 'These schemas define the input structure for creating/updating resources.\n\n';
markdown += '| Schema Name | Referenced As |\n';
markdown += '|-------------|---------------|\n';
writeSchemas.sort().forEach(schema => {
markdown += `| ${schema} | #/components/schemas/${schema} |\n`;
});
markdown += '\n';
// Full Object Schemas Section
markdown += '## Full Object Schemas\n\n';
markdown += 'These schemas define complete resource objects including system-generated properties.\n\n';
markdown += '| Schema Name | Referenced As |\n';
markdown += '|-------------|---------------|\n';
objectSchemas.sort().forEach(schema => {
markdown += `| ${schema} | #/components/schemas/${schema} |\n`;
});
markdown += '\n';
// Common Schemas Section
markdown += '## Common Schemas\n\n';
markdown += 'These are reusable schema components defined in common.yml files.\n\n';
markdown += '| Schema Name | Referenced As |\n';
markdown += '|-------------|---------------|\n';
commonSchemas.sort().forEach(schema => {
markdown += `| ${schema} | #/components/schemas/${schema} |\n`;
});
markdown += '\n';
// Quick Reference Section
markdown += '## Quick Reference Rules\n\n';
markdown += '### File to Schema Name Transformations\n\n';
markdown += '**Write Entities:**\n';
markdown += '- File: `entities/writes/[name].yml`\n';
markdown += '- Schema: `write[Name]` (capitalized)\n';
markdown += '- Example: `entities/writes/user.yml` → `writeUser`\n\n';
markdown += '**Full Entities:**\n';
markdown += '- File: `entities/[name].yml`\n';
markdown += '- Schema: `[name]Object`\n';
markdown += '- Example: `entities/user.yml` → `userObject`\n\n';
markdown += '**Common Definitions:**\n';
markdown += '- File: `entities/common.yml#/definitions/[name]`\n';
markdown += '- Schema: `[name]`\n';
markdown += '- Example: `common.yml#/definitions/address` → `address`\n\n';
markdown += '### Using in Path Definitions\n\n';
markdown += 'In your `paths/*Paths.yml` files, always reference schemas with:\n';
markdown += '```yaml\n';
markdown += '$ref: \'#/components/schemas/[schemaName]\'\n';
markdown += '```\n\n';
markdown += 'Example:\n';
markdown += '```yaml\n';
markdown += 'responses:\n';
markdown += ' \'200\':\n';
markdown += ' description: successful operation\n';
markdown += ' content:\n';
markdown += ' application/json:\n';
markdown += ' schema:\n';
markdown += ' $ref: \'#/components/schemas/userObject\'\n';
markdown += '```\n';
// Write to file
await fs.promises.writeFile('./API_REFERENCE.md', markdown);
console.log('✓ API reference generated: API_REFERENCE.md');
} catch (error) {
console.error('Error generating documentation:', error.message);
process.exit(1);
}
})()