npm install moxai --save
Setup as standard third-party middleware which requires Express and mounting on a route, such as '/mocks'.
var express = ;var moxai = ;var app = ;app;app
Options are passed as an object to moxai and all arguments are optional.
var opts ='dir': 'mocks''file': 'api''random': false;app;
|dir||string||mocks||optional||The directory location of OAI files relative to parent directory.|
|file||string||api||optional||The name of OAI JSON file. Must be located within directory location.|
|random||boolean||false||optional||Use random output for regex values in OAI JSON file.|
The directory where the files are stored. This is relative to the parent directory and the default is mocks. In most applications, simply add a mocks directory in the root of the application.
/├── mocks/├── app.js|index.js└── package.json
The file of the OAI (formerly Swagger) JSON file to use. This is compatible with OAI version 2.0. This must have a .json extension and the default is api, therefore the default file is api.json. The file must be in the designated directory, which defaults to mocks.
/├── mocks/└── api.json├── app.js|index.js└── package.json
Mock output should be in the response examples section of the OAI JSON. This should be the exact JSON output expected by the mock API request.
Randomizes the output from the OAI JSON using regular expressions. Only randomizes values that are valid regex and are enclosed in forward slashes (/). Back slashes (\) must be escaped by using double backslash (\\). Ignores any flags such as /i (ignore case) and /g (global). If error with regex, then will output original string.
npm testto run Mocha unit tests.
npm run coveragefor Istanbul code coverage. Results in
npm run lintfor ESLint static code analysis. Results in
npm run docsto run JSDoc code documentation. Results in
Point of Contact
You can report issues and submit questions by opening a new Issue in GitHub.
You can Watch this repo to receive notifications from GitHub when a new issue is posted, when an existing issue’s status is updated, and when a pull request is created.
See CONTRIBUTING for additional information.
This open source project was developed for the U.S. Forest Service ePermit API project under the General Services Administration (GSA) Technology Transformation Service (TTS) 18F Agile Delivery Services Blanket Purchase Agreement (Agile BPA). Moxai is a testing dependency for the ePermit API which used this package as a temporary, placeholder mock API. Moxai is published as an independent npm package that can be used with any Express application.
This project is in the public domain within the United States, and copyright and related rights in the work worldwide are waived through the CC0 1.0 Universal public domain dedication.
All contributions to this project will be released under the CC0 dedication. By submitting a pull request, you are agreeing to comply with this waiver of copyright interest.