MCPcopy Create free account
hub / github.com/goadesign/goa / buildPaths

Function buildPaths

http/codegen/openapi/v3/builder.go:118–189  ·  view source on GitHub ↗

buildPaths builds the OpenAPI Paths map with key as the HTTP path string and the value as the corresponding PathItem object.

(h *expr.HTTPExpr, bodies map[string]map[string]*EndpointBodies, api *expr.APIExpr)

Source from the content-addressed store, hash-verified

116// buildPaths builds the OpenAPI Paths map with key as the HTTP path string and
117// the value as the corresponding PathItem object.
118func buildPaths(h *expr.HTTPExpr, bodies map[string]map[string]*EndpointBodies, api *expr.APIExpr) map[string]*PathItem {
119 var paths = make(map[string]*PathItem)
120 for _, svc := range h.Services {
121 if !openapi.MustGenerate(svc.Meta) || !openapi.MustGenerate(svc.ServiceExpr.Meta) {
122 continue
123 }
124 exts := openapi.ExtensionsFromExpr(svc.Meta)
125 sbod := bodies[svc.Name()]
126
127 // endpoints
128 for _, e := range svc.HTTPEndpoints {
129 if !openapi.MustGenerate(e.Meta) || !openapi.MustGenerate(e.MethodExpr.Meta) {
130 continue
131 }
132 for _, r := range e.Routes {
133 for _, key := range r.FullPaths() {
134 // Remove any wildcards that is defined in path as a workaround to
135 // https://github.com/OAI/OpenAPI-Specification/issues/291
136 key = expr.HTTPWildcardRegex.ReplaceAllString(key, "/{$1}")
137 operation := buildOperation(key, r, sbod[e.Name()], api.ExampleGenerator, api.Meta)
138 path, ok := paths[key]
139 if !ok {
140 path = new(PathItem)
141 paths[key] = path
142 }
143 switch r.Method {
144 case "GET":
145 path.Get = operation
146 case "PUT":
147 path.Put = operation
148 case "POST":
149 path.Post = operation
150 case "DELETE":
151 path.Delete = operation
152 case "OPTIONS":
153 path.Options = operation
154 case "HEAD":
155 path.Head = operation
156 case "PATCH":
157 path.Patch = operation
158 }
159 path.Extensions = openapi.ExtensionsFromExpr(r.Endpoint.Meta)
160 if len(exts) > 0 {
161 path.Extensions = make(map[string]any)
162 maps.Copy(path.Extensions, exts)
163 }
164 }
165 }
166 }
167
168 // file servers
169 for _, f := range svc.FileServers {
170 if !openapi.MustGenerate(f.Meta) || !openapi.MustGenerate(f.Service.Meta) {
171 continue
172 }
173
174 for _, key := range f.RequestPaths {
175 // Replace wildcards in the path to OpenAPI path parameter form

Callers 1

NewFunction · 0.85

Calls 6

MustGenerateFunction · 0.92
ExtensionsFromExprFunction · 0.92
buildOperationFunction · 0.85
buildFileServerOperationFunction · 0.85
NameMethod · 0.65
FullPathsMethod · 0.45

Tested by

no test coverage detected