Code Monkey home page Code Monkey logo

oatts's Introduction

OpenAPI Test Templates (oatts)

Generate basic unit test scaffolding for your OpenAPI specification.

Disclaimer

oatts is based off of the swagger-test-templates module and the lessons learned during its development.

This is a work in progress.

Goal

The goal of oatts is to provide a standalone module for generating Node.js unit test code scaffolding based on a given OpenAPI specification.

The hope is that by providing such a tool, API developers will be encouraged to test the contract between their spec and backend early, often and continuously as the project grows.

Usage

There are a couple ways to use oatts.

Module

Install via npm

npm install --save oatts

Then use it in code

var oatts = require('oatts');

var options = {
    // see "Options" section below for available options
};

var tests = oatts.generate('/path/to/openapi.yaml', options);

console.log(tests)

Command line interface

Install globally via npm

npm install -g oatts

Then use in your command line

> oatts generate --help

  Usage: generate [options]

  generate unit test scaffolding for a given OpenAPI/Swagger spec

  Options:

    -h, --help               output usage information
    --host <host>            target hostname to use in test generation
    -p, --paths <paths>      comma separated list of paths to generate tests for
    -e, --sample             generate sample response bodies rather than schema, if applicable
    -s, --spec <spec>        path to the target OpenAPI/Swagger spec document to consume
    -w, --writeTo <writeTo>  directory to write the generated tests to file

> oatts generate -s ./path/to/openapi.yaml -w ./output/dir
> ls ./output/dir
pet-test.js  pet-{petId}-uploadImage-test.js  user-test.js 
. . .

Options

The following options can be passed to the generation function, some/all are exposed in the accompanying CLI:

Name CLI Flag Default Required Description
spec --spec -s n/a true Path to a swagger.yaml or openapi.yaml
host --host spec.host false Hostname to put in test requests; defaults to host in given spec
paths --paths -p spec.paths false API paths to generate tests for; defaults to all paths in given spec
samples --samples -e false false Toggle generating sample responses for assertion
writeTo --writeTo -w n/a false Directory to write generated tests to; will create the directory if it doesn't exist

Testing

To test this module simply use the npm script

npm test

Contributing

Contributors are welcome! Please see CONTRIBUTING.md.

License

See LICENSE file.

oatts's People

Contributors

noahdietz avatar

Watchers

James Cloos avatar Simon Baynes avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.