Skip to content

Commit a74d90e

Browse files
author
Reuven
committed
simplified
1 parent 5172494 commit a74d90e

54 files changed

Lines changed: 567 additions & 747 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

diff/callbacks_diff.go

Lines changed: 7 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -25,30 +25,18 @@ func (callbacksDiff *CallbacksDiff) Empty() bool {
2525
len(callbacksDiff.Modified) == 0
2626
}
2727

28-
// Breaking indicates whether this element includes a breaking change
29-
func (diff *CallbacksDiff) Breaking() bool {
28+
func (diff *CallbacksDiff) removeNonBreaking() {
29+
3030
if diff.Empty() {
31-
return false
31+
return
3232
}
3333

34-
return len(diff.Deleted) > 0 ||
35-
diff.Modified.Breaking()
34+
diff.Added = nil
3635
}
3736

3837
// ModifiedCallbacks is map of callback names to their respective diffs
3938
type ModifiedCallbacks map[string]*PathsDiff
4039

41-
// Breaking indicates whether this element includes a breaking change
42-
func (diff ModifiedCallbacks) Breaking() bool {
43-
for _, pathsDiff := range diff {
44-
if pathsDiff.Breaking() {
45-
return true
46-
}
47-
}
48-
49-
return false
50-
}
51-
5240
func newCallbacksDiff() *CallbacksDiff {
5341
return &CallbacksDiff{
5442
Added: StringList{},
@@ -64,11 +52,11 @@ func getCallbacksDiff(config *Config, callbacks1, callbacks2 openapi3.Callbacks)
6452
return nil, err
6553
}
6654

67-
if diff.Empty() {
68-
return nil, nil
55+
if config.BreakingOnly {
56+
diff.removeNonBreaking()
6957
}
7058

71-
if config.BreakingOnly && !diff.Breaking() {
59+
if diff.Empty() {
7260
return nil, nil
7361
}
7462

diff/components_diff.go

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,3 +67,20 @@ func getComponentsDiff(config *Config, s1, s2 openapi3.Components) (ComponentsDi
6767

6868
return result, nil
6969
}
70+
71+
func (diff *ComponentsDiff) removeNonBreaking() {
72+
73+
if diff == nil {
74+
return
75+
}
76+
77+
diff.SchemasDiff = nil
78+
diff.ParametersDiff = nil
79+
diff.HeadersDiff = nil
80+
diff.RequestBodiesDiff = nil
81+
diff.ResponsesDiff = nil
82+
diff.SecuritySchemesDiff = nil
83+
diff.ExamplesDiff = nil
84+
diff.LinksDiff = nil
85+
diff.CallbacksDiff = nil
86+
}

diff/contact.go

Lines changed: 3 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -17,22 +17,13 @@ func (diff *ContactDiff) Empty() bool {
1717
return diff == nil || *diff == ContactDiff{}
1818
}
1919

20-
// Breaking indicates whether this element includes a breaking change
21-
func (diff *ContactDiff) Breaking() bool {
22-
return false
23-
}
24-
2520
func getContactDiff(config *Config, contact1, contact2 *openapi3.Contact) *ContactDiff {
2621
diff := getContactDiffInternal(config, contact1, contact2)
2722

2823
if diff.Empty() {
2924
return nil
3025
}
3126

32-
if config.BreakingOnly && !diff.Breaking() {
33-
return nil
34-
}
35-
3627
return diff
3728
}
3829

@@ -55,9 +46,9 @@ func getContactDiffInternal(config *Config, contact1, contact2 *openapi3.Contact
5546
}
5647

5748
result.ExtensionsDiff = getExtensionsDiff(config, contact1.ExtensionProps, contact2.ExtensionProps)
58-
result.NameDiff = getValueDiff(config, false, contact1.Name, contact2.Name)
59-
result.URLDiff = getValueDiff(config, false, contact1.URL, contact2.URL)
60-
result.EmailDiff = getValueDiff(config, false, contact1.Email, contact2.Email)
49+
result.NameDiff = getValueDiff(config, contact1.Name, contact2.Name)
50+
result.URLDiff = getValueDiff(config, contact1.URL, contact2.URL)
51+
result.EmailDiff = getValueDiff(config, contact1.Email, contact2.Email)
6152

6253
return &result
6354
}

diff/content_diff.go

Lines changed: 6 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -14,16 +14,6 @@ type ContentDiff struct {
1414
// ModifiedMediaTypes is map of media type names to their respective diffs
1515
type ModifiedMediaTypes map[string]*MediaTypeDiff
1616

17-
// Breaking indicates whether this element includes a breaking change
18-
func (diff ModifiedMediaTypes) Breaking() bool {
19-
for _, mediaTypeDiff := range diff {
20-
if mediaTypeDiff.Breaking() {
21-
return true
22-
}
23-
}
24-
return false
25-
}
26-
2717
func newContentDiff() *ContentDiff {
2818
return &ContentDiff{
2919
MediaTypeAdded: StringList{},
@@ -43,14 +33,12 @@ func (diff *ContentDiff) Empty() bool {
4333
len(diff.MediaTypeModified) == 0
4434
}
4535

46-
// Breaking indicates whether this element includes a breaking change
47-
func (diff *ContentDiff) Breaking() bool {
36+
func (diff *ContentDiff) removeNonBreaking() {
4837
if diff.Empty() {
49-
return false
38+
return
5039
}
5140

52-
return len(diff.MediaTypeDeleted) > 0 ||
53-
diff.MediaTypeModified.Breaking()
41+
diff.MediaTypeAdded = nil
5442
}
5543

5644
func getContentDiff(config *Config, content1, content2 openapi3.Content) (*ContentDiff, error) {
@@ -59,11 +47,11 @@ func getContentDiff(config *Config, content1, content2 openapi3.Content) (*Conte
5947
return nil, err
6048
}
6149

62-
if diff.Empty() {
63-
return nil, nil
50+
if config.BreakingOnly {
51+
diff.removeNonBreaking()
6452
}
6553

66-
if config.BreakingOnly && !diff.Breaking() {
54+
if diff.Empty() {
6755
return nil, nil
6856
}
6957

diff/diff.go

Lines changed: 14 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -30,16 +30,19 @@ func (diff *Diff) Empty() bool {
3030
return diff == nil || *diff == Diff{}
3131
}
3232

33-
// Breaking indicates whether this element includes a breaking change
34-
func (diff *Diff) Breaking() bool {
33+
func (diff *Diff) removeNonBreaking() {
34+
3535
if diff.Empty() {
36-
return false
36+
return
3737
}
3838

39-
return diff.PathsDiff.Breaking() ||
40-
diff.EndpointsDiff.Breaking() ||
41-
diff.SecurityDiff.Breaking() ||
42-
diff.ServersDiff.Breaking()
39+
diff.ExtensionsDiff = nil
40+
diff.OpenAPIDiff = nil
41+
diff.InfoDiff = nil
42+
diff.TagsDiff = nil
43+
diff.ExternalDocsDiff = nil
44+
45+
diff.ComponentsDiff.removeNonBreaking()
4346
}
4447

4548
/*
@@ -69,11 +72,11 @@ func getDiff(config *Config, s1, s2 *openapi3.T) (*Diff, error) {
6972
return nil, err
7073
}
7174

72-
if diff.Empty() {
73-
return nil, nil
75+
if config.BreakingOnly {
76+
diff.removeNonBreaking()
7477
}
7578

76-
if config.BreakingOnly && !diff.Breaking() {
79+
if diff.Empty() {
7780
return nil, nil
7881
}
7982

@@ -86,7 +89,7 @@ func getDiffInternal(config *Config, s1, s2 *openapi3.T) (*Diff, error) {
8689
var err error
8790

8891
result.ExtensionsDiff = getExtensionsDiff(config, s1.ExtensionProps, s2.ExtensionProps)
89-
result.OpenAPIDiff = getValueDiff(config, false, s1.OpenAPI, s2.OpenAPI)
92+
result.OpenAPIDiff = getValueDiff(config, s1.OpenAPI, s2.OpenAPI)
9093

9194
result.InfoDiff, err = getInfoDiff(config, s1.Info, s2.Info)
9295
if err != nil {

diff/diff_breaking_test.go

Lines changed: 27 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,11 @@ import (
99
)
1010

1111
func TestBreaking_Same(t *testing.T) {
12-
require.False(t, d(t, diff.NewConfig(), 1, 1).Breaking())
12+
require.True(t, d(t, &diff.Config{BreakingOnly: true}, 1, 1).Empty())
1313
}
1414

1515
func TestBreaking_DeletedPaths(t *testing.T) {
16-
require.True(t, d(t, diff.NewConfig(), 1, 2).Breaking())
16+
require.False(t, d(t, &diff.Config{BreakingOnly: true}, 1, 2).Empty())
1717
}
1818

1919
func TestBreaking_DeletedTagAllChanges(t *testing.T) {
@@ -36,24 +36,35 @@ func TestBreaking_DeletedEnum(t *testing.T) {
3636
}
3737

3838
func TestBreaking_AddedEnum(t *testing.T) {
39-
require.False(t,
39+
require.Nil(t,
4040
d(t, &diff.Config{
4141
BreakingOnly: true,
42-
}, 1, 3).PathsDiff.Modified[installCommandPath].OperationsDiff.Modified["GET"].ParametersDiff.Modified[openapi3.ParameterInPath].Breaking())
42+
}, 1, 3).PathsDiff.Modified[installCommandPath].OperationsDiff.Modified["GET"].ParametersDiff.Modified[openapi3.ParameterInPath])
4343
}
4444

4545
func TestBreaking_ModifiedExtension(t *testing.T) {
4646
config := diff.Config{
47+
BreakingOnly: true,
4748
IncludeExtensions: diff.StringSet{"x-extension-test2": struct{}{}},
4849
}
4950

50-
require.False(t, d(t, &config, 1, 3).ExtensionsDiff.Breaking())
51+
require.True(t, d(t, &config, 1, 3).ExtensionsDiff.Empty())
5152
}
5253

53-
func TestBreaking_Ref(t *testing.T) {
54-
require.True(t,
55-
d(t, diff.NewConfig(), 1, 3).RequestBodiesDiff.Modified["reuven"].ContentDiff.MediaTypeModified["application/json"].SchemaDiff.PropertiesDiff.Modified["meter_value"].TypeDiff.Breaking(),
56-
)
54+
func TestBreaking_Components(t *testing.T) {
55+
56+
dd := d(t, &diff.Config{BreakingOnly: true},
57+
1, 3)
58+
59+
require.Empty(t, dd.SchemasDiff)
60+
require.Empty(t, dd.ParametersDiff)
61+
require.Empty(t, dd.HeadersDiff)
62+
require.Empty(t, dd.RequestBodiesDiff)
63+
require.Empty(t, dd.ResponsesDiff)
64+
require.Empty(t, dd.SecuritySchemesDiff)
65+
require.Empty(t, dd.ExamplesDiff)
66+
require.Empty(t, dd.LinksDiff)
67+
require.Empty(t, dd.CallbacksDiff)
5768
}
5869

5970
func TestCompareWithDefault(t *testing.T) {
@@ -82,7 +93,7 @@ func TestBreaking_MaxLengthSmaller(t *testing.T) {
8293
BreakingOnly: true,
8394
}, s1, s2)
8495
require.NoError(t, err)
85-
require.True(t, d.Breaking())
96+
require.False(t, d.Empty())
8697
}
8798

8899
func TestBreaking_MaxLengthGreater(t *testing.T) {
@@ -99,7 +110,7 @@ func TestBreaking_MaxLengthGreater(t *testing.T) {
99110
BreakingOnly: true,
100111
}, s1, s2)
101112
require.NoError(t, err)
102-
require.False(t, d.Breaking())
113+
require.True(t, d.Empty())
103114
}
104115

105116
func TestBreaking_MaxLengthFromNil(t *testing.T) {
@@ -115,7 +126,7 @@ func TestBreaking_MaxLengthFromNil(t *testing.T) {
115126
BreakingOnly: true,
116127
}, s1, s2)
117128
require.NoError(t, err)
118-
require.True(t, d.Breaking())
129+
require.False(t, d.Empty())
119130
}
120131

121132
func TestBreaking_MaxLengthToNil(t *testing.T) {
@@ -131,7 +142,7 @@ func TestBreaking_MaxLengthToNil(t *testing.T) {
131142
BreakingOnly: true,
132143
}, s1, s2)
133144
require.NoError(t, err)
134-
require.False(t, d.Breaking())
145+
require.True(t, d.Empty())
135146
}
136147

137148
func TestBreaking_MaxLengthBothNil(t *testing.T) {
@@ -145,7 +156,7 @@ func TestBreaking_MaxLengthBothNil(t *testing.T) {
145156
BreakingOnly: true,
146157
}, s1, s2)
147158
require.NoError(t, err)
148-
require.False(t, d.Breaking())
159+
require.True(t, d.Empty())
149160
}
150161

151162
func TestBreaking_MinItemsSmaller(t *testing.T) {
@@ -159,7 +170,7 @@ func TestBreaking_MinItemsSmaller(t *testing.T) {
159170
BreakingOnly: true,
160171
}, s1, s2)
161172
require.NoError(t, err)
162-
require.False(t, d.Breaking())
173+
require.True(t, d.Empty())
163174
}
164175

165176
func TestBreaking_MinItemsGreater(t *testing.T) {
@@ -173,5 +184,5 @@ func TestBreaking_MinItemsGreater(t *testing.T) {
173184
BreakingOnly: true,
174185
}, s1, s2)
175186
require.NoError(t, err)
176-
require.True(t, d.Breaking())
187+
require.False(t, d.Empty())
177188
}

diff/discriminator_diff.go

Lines changed: 9 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -18,16 +18,13 @@ func (diff *DiscriminatorDiff) Empty() bool {
1818
return diff == nil || *diff == DiscriminatorDiff{}
1919
}
2020

21-
// Breaking indicates whether this element includes a breaking change
22-
func (diff *DiscriminatorDiff) Breaking() bool {
21+
func (diff *DiscriminatorDiff) removeNonBreaking() {
22+
2323
if diff.Empty() {
24-
return false
24+
return
2525
}
2626

27-
return diff.Added ||
28-
diff.Deleted ||
29-
!diff.PropertyNameDiff.Breaking() ||
30-
!diff.MappingDiff.Breaking()
27+
diff.ExtensionsDiff = nil
3128
}
3229

3330
func newDiscriminatorDiff() *DiscriminatorDiff {
@@ -38,11 +35,11 @@ func newDiscriminatorDiff() *DiscriminatorDiff {
3835
func getDiscriminatorDiff(config *Config, discriminator1, discriminator2 *openapi3.Discriminator) *DiscriminatorDiff {
3936
diff := getDiscriminatorDiffInternal(config, discriminator1, discriminator2)
4037

41-
if diff.Empty() {
42-
return nil
38+
if config.BreakingOnly {
39+
diff.removeNonBreaking()
4340
}
4441

45-
if config.BreakingOnly && !diff.Breaking() {
42+
if diff.Empty() {
4643
return nil
4744
}
4845

@@ -68,8 +65,8 @@ func getDiscriminatorDiffInternal(config *Config, discriminator1, discriminator2
6865
}
6966

7067
result.ExtensionsDiff = getExtensionsDiff(config, discriminator1.ExtensionProps, discriminator2.ExtensionProps)
71-
result.PropertyNameDiff = getValueDiff(config, true, discriminator1.PropertyName, discriminator2.PropertyName)
72-
result.MappingDiff = getStringMapDiff(config, true, discriminator1.Mapping, discriminator2.Mapping)
68+
result.PropertyNameDiff = getValueDiff(config, discriminator1.PropertyName, discriminator2.PropertyName)
69+
result.MappingDiff = getStringMapDiff(config, discriminator1.Mapping, discriminator2.Mapping)
7370

7471
return result
7572
}

0 commit comments

Comments
 (0)