swagger-mocker

0.0.7 • Public • Published

Swagger Mocker

Mock generator and validator for swagger

Inspired by https://github.com/krakenjs/swaggerize-hapi, it generates an HAPI based mock skeleton

How to run it

Install it globally with npm i swagger-mocker -g, then:

swagger-mocker create -s swagger.json -n mymock -t ~/test

That will create the mock in ~/test/mymock

npm install is not launched automatically, you have to do it by yourself.

This tool can be used also for validation:

swagger-mocker validate -s swagger.json

Handlers

Handlers skeleton are created into the handlers folder, starting from each path/verb defined in the swagger definition. Starting from these, you can add mock responses easily. The basic structure for an handler is:

module.exports = {
    get: function (req, reply) {
        return reply("GET");
    },
    post: function (req, reply) {
      return reply("POST");
    },
    put: function (req, reply) {
        return reply("PUT");  
    },
    delete: function (req, reply) {
      return reply("DELETE");
    }
}

For instance, using the petstore swagger, the created handlers are:

handlers/pet.js
handlers/pet/findByStatus.js
handlers/pet/findByTags.js
handlers/pet/{petId}.js
handlers/pet/{petId}/uploadImage.js
handlers/store/inventory.js
handlers/store/order.js
handlers/store/order/{orderId}.js
handlers/user.js
handlers/user/createWithArray.js
handlers/user/createWithList.js
handlers/user/login.js
handlers/user/logout.js
handlers/user/{username}.js

Options defaults

-p--port10010
-n--namemock
-t--targettest

Contributors

swagger-mocker has been created by:

Marco PiracciniGitHub/MarcoPiracciniTwitter/@MarcoPiraccini

License

Swagger Mocker is Copyright (c) 2016 swagger-mocker contributors (listed above) and licensed under the MIT licence. See the included LICENSE file for more details

Versions

Current Tags

  • Version
    Downloads (Last 7 Days)
    • Tag
  • 0.0.7
    1
    • latest

Version History

Package Sidebar

Install

npm i swagger-mocker

Weekly Downloads

1

Version

0.0.7

License

MIT

Last publish

Collaborators

  • marcopiraccini