methodOps parses a method's comments for //meta:operation lines and returns the corresponding operations.
(opsFile *operationsFile, cmap ast.CommentMap, fn *ast.FuncDecl)
| 436 | |
| 437 | // methodOps parses a method's comments for //meta:operation lines and returns the corresponding operations. |
| 438 | func methodOps(opsFile *operationsFile, cmap ast.CommentMap, fn *ast.FuncDecl) ([]*operation, error) { |
| 439 | var ops []*operation |
| 440 | var err error |
| 441 | seen := map[string]bool{} |
| 442 | for _, g := range cmap[fn] { |
| 443 | for _, c := range g.List { |
| 444 | match := metaOpRe.FindStringSubmatch(c.Text) |
| 445 | if match == nil { |
| 446 | continue |
| 447 | } |
| 448 | opName := strings.TrimSpace(match[1]) |
| 449 | opsFile.resolve() |
| 450 | var found []*operation |
| 451 | norm := normalizedOpName(opName) |
| 452 | for n := range opsFile.resolvedOps { |
| 453 | if normalizedOpName(n) == norm { |
| 454 | found = append(found, opsFile.resolvedOps[n]) |
| 455 | } |
| 456 | } |
| 457 | switch len(found) { |
| 458 | case 0: |
| 459 | err = errors.Join(err, fmt.Errorf("could not find operation %q in openapi_operations.yaml", opName)) |
| 460 | case 1: |
| 461 | name := found[0].Name |
| 462 | if seen[name] { |
| 463 | err = errors.Join(err, fmt.Errorf("duplicate operation: %v", name)) |
| 464 | } |
| 465 | seen[name] = true |
| 466 | ops = append(ops, found[0]) |
| 467 | default: |
| 468 | var foundNames []string |
| 469 | for _, op := range found { |
| 470 | foundNames = append(foundNames, op.Name) |
| 471 | } |
| 472 | slices.Sort(foundNames) |
| 473 | err = errors.Join(err, fmt.Errorf("ambiguous operation %q could match any of: %v", opName, foundNames)) |
| 474 | } |
| 475 | } |
| 476 | } |
| 477 | sortOperations(ops) |
| 478 | return ops, err |
| 479 | } |
| 480 | |
| 481 | // metadataDocsAPIVersion is appended to generated docs links. |
| 482 | // Keep this in sync with defaultAPIVersion in github/github.go. |
no test coverage detected
searching dependent graphs…