Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including driven-swagger-test with all npm packages installed. Try it out:

driven-swagger-test lists no main file and has no index.js, so it can't be directly required. If this is a mistake, please let us know. It may however contain internal files that you can require manually:

// require("driven-swagger-test/[??]")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

driven-swagger-test v1.1.6

Test swagger quality definition and create Postman collection with test

Swagger for definition and REST API testing

Build Status Coverage Status

Testing as cli application

$ npm install -g driven-swagger-test
$ driven-swagger-test

Usage: driven-swagger-test <JSON or YAML Swagger file definition> [options]

Create Postman collection with test from swagger

  -v, --version              output the version number
  -g --global [var]          Add global variables (default: [])
  -r, --run [dataFile]       Run postman collection using newman cli.
  -s, --save                 Save postman collection to disk
  -t, --tokenUrl [tokenUrl]  Override token url in swagger.
  -h, --help                 output usage information

Usage in node applications as integration test

$ npm install driven-swagger-test --save-dev

const swaggerTests = require('driven-swagger-test/src/swagger');
const server = require('./server');

describe('Swagger definition to Postman test', () => {
  before(done => {
    // Run your REST API Server => {
      console.log('Server is running');

  it.only('Pet Store run all', async () => {
    try {
      const results = await swaggerTests(`${__dirname}/swaggers/petstore-swagger.yaml`, {
        run: `${__dirname}/data.json`,
        save: true

      console.assert(!results.tests.definition.some(result => result.code >= 5000), 'Errors in test.');
    } catch (error) { throw error; }

  after(done => {
    server.stop(() => {

Why definition test?

Becouse API-First definition, is better with test

  • Do you have security in operations? Your response should be contain 401 (unauthorized)!
  • Do you have GET operation? You should be contain consumes (accept) definition.
  • Do you have any param in PATH? Your response should be contain 404 (not found)!
  • Do you have POST/PUT/PATCH operation? Your response should be contain 400 (bad request)!

These are just some of the many test included in this tool.

REST API testing directly in Swagger!

Vendor extension x-pm-test for test (These can be specified for any response, except default.)

    description: "successful operation"
      type: "array"
        $ref: "#/definitions/Pet"
    - params:
      - name: status
        in: query
        value: '{{status}}'
    description: "Invalid status value"
      - params:
        - name: status
          in: query
          value: 'aaaaaa'

x-pm-test object representation

  • x-pm-test (array, optional) - Tests array.
    • description (string, optional) - Description used in postman endpoint name.
    • params (array, optional) - Define parameters values in test
      • name (string, required) - Param name. Required to all parameters, except body.
      • in (string, required) - The location of the parameter. Possible values are "query", "header", "path", "formData" or "body*".
      • value (string, required) - Value to fetch in parameter
    • plugins (array, optional)
      • name (string, required) - Plugin name to use
      • params (object) - Object to define parameters to plugin
    • raw (string, optional) - Define your custom postman test.

YAML example

- description: Get pets by status
  - name: status
    in: query
    value: '{{status}}'
    - name: valueCheck
        item: 'id'
        value: 0
    - name: isArray
        item: 'tags'
    - name: isObject
        item: 'category'

Integration test on wiki

Special thank you

To Marco Antonio Sanz and CloudAppi for the whole idea.


  1. Refactoring
  2. Clean code
  3. Use external plugins
  4. More defaults definition test
  5. More defaults integration test
  6. Support Swagger 3.0 (Aka. Open API)
  7. Better documentation


RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free