Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/leboncoin/morphlingjs
A CLI to mock with meaningful data a REST API from a Swagger file
https://github.com/leboncoin/morphlingjs
cli docker faker leboncoin mock nodejs swagger
Last synced: 1 day ago
JSON representation
A CLI to mock with meaningful data a REST API from a Swagger file
- Host: GitHub
- URL: https://github.com/leboncoin/morphlingjs
- Owner: leboncoin
- License: mit
- Created: 2017-10-25T10:07:53.000Z (about 7 years ago)
- Default Branch: master
- Last Pushed: 2022-12-06T16:37:33.000Z (almost 2 years ago)
- Last Synced: 2024-10-14T00:13:43.227Z (about 1 month ago)
- Topics: cli, docker, faker, leboncoin, mock, nodejs, swagger
- Language: JavaScript
- Homepage:
- Size: 385 KB
- Stars: 149
- Watchers: 18
- Forks: 1
- Open Issues: 14
-
Metadata Files:
- Readme: README.md
- License: LICENSE.md
Awesome Lists containing this project
README
# Morphling
*Cause nobody aint got time to wait for back-ends to be developped.*
## Features
- A sweet all-in-CLI with **no knowledge of Javascript necessary** _(if you can write JSON you good 👍 )_
- **Mocks any object, array or field** declared in a swagger with meaningful **autogenerated data**
- **Persists route mocks** to allow you to develop your front-end as fast as a lightning
- Uses **Faker generators** behind the curtains
- **Empty responses, error codes, any http method, any body** _not sure about that last one but I'm trying ok_
- Two lines install and **minimal knowledge of backend necessary**
- Supports **JSON and YAML** swaggers
- Supports (a big part of) **OpenAPI 3.0**## Installation
- Ensure that you have both `docker` and `docker-compose` installed and available to your terminal.
- Also, make sure that the docker daemon is running.
- Now just go for it: `npm i -g morphlingjs` it takes a while so grab a cub of coffee on the way.
- Run the configuration utility to select the port morphling will run on: `morphling config`
- Add a swagger.yml file to Morphling by doing a `morphling apply your/file`
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](https://github.com/leboncoin/morphlingjs/tree/master/swagger-override-examples).
Doing a
- `morphling apply swagger-override-examples/demo.json -o`
and then
- `morphling toggle demo.json`
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
- `help [cmd] display help for [cmd]`Displays the help
### apply
`apply|a 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
- `bash|b Bash into the morphling container`Open a bash straight into the container. Useful for checking logs with `pm2 logs` for instance.
### config
- `config|c Configure the morphling server`
Persist CLI options, for instance the port that the CLI will hit on localhost### describe
- `describe|d Describe a morphling override`
Describe an override file's content.### list
- `list|ls List files saved in morphling`List all swaggers saved to Morphling. Use with `-o` to list override files.
### remove - NOT IMPLEMENTED YET- `remove|rm Remove a Swagger file saved in Morphling`
### remove-all - NOT IMPLEMENTED YET- `remove-all|rma Clear Swagger files saved in Morphling`
### restart
- `restart|rr Restart the morphling server`
Restart the Morphling instance. _who would have thought_### start
- `start|s Start the morphling server on 8883 if no port is provided`
Start the morphling instance.### stop
- `stop|k Stop the morphling server`\
Stop the morphling instance.### toggle
- `toggle|t Toggle an override`
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.
- Clone the package
- Inside the package: `make start` and wait for the build to be over
- If the message `Morphling started on 8883` pops, it means that everything went well!
- `npm link` to make `morphling` available globally to your terminal
- `morphling config` and go through the short process
- `morphling --help` for other informations should help you out.*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 `
- `start` Run the build proces and start the Morphling docker instance immediatly then pipe the logs
- `dev` Start the server without docker on a bare Nodejs process
- `build` Build all javascript files with *Babel*.
- `docker-build` Run the docker build process and run the server.
- `clear-docker` Hard-delete the Morphling instance from your local Docker
- `devstart-hard` Clear all dependencies and docker Morphling instances and start## Upcoming features _feel free to submit PRs_
- SwaggerUI!
- Print proper Morphlingjs version with `--version / -v`
- On the go switching of running ports
- Add ID to overrides and Swagger files so you dont have to type them down / or maybe just autocomplete them
- `morphling validate` A proper validator for the swagger files and an associated CLI command
- `morphling remove` Remove a file from Morphling
- `morphling remove-all` Remove all files from Morphling (also remove local saves of fixtures) always with --force
- A better autocompletion using the npm package `commander-completion`
- Overriding a field key in an object with a specific faker generator (ie: zipcode, username...)
- Override checker (ensure that a specific override does not already exist when adding another one)