1
0
mirror of synced 2025-12-20 10:28:40 -05:00
Files
docs/script/rest/utils/get-operations.js
Kevin Heis 8a56437c93 Pretty format (#20352)
* Update prettier flow to include JS

* Run prettier

* ...run prettier
2021-07-14 14:35:01 -07:00

21 lines
672 B
JavaScript

#!/usr/bin/env node
import Operation from './operation.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, props] of Object.entries(operationsAtPath)) {
const serverUrl = schema.servers[0].url.replace('{protocol}', 'http(s)')
const operation = new Operation(verb, requestPath, props, serverUrl)
operations.push(operation)
}
}
return operations
}