@filho/kunware
v1.3.1
Published
[![npm version](https://badge.fury.io/js/kunware.svg)](https://badge.fury.io/js/kunware) [![Build Status](https://travis-ci.org/kalibrr/kunware.svg?branch=master)](https://travis-ci.org/kalibrr/kunware) [![Build status](https://ci.appveyor.com/api/project
Downloads
3
Readme
Kunware
A fork of pokemock with options for developer convenience. The Kunware package generates a mock server from one or more arbitrary Swagger files with supports seeding, timeouts, response picking, entity memory, semantic action inference, etc.
Usage
Syntax:
kunware <swagger-urls-or-files> ... [-h] [-v] [-w] [-p <port>]
Options:
-h, --help Show help
-v, --version Show version
-p, --port <port> Set server port, default is 8000
-w, --watch Watch mode: Restart on Swagger changes
-k, --killable Publish /kill endpoint to stop the service
--no-ui Disables the swagger ui from running
--no-config-ui Disables the configuration ui from running
--no-config-back Disables the configuration feature
--config <config file> YAML file containing the configuration (default is config.yaml if it exists)
--example <enabled|disabled|preferably>
Whether to use the examples or not or to use example if there is one
--memory Enable memory module (experimental)
Server
The mock server listens to the specified port and
mocks endpoints defined in the provided Swagger document.
Additionally, it publishes a Swagger UI under /ui
,
the Swagger API under /api-docs
and a /kill
endpoint for shutdown.
Request Headers
Using optional headers, clients can control the server's behavior:
- X-Mock-Status
- Specifies the response status code
- The correct response is inferred from the API if possible
- Defaults to the first response code specified in the API
- X-Mock-Seed
- Specifies a seed for data generation
- If omitted, a random seed is generated
- The current seed is always returned in a X-Mock-Seed response header
- X-Mock-Time
- Specifies the minimum response time (milliseconds)
- X-Mock-Size
- Specifies array size(s) in the response
- Must be a valid JSON object of
<definitionName|attributeName>: <size>
pairs - If omitted, array sizes are randomly between 1 and 5
- X-Mock-Depth
- Specifies the maximum JSON data depth
- Defaults to 5
- X-Mock-Example
- Specifies if the response should use the example in the top level schema
- Defaults to
disabled
and turned on withenabled
- X-Mock-Override
- Specifies response data via JSON Path
- Must be a valid JSON object of
<jsonPath>: <data>
pairs <data>
is arbitrary JSON
- X-Mock-Replay
- Specifies the number of times the current X-Mock-* headers should be replayed
- The next N requests to the requested URL will replay the current X-Mock-* headers
- X-Mock-Replay-Pattern
- Specifies a regular expression to match for X-Mock-Replay
- If omitted, the exact path is used for replaying
Memory (experimental)
Use the --memory
switch to enable the memory module.
When enabled, entities containing an ID are remembered by the server.
If the entity is requested again, the remembered data is returned.
This also applies to sub-entities across endpoints.
Additionally, the server tries to infer semantic actions from requests, such as:
- Get by id
- Delete by id
- Update by id
- Create new entity
These actions are applied to known entities in memory. For example, requesting a deleted entity will result in a 404 response.
Customization
Kunware provides a set of Express middlewares
which you can use independently.
The default app defined in createDefaultApp.js
is an opinionated stack of
middlewares which you're encouraged to hack on.
By re-arranging and adding middlewares (especially generators)
you can tailor Kunware to fit your APIs.