diff --git a/http/codegen/openapi/json_schema.go b/http/codegen/openapi/json_schema.go index b41e16358c..72c5567500 100644 --- a/http/codegen/openapi/json_schema.go +++ b/http/codegen/openapi/json_schema.go @@ -346,7 +346,7 @@ func TypeSchemaWithPrefix(api *expr.APIExpr, t expr.DataType, prefix string) *Sc case *expr.Object: s.Type = Object for _, nat := range *actual { - if !mustGenerate(nat.Attribute.Meta) { + if !MustGenerate(nat.Attribute.Meta) { continue } prop := NewSchema() @@ -529,7 +529,7 @@ func initAttributeValidation(s *Schema, at *expr.AttributeExpr) { } for _, v := range val.Required { if a := at.Find(v); a != nil { - if !mustGenerate(a.Meta) { + if !MustGenerate(a.Meta) { continue } } @@ -580,9 +580,9 @@ func buildResultTypeSchema(api *expr.APIExpr, mt *expr.ResultTypeExpr, view stri buildAttributeSchema(api, s, projected.AttributeExpr) } -// mustGenerate returns true if the meta indicates that a OpenAPI specification should be +// MustGenerate returns true if the meta indicates that a OpenAPI specification should be // generated, false otherwise. -func mustGenerate(meta expr.MetaExpr) bool { +func MustGenerate(meta expr.MetaExpr) bool { m, ok := meta.Last("openapi:generate") if !ok { m, ok = meta.Last("swagger:generate") diff --git a/http/codegen/openapi/v2/builder.go b/http/codegen/openapi/v2/builder.go index 875c7300f0..d41ec13487 100644 --- a/http/codegen/openapi/v2/builder.go +++ b/http/codegen/openapi/v2/builder.go @@ -25,7 +25,7 @@ func NewV2(root *expr.RootExpr, h *expr.HostExpr) (*V2, error) { return nil, fmt.Errorf("failed to parse server URL: %s", err) } host := u.Host - if !mustGenerate(root.API.Servers[0].Meta) || !mustGenerate(h.Meta) { + if !openapi.MustGenerate(root.API.Servers[0].Meta) || !openapi.MustGenerate(h.Meta) { host = "" } @@ -63,20 +63,20 @@ func NewV2(root *expr.RootExpr, h *expr.HostExpr) (*V2, error) { ExternalDocs: openapi.DocsFromExpr(root.API.Docs, root.API.Meta), } for _, res := range root.API.HTTP.Services { - if !mustGenerate(res.Meta) || !mustGenerate(res.ServiceExpr.Meta) { + if !openapi.MustGenerate(res.Meta) || !openapi.MustGenerate(res.ServiceExpr.Meta) { continue } for k, v := range openapi.ExtensionsFromExpr(res.Meta) { s.Paths[k] = v } for _, fs := range res.FileServers { - if !mustGenerate(fs.Meta) || !mustGenerate(fs.Service.Meta) { + if !openapi.MustGenerate(fs.Meta) || !openapi.MustGenerate(fs.Service.Meta) { continue } buildPathFromFileServer(s, root, fs) } for _, a := range res.HTTPEndpoints { - if !mustGenerate(a.Meta) || !mustGenerate(a.MethodExpr.Meta) { + if !openapi.MustGenerate(a.Meta) || !openapi.MustGenerate(a.MethodExpr.Meta) { continue } for _, route := range a.Routes { @@ -118,19 +118,6 @@ func defaultURI(h *expr.HostExpr) string { return uri } -// mustGenerate returns true if the meta indicates that a OpenAPI specification should be -// generated, false otherwise. -func mustGenerate(meta expr.MetaExpr) bool { - m, ok := meta.Last("openapi:generate") - if !ok { - m, ok = meta.Last("swagger:generate") - } - if ok && m == "false" { - return false - } - return true -} - // addScopeDescription generates and adds required scopes to the scheme's description. func addScopeDescription(scopes []*expr.ScopeExpr, sd *SecurityDefinition) { // Generate scopes to add to description @@ -216,18 +203,18 @@ func securitySpecFromExpr(root *expr.RootExpr) map[string]*SecurityDefinition { func hasAbsoluteRoutes(root *expr.RootExpr) bool { hasAbsoluteRoutes := false for _, res := range root.API.HTTP.Services { - if !mustGenerate(res.Meta) || !mustGenerate(res.ServiceExpr.Meta) { + if !openapi.MustGenerate(res.Meta) || !openapi.MustGenerate(res.ServiceExpr.Meta) { continue } for _, fs := range res.FileServers { - if !mustGenerate(fs.Meta) || !mustGenerate(fs.Service.Meta) { + if !openapi.MustGenerate(fs.Meta) || !openapi.MustGenerate(fs.Service.Meta) { continue } hasAbsoluteRoutes = true break } for _, a := range res.HTTPEndpoints { - if !mustGenerate(a.Meta) || !mustGenerate(a.MethodExpr.Meta) { + if !openapi.MustGenerate(a.Meta) || !openapi.MustGenerate(a.MethodExpr.Meta) { continue } for _, ro := range a.Routes { diff --git a/http/codegen/openapi/v3/builder.go b/http/codegen/openapi/v3/builder.go index fef6cda024..d45468f420 100644 --- a/http/codegen/openapi/v3/builder.go +++ b/http/codegen/openapi/v3/builder.go @@ -119,7 +119,7 @@ func buildComponents(root *expr.RootExpr, types map[string]*openapi.Schema) *Com func buildPaths(h *expr.HTTPExpr, bodies map[string]map[string]*EndpointBodies, api *expr.APIExpr) map[string]*PathItem { var paths = make(map[string]*PathItem) for _, svc := range h.Services { - if !mustGenerate(svc.Meta) || !mustGenerate(svc.ServiceExpr.Meta) { + if !openapi.MustGenerate(svc.Meta) || !openapi.MustGenerate(svc.ServiceExpr.Meta) { continue } @@ -128,7 +128,7 @@ func buildPaths(h *expr.HTTPExpr, bodies map[string]map[string]*EndpointBodies, // endpoints for _, e := range svc.HTTPEndpoints { - if !mustGenerate(e.Meta) || !mustGenerate(e.MethodExpr.Meta) { + if !openapi.MustGenerate(e.Meta) || !openapi.MustGenerate(e.MethodExpr.Meta) { continue } @@ -172,7 +172,7 @@ func buildPaths(h *expr.HTTPExpr, bodies map[string]map[string]*EndpointBodies, // file servers for _, f := range svc.FileServers { - if !mustGenerate(f.Meta) || !mustGenerate(f.Service.Meta) { + if !openapi.MustGenerate(f.Meta) || !openapi.MustGenerate(f.Service.Meta) { continue } @@ -482,12 +482,12 @@ func parseOperationIDTemplate(template, service, method string, routeIndex int) func buildServers(servers []*expr.ServerExpr) []*Server { var svrs []*Server for _, svr := range servers { - if !mustGenerate(svr.Meta) { + if !openapi.MustGenerate(svr.Meta) { continue } var server *Server for _, host := range svr.Hosts { - if !mustGenerate(host.Meta) { + if !openapi.MustGenerate(host.Meta) { continue } @@ -642,7 +642,7 @@ func buildTags(api *expr.APIExpr) []*openapi.Tag { m[t.Name] = t } for _, s := range api.HTTP.Services { - if !mustGenerate(s.Meta) || !mustGenerate(s.ServiceExpr.Meta) { + if !openapi.MustGenerate(s.Meta) || !openapi.MustGenerate(s.ServiceExpr.Meta) { continue } for _, t := range openapi.TagsFromExpr(s.Meta) { @@ -667,7 +667,7 @@ func buildTags(api *expr.APIExpr) []*openapi.Tag { // add service name and description to the tags since we tag every // operation with service name when no custom tag is defined for _, s := range api.HTTP.Services { - if !mustGenerate(s.Meta) || !mustGenerate(s.ServiceExpr.Meta) { + if !openapi.MustGenerate(s.Meta) || !openapi.MustGenerate(s.ServiceExpr.Meta) { continue } tags = append(tags, &openapi.Tag{ @@ -679,16 +679,3 @@ func buildTags(api *expr.APIExpr) []*openapi.Tag { } return tags } - -// mustGenerate returns true if the meta indicates that a OpenAPI specification should be -// generated, false otherwise. -func mustGenerate(meta expr.MetaExpr) bool { - m, ok := meta.Last("openapi:generate") - if !ok { - m, ok = meta.Last("swagger:generate") - } - if ok && m == "false" { - return false - } - return true -} diff --git a/http/codegen/openapi/v3/types.go b/http/codegen/openapi/v3/types.go index f54b2e8bc6..29df754dbd 100644 --- a/http/codegen/openapi/v3/types.go +++ b/http/codegen/openapi/v3/types.go @@ -78,13 +78,13 @@ func buildBodyTypes(api *expr.APIExpr) (map[string]map[string]*EndpointBodies, m } for _, s := range api.HTTP.Services { - if !mustGenerate(s.Meta) || !mustGenerate(s.ServiceExpr.Meta) { + if !openapi.MustGenerate(s.Meta) || !openapi.MustGenerate(s.ServiceExpr.Meta) { continue } sbodies := make(map[string]*EndpointBodies, len(s.HTTPEndpoints)) for _, e := range s.HTTPEndpoints { - if !mustGenerate(e.Meta) || !mustGenerate(e.MethodExpr.Meta) { + if !openapi.MustGenerate(e.Meta) || !openapi.MustGenerate(e.MethodExpr.Meta) { continue } @@ -187,7 +187,7 @@ func (sf *schemafier) schemafy(attr *expr.AttributeExpr, noref ...bool) *openapi s.Type = openapi.Object var itemNotes []string for _, nat := range *t { - if !mustGenerate(nat.Attribute.Meta) { + if !openapi.MustGenerate(nat.Attribute.Meta) { continue } s.Properties[nat.Name] = sf.schemafy(nat.Attribute) @@ -297,7 +297,7 @@ func (sf *schemafier) schemafy(attr *expr.AttributeExpr, noref ...bool) *openapi } for _, v := range val.Required { if a := attr.Find(v); a != nil { - if !mustGenerate(a.Meta) { + if !openapi.MustGenerate(a.Meta) { continue } } @@ -393,7 +393,7 @@ func hashAttribute(att *expr.AttributeExpr, h hash.Hash64, seen map[string]*uint case expr.ObjectKind: o := expr.AsObject(t) for _, m := range *o { - if !mustGenerate(m.Attribute.Meta) { + if !openapi.MustGenerate(m.Attribute.Meta) { continue } kh := hashString(m.Name, h)