0.0.1 • Published 7 years ago

openapi-utils-path-methods v0.0.1

Weekly downloads
4
License
ISC
Repository
github
Last release
7 years ago

openapi-utils-path-methods

npm version Build Status JavaScript Style Guide

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']
*/