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

Function buildFileServerOperation

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

buildFileServerOperation builds the OpenAPI Operation object for the given file server.

(key string, fs *expr.HTTPFileServerExpr, api *expr.APIExpr)

Source from the content-addressed store, hash-verified

352
353// buildFileServerOperation builds the OpenAPI Operation object for the given file server.
354func buildFileServerOperation(key string, fs *expr.HTTPFileServerExpr, api *expr.APIExpr) *Operation {
355 wildcards := expr.ExtractHTTPWildcards(key)
356 svc := fs.Service
357
358 // parameters
359 var params []*ParameterRef
360 if len(wildcards) > 0 {
361 pref := ParameterRef{
362 Value: &Parameter{
363 // Use the literal wildcard (including leading '*') as name to match path if needed
364 // Note: HTTPWildcardRegex already strips '*' in ExtractHTTPWildcards; however
365 // the path key has been normalized to "/{name}" so the correct parameter name
366 // is the bare wildcard identifier.
367 Name: wildcards[0],
368 Description: "Relative file path",
369 In: "path",
370 Required: true,
371 Schema: &openapi.Schema{ // string schema makes validators happy
372 Type: openapi.String,
373 },
374 },
375 }
376 params = []*ParameterRef{&pref}
377 }
378
379 // responses
380 var responses map[string]*ResponseRef
381 {
382 desc200 := "File downloaded"
383 rref := ResponseRef{
384 Value: &Response{
385 Description: &desc200,
386 },
387 }
388 responses = map[string]*ResponseRef{
389 "200": &rref,
390 }
391 if len(wildcards) > 0 {
392 desc404 := "File not found"
393 responses["404"] = &ResponseRef{
394 Value: &Response{
395 Description: &desc404,
396 },
397 }
398 }
399 }
400
401 // OpenAPI summary
402 var summary string
403 summary = fmt.Sprintf("Download %s", fs.FilePath)
404 for n, mdata := range fs.Meta {
405 if (n == "openapi:summary" || n == "swagger:summary") && len(mdata) > 0 {
406 summary = mdata[0]
407 }
408 }
409
410 // OpenAPI operationId
411 var operationIDFormat string

Callers 1

buildPathsFunction · 0.85

Calls 7

ExtractHTTPWildcardsFunction · 0.92
TagNamesFromExprFunction · 0.92
DocsFromExprFunction · 0.92
ExtensionsFromExprFunction · 0.92
parseOperationIDTemplateFunction · 0.85
NameMethod · 0.65

Tested by

no test coverage detected