forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathget-operations.js
More file actions
28 lines (22 loc) · 826 Bytes
/
get-operations.js
File metadata and controls
28 lines (22 loc) · 826 Bytes
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
#!/usr/bin/env node
import Operation from './operation.js'
import Webhook from './webhook.js'
// The module accepts a JSON schema object as input
// and returns an array of its operation objects with their
// HTTP verb and requestPath attached as properties
export default async function getOperations(schema) {
const operations = []
for (const [requestPath, operationsAtPath] of Object.entries(schema.paths)) {
for (const [verb, operationProps] of Object.entries(operationsAtPath)) {
const operation = new Operation(verb, requestPath, operationProps, schema.servers)
operations.push(operation)
}
}
return operations
}
export async function getWebhooks(schema) {
if (schema.webhooks) {
return Object.values(schema.webhooks).map((webhook) => new Webhook(webhook.post))
}
return []
}