1 | const { paths } = require('@netlify/open-api')
|
2 |
|
3 | const { omit } = require('./utils/omit')
|
4 |
|
5 |
|
6 | const getOperations = function() {
|
7 | return [].concat(
|
8 | ...Object.entries(paths).map(([path, pathItem]) => {
|
9 | const operations = omit(pathItem, ['parameters'])
|
10 | return Object.entries(operations).map(([method, operation]) => {
|
11 | const parameters = getParameters(pathItem.parameters, operation.parameters)
|
12 | return Object.assign({}, operation, { verb: method, path, parameters })
|
13 | })
|
14 | })
|
15 | )
|
16 | }
|
17 |
|
18 | const getParameters = function(pathParameters = [], operationParameters = []) {
|
19 | const parameters = [...pathParameters, ...operationParameters]
|
20 | return parameters.reduce(addParameter, { path: {}, query: {}, body: {} })
|
21 | }
|
22 |
|
23 | const addParameter = function(parameters, param) {
|
24 | return Object.assign({}, parameters, {
|
25 | [param.in]: Object.assign({}, parameters[param.in], { [param.name]: param })
|
26 | })
|
27 | }
|
28 |
|
29 | module.exports = { getOperations }
|