Socket
Socket
Sign inDemoInstall

swagger-parameters

Package Overview
Dependencies
23
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    swagger-parameters

Validate and parse request data using swagger parameters arrays


Version published
Weekly downloads
210
increased by4.48%
Maintainers
1
Install size
1.43 MB
Created
Weekly downloads
 

Readme

Source

swagger-parameters Build Status

Validate and parse request data using swagger parameters arrays

swagger-parameters turns your Swagger/OpenAPI parameters into a full JSON schema that can be used to parse and validate HTTP request data. The library is fully server-agnostic. You're responsible for converting your request paths and queries into key-value data. swagger-parameters will perform validation and type coercion and return a copy of your parsed data (if valid).

Install

$ npm install --save swagger-parameters

Usage

var Parser = require('swagger-parameters')
// var Schema = require('swagger-parameters/schema')

// /users/{id}/orders?page={page}
var parse = Parser([
  {
    name: 'id',
    in: 'path',
    type: 'integer',
    required: true
  },
  {
    name: 'page',
    in: 'query',
    default: 1,
    type: 'integer'
  },
  {
    name: 'token',
    in: 'header',
    required: true
  }
])

parse({
  path: {id: '1'},
  query: {page: '5'},
  headers: {token: 't'}
}, function (err, data) {
  if (err) throw err
  console.log(data)
  //=> {path: {id: 1}, query: {page: 5}, headers: {token: 't'}}
})

API

Parser(parameters, [data]) -> function<parse>
parameters

Type: array[object]
Default: []

An array of Swagger/OpenAPI parameter definition.

data

Required
Type: object

Data that can be resolved by $ref parameters.

parse(data, callback) -> undefined
data

Required
Type: object

A {path, query, headers} object, each with key-value data.

callback

Required
Type: function
Arguments: err, data

A callback to be called with a validation error or a parsed copy of the data. Validation errors will have an errors property which is an array of JSON schema error objects from ajv.

License

MIT © Ben Drucker

Keywords

FAQs

Last updated on 09 Oct 2018

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc