(data []byte)
| 40 | var slashParams = map[string]bool{"path": true, "ref": true, "branch": true, "basehead": true, "tag": true} |
| 41 | |
| 42 | func 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 | |
| 58 | func parseTemplate(tmpl string) []routeSegment { |
| 59 | parts := splitPath(tmpl) |
no test coverage detected