-
Notifications
You must be signed in to change notification settings - Fork 28
/
inspect.go
46 lines (43 loc) · 1.05 KB
/
inspect.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
45
46
package openapi3
import (
"strings"
)
// ExtensionNames is not complete yet.
func (sm *SpecMore) ExtensionNames() map[string]int {
extNames := map[string]int{}
for _, schRef := range sm.Spec.Components.Schemas {
if schRef.Value == nil {
continue
}
sch := schRef.Value
for extName := range sch.ExtensionProps.Extensions {
count, ok := extNames[extName]
if !ok {
extNames[extName] = 1
}
extNames[extName] = count + 1
}
}
return extNames
}
func (sm *SpecMore) HasComponentSchema(componentSchemaName string, lowerCaseMatch bool) bool {
componentSchemaName = strings.TrimSpace(componentSchemaName)
if lowerCaseMatch {
componentSchemaName = strings.ToLower(componentSchemaName)
}
if len(sm.Spec.Components.Schemas) == 0 {
return false
}
if _, ok := sm.Spec.Components.Schemas[componentSchemaName]; ok {
return true
}
if lowerCaseMatch {
for nameTry := range sm.Spec.Components.Schemas {
nameTry = strings.ToLower(strings.TrimSpace(nameTry))
if nameTry == componentSchemaName {
return true
}
}
}
return false
}