npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

driven-swagger-test

v1.3.1

Published

Test swagger quality definition and create Postman collection with test

Downloads

46

Readme

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

Options:
  -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
    server.run(() => {
      console.log('Server is running');
      done();
    });
  });

  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(() => {
      done();
    });
  });
});

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.)

responses:
  200:
    description: "successful operation"
    schema:
      type: "array"
      items:
        $ref: "#/definitions/Pet"
    x-pm-test:
    - params:
      - name: status
        in: query
        value: '{{status}}'
  400:
    description: "Invalid status value"
    x-pm-test:
      - 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

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

Integration test on wiki

Special thank you

To Marco Antonio Sanz and CloudAppi for the whole idea.

TODO:

  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