webpack-middleware-swagger-faker
v0.0.23
Published
Generate mocker services automatically through Swagger or OpenAPI
Downloads
9
Maintainers
Readme
webpack-middleware-swagger-faker
Tool for generation webpack middleware
for webpack-dev-server
with mock-data by swagger
original package: swagger-faker
The main difference is that you can now use swagger-faker
in webpack-dev-server middlewares
- create: index.js
var wmsf = require('webpack-middleware-swagger-faker');
wmsf.run({
"sourcePaths": ["./openapi.json"], <- path to json swagger file (yaml support)
"outputFolder": "mock-server" <- path to folder for output files
});
- run: node index.js
// output files in "outputFolder":
folder "data" contains *.json <- autogenerated mocks for each OperationId
folder "middlewares": contains *.js <- autogenerated middlewares for each OperationId
- use in webpack devServer configuration:
const mockMiddlewares = require('"outputFolder"/middlewares')
devServer:{
setupMiddlewares: (middlewares, devServer) => {
if (!devServer) {
throw new Error('webpack-dev-server is not defined');
}
middlewares.unshift(mockMiddlewares.OperationId)
return middlewares;
}
}
- feel the magic