Go server generator is used to generate HTTP router and models along with initial controller and service based on OpenAPI spec. So it’s just a matter of setting up the right service and wiring them to the router.
The openapi directory looks like:
├── openapi
│ ├── components
│ │ └── schemas.yaml
│ ├── config
│ │ └── go-server.yaml
│ ├── openapi.yaml
│ └── paths
│ └── journals.yaml
The configuration specifies the generator name, go-server, the source of specification, the output directory for the generated code, and the package name of the generated Go files.
go-server.yaml
generatorName: go-server
inputSpec: openapi/openapi.yaml
outputDir: server/gen
additionalProperties:
packageName: gen
enumClassPrefix: true
To run the generator:
openapi-generator-cli generate -c openapi/config/go-server.yaml