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

Function buildPathFromFileServer

http/codegen/openapi/v2/builder.go:438–504  ·  view source on GitHub ↗
(s *V2, root *expr.RootExpr, fs *expr.HTTPFileServerExpr)

Source from the content-addressed store, hash-verified

436}
437
438func buildPathFromFileServer(s *V2, root *expr.RootExpr, fs *expr.HTTPFileServerExpr) {
439 for _, path := range fs.RequestPaths {
440 wcs := expr.ExtractHTTPWildcards(path)
441 var param []*Parameter
442 if len(wcs) > 0 {
443 param = []*Parameter{{
444 In: "path",
445 Name: wcs[0],
446 Description: "Relative file path",
447 Required: true,
448 Type: "string",
449 }}
450 }
451
452 responses := map[string]*Response{
453 "200": {
454 Description: "File downloaded",
455 Schema: &openapi.Schema{Type: openapi.File},
456 },
457 }
458 if len(wcs) > 0 {
459 schema := openapi.TypeSchema(root.API, expr.ErrorResult)
460 responses["404"] = &Response{Description: "File not found", Schema: schema}
461 }
462
463 operationID := fmt.Sprintf("%s#%s", fs.Service.Name(), path)
464 schemes := root.API.Schemes()
465 // remove grpc and grpcs from schemes since it is not a valid scheme in
466 // openapi.
467 for i := len(schemes) - 1; i >= 0; i-- {
468 if schemes[i] == "grpc" || schemes[i] == "grpcs" {
469 schemes = append(schemes[:i], schemes[i+1:]...)
470 }
471 }
472
473 tagNames := openapi.TagNamesFromExpr(fs.Meta)
474 if len(tagNames) == 0 {
475 // By default tag with service name
476 tagNames = []string{fs.Service.Name()}
477 }
478
479 operation := &Operation{
480 Description: fs.Description,
481 Summary: summaryFromMeta(fmt.Sprintf("Download %s", fs.FilePath), fs.Meta),
482 ExternalDocs: openapi.DocsFromExpr(fs.Docs, fs.Meta),
483 OperationID: operationID,
484 Parameters: param,
485 Responses: responses,
486 Schemes: schemes,
487 Tags: tagNames,
488 }
489
490 key := expr.HTTPWildcardRegex.ReplaceAllString(path, "/{$1}")
491 if key == "" {
492 key = "/"
493 }
494 var path any
495 var ok bool

Callers 2

NewV2Function · 0.85

Calls 8

ExtractHTTPWildcardsFunction · 0.92
TypeSchemaFunction · 0.92
TagNamesFromExprFunction · 0.92
DocsFromExprFunction · 0.92
ExtensionsFromExprFunction · 0.92
summaryFromMetaFunction · 0.85
NameMethod · 0.65
SchemesMethod · 0.45

Tested by 1