-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidateFull.ts
More file actions
71 lines (66 loc) · 1.63 KB
/
validateFull.ts
File metadata and controls
71 lines (66 loc) · 1.63 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
import { AsyncAPIDocumentInterface } from '@asyncapi/parser';
import { writeFile } from 'fs';
export function write_json(data: string, filename: string) {
writeFile(filename, data, 'utf8', (err) => {
if (err) {
console.error('Error writing to the file:', err);
return;
}
console.log('JSON file has been written successfully!');
});
}
export function validateAsyncApi(item: AsyncAPIDocumentInterface): string[] {
const missing: string[] = [];
// metadata
if (item.version == undefined) {
missing.push('version');
}
if (item.defaultContentType == undefined) {
missing.push('defaultContentType');
}
if (item.hasDefaultContentType == undefined) {
missing.push('hasDefaultContentType');
}
if (item.info == undefined) {
missing.push('info');
}
// root
if (item.servers == undefined) {
missing.push('servers');
}
if (item.channels == undefined) {
missing.push('channels');
}
if (item.operations == undefined) {
missing.push('operations');
}
if (item.messages == undefined) {
missing.push('messages');
}
if (item.schemas == undefined) {
missing.push('schemas');
}
if (item.securitySchemes == undefined) {
missing.push('securitySchemes');
}
if (item.components == undefined) {
missing.push('components');
}
// all
if (item.allServers == undefined) {
missing.push('allServers');
}
if (item.allChannels == undefined) {
missing.push('allChannels');
}
if (item.allOperations == undefined) {
missing.push('allOperations');
}
if (item.allMessages == undefined) {
missing.push('allMessages');
}
if (item.allSchemas == undefined) {
missing.push('allSchemas');
}
return missing.map(i => 'root.' + i);
}