-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathspec_table_response_status.go
44 lines (41 loc) · 1.17 KB
/
spec_table_response_status.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package openapi3
import (
oas3 "github.com/getkin/kin-openapi/openapi3"
"github.com/grokify/gocharts/v2/data/histogram"
)
func (sm *SpecMore) StatusCodesHistogram() *histogram.HistogramSets {
hsets := histogram.NewHistogramSets("Response Codes by Endpoint")
if sm.Spec == nil {
return hsets
}
VisitOperations(sm.Spec, func(path, method string, op *oas3.Operation) {
/*
if op == nil ||
op.Responses == nil ||
len(op.Responses) == 0 { // getkin v0.121.0 to v0.122.0
return
}
*/
if op == nil || op.Responses == nil {
return
}
responsesMap := op.Responses.Map() // getkin v0.121.0 to v0.122.0
if len(responsesMap) == 0 {
return
}
for responseStatusCode := range responsesMap {
hsets.Add(path, method, responseStatusCode, 1, true)
}
})
return hsets
}
func (sm *SpecMore) WriteFileXLSXOperationStatusCodes(filename string) error {
hsets := sm.StatusCodesHistogram()
// return hsets.WriteXLSXPivot(filename, hsets.Name, "Method", "Path", "", "")
return hsets.WriteXLSXPivot(filename, histogram.TablePivotOpts{
TableName: hsets.Name,
ColNameHistogramSet: "Method",
ColNameHistogram: "Path",
InclBinCounts: true,
})
}