-
Notifications
You must be signed in to change notification settings - Fork 93
Expand file tree
/
Copy pathextensions_diff.go
More file actions
49 lines (39 loc) · 1.37 KB
/
extensions_diff.go
File metadata and controls
49 lines (39 loc) · 1.37 KB
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
47
48
49
package diff
// ExtensionsDiff describes the changes between a pair of sets of specification extensions: https://swagger.io/specification/#specification-extensions
type ExtensionsDiff InterfaceMapDiff
// Empty indicates whether a change was found in this element
func (diff *ExtensionsDiff) Empty() bool {
return (*InterfaceMapDiff)(diff).Empty()
}
func getExtensionsDiff(config *Config, extensions1, extensions2 map[string]any) (*ExtensionsDiff, error) {
if config.IsExcludeExtensions() {
return nil, nil
}
// Filter out excluded extension names
filtered1 := filterExtensions(extensions1, config)
filtered2 := filterExtensions(extensions2, config)
diff, err := getExtensionsDiffInternal(filtered1, filtered2)
if err != nil {
return nil, err
}
if diff.Empty() {
return nil, nil
}
return (*ExtensionsDiff)(diff), nil
}
func getExtensionsDiffInternal(extensions1, extensions2 map[string]any) (*InterfaceMapDiff, error) {
return getInterfaceMapDiff(extensions1, extensions2)
}
// filterExtensions returns a copy of the extensions map with excluded extensions removed
func filterExtensions(extensions map[string]any, config *Config) map[string]any {
if len(config.ExcludeExtensions) == 0 {
return extensions
}
filtered := make(map[string]any)
for name, value := range extensions {
if !config.IsExcludedExtension(name) {
filtered[name] = value
}
}
return filtered
}