Microservice code generator: from OpenAPI (Swagger) REST API specification to TypeScript project with Docker.
MIT License
Microservice code generator with interface-first approach: from OpenAPI - Swagger REST API specification is generated complete project skeleton with TypeScript code, tests and Docker configuration.
Generated code has the ambition to minimize implementation time for new microservices.
The openapi-micro-ts generator is a simple "one-shot" project initialization tool - after the code is generated, the service functionality is implemented with traditional manual coding.
npm i -g microts
cd [NEW-PROJECT]
.swagger.yaml
in root of the project.microts
with default port 3000.npm i
and start the microservice with npm start
.localhost:3000/[base-path]/ui
(base path is defined by schema).cd [NEW-PROJECT]
.microts -p PORT -s SCHEMA
. Parameter PORT defines the default port on which the server will listen (if not set, default port 3000 will be used for code generation). Parameter SCHEMA is the name of the schema - may be with absolute or relative path, if schema is not in working directory. If schema is not set, generator tries to open swagger.yaml
file for API definition.README.md
file.package.json
.src/conf/swagger.yaml
file. The source schema can be deleted - as it is not used by the server.TODO
in code, and implement the functionality.For all command line properties of the microts
code generator use the command microts -h
.
npm run dev
./dist
directory and the server is restarted.curl
commands to call the actions in the service.Microservice is declared with OpenAPI 2.0 (Swagger) swagger.yaml
schema with API definition - you can use Swgger editor for schema definition. This design step is crucial for further quality and usage simplicity of the new API. Design is best made in discussion. It may be useful to author the schema with Online Swagger Editor.
For cloud deployments code generator generates code for health check, if in schema is defined action GET /health
.
git clone https://github.com/tomi-vanek/openapi-micro-ts.git
and go to project repository with cd microts
npm i
.npm link
command, so you can use it from command line in any directory with command microts
.The microservice interface is defined in form of OpenAPI 2.0 schema, as the libraries / tools used in generated code do not support the current version of OpenAPI yet.
Generated application code is in TypeScript language.
Basic features of the generated code:
/src/conf
/src
/src/handlers
- request path corresponds the directory path, no explicit routing logic is needed/src/ui
Dockerfile
for deployment image and docker-compose.yaml
as an example usage in application integration/test
Generator does not offer rich set of options to tailor the result into different forms. This approach expresses author's architecture experience: generator is a way to define architecture without complex documentation, that gently directs developers in the architecture-envisioned direction:
Generator in architecture:
As an architect you have your own technical opinion, technology constraints / preferences and infrastructure & security services that have to be integrated into the (micro)service servers.
Just fork this project, or take an inspiration and build your own generator from an proof-of-concept service that best fits your expectations.