Tools for validating OpenAPI (Swagger) files.
Перейти к файлу
Amar Zavery 00393f0417 improved support for logging, added support to add custom log file path, dependency on a forked version of sway, added support for running cli commands. 2017-02-01 20:46:56 -08:00
.vscode resolve allof and some more modifications 2017-01-26 21:04:10 -08:00
arm-mediaservices/2015-10-01/swagger - added support for validating examples in spec 2016-11-14 22:26:48 -08:00
arm-search Initial commit 2016-11-08 16:38:30 -08:00
arm-storage Initial commit 2016-11-08 16:38:30 -08:00
lib improved support for logging, added support to add custom log file path, dependency on a forked version of sway, added support for running cli commands. 2017-02-01 20:46:56 -08:00
.gitignore resolve allof and some more modifications 2017-01-26 21:04:10 -08:00
LICENSE.txt move to sway and promises, better logging support, structured cli commands using yargs package, initial protype for live testing 2017-01-16 23:06:51 -08:00
README.md added support for setting console log level and made minor tweaks to the source code 2017-01-23 21:16:27 -08:00
ValidationTool.njsproj addressed some of the review feedback 2017-01-26 21:30:06 -08:00
ValidationTool.sln restrucuture the code base 2016-11-13 22:45:53 -08:00
cli.js improved support for logging, added support to add custom log file path, dependency on a forked version of sway, added support for running cli commands. 2017-02-01 20:46:56 -08:00
package.json improved support for logging, added support to add custom log file path, dependency on a forked version of sway, added support for running cli commands. 2017-02-01 20:46:56 -08:00
validate.js resolve allof and some more modifications 2017-01-26 21:04:10 -08:00

README.md

openapi-validation-tools

Tools for validating OpenAPI (Swagger) files.

What does the tool do? What issues does the tool catch?

Model validation checks whether definitions for request parameters and responses, match an expected input/output payload of the service.

Examples of issues:

  • required properties not sent in requests or responses;
  • defined types not matching the value provided in the payload;
  • constraints on properties not met; enumeration values that dont match the value used by the service.

References: https://github.com/Azure/azure-rest-api-specs/issues/778 , https://github.com/Azure/azure-rest-api-specs/issues/755 , https://github.com/Azure/azure-rest-api-specs/issues/773

Model validation requires example payloads (request/response) of the service, so the data can be matched with the defined models. See x-ms-examples extension on how to specify the examples/payloads. Swagger “examples” is also supported and data included there is validated as well. To get the most benefit from this tool, make sure to have the simplest and most complex examples possible as part of x-ms-examples. The tool relies on swagger-tools package to perform model validation.

How does this tool fit with others?

Swagger specs validation could be split in the following:

    1. Schema validation
    1. Semantic validation
    1. Model definition validation
    1. Swagger operations execution (against mocked data or live tests)
    1. Human-eye review to complement the above

In the context of “azure-rest-api-specs” repo:

  • #1 is being performed on every PR as part of CI.
  • #2 and #3 are performed by the tool currently in openapi-validation-tools repo and by AutoRest linter. Were working towards integrating them into CI for “azure-rest-api-specs” repo.
  • #4 is not available yet, though were starting to work on it.
  • #5 will be done by the approvers of PRs in “azure-rest-api-specs”, as this wont be automated.

Requirements

  • node version > 4.x

You can install the latest stable release of node.js from here. For a machine with a linux flavored OS, please follow the node.js installation instructions over here

How to run the tool

  • After cloning the repo execute following steps from your terminal/cmd prompt
npm install
node validate.js

Command usage:

MacBook-Pro:openapi-validation-tools someUser$ node cli.js -h
Commands:
  live-test <spec-path>         Performs validation of x-ms-examples and
                                examples present in the spec.
  validate-example <spec-path>  Performs validation of x-ms-examples and
                                examples present in the spec.
  validate-spec <spec-path>     Performs semantic validation of the spec.

Options:
  --version       Show version number                                  [boolean]
  -j, --json      Show json output                                     [boolean]
  -l, --logLevel  Set the logging level for console.
       [choices: "error", "warn", "info", "verbose", "debug", "silly"] [default:
                                                                         "warn"]
  -h, --help      Show help                                            [boolean]

This project has adopted the Microsoft Open Source Code of Conduct. For more information see the Code of Conduct FAQ or contact opencode@microsoft.com with any additional questions or comments.