MCPcopy Create free account
hub / github.com/kubernetes/test-infra / parseOpenAPI

Function parseOpenAPI

experiment/coverage/apicoverage.go:52–88  ·  view source on GitHub ↗
(rawdata []byte)

Source from the content-addressed store, hash-verified

50type apiArray []apiData
51
52func parseOpenAPI(rawdata []byte) apiArray {
53 var swaggerSpec spec.Swagger
54 var apisOpenapi apiArray
55
56 err := swaggerSpec.UnmarshalJSON(rawdata)
57 if err != nil {
58 log.Fatal(err)
59 }
60
61 for path, pathItem := range swaggerSpec.Paths.Paths {
62 // Some paths contain "/" at the end of swagger spec, here removes "/" for comparing them easily later.
63 path = strings.TrimRight(path, "/")
64
65 // Standard HTTP methods: https://github.com/OAI/OpenAPI-Specification/blob/master/versions/2.0.md#path-item-object
66 methods := []string{"get", "put", "post", "delete", "options", "head", "patch"}
67 for _, method := range methods {
68 methodSpec, err := pathItem.JSONLookup(method)
69 if err != nil {
70 log.Fatal(err)
71 }
72 t, ok := methodSpec.(*spec.Operation)
73 if !ok {
74 log.Fatal("Failed to convert methodSpec.")
75 }
76 if t == nil {
77 continue
78 }
79 method := strings.ToUpper(method)
80 api := apiData{
81 Method: method,
82 URL: path,
83 }
84 apisOpenapi = append(apisOpenapi, api)
85 }
86 }
87 return apisOpenapi
88}
89
90func getOpenAPISpec(url string) apiArray {
91 resp, err := http.Get(url)

Callers 2

getOpenAPISpecFunction · 0.85
TestParseOpenAPIFunction · 0.85

Calls 1

UnmarshalJSONMethod · 0.45

Tested by 1

TestParseOpenAPIFunction · 0.68