Swagger Faker
About
Generate mocker services automatically through Swagger or OpenAPI.
Details
- Author
- Pingtouges
- Downloads
- 224
- Categories
- Other
Jump to
- Generates fake data from swagger/openapi JSON specifications.
- Automatically starts a mock server on a configurable port.
- Configurable output folder, timeout, and port.
- Generated mock data is stored locally and is customizable.
Install it globally via npm i swagger-faker -g. Run swagger-faker init to create a configuration file, update it with your swagger source paths, then run swagger-faker gen to generate mock data and swagger-faker run to start the mock server.
Swagger Faker
Swagger Faker is a tool which can help you generate fake data from your swagger.json file, then it will start a mock server automatically with the generated fake data.
How to Use
1. Install
npm i swagger-faker -g
2. Init config file by command:
swagger-faker init
Then it will generate a config file swagger-faker.config.json in current path, update that config file:
{
"sourcePaths": ["./source/openapi.json"],
"outputFolder": "mock-server",
"timeout": 180000,
"port": 8081
}
- sourcePaths: required, put your swagger/openapi file path here
- outputFolder: optional
- timeout: optional,
- port: optional
3. Generate fake data
swagger-faker gen
4. Start the mock server
swagger-faker run
Examples
git clone https://github.com/reeli/swagger-faker-examples.git
cd swagger-faker-examples
npm install
npm start
Then you'll see:
1. A mock-server folder has been generated in your current path, and all mock data is setting in mock-server/data folder, you can customize them if needed.
2. A mock server has been started in http://localhost:8081, you can open your browser and visit one of the mock API by http://localhost:8081/api/v2/store/order/1 (The mock data is setting in: mock-server/data/getOrderById.json)
Sign in to leave a review
Use Google, GitHub, or an email account so ratings stay tied to real people.
No reviews posted yet.



