https://github.com/deepmap/oapi-codegen#extensions
こちらに書いてあるとおりだが、 oapi-codegen でstringやintといった基本型以外の型にバインディングするには以下のようにする
components:
schemas:
Fruits:
type: string
enum:
- orange
- apple
- banan
description: favorite fruits
x-go-type: mypackage.Fruits
x-go-type-import:
path: example.com/mypackage
package mypackage
type Fruits string
const (
Apple Fruits = "apple"
Orange Fruits = "orange"
Banana Fruits = "banana"
)
生成されるコードは以下のようにtype aliasが使われる。
// Fruits
type Fruits = mypackage.Fruits