Tools for validating OpenAPI (Swagger) files.
Перейти к файлу
Veronica Giaudrone 1a94f6a365 updating model validator plugin to autorest 2017-10-02 14:10:39 -07:00
.vscode Fixing bug found via CI - live validator tests 2017-08-02 17:01:19 -07:00
lib updating model validator plugin to autorest 2017-10-02 14:10:39 -07:00
test addressed feedback 2017-09-14 11:53:25 -07:00
.gitattributes adding gitattributes. 2017-04-18 16:41:23 -07:00
.gitignore resolve allof and some more modifications 2017-01-26 21:04:10 -08:00
.jshintrc added jshint 2017-04-18 12:29:25 -07:00
.travis.yml Adding travis file to repo 2017-04-13 15:17:53 -07:00
ChangeLog.md update changelog and package.json 2017-09-25 12:03:33 -07: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 updating model validator plugin to autorest 2017-10-02 14:10:39 -07:00
cli.js added support for curl 2017-04-28 20:31:07 -07:00
index.js Exporting constants 2017-04-17 21:33:53 -07:00
package-lock.json update changelog and package.json 2017-09-25 12:03:33 -07:00
package.json updating model validator plugin to autorest 2017-10-02 14:10:39 -07:00

README.md

openapi-validation-tools [oav]

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.

  • Please take a look at the redis-cache swagger spec as an example for providing "x-ms-examples" over here.
  • The examples need to be provided in a separate file in the examples directory under the api-version directory azure-rest-api-specs/arm-<yourService>/<api-version>/examples/<exampleName>.json. You can take a look over here for the structure of examples.
  • We require you to provide us a minimum (just required properties/parameters of the request/response) and a maximum (full blown) example. Feel free to provide more examples as deemed necessary.
  • We have provided schemas for examples to be provided in the examples directory. It can be found over here. This will help you with intellisene and validation.
    • If you are using vscode to edit your swaggers in the azure-rest-api-specs repo then everything should work out of the box as the schemas have been added in the .vscode/settings.json file over here.
    • If you are using Visual Studio then you can use the urls provided in the settings.json file and put them in the drop down list at the top of a json file when the file is opened in VS.

How does this tool fit with others?

Swagger specs validation could be split in the following:

  1. Schema validation
  2. Semantic validation
  3. Model definition validation
  4. Swagger operations execution (against mocked data or live tests)
  5. 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 > 6.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 -g oav

Command usage:

bash-3.2$ oav -h
Commands:
  extract-xmsexamples <spec-path>           Extracts the x-ms-examples for a
  <recordings>                              given swagger from the .NET session
                                            recordings and saves them in a file.
  generate-wireformat <spec-path>           Transforms the x-ms-examples for a
                                            given operation into raw
                                            request/response format and saves
                                            them in a markdown file.
  resolve-spec <spec-path>                  Resolves the swagger spec based on
                                            the selected options like allOfs,
                                            relativePaths, examples etc.
  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]
  -l, --logLevel     Set the logging level for console.
  [choices: "off", "json", "error", "warn", "info", "verbose", "debug", "silly"]
                                                               [default: "warn"]
  -f, --logFilepath  Set the log file path. It must be an absolute filepath. By
                     default the logs will stored in a timestamp based log file
                     at "/Users/{username}/oav_output".
  -h, --help         Show help                                         [boolean]

bash-3.2$

Autorest plugin configuration

pipeline:
  swagger-document/model-validator:
    input: swagger-document/identity
    scope: azure-validator-composed

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.