MCPcopy Create free account
hub / github.com/cli/cli / loadRESTIndex

Function loadRESTIndex

script/ghmock/restcheck.go:42–56  ·  view source on GitHub ↗
(data []byte)

Source from the content-addressed store, hash-verified

40var slashParams = map[string]bool{"path": true, "ref": true, "branch": true, "basehead": true, "tag": true}
41
42func loadRESTIndex(data []byte) (*restIndex, error) {
43 doc, err := openapi3.NewLoader().LoadFromData(data)
44 if err != nil {
45 return nil, err
46 }
47 if doc.Paths == nil || doc.Paths.Len() == 0 {
48 return nil, errors.New("the description has no paths")
49 }
50 idx := &restIndex{}
51 for tmpl, item := range doc.Paths.Map() {
52 idx.routes = append(idx.routes, restRoute{template: tmpl, segments: parseTemplate(tmpl), item: item})
53 }
54 sort.Slice(idx.routes, func(i, j int) bool { return idx.routes[i].template < idx.routes[j].template })
55 return idx, nil
56}
57
58func parseTemplate(tmpl string) []routeSegment {
59 parts := splitPath(tmpl)

Callers 2

schemafiles.goFile · 0.85
restMethod · 0.85

Calls 3

parseTemplateFunction · 0.85
MapMethod · 0.80
LenMethod · 0.65

Tested by

no test coverage detected