Skip to content

Generate mocker services automatically through Swagger or OpenAPI.

Notifications You must be signed in to change notification settings

smff/webpack-middleware-swagger-faker

 
 

Repository files navigation

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

About

Generate mocker services automatically through Swagger or OpenAPI.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • TypeScript 99.4%
  • Other 0.6%