podhmo / reflect-openapi

Define OpenAPI with reflect package
Apache License 2.0
3 stars 0 forks source link

modify operationId option #102

Closed podhmo closed 1 year ago

podhmo commented 1 year ago
package main

import (
    "github.com/getkin/kin-openapi/openapi3"
    reflectopenapi "github.com/podhmo/reflect-openapi"
)

type Foo struct {
    Name string `json:"name"`
}

func GetFoo() *Foo { return nil }

func main() {
    c := &reflectopenapi.Config{}
    c.EmitDoc(func(m *reflectopenapi.Manager) {
        m.RegisterFunc(GetFoo).After(func(op *openapi3.Operation) {
            op.OperationID = "Foo" // main.GetFoo -> Foo
            m.Doc.AddOperation("/foo", "GET", op)
        })
    })
}