fleek-parser

1.2.5 • Public • Published

Fleek Parser

Build Status npm Dependencies Join the chat at https://gitter.im/fleekjs/fleek-parser

Parser module that parses swagger documentation json into a single fully dereferenced object. Acts as the linch pin to the Fleekjs environment of micro-utilities.

$ npm install fleek-parser

Beyond basic JSON parse:

  • Render all $ref within the JSON
  • Render all $ref referring to a separate file - TODO
  • Merge allOf objects
  • provide various utilities to access the Swagger document in a non-standard way

Key

Usage

Basic

app.js

var parser = require('fleek-parser');
 
// parse stringified JSON as json object
var swaggerFile = fs.readFileSync('./path/to/swagger.json')
var swagger     = parser.parse(swaggerFile);
 
// OR
 
// parse JSON file from path
var swagger = parser.parse("./path/to/swagger.json");

swagger.json

{
  "swagger": "2.0",
  "info": {
    "version": "2.0.0",
    "title": "Swagger Petstore",
    "contact": {
      "name": "Swagger API Team",
      "url": "http://swagger.io"
    }
  },
  "host": "petstore.swagger.io",
  "basePath": "/api",
  "schemes": [
    "http"
  ],
  "paths": {
    "/pets": {
      "get": {
        "tags": [ "Pet Operations" ],
        "summary": "finds pets in the system",
        "responses": {
          "200": {
            "description": "pet response",
            "schema": {
              "type": "array",
              "items": {
                "$ref": "#/definitions/Pet"
              }
            }
          }
        }
      }
    }
  },
  "definitions": {
    "Pet": {
      "type": "object",
      "required": [
        "id"
      ],
      "properties": {
        "id": {
          "type": "integer",
          "format": "int64"
        }
      }
    }
  }
}

Dereference example

console.log(swagger.paths['/pets'].get.responses['200'].schema.items)
// {
//   "type": "object",
//   "required": [
//     "id"
//   ],
//   "properties": {
//     "id": {
//       "type": "integer",
//       "format": "int64"
//     }
//   }
// }

Utilities

Additional properties are attached to the result to simplify usage

var parser  = require('fleek-parser');
var swagger = parser.parse('./swager.json');
 
console.log(swagger.controllers);
console.log(swagger.routeValidationMap);
console.log(swagger.sanitizedRoutes);

Reference Material

Swagger

By the authors

Authors

Built and maintained with by the Hart team.

Package Sidebar

Install

npm i fleek-parser

Weekly Downloads

4

Version

1.2.5

License

MIT

Last publish

Collaborators

  • ptariche
  • lannguyen
  • johnhof