1.2.5 • Published 9 years ago

fleek-parser v1.2.5

Weekly downloads
4
License
MIT
Repository
github
Last release
9 years ago

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.

1.2.5

9 years ago

1.2.4

9 years ago

1.2.3

9 years ago

1.2.2

9 years ago

1.2.1

9 years ago

1.2.0

9 years ago

1.1.3

9 years ago

1.1.2

9 years ago

1.1.1

9 years ago

1.1.0

9 years ago

1.0.0

10 years ago

0.1.8

10 years ago

0.1.7

10 years ago

0.1.6

10 years ago

0.1.5

10 years ago

0.1.4

10 years ago

0.1.3

10 years ago

0.0.2

10 years ago

0.1.2

10 years ago

0.1.1

10 years ago

0.1.0

10 years ago