パッケージの詳細

swagger-spec-validator

kevinoid7.6kMIT5.0.0

Validate an OpenAPI/Swagger API specification using the swagger.io online validator.

cli, openapi, openapi2, openapi3

readme

OpenAPI/Swagger Specification Validator

Build Status Coverage Dependency Status Supported Node Version Version on NPM

Validate an OpenAPI/Swagger v2 or v3 API specification against the OpenAPI Specification using the swagger.io online validator.

The validation performed by this module differs from the validation performed by swagger-cli. swagger-cli uses swagger-parser for validation, which is a pure JavaScript implementation that can be used offline. This module relies on the validator hosted at swagger.io which uses Java-based parser and validator implementations. Therefore, it requires Internet access to use and requires significantly less code to be installed as a result.

Introductory Example

To use swagger-spec-validator from the command line, simply invoke it with the specification files to validate as arguments:

$ swagger-spec-validator swagger.yaml

If no arguments are given, the specification will be read from stdin.

swagger-spec-validator can be used as a library as follows:

const swaggerSpecValidator = require('swagger-spec-validator');
swaggerSpecValidator.validateFile('swagger.yaml')
  .then((result) => {
    if (Object.keys(result).length > 0) {
      console.log('Invalid.');
    } else {
      console.log('Valid!');
    }
  })
  .catch(err => console.error('Unable to validate: ' + err));

Installation

This package can be installed using npm, either globally or locally, by running:

npm install swagger-spec-validator

Recipes

More examples can be found in the test specifications.

API Docs

To use this module as a library, see the API Documentation.

Contributing

Contributions are appreciated. Contributors agree to abide by the Contributor Covenant Code of Conduct. If this is your first time contributing to a Free and Open Source Software project, consider reading How to Contribute to Open Source in the Open Source Guides.

If the desired change is large, complex, backwards-incompatible, can have significantly differing implementations, or may not be in scope for this project, opening an issue before writing the code can avoid frustration and save a lot of time and effort.

License

This project is available under the terms of the MIT License. See the summary at TLDRLegal.

更新履歴

5.0.0 (2022-11-17)

BREAKING CHANGES

  • Drop support for Node.js 15 and 14.17 and below.
  • The ? CLI option was dropped in favor of -h or --help.
  • Only index.js, cli.js, and package.json are exported from this package.
  • require('swagger-spec-validator/bin/swagger-spec-validator.js') has been renamed to require('swagger-spec-validator/cli.js').
  • The in, out, and err properties of the options argument of swagger-spec-validator/cli.js are now stdin, stdout, and stderr to match process for easier calling.
  • Default values for the args and options arguments of swagger-spec-validator/cli.js are no longer provided, due to lack of compelling use-case, to avoid ambiguity, and to reduce code.
  • swagger-spec-validator/cli.js no longer accepts a callback argument. It returns a Promise with exit code.

Features

  • Use commander instead of yargs for command-line parsing (2a7c9c8)
  • Switch from nyc to c8 for native V8 coverage collection (d72a313)
  • Set process.exitCode instead of calling process.exit() in cli.js (247de91)

v4.0.1 (2019-11-16)

Full Changelog

  • Update yargs to ^15.0.1.

v4.0.0 (2019-11-03)

Full Changelog

  • BREAKING Drop support for Node < 8.3.
  • Default to https://validator.swagger.io instead of https://online.swagger.io which is newer and described in the swagger-api/validator-badge README and supports OpenAPI Specification v3.
  • The Content-Type header is now sent on every request (since it is now required by validator.swagger.io and online.swagger.io). It is determined from caller (or command-line) options, or file extension, or file content (which requires buffering the document before sending), in that order.
  • Specification data may now be passed as Uint8Array in addition to string, Buffer, and stream.Readable types.
  • New url option which allows specifying the validator URL separately from any request options and (optionally) as a URL object.
  • Remove HTTPS workarounds for https://online.swagger.io which are no longer necessary (see swagger-api/validator-badge#98).
  • Replace pify dependency with util.promisify.
  • Dependency version updates.

v3.0.1 (2019-01-24)

Full Changelog

  • Fix support for http://online.swagger.io (without HTTPS), when requested by callers.
  • Developmental dependency version updates.

v3.0.0 (2018-06-29)

Full Changelog

  • BREAKING Drop support for Node < 6.
  • Dependency version updates.
  • Drop unnecessary dependencies.
  • Code style improvements.

v2.0.0 (2018-04-19)

Full Changelog

  • Major: Drop support for Node v0.12. Require Node v4 or later.
  • Replace DigiCert intermediate+root certificates with GoDaddy, which is now the CA for https://online.swagger.io/ (#38)
  • Update dependency versions. Drop unnecessary dependencies.

v1.0.1 (2017-05-07)

Full Changelog

  • Include DigiCert Global Root CA in package to fix SSL validation on Debian.

v1.0.0 (2017-03-16)

Full Changelog

  • No API Changes Change to v1.0.0 is only a declaration of stability.
  • Dev dependency version updates.

v0.1.2 (2017-03-03)

Full Changelog

v0.1.2 (2017-03-03)

Full Changelog

Merged pull requests:

v0.1.1 (2017-01-13)

Full Changelog

v0.1.0 (2017-01-13)

* This Change Log was automatically generated by github_changelog_generator