{"id":22221122,"url":"https://github.com/davesag/microservice-generator","last_synced_at":"2026-04-17T10:31:51.746Z","repository":{"id":36984181,"uuid":"144853034","full_name":"davesag/microservice-generator","owner":"davesag","description":"An opinionated generator for Swagger based Rest API servers","archived":false,"fork":false,"pushed_at":"2023-11-30T15:20:29.000Z","size":1821,"stargazers_count":0,"open_issues_count":9,"forks_count":0,"subscribers_count":2,"default_branch":"develop","last_synced_at":"2025-03-25T07:42:23.827Z","etag":null,"topics":["code-generator","expressjs","microservice","rabbitmq","rest-api","sequelize","swagger"],"latest_commit_sha":null,"homepage":null,"language":"JavaScript","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/davesag.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":".github/FUNDING.yml","license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":"SECURITY.md","support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null},"funding":{"github":["davesag"]}},"created_at":"2018-08-15T12:56:11.000Z","updated_at":"2022-01-05T01:57:05.000Z","dependencies_parsed_at":"2023-11-30T16:43:03.030Z","dependency_job_id":null,"html_url":"https://github.com/davesag/microservice-generator","commit_stats":null,"previous_names":[],"tags_count":1,"template":false,"template_full_name":null,"purl":"pkg:github/davesag/microservice-generator","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesag%2Fmicroservice-generator","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesag%2Fmicroservice-generator/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesag%2Fmicroservice-generator/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesag%2Fmicroservice-generator/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/davesag","download_url":"https://codeload.github.com/davesag/microservice-generator/tar.gz/refs/heads/develop","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/davesag%2Fmicroservice-generator/sbom","scorecard":null,"host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":286080680,"owners_count":31925334,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2026-04-17T10:19:20.377Z","status":"ssl_error","status_checked_at":"2026-04-17T10:19:18.682Z","response_time":62,"last_error":"SSL_connect returned=1 errno=0 peeraddr=140.82.121.6:443 state=error: unexpected eof while reading","robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":false,"can_crawl_api":true,"host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["code-generator","expressjs","microservice","rabbitmq","rest-api","sequelize","swagger"],"created_at":"2024-12-02T23:12:20.522Z","updated_at":"2026-04-17T10:31:51.731Z","avatar_url":"https://github.com/davesag.png","language":"JavaScript","funding_links":["https://github.com/sponsors/davesag"],"categories":[],"sub_categories":[],"readme":"# microservice-generator\n\nAn opinionated generator for Swagger based Rest API servers\n\n## Prerequisites\n\nThis library assumes you are using NodeJS 12.18.2+\n\n## Install\n\n**Note**: This project is currently in development and _not_ ready to be installed.\n\n## Run (_proposed command-line interface_)\n\n    ms-new path/to/api.yml [--gateway --api --output path/to/output/dir]\n\nThis will read your swagger formatted api.yml file and do the following\n\n1. Generate boilerplate\n\n   - `package.json` file,\n   - various dotfiles,\n   - a `CONTRIBUTING.md` file,\n   - a `README.md` file\n   - a `.circleci/config.yml` file\n   - a `src` folder as described below,\n   - a `test` folder as described below\n\n2. Generate Project source\n\n   ```text\n   src/\n     api/\n       index.js\n       ping.js\n       versions.js\n     events/\n       registerService.js\n     models/\n       index.js\n     serialisers/\n     utils/\n       apiValidator.js\n       appMaker.js\n       config.js\n       genericErrors.js\n       handleMigrationError.js\n       logger.js\n       makeUri.js\n       messageMaker.js\n       uptime.js\n     errors.js\n     exchange.js\n     index.js\n     server.js\n     service.js\n   ```\n\n3. Generate Tests\n\n   ```text\n   test/\n     db/\n       models/\n       _.spec.js\n       test_helper.js\n     server/\n       routes/\n       _.spec.js\n       test_helper.js\n     unit/\n       api/\n       events/\n       models/\n       serialisers/\n       utils/\n         apiValidator.spec.js\n         appMaker.spec.js\n         genericErrors.spec.js\n         handleMigrationError.spec.js\n         makeUri.spec.js\n         messageMaker.spec.js\n         uptime.spec.js\n       server.spec.js\n       service.spec.js\n       test_helper.js\n       utils/\n         data/\n           index.js\n         eventTest.js\n         mockApi.js\n         mockLogger.js\n         mockSerialiser.js\n         mockService.js\n     .eslintrc.js\n   ```\n\n4. Generate supporting files and dotfiles\n\n   ```text\n   config/\n     db_config.yml\n   migrations/\n   tasks/\n     generateERD/\n       index.js\n     initDb/\n       index.js\n     migrationConfig.js\n   .circleci/\n     config.yml\n   .eslintrc.js\n   .eslintignore\n   .gitignore\n   .prettiergnore\n   .sequelizerc\n   api.yml\n   CONTRIBUTING.md\n   Dockerfile\n   docker-compose.yml\n   index.js\n   Procfile\n   ```\n\n5. For each path extract the `path` details and the corresponding `operationId` and generate the following\n\n   ```text\n   src/api/{basename}/\n     {operationId}.js // folder paths are generated as required\n   test/unit/api/{basename}\n     {operationId}.spec.js\n   test/server/routes/{basename}\n     {operationId}.spec.js\n   ```\n\n6. For each definition in the `definitions` section\n\n   ```text\n   migrations/\n     {timestamp}-create-{plural(definition)}.js\n   src/models/\n     {definition}.js\n   test/unit/models/\n     {definition}.spec.js\n   test/db/models/\n     {definition}.spec.js\n   test/utils/data/\n   {definition}Data.js\n     make{operationId}.js\n   ```\n\nOnce these files have been generated, you can then start filling in whatever implementation details you wish. Where possible the generator will fill in complete code. Where not possible it will generate working stubs and some documentation to get you going.\n\n### Parameters and Options\n\n`ms-new` takes the following parameters\n\n- The path to a swagger YAML file.\n- `--gateway` Tells the generator you are generating an api gateway, not an underlying service.\n- `--output path/to/output/dir` Tells the generator which folder to write files to. Note that folder must be empty apart from the following files or directories which will be ignored.\n\n  ```text\n  .git/\n  .gitignore\n  LICENCE\n  README.md\n  {api.yml} // whatever name you specified when you invoked the generator\n  ```\n\n## Once you have generated a server\n\n`cd` into your server folder if you need to, then\n\n```sh\nnpm install\nnpm test\nnpm run backend\nnpm run test:db\nnpm run test:server\nnpm start\n```\n\nThe service's tests should all pass and it should run, it should expose an api, and, if it's a microservice it should emit a `heartbeat` event to rabbitmq.\n\nIf it's a `gateway` service then it will listen for `heartbeat` events and keep track of the services and their access tokens.\n\nIt will expose the rest api outlined in the swagger documentation and link those paths to their nominated routes. These routes will simply emit example data.\n\n## Now write some code\n\n### Models\n\nOverwrite the generated tests and source models to suit your own needs.\n\n### Route Controllers\n\nThe default route controller will be an async function that includes code to read any of the params defined, and to emit the relevant errors or response. The specifics of how the response is generated are left to you.\n\nControllers for the `ping` and `versions` root level functions common to all servers are installed along with their corresponding unit and integration tests.\n\n### Services\n\nService definition is not covered in the swagger file, so we leave this blank apart from the default heartbeat service\n\n### Migrations\n\nThe default migrations are certain to be lacking some subtlety.\n\n## Development\n\nYou may add environment variables to your local `.env` file\n\n### Branches\n\n\u003c!-- prettier-ignore --\u003e\n| Branch | Tests | Code Coverage | Audit | Comments |\n| ------ | ----- | ------------- | ----- | -------- |\n| `develop` | [![CircleCI](https://circleci.com/gh/davesag/microservice-generator/tree/develop.svg?style=svg)](https://circleci.com/gh/davesag/microservice-generator/tree/develop) | [![codecov](https://codecov.io/gh/davesag/microservice-generator/branch/develop/graph/badge.svg)](https://codecov.io/gh/davesag/microservice-generator) | [![Vulnerabilities](https://snyk.io/test/github/davesag/microservice-generator/develop/badge.svg)](https://snyk.io/test/github/davesag/microservice-generator/develop) | Work in progress |\n| `main` | [![CircleCI](https://circleci.com/gh/davesag/microservice-generator/tree/main.svg?style=svg)](https://circleci.com/gh/davesag/microservice-generator/tree/main) | [![codecov](https://codecov.io/gh/davesag/microservice-generator/branch/main/graph/badge.svg)](https://codecov.io/gh/davesag/microservice-generator) | [![Vulnerabilities](https://snyk.io/test/github/davesag/microservice-generator/main/badge.svg)](https://snyk.io/test/github/davesag/microservice-generator/main) | Latest stable release |\n\n### Prerequisites\n\n- [NodeJS](htps://nodejs.org). I use [`nvm`](https://github.com/creationix/nvm) to manage Node versions — `brew install nvm`.\n- [Docker](https://www.docker.com) (if on a Mac then use [Docker for Mac](https://docs.docker.com/docker-for-mac/), not the homebrew version)\n\n### Initialisation\n\n    npm install\n\n### Starting the server and syncing the database with the model definitions.\n\nBefore you run the server you will need to set up the database.\n\n    npm run db:init\n\nthen\n\n    npm run db:migrate\n\nthen you can\n\n    npm start\n\n### Test it\n\n- `npm test` — runs the unit tests (quick)\n\n### Lint it\n\n    npm run lint\n\nTo auto-fix linting issues.\n\n    npm run lint -- --fix\n\n### Make the code prettier\n\nThis runs on every commit but you can do this manually as well via:\n\n    npm run prettier\n\n## Contributing\n\nPlease see the [contributing notes](CONTRIBUTING.md).\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavesag%2Fmicroservice-generator","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fdavesag%2Fmicroservice-generator","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fdavesag%2Fmicroservice-generator/lists"}