JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3562
  • Score
    100M100P100Q128671F
  • License MIT

Validates embedded examples in OpenAPI-JSONs

Package Exports

  • openapi-examples-validator

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (openapi-examples-validator) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

openapi-examples-validator

Validates embedded JSON-examples in OpenAPI-specs (v2 and v3 are supported)

npm version Standard Version Build Status Coverage Status dependencies Status Maintainability Greenkeeper badge

Install

Install using npm:

npm install -g openapi-examples-validator

Usage

openapi-examples-validator [options] <filepath>

Validate embedded examples in OpenAPI-JSONs.
To validate external examples, use the `-s` and `-e` option.
To pass a mapping-file, to validate multiple external examples, use the `-m` option.

Options:

  -V, --version                              output the version number
  -s, --schema-jsonpath <schema-jsonpath>    JSON-path to schema, to validate the example file against
  -e, --example-filepath <example-filepath>  file path to example file, to be validated
  -m, --mapping-filepath <mapping-filepath>  file path to map, containing schema-paths as key and the file-path(s) to
                                             examples as value. If wildcards are used, the parameter has to be put in
                                             quotes.
  -c, --cwd-to-mapping-file                  changes to the directory of the mapping-file, before resolving the
                                             example's paths. Use this option, if your mapping-files use relative paths
                                             for the examples
  -h, --help                                 output usage information

The validator will search the OpenAPI-JSON for response-examples and validate them against its schema.

If an external example has to be verified, the -s and -e option has to be used.

For example:

$ openapi-examples-validator -s $.paths./.get.responses.200.schema -e example.json openapi-spec.json

To validate multiple external examples, pass a mapping file with a similar structure along with the -m option:

{
  "$.paths./.get.responses.200.schema": [
    "test/data/external-examples-valid-example1.json",
    "test/data/external-examples-valid-example2.json",
    "test/data/external-examples-invalid-type.json"
  ],
  "$.paths./.get.responses.300.schema": "test/data/external-examples-invalid-missing-link.json"
}

Errors will be written to stderr.

Sample output of validation errors:

[
    {
        "keyword": "type",
        "dataPath": ".versions[0].id",
        "schemaPath": "#/properties/versions/items/properties/id/type",
        "params": {
            "type": "string"
        },
        "message": "should be string",
        "examplePath": "/~1/get/responses/200/examples/application~1json"
    }
]

Test

To run the tests, execute

npm test

or to check the coverage

npm run coverage

Future features

  • YAML support