MCPcopy Index your code
hub / github.com/coder/coder / ParseSwaggerComments

Function ParseSwaggerComments

coderd/coderdtest/swaggerparser.go:48–82  ·  view source on GitHub ↗
(dirs ...string)

Source from the content-addressed store, hash-verified

46}
47
48func ParseSwaggerComments(dirs ...string) ([]SwaggerComment, error) {
49 fileSet := token.NewFileSet()
50
51 var swaggerComments []SwaggerComment
52 for _, dir := range dirs {
53 nodes, err := parser.ParseDir(fileSet, dir, nil, parser.ParseComments)
54 if err != nil {
55 return nil, xerrors.Errorf(`parser.ParseDir failed for "%s": %w`, dir, err)
56 }
57
58 for _, node := range nodes {
59 ast.Inspect(node, func(n ast.Node) bool {
60 commentGroup, ok := n.(*ast.CommentGroup)
61 if !ok {
62 return true
63 }
64
65 var isSwaggerComment bool
66 for _, line := range commentGroup.List {
67 text := strings.TrimSpace(line.Text)
68 if strings.HasPrefix(text, "//") && strings.Contains(text, "@Router") {
69 isSwaggerComment = true
70 break
71 }
72 }
73
74 if isSwaggerComment {
75 swaggerComments = append(swaggerComments, parseSwaggerComment(commentGroup))
76 }
77 return true
78 })
79 }
80 }
81 return swaggerComments, nil
82}
83
84func parseSwaggerComment(commentGroup *ast.CommentGroup) SwaggerComment {
85 c := SwaggerComment{

Callers 2

TestEndpointsDocumentedFunction · 0.92

Calls 3

parseSwaggerCommentFunction · 0.85
ErrorfMethod · 0.45
ContainsMethod · 0.45

Tested by 2

TestEndpointsDocumentedFunction · 0.74