forked from github/docs
-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathget-operations.js
More file actions
21 lines (17 loc) · 713 Bytes
/
Copy pathget-operations.js
File metadata and controls
21 lines (17 loc) · 713 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
const Operation = require('./operation')
// 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
module.exports = async function getOperations (schema) {
const operations = []
for (const [requestPath, operationsAtPath] of Object.entries(schema.paths)) {
for (const [verb, props] of Object.entries(operationsAtPath)) {
const serverUrl = schema.servers[0].url
.replace('{protocol}', 'https')
.replace('{hostname}', 'api.github.com')
const operation = new Operation(verb, requestPath, props, serverUrl)
operations.push(operation)
}
}
return operations
}