Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

swagmock

Package Overview
Dependencies
Maintainers
1
Versions
10
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

swagmock - npm Package Compare versions

Comparing version 1.0.0-alpha.1 to 1.0.0

11

CHANGELOG.md

@@ -0,1 +1,12 @@

# v1.0.0
## Features
- es6 support and node engine changed to 6.x
- promise response if callback is not provided as an argument #20
- option to set validated = true to generate mocks for already parsed api #24
- parameter override at operation level #25
## Bugfixes
- exclusive limit issue #27 and multipleOf max value enhancement #26
- mock gen issue for type number with minimum =0 #28
# v0.0.4

@@ -2,0 +13,0 @@ ## Features

2

package.json
{
"name": "swagmock",
"version": "1.0.0-alpha.1",
"version": "1.0.0",
"description": "Mock data generator for swagger api",

@@ -5,0 +5,0 @@ "main": "lib/index.js",

@@ -13,7 +13,49 @@ # swagmock

```javascript
var apiPath = 'http://petstore.swagger.io/v2/swagger.json';
var Swagmock = require('swagmock');
var mockgen = Swagmock(apiPath);
var assert = require('assert');
let Swagmock = require('swagmock');
let Mockgen = Swagmock(api, options);
// api Can be one of the following.
// 1) A relative or absolute path to the Swagger api document.
// 2) A swagger api Object.
// 3) A promise (or a `thenable`) that resolves to the swagger api Object.
// Set the `validated` : `true` in `options`, if the api Object is already validated
// and dereferenced ($ref are resolved ).
```
Promise response:
```javascript
let responseMock = Mockgen.responses({}); //returns a promise that resolves to response mock
responseMock.then(mock => {
//Use mock here
}).catch(error => {
Assert.ifError(error);
});
```
Callback style:
```javascript
Mockgen.responses({ path: '/somepath'}, (error, mock) => {
Assert.ifError(error);
//Use mock here
});
```
Check the [API](README.md#api) for more details.
## Example
Initialize the mock generator
```javascript
const apiPath = 'http://petstore.swagger.io/v2/swagger.json';
let Assert = require('assert');
let Swagmock = require('swagmock');
let Mockgen = Swagmock(apiPath);
```
Response mock generation:
```javascript
mockgen.responses({

@@ -23,7 +65,4 @@ path: '/pet/findByStatus',

response: 200
}, function (error, mock) {
assert.ifError(error);
console.log(mock);
//This would print:
}).then(mock => {
console.log(mock); // This would print:
// {

@@ -48,12 +87,16 @@ // "responses": [{

// }
}).catch(error => {
Assert.ifError(error);
});
```
Parameters mock generation:
```javascript
mockgen.parameters({
path: '/pet/findByStatus',
operation: 'get'
}, function (error, mock) {
assert.ifError(error);
console.log(mock);
//This would print:
}).then(mock => {
console.log(mock);//This would print:
// {

@@ -68,3 +111,6 @@ // "parameters": {

// }
});
}).catch(error => {
Assert.ifError(error);
})
```

@@ -76,9 +122,16 @@

`Swagmock(apiPath)`
`Swagmock(api, [options])`
* `apiPath` - (*String*) - (required) - The url or local path of the Swagger api.
* `api` - (*Object*) or (*String*) or (*Promise*) - (required) - api can be one of the following.
- A relative or absolute path to the Swagger api document.
- A URL of the Swagger api document.
- The swagger api Object
- A promise (or a `thenable`) that resolves to the swagger api Object
* `options` - (*Object*) - (optional) - Additional options to create the mock generator.
- `validated` - Set this property to `true` if the api is already validated against swagger schema and already dereferenced all the `$ref`. This is really useful to generate mocks for parsed api specs. Default value for this is `false` and the api will be validated using [swagger-parser validate](https://github.com/BigstickCarpet/swagger-parser/blob/master/docs/swagger-parser.md#validateapi-options-callback).
## responses
`mockgen.responses(options, callback)`
`mockgen.responses(options, [callback])`

@@ -89,3 +142,3 @@ This generates the mock response objects based on the `options`

* `callback` - (*Function*) - (required) - `function (error, mock)`.
* `callback` - (*Function*) - (optional) - `function (error, mock)`. If a callback is not provided a `Promise` will be returned.

@@ -102,3 +155,3 @@ ### options

`mockgen.parameters(options, callback)`
`mockgen.parameters(options, [callback])`

@@ -109,3 +162,3 @@ This generates the mock parameters objects based on the `options`

* `callback` - (*Function*) - (required) - `function (error, mock)`.
* `callback` - (*Function*) - (optional) - `function (error, mock)`. If a callback is not provided a `Promise` will be returned.

@@ -121,3 +174,3 @@ ### options

`mockgen.requests(options, callback)`
`mockgen.requests(options, [callback])`

@@ -128,3 +181,3 @@ This generates the mock request object based on the `options`. `requests` API resolves the `parameters` mock data to generate the `request` mock object useful for unit tests.

* `callback` - (*Function*) - (required) - `function (error, mock)`.
* `callback` - (*Function*) - (optional) - `function (error, mock)`. If a callback is not provided a `Promise` will be returned.

@@ -131,0 +184,0 @@ ### options

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc