Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swagger-mock-validator

Package Overview
Dependencies
Maintainers
3
Versions
30
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagger-mock-validator

A CLI tool to validate mocks against swagger specs.

  • 3.0.0
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
412
decreased by-53.76%
Maintainers
3
Weekly downloads
 
Created
Source

Swagger Mock Validator

A CLI tool to validate mocks against swagger specs.

What is Swagger Mock Validator

  • A command line tool that confirms mock request and responses conform to the schema specified in a swagger specification.
  • Supports mocks in Pact format (1.0, 1.1 or 2.0) and the Pact Broker (1.8.0 or higher)
  • Supports local files and urls
  • Supports swagger files in json or yaml format
  • Can be invoked from the command line in any language

For a list of all the validation rules see RULES.md.

Requirements

  • nodejs 4.x or higher (tested using 4.x, 6.x, 8.x and 9.x)
  • npm 2.x or higher (tested using 2.x, 3.x and 5x)

Installation

Install the tool using npm

npm install --global swagger-mock-validator

Usage

Invoke the tool with a path or url to a swagger file and a path or url to a mock file. These files should be in json format.

swagger-mock-validator /path/to/swagger.json /path/to/pact.json

swagger-mock-validator https://api.com/swagger.json https://pact-broker.com/pact.json

swagger-mock-validator /path/to/swagger.json https://pact-broker.com/pact.json

Invoking this command will confirm the swagger spec and mock are compatible with each other. RULES.md contains the details of what is verified.

If the two files are compatible with each other an exit status of 0 is returned.

If the two files are not compatible with each other an exit status of 1 is returned, along with a message containing the reason why the two files are not compatible.

For more options on how to use the command run the command with the help flag.

swagger-mock-validator --help

Providers using the Pact Broker

Provider services can easily verify all the consumer pact files uploaded to a Pact Broker using this tool. Invoke the tool with a url to the Pact Broker along with the name of the provider service and the tool will automatically discover and validate the latest versions of the consumer pact files for the provider service.

swagger-mock-validator /path/to/swagger.json https://pact-broker.com --provider my-provider-name

Analytics (Opt-In)

The tool can be configured to send analytics events to a server of your choosing. Use the --analyticsUrl flag to pass a url that the tool should post the event to. The tool will send this event via a http post request and will timeout after 5 seconds. See analytics.ts for the post body schema.

swagger-mock-validator /path/to/swagger.json /path/to/pact.json --analyticsUrl https://analytics-server.com/event

Any errors sending the analytic events are ignored and do not impact the validation results, a successful validation that had an error while trying to send the analytic event is still a successful validation.

By default analytics are disabled. To protect your privacy this is an opt-in feature.

Changelog

See CHANGELOG.md

Contributing

See CONTRIBUTING.md

License

See LICENSE.txt

FAQs

Package last updated on 31 Jan 2018

Did you know?

Socket

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc