A centralized parser for versioned parsing of swagger docs in fleek modules
JavaScript
Latest commit 52ce06a Dec 5, 2016 @johnhof johnhof committed on GitHub Merge pull request #43 from fleekjs/snyk-patch
added snyk
Permalink
Failed to load latest commit information.
examples
lib removed console log Nov 15, 2016
tests
.gitignore
.jscsrc Added jscs Oct 12, 2015
.snyk added snyk Dec 5, 2016
.travis.yml Updated readme && travis integration Oct 4, 2015
LICENSE
README.md
package.json

README.md

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.