sql-enum-generator
sql-enum-generator is a tool that converts SQL INSERT statements into OpenAPI schema files. This application enables developers to easily convert database master data into API specifications, streamlining the development process.
Features
- Parses SQL INSERT statements and generates corresponding OpenAPI schemas
- Generated OpenAPI schemas can be utilized with other tools for type generation
Quick Start
- Create a configuration file named
sqlenumgen.yml with the following content:
version: "1"
tables:
- name: products
key: name
value: id
- Run the application using the following command:
$ go run github.com/flum1025/sql-enum-generator generate --source-path ./example/master.sql --output-path ./example/openapi.generated.json --config ./example/sqlenumgen.yml
- Utilize language-specific generation tools to create enums from the generated OpenAPI schema.
Language-Specific Usage Examples
Go
For Go, you can use oapi-codegen to generate code from the OpenAPI schema. Create a configuration file named oapi-codegen.yml with the following content:
package: main
output: ./openapi.generated.go
generate:
models: true
compatibility:
always-prefix-enum-values: true
output-options:
skip-prune: true
Then, run the following command to generate the Go code:
$ go run github.com/oapi-codegen/oapi-codegen/v2/cmd/oapi-codegen -config ./example/oapi-codegen.yml ./example/openapi.generated.json
TypeScript
For TypeScript, you can use openapi-typescript to generate TypeScript definitions. Run the following command:
$ npx openapi-typescript ./example/openapi.generated.json -o ./example/openapi.generated.d.ts --enum
License
This project is licensed under the MIT License. See the LICENSE file for details.