-
Notifications
You must be signed in to change notification settings - Fork 92
Expand file tree
/
Copy pathexternal_docs_diff.go
More file actions
64 lines (51 loc) · 1.87 KB
/
external_docs_diff.go
File metadata and controls
64 lines (51 loc) · 1.87 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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
package diff
import (
"github.com/oasdiff/kin-openapi/openapi3"
)
// ExternalDocsDiff describes the changes between a pair of external documentation objects: https://swagger.io/specification/#external-documentation-object
type ExternalDocsDiff struct {
Added bool `json:"added,omitempty" yaml:"added,omitempty"`
Deleted bool `json:"deleted,omitempty" yaml:"deleted,omitempty"`
ExtensionsDiff *ExtensionsDiff `json:"extensions,omitempty" yaml:"extensions,omitempty"`
DescriptionDiff *ValueDiff `json:"description,omitempty" yaml:"description,omitempty"`
URLDiff *ValueDiff `json:"url,omitempty" yaml:"url,omitempty"`
}
func newExternalDocsDiff() *ExternalDocsDiff {
return &ExternalDocsDiff{}
}
// Empty indicates whether a change was found in this element
func (diff *ExternalDocsDiff) Empty() bool {
return diff == nil || *diff == ExternalDocsDiff{}
}
func getExternalDocsDiff(config *Config, docs1, docs2 *openapi3.ExternalDocs) (*ExternalDocsDiff, error) {
diff, err := getExternalDocsDiffInternal(config, docs1, docs2)
if err != nil {
return nil, err
}
if diff.Empty() {
return nil, nil
}
return diff, nil
}
func getExternalDocsDiffInternal(config *Config, docs1, docs2 *openapi3.ExternalDocs) (*ExternalDocsDiff, error) {
result := newExternalDocsDiff()
var err error
if docs1 == nil && docs2 == nil {
return result, nil
}
if docs1 == nil && docs2 != nil {
result.Added = true
return result, nil
}
if docs1 != nil && docs2 == nil {
result.Deleted = true
return result, nil
}
result.ExtensionsDiff, err = getExtensionsDiff(config, docs1.Extensions, docs2.Extensions)
if err != nil {
return nil, err
}
result.DescriptionDiff = getValueDiffConditional(config.IsExcludeDescription(), docs1.Description, docs2.Description)
result.URLDiff = getValueDiff(docs1.URL, docs2.URL)
return result, nil
}