Skip to content

Latest commit

 

History

History
44 lines (32 loc) · 1.27 KB

File metadata and controls

44 lines (32 loc) · 1.27 KB

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

  1. 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
});
  1. 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
  1. 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;
    }
}
  1. feel the magic