Skip to content
This repository has been archived by the owner. It is now read-only.
A centralized parser for versioned parsing of swagger docs in fleek modules
JavaScript
Branch: master
Clone or download
Fetching latest commit…
Cannot retrieve the latest commit at this time.
Permalink
Type Name Latest commit message Commit time
Failed to load latest commit information.
examples
lib
tests
.gitignore
.jscsrc
.snyk
.travis.yml
LICENSE
README.md
package.json

README.md

Fleek Parser - [DEPRECATED]

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.

You can’t perform that action at this time.