diff --git a/tools/cli/internal/openapi/oasdiff.go b/tools/cli/internal/openapi/oasdiff.go index a3ee835cc5..e63ef5b1f1 100644 --- a/tools/cli/internal/openapi/oasdiff.go +++ b/tools/cli/internal/openapi/oasdiff.go @@ -76,7 +76,7 @@ func (o OasDiff) mergePaths() error { if originalPathData := basePaths.Value(path); originalPathData == nil { basePaths.Set(path, removeExternalRefs(externalPathData)) } else { - if err := o.handlePathConflict(originalPathData, path); err != nil { + if err := o.handlePathConflict(externalPathData, path); err != nil { return err } basePaths.Set(path, removeExternalRefs(externalPathData)) diff --git a/tools/cli/internal/openapi/oasdiff_test.go b/tools/cli/internal/openapi/oasdiff_test.go index bf44ffa6bc..6c7d33796f 100644 --- a/tools/cli/internal/openapi/oasdiff_test.go +++ b/tools/cli/internal/openapi/oasdiff_test.go @@ -73,7 +73,7 @@ func TestOasDiff_mergePaths(t *testing.T) { wantErr: require.NoError, }, { - name: "SuccessfulMergeWithEmptyBasePaths", + name: "SuccessfulMergeWithEmptyexternalPaths", inputBase: &load.SpecInfo{ Url: "base", Spec: &openapi3.T{ @@ -1152,15 +1152,15 @@ func TestUpdateExternalRefReqBody(t *testing.T) { func TestHandlePathConflict(t *testing.T) { testCases := []struct { - name string - basePath *openapi3.PathItem - basePathName string - specDiff *diff.Diff - expectedError error + name string + externalPath *openapi3.PathItem + externalPathName string + specDiff *diff.Diff + expectedError error }{ { name: "No Conflict - Identical Paths", - basePath: &openapi3.PathItem{ + externalPath: &openapi3.PathItem{ Get: &openapi3.Operation{ Extensions: map[string]interface{}{ "x-xgen-soa-migration": map[string]interface{}{ @@ -1169,7 +1169,7 @@ func TestHandlePathConflict(t *testing.T) { }, }, }, - basePathName: "/test", + externalPathName: "/test", specDiff: &diff.Diff{ PathsDiff: &diff.PathsDiff{ Modified: map[string]*diff.PathDiff{}, @@ -1179,7 +1179,7 @@ func TestHandlePathConflict(t *testing.T) { }, { name: "Conflict with AllowDocsDiff", - basePath: &openapi3.PathItem{ + externalPath: &openapi3.PathItem{ Get: &openapi3.Operation{ Extensions: map[string]interface{}{ "x-xgen-soa-migration": map[string]interface{}{ @@ -1188,7 +1188,7 @@ func TestHandlePathConflict(t *testing.T) { }, }, }, - basePathName: "/test", + externalPathName: "/test", specDiff: &diff.Diff{ PathsDiff: &diff.PathsDiff{ Modified: map[string]*diff.PathDiff{ @@ -1212,7 +1212,7 @@ func TestHandlePathConflict(t *testing.T) { }, { name: "Conflict with Different Operations", - basePath: &openapi3.PathItem{ + externalPath: &openapi3.PathItem{ Get: &openapi3.Operation{ Extensions: map[string]interface{}{ "x-xgen-soa-migration": map[string]interface{}{ @@ -1221,7 +1221,7 @@ func TestHandlePathConflict(t *testing.T) { }, }, }, - basePathName: "/test", + externalPathName: "/test", specDiff: &diff.Diff{ PathsDiff: &diff.PathsDiff{ Modified: map[string]*diff.PathDiff{ @@ -1240,7 +1240,7 @@ func TestHandlePathConflict(t *testing.T) { }, { name: "Conflict with Different Path Operation", - basePath: &openapi3.PathItem{ + externalPath: &openapi3.PathItem{ Get: &openapi3.Operation{ Extensions: map[string]interface{}{ "x-xgen-soa-migration": map[string]interface{}{ @@ -1249,7 +1249,7 @@ func TestHandlePathConflict(t *testing.T) { }, }, }, - basePathName: "/test", + externalPathName: "/test", specDiff: &diff.Diff{ PathsDiff: &diff.PathsDiff{ Modified: map[string]*diff.PathDiff{ @@ -1290,7 +1290,7 @@ func TestHandlePathConflict(t *testing.T) { }, { name: "Identical Paths with Extensions", - basePath: &openapi3.PathItem{ + externalPath: &openapi3.PathItem{ Get: &openapi3.Operation{ Extensions: map[string]interface{}{ "x-xgen-soa-migration": map[string]interface{}{ @@ -1299,7 +1299,7 @@ func TestHandlePathConflict(t *testing.T) { }, }, }, - basePathName: "/test", + externalPathName: "/test", specDiff: &diff.Diff{ PathsDiff: &diff.PathsDiff{ Modified: map[string]*diff.PathDiff{}, @@ -1342,7 +1342,7 @@ func TestHandlePathConflict(t *testing.T) { Return(tc.specDiff, nil). AnyTimes() - err := o.handlePathConflict(tc.basePath, tc.basePathName) + err := o.handlePathConflict(tc.externalPath, tc.externalPathName) if tc.expectedError != nil { require.Error(t, err) assert.IsType(t, tc.expectedError, err) diff --git a/tools/cli/internal/openapi/paths.go b/tools/cli/internal/openapi/paths.go index 486da12188..1dd60c4b9e 100644 --- a/tools/cli/internal/openapi/paths.go +++ b/tools/cli/internal/openapi/paths.go @@ -26,42 +26,42 @@ const ( ) // allOperationsHaveExtension checks if all the operations in the base path have the given extension name. -func allOperationsHaveExtension(basePath *openapi3.PathItem, basePathName, extensionName string) bool { - if basePath.Operations() == nil || len(basePath.Operations()) == 0 { +func allOperationsHaveExtension(pathData *openapi3.PathItem, path, extensionName string) bool { + if pathData.Operations() == nil || len(pathData.Operations()) == 0 { return false } - if basePath.Get != nil { - if result := getOperationExtensionWithName(basePath.Get, extensionName); result == nil { + if pathData.Get != nil { + if result := getOperationExtensionWithName(pathData.Get, extensionName); result == nil { return false } } - if basePath.Put != nil { - if result := getOperationExtensionWithName(basePath.Put, extensionName); result == nil { + if pathData.Put != nil { + if result := getOperationExtensionWithName(pathData.Put, extensionName); result == nil { return false } } - if basePath.Post != nil { - if result := getOperationExtensionWithName(basePath.Post, extensionName); result == nil { + if pathData.Post != nil { + if result := getOperationExtensionWithName(pathData.Post, extensionName); result == nil { return false } } - if basePath.Patch != nil { - if result := getOperationExtensionWithName(basePath.Patch, extensionName); result == nil { + if pathData.Patch != nil { + if result := getOperationExtensionWithName(pathData.Patch, extensionName); result == nil { return false } } - if basePath.Delete != nil { - if result := getOperationExtensionWithName(basePath.Delete, extensionName); result == nil { + if pathData.Delete != nil { + if result := getOperationExtensionWithName(pathData.Delete, extensionName); result == nil { return false } } - log.Printf("Detected %s annotation in all operations for path: %s\n", extensionName, basePathName) + log.Printf("Detected %s annotation in all operations for path: %s\n", extensionName, path) return true } @@ -74,41 +74,41 @@ func getOperationExtensionWithName(operation *openapi3.Operation, extensionName return operation.Extensions[extensionName] } -func allOperationsAllowDocsDiff(basePath *openapi3.PathItem) bool { - if basePath.Operations() == nil || len(basePath.Operations()) == 0 { +func allOperationsAllowDocsDiff(pathData *openapi3.PathItem) bool { + if pathData.Operations() == nil || len(pathData.Operations()) == 0 { return false } - if basePath.Get != nil { - prop := getOperationExtensionProperty(basePath.Get, xgenSoaMigration, allowDocsDiff) + if pathData.Get != nil { + prop := getOperationExtensionProperty(pathData.Get, xgenSoaMigration, allowDocsDiff) if prop != "true" { return false } } - if basePath.Put != nil { - prop := getOperationExtensionProperty(basePath.Put, xgenSoaMigration, allowDocsDiff) + if pathData.Put != nil { + prop := getOperationExtensionProperty(pathData.Put, xgenSoaMigration, allowDocsDiff) if prop != "true" { return false } } - if basePath.Post != nil { - prop := getOperationExtensionProperty(basePath.Post, xgenSoaMigration, allowDocsDiff) + if pathData.Post != nil { + prop := getOperationExtensionProperty(pathData.Post, xgenSoaMigration, allowDocsDiff) if prop != "true" { return false } } - if basePath.Patch != nil { - prop := getOperationExtensionProperty(basePath.Patch, xgenSoaMigration, allowDocsDiff) + if pathData.Patch != nil { + prop := getOperationExtensionProperty(pathData.Patch, xgenSoaMigration, allowDocsDiff) if prop != "true" { return false } } - if basePath.Delete != nil { - prop := getOperationExtensionProperty(basePath.Delete, xgenSoaMigration, allowDocsDiff) + if pathData.Delete != nil { + prop := getOperationExtensionProperty(pathData.Delete, xgenSoaMigration, allowDocsDiff) if prop != "true" { return false }