open-api-test-generator
v0.1.5
Published
Generate mockdata and tests based on an OpenApi specification (fka Swagger Specification)
Downloads
6
Maintainers
Readme
OpenAPI test and mock data generator
This small module makes it easy to generate tests and request and response data for you openAPI spec (f.k.a. Swagger-spec). It makes use of some great modules out there to generate request mocks, response mocks, and then ties 'em together.
The generated response data is great for communication with the Frontend devvers in your team: tell 'em to use these files as mocks. As time and your API progresses they can just generate the most up date mocks.
If you would like to use the seperate functionality, (ie just generate mocks, or only the test templates) check these dependencies we use:
Installing
npm install open-api-test-generator
Usage
//Simply import the module with
var OpenApiGenerator = require('open-api-test-generator');
//Import your openAPI spec:
var spec = require('path/to/swagger.json');
//Construct the generator object:
var generator = OpenApiGenerator(spec, 'path/to/write/tests/and/mocks');
//Then use it:
generator.generate();
options
The generate function can also be called with 2 optional parameters
- writeRequestMocks: should we write request mocks to file? default false
- templatesPath: path to overwrite the templates used to generate tests
ng-apimock
To generate mocks for the ng-api-mock module:
generator.generateNgApiMockData().then(function(mockData) {
// do something with mocks
});