npm.io
0.0.9 • Published 8 years ago

openapi-utils-path-for-uri

Licence
ISC
Version
0.0.9
Deps
0
Size
5 kB
Vulns
0
Weekly
0

openapi-utils-path-for-uri

npm version Build Status JavaScript Style Guide

Get an openApi path for an URI.

Installation

npm install --save openapi-utils-path-for-uri

Usage

Given the following openApi definition:

{
  "paths": {
    "/animals/cats": {
      "get": { }
    },
    "/animals/{species}/cats": {
      "get": { }
    },
    "/animals/{species}/dogs": {
      "get": { }
    },
    "/animals/{species}/dogs/{breed}": {
      "get": { }
    }
  }
}

You can retrieve the paths like this:

var api = require('./your-openapi.json')
var openApiUtils = require('openapi-utils-path-for-uri')

var openApiPath1 = openApiUtils.pathForUri(api, '/animals/mammal/cats')
console.log(openApiPath1)
/*
/animals/{species}/cats
*/

var openApiPath2 = openApiUtils.pathForUri(api, '/animals/mammal/dogs/terrier')
console.log(openApiPath2)
/*
/animals/{species}/dogs/{breed}
*/

var openApiPath3 = openApiUtils.pathForUri(api, '/animals/cats')
console.log(openApiPath3)
/*
/animals/cats
*/

Keywords