npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

swagger-mock-validator

v11.0.0

Published

A CLI tool to validate mocks against swagger/OpenApi specs.

Downloads

2,961

Readme

Swagger Mock Validator

A CLI tool to validate mocks against swagger/OpenApi specs.

What is Swagger Mock Validator

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

For a list of all the validation features see FEATURES.md.

Requirements

  • nodejs 12.x or higher (tested using 12.x, 14.x and 16.x)
  • npm 6.x or higher (tested using 6.x and 8.x)

Installation

Install the tool using npm

npm install --global swagger-mock-validator

Usage

Invoke the tool with a path or url to a Swagger or OpenApi 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/OpenApi spec and mock are compatible with each other. FEATURES.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.

The depth of the objects in the output can be modified by using --outputDepth flag, default depth is 4.

swagger-mock-validator spec.json mock.json --outputDepth 5

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

Additionally, provide a Pact Broker version tag alongside the name of the provider service to filter the retrieved consumer pacts for the provider by the given tag.

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

If the Pact Broker is behind basic auth, you can pass credentials with the --user option while invoking the tool.

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

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.

Frequently Asked Questions

See FAQ.md

Changelog

See CHANGELOG.md

Contributing

See CONTRIBUTING.md

License

See LICENSE.txt