Skip to content

Commit b69e8a1

Browse files
committed
Simplify
1 parent 5c1b255 commit b69e8a1

File tree

2 files changed

+20
-32
lines changed

2 files changed

+20
-32
lines changed

tools/cli/internal/openapi/oasdiff.go

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -118,7 +118,7 @@ func (o OasDiff) mergePaths() error {
118118
if originalPath := basePaths.Value(externalPath); originalPath == nil {
119119
basePaths.Set(externalPath, removeExternalRefs(externalPathData))
120120
} else {
121-
if shouldSkipPathConflict(originalPath, externalPathData, externalPath) {
121+
if o.shouldSkipPathConflict(originalPath, externalPath) {
122122
log.Printf("Skipping conflict for path: %s", externalPath)
123123
if o.arePathsIdenticalWithExcludeExtensions(externalPath) {
124124
log.Printf("No doc diff detected for path %s, merging the paths", externalPath)
@@ -172,6 +172,25 @@ func removeExternalRefs(path *openapi3.PathItem) *openapi3.PathItem {
172172
return path
173173
}
174174

175+
// shouldSkipConflict checks if the conflict should be skipped.
176+
// The method goes through each path operation and performs the following checks:
177+
// 1. Validates if both paths have same operations, if not, then it returns false.
178+
// 2. If both paths have the same operations, then it checks if there is an x-xgen-soa-migration annotation.
179+
// If there is no annotation, then it returns false.
180+
func (o OasDiff) shouldSkipPathConflict(basePath *openapi3.PathItem, basePathName string) bool {
181+
if ok := o.specDiff.PathsDiff.Modified[basePathName].OperationsDiff.Added; !ok.Empty() {
182+
return false
183+
}
184+
185+
if ok := o.specDiff.PathsDiff.Modified[basePathName].OperationsDiff.Deleted; !ok.Empty() {
186+
return false
187+
}
188+
189+
// now check if there is an x-xgen-soa-migration annotation in any of the operations, but if any of the operations
190+
// doesn't have, then we should not skip the conflict
191+
return allOperationsHaveExtension(basePath, basePathName, xgenSoaMigration)
192+
}
193+
175194
// updateExternalRefResponses updates the external references of OASes to remove the reference to openapi-mms.json
176195
// in the Responses.
177196
// A Response can have an external ref in Response.Ref or in its content (Response.Content.Schema.Ref)

tools/cli/internal/openapi/paths.go

Lines changed: 0 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -24,37 +24,6 @@ const (
2424
xgenSoaMigration = "x-xgen-soa-migration"
2525
)
2626

27-
// shouldSkipConflict checks if the conflict should be skipped.
28-
// The method goes through each path operation and performs the following checks:
29-
// 1. Validates if both paths have same operations, if not, then it returns false.
30-
// 2. If both paths have the same operations, then it checks if there is an x-xgen-soa-migration annotation.
31-
// If there is no annotation, then it returns false.
32-
func shouldSkipPathConflict(basePath, externalPath *openapi3.PathItem, basePathName string) bool {
33-
if basePath.Get != nil && externalPath.Get == nil || basePath.Get == nil && externalPath.Get != nil {
34-
return false
35-
}
36-
37-
if basePath.Put != nil && externalPath.Put == nil || basePath.Put == nil && externalPath.Put != nil {
38-
return false
39-
}
40-
41-
if basePath.Post != nil && externalPath.Post == nil || basePath.Post == nil && externalPath.Post != nil {
42-
return false
43-
}
44-
45-
if basePath.Patch != nil && externalPath.Patch == nil || basePath.Patch == nil && externalPath.Patch != nil {
46-
return false
47-
}
48-
49-
if basePath.Delete != nil && externalPath.Delete == nil || basePath.Delete == nil && externalPath.Delete != nil {
50-
return false
51-
}
52-
53-
// now check if there is an x-xgen-soa-migration annotation in any of the operations, but if any of the operations
54-
// doesn't have, then we should not skip the conflict
55-
return allOperationsHaveExtension(basePath, basePathName, xgenSoaMigration)
56-
}
57-
5827
// allMethodsHaveExtension checks if all the operations in the base pat have the given extension name.
5928
func allOperationsHaveExtension(basePath *openapi3.PathItem, basePathName, extensionName string) bool {
6029
if basePath.Get != nil {

0 commit comments

Comments
 (0)