leboncoin / morphlingjs

A CLI to mock with meaningful data a REST API from a Swagger file
MIT License
149 stars 1 forks source link
cli docker faker leboncoin mock nodejs swagger

Morphling

Cause nobody aint got time to wait for back-ends to be developped.

Features

Installation

Now morphling knows your swagger and can mock it properly. Just try to hit a route that is described in your swagger !

To see what swaggers Morphling knows do a morphling list.

Note: If having any issues during the install with npm such as 'Cannot read property 0 of undefined', try to downgrade your current npm install to 5.2.0

Overriding a route

Morphling allows you to create a mock for a specific route ; because sometimes you need a specific body from your server.

For instance, you want your local server to return a specific response on a given route. It can be a route that is described in your swagger where you don't want autogenerated data or just a route you don't want to bother putting in the swagger.

You will want to use an override file, which you can find two examples of in the examples.

Doing a

and then

will create a route on localhost:8883/v2/store/order/1 and then enable it (if morphling runs on 8883). This route will return, as seen in the example file, a 200 (OK) HTTP code, with an empty body.

CLI Commands

Any command here can be run with the --help flag to give you a tad more info 👍

help

Displays the help

apply

apply|a <file> Apply a Swagger to morphling

Send a Swagger file to the Morphling instance for it to be mocked.

If used with -o flag, save file as an Override file to Morphling. Overrides are disabled by default. To enable/disable them, check the toggle command.

There is no validation working on the server at the time of writing this which means that it will break silently. If a route is not mocked, I suggest that you morphling bash into the instance and run pm2 logs while trying to apply the swagger. Might give you some info. If not, please send an issue! I'll do my best to fix it ASAP.

bash

Open a bash straight into the container. Useful for checking logs with pm2 logs for instance.

config

Persist CLI options, for instance the port that the CLI will hit on localhost

describe

Describe an override file's content.

list

List all swaggers saved to Morphling. Use with -o to list override files.

remove - NOT IMPLEMENTED YET

restart

Restart the Morphling instance. who would have thought

start

Start the morphling instance.

stop

Stop the morphling instance.

toggle

Enable/disable an override. Use with -d to disable all, or -e to enable all.

Note: if you think about other useful commands, feel free to submit an issue! 😉

Installation from source

Here be dragons, you probably don't need to do this, except if want to contribute, which would be lovely.

Ensure that you have both docker and docker-compose installed and available to your terminal.

Note: If having any issues during the install with npm such as 'Cannot read property 0 of undefined', try to downgrade your current npm install to 5.2.0

Useful development commands

I've made available a morphling bash command which immediately bashes you inside the currently-running Docker instance of Morphling

make

Upcoming features feel free to submit PRs