package api import ( "net/http" "github.com/getkin/kin-openapi/openapi3" "github.com/labstack/echo/v4" "gopkg.in/yaml.v3" ) func getSwaggerJSONFunc(opnapi *openapi3.T) (func(echo.Context) error, error) { spec, err := opnapi.MarshalJSON() if err != nil { return nil, err } return func(c echo.Context) error { return c.Blob(http.StatusOK, "application/json", spec) }, nil } func getSwaggerYAMLFunc(opnapi *openapi3.T) (func(echo.Context) error, error) { spec, err := opnapi.MarshalYAML() if err != nil { return nil, err } yaml, err := yaml.Marshal(spec) if err != nil { return nil, err } return func(c echo.Context) error { return c.Blob(http.StatusOK, "application/yaml", yaml) }, nil }