openapi-utils-path-for-uri

0.0.9 • Public • Published

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

Readme

Keywords

Package Sidebar

Install

npm i openapi-utils-path-for-uri

Weekly Downloads

38

Version

0.0.9

License

ISC

Unpacked Size

4.71 kB

Total Files

6

Last publish

Collaborators

  • robodo