openapi-utils-path-methods
v0.0.1
Published
Get openapi path methods
Downloads
3
Readme
openapi-utils-path-methods
Get openapi path methods.
Installation
npm install --save openapi-utils-path-methods
Usage
Given the following openApi definition:
{
"paths": {
"/animals/cats": {
"get": { },
"post": { }
},
"/animals/{species}/cats": {
"get": { },
"put": { }
},
"/animals/{species}/dogs": {
"get": { }
},
"/animals/{species}/dogs/{breed}": {
"get": { },
"patch": { }
}
}
}
You can retrieve the path methods like this:
var api = require('./your-openapi.json')
var openApiUtils = require('openapi-utils-path-methods')
var m = openApiUtils.methods(api, '/animals/{species}/cats')
console.log(m)
/*
['GET', 'PUT']
*/
m = openApiUtils.methods(api, '/animals/{species}/dogs/{breed}')
console.log(m)
/*
['GET', 'PATCH']
*/
m = openApiUtils.methods(api, '/animals/cats')
console.log(m)
/*
['GET', 'POST']
*/
m = openApiUtils.methods(api, '/animals/{species}/dogs')
console.log(m)
/*
['GET']
*/