Oapi-codegen: Difference between revisions

From NovaOrdis Knowledge Base
Jump to navigation Jump to search
Line 3: Line 3:
=Internal=
=Internal=
* [[Go OpenAPI#Subjects|Go OpenAPI]]
* [[Go OpenAPI#Subjects|Go OpenAPI]]
* [[A Simple CRUD REST Application with OpenAPI#Overview|A Simple CRUD REST Application with OpenAPI]]
=Overview=
=Overview=



Revision as of 01:15, 26 January 2024

External

Internal

Overview

Installation

Get the latest version from https://github.com/deepmap/oapi-codegen/tags

Then:

go install github.com/deepmap/oapi-codegen/v2/cmd/oapi-codegen@v2.1.0

The installation will place the package under $GOPATH/pkg/mod/cache/download/github.com/deepmap and $GOPATH/pkg/mod/github.com/deepmap, will compile the binary and place it under ~/go/bin.

Generate Code

Generate client and server code:

oapi-codegen -package petstore ./petstore-expanded.yaml > ./internal/petstore/petstore.gen.go
go mod tidy

Options

-package

The package name for the generated code.

-generate

Comma-separated list of code to generate; valid options: "types", "client", "chi-server", "server", "gin", "gorilla", "spec", "skip-fmt", "skip-prune", "fiber", "iris". The default is "types,client,server,spec".

types

client

server

spec