Skip to content

Commit a1c638f

Browse files
authored
CLOUDP-284014: Check soa migration in external path (#274)
1 parent 241e16e commit a1c638f

File tree

3 files changed

+43
-43
lines changed

3 files changed

+43
-43
lines changed

tools/cli/internal/openapi/oasdiff.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,7 +76,7 @@ func (o OasDiff) mergePaths() error {
7676
if originalPathData := basePaths.Value(path); originalPathData == nil {
7777
basePaths.Set(path, removeExternalRefs(externalPathData))
7878
} else {
79-
if err := o.handlePathConflict(originalPathData, path); err != nil {
79+
if err := o.handlePathConflict(externalPathData, path); err != nil {
8080
return err
8181
}
8282
basePaths.Set(path, removeExternalRefs(externalPathData))

tools/cli/internal/openapi/oasdiff_test.go

Lines changed: 17 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ func TestOasDiff_mergePaths(t *testing.T) {
7373
wantErr: require.NoError,
7474
},
7575
{
76-
name: "SuccessfulMergeWithEmptyBasePaths",
76+
name: "SuccessfulMergeWithEmptyexternalPaths",
7777
inputBase: &load.SpecInfo{
7878
Url: "base",
7979
Spec: &openapi3.T{
@@ -1152,15 +1152,15 @@ func TestUpdateExternalRefReqBody(t *testing.T) {
11521152

11531153
func TestHandlePathConflict(t *testing.T) {
11541154
testCases := []struct {
1155-
name string
1156-
basePath *openapi3.PathItem
1157-
basePathName string
1158-
specDiff *diff.Diff
1159-
expectedError error
1155+
name string
1156+
externalPath *openapi3.PathItem
1157+
externalPathName string
1158+
specDiff *diff.Diff
1159+
expectedError error
11601160
}{
11611161
{
11621162
name: "No Conflict - Identical Paths",
1163-
basePath: &openapi3.PathItem{
1163+
externalPath: &openapi3.PathItem{
11641164
Get: &openapi3.Operation{
11651165
Extensions: map[string]interface{}{
11661166
"x-xgen-soa-migration": map[string]interface{}{
@@ -1169,7 +1169,7 @@ func TestHandlePathConflict(t *testing.T) {
11691169
},
11701170
},
11711171
},
1172-
basePathName: "/test",
1172+
externalPathName: "/test",
11731173
specDiff: &diff.Diff{
11741174
PathsDiff: &diff.PathsDiff{
11751175
Modified: map[string]*diff.PathDiff{},
@@ -1179,7 +1179,7 @@ func TestHandlePathConflict(t *testing.T) {
11791179
},
11801180
{
11811181
name: "Conflict with AllowDocsDiff",
1182-
basePath: &openapi3.PathItem{
1182+
externalPath: &openapi3.PathItem{
11831183
Get: &openapi3.Operation{
11841184
Extensions: map[string]interface{}{
11851185
"x-xgen-soa-migration": map[string]interface{}{
@@ -1188,7 +1188,7 @@ func TestHandlePathConflict(t *testing.T) {
11881188
},
11891189
},
11901190
},
1191-
basePathName: "/test",
1191+
externalPathName: "/test",
11921192
specDiff: &diff.Diff{
11931193
PathsDiff: &diff.PathsDiff{
11941194
Modified: map[string]*diff.PathDiff{
@@ -1212,7 +1212,7 @@ func TestHandlePathConflict(t *testing.T) {
12121212
},
12131213
{
12141214
name: "Conflict with Different Operations",
1215-
basePath: &openapi3.PathItem{
1215+
externalPath: &openapi3.PathItem{
12161216
Get: &openapi3.Operation{
12171217
Extensions: map[string]interface{}{
12181218
"x-xgen-soa-migration": map[string]interface{}{
@@ -1221,7 +1221,7 @@ func TestHandlePathConflict(t *testing.T) {
12211221
},
12221222
},
12231223
},
1224-
basePathName: "/test",
1224+
externalPathName: "/test",
12251225
specDiff: &diff.Diff{
12261226
PathsDiff: &diff.PathsDiff{
12271227
Modified: map[string]*diff.PathDiff{
@@ -1240,7 +1240,7 @@ func TestHandlePathConflict(t *testing.T) {
12401240
},
12411241
{
12421242
name: "Conflict with Different Path Operation",
1243-
basePath: &openapi3.PathItem{
1243+
externalPath: &openapi3.PathItem{
12441244
Get: &openapi3.Operation{
12451245
Extensions: map[string]interface{}{
12461246
"x-xgen-soa-migration": map[string]interface{}{
@@ -1249,7 +1249,7 @@ func TestHandlePathConflict(t *testing.T) {
12491249
},
12501250
},
12511251
},
1252-
basePathName: "/test",
1252+
externalPathName: "/test",
12531253
specDiff: &diff.Diff{
12541254
PathsDiff: &diff.PathsDiff{
12551255
Modified: map[string]*diff.PathDiff{
@@ -1290,7 +1290,7 @@ func TestHandlePathConflict(t *testing.T) {
12901290
},
12911291
{
12921292
name: "Identical Paths with Extensions",
1293-
basePath: &openapi3.PathItem{
1293+
externalPath: &openapi3.PathItem{
12941294
Get: &openapi3.Operation{
12951295
Extensions: map[string]interface{}{
12961296
"x-xgen-soa-migration": map[string]interface{}{
@@ -1299,7 +1299,7 @@ func TestHandlePathConflict(t *testing.T) {
12991299
},
13001300
},
13011301
},
1302-
basePathName: "/test",
1302+
externalPathName: "/test",
13031303
specDiff: &diff.Diff{
13041304
PathsDiff: &diff.PathsDiff{
13051305
Modified: map[string]*diff.PathDiff{},
@@ -1342,7 +1342,7 @@ func TestHandlePathConflict(t *testing.T) {
13421342
Return(tc.specDiff, nil).
13431343
AnyTimes()
13441344

1345-
err := o.handlePathConflict(tc.basePath, tc.basePathName)
1345+
err := o.handlePathConflict(tc.externalPath, tc.externalPathName)
13461346
if tc.expectedError != nil {
13471347
require.Error(t, err)
13481348
assert.IsType(t, tc.expectedError, err)

tools/cli/internal/openapi/paths.go

Lines changed: 25 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -26,42 +26,42 @@ const (
2626
)
2727

2828
// allOperationsHaveExtension checks if all the operations in the base path have the given extension name.
29-
func allOperationsHaveExtension(basePath *openapi3.PathItem, basePathName, extensionName string) bool {
30-
if basePath.Operations() == nil || len(basePath.Operations()) == 0 {
29+
func allOperationsHaveExtension(pathData *openapi3.PathItem, path, extensionName string) bool {
30+
if pathData.Operations() == nil || len(pathData.Operations()) == 0 {
3131
return false
3232
}
3333

34-
if basePath.Get != nil {
35-
if result := getOperationExtensionWithName(basePath.Get, extensionName); result == nil {
34+
if pathData.Get != nil {
35+
if result := getOperationExtensionWithName(pathData.Get, extensionName); result == nil {
3636
return false
3737
}
3838
}
3939

40-
if basePath.Put != nil {
41-
if result := getOperationExtensionWithName(basePath.Put, extensionName); result == nil {
40+
if pathData.Put != nil {
41+
if result := getOperationExtensionWithName(pathData.Put, extensionName); result == nil {
4242
return false
4343
}
4444
}
4545

46-
if basePath.Post != nil {
47-
if result := getOperationExtensionWithName(basePath.Post, extensionName); result == nil {
46+
if pathData.Post != nil {
47+
if result := getOperationExtensionWithName(pathData.Post, extensionName); result == nil {
4848
return false
4949
}
5050
}
5151

52-
if basePath.Patch != nil {
53-
if result := getOperationExtensionWithName(basePath.Patch, extensionName); result == nil {
52+
if pathData.Patch != nil {
53+
if result := getOperationExtensionWithName(pathData.Patch, extensionName); result == nil {
5454
return false
5555
}
5656
}
5757

58-
if basePath.Delete != nil {
59-
if result := getOperationExtensionWithName(basePath.Delete, extensionName); result == nil {
58+
if pathData.Delete != nil {
59+
if result := getOperationExtensionWithName(pathData.Delete, extensionName); result == nil {
6060
return false
6161
}
6262
}
6363

64-
log.Printf("Detected %s annotation in all operations for path: %s\n", extensionName, basePathName)
64+
log.Printf("Detected %s annotation in all operations for path: %s\n", extensionName, path)
6565
return true
6666
}
6767

@@ -74,41 +74,41 @@ func getOperationExtensionWithName(operation *openapi3.Operation, extensionName
7474
return operation.Extensions[extensionName]
7575
}
7676

77-
func allOperationsAllowDocsDiff(basePath *openapi3.PathItem) bool {
78-
if basePath.Operations() == nil || len(basePath.Operations()) == 0 {
77+
func allOperationsAllowDocsDiff(pathData *openapi3.PathItem) bool {
78+
if pathData.Operations() == nil || len(pathData.Operations()) == 0 {
7979
return false
8080
}
8181

82-
if basePath.Get != nil {
83-
prop := getOperationExtensionProperty(basePath.Get, xgenSoaMigration, allowDocsDiff)
82+
if pathData.Get != nil {
83+
prop := getOperationExtensionProperty(pathData.Get, xgenSoaMigration, allowDocsDiff)
8484
if prop != "true" {
8585
return false
8686
}
8787
}
8888

89-
if basePath.Put != nil {
90-
prop := getOperationExtensionProperty(basePath.Put, xgenSoaMigration, allowDocsDiff)
89+
if pathData.Put != nil {
90+
prop := getOperationExtensionProperty(pathData.Put, xgenSoaMigration, allowDocsDiff)
9191
if prop != "true" {
9292
return false
9393
}
9494
}
9595

96-
if basePath.Post != nil {
97-
prop := getOperationExtensionProperty(basePath.Post, xgenSoaMigration, allowDocsDiff)
96+
if pathData.Post != nil {
97+
prop := getOperationExtensionProperty(pathData.Post, xgenSoaMigration, allowDocsDiff)
9898
if prop != "true" {
9999
return false
100100
}
101101
}
102102

103-
if basePath.Patch != nil {
104-
prop := getOperationExtensionProperty(basePath.Patch, xgenSoaMigration, allowDocsDiff)
103+
if pathData.Patch != nil {
104+
prop := getOperationExtensionProperty(pathData.Patch, xgenSoaMigration, allowDocsDiff)
105105
if prop != "true" {
106106
return false
107107
}
108108
}
109109

110-
if basePath.Delete != nil {
111-
prop := getOperationExtensionProperty(basePath.Delete, xgenSoaMigration, allowDocsDiff)
110+
if pathData.Delete != nil {
111+
prop := getOperationExtensionProperty(pathData.Delete, xgenSoaMigration, allowDocsDiff)
112112
if prop != "true" {
113113
return false
114114
}

0 commit comments

Comments
 (0)