Skip to content

Commit

Permalink
Simplify
Browse files Browse the repository at this point in the history
  • Loading branch information
blva committed Oct 8, 2024
1 parent 9df5a39 commit ef3b6e6
Showing 1 changed file with 24 additions and 11 deletions.
35 changes: 24 additions & 11 deletions tools/cli/internal/openapi/oasdiff.go
Original file line number Diff line number Diff line change
Expand Up @@ -118,19 +118,12 @@ func (o OasDiff) mergePaths() error {
if originalPath := basePaths.Value(externalPath); originalPath == nil {
basePaths.Set(externalPath, removeExternalRefs(externalPathData))
} else {
if o.shouldSkipPathConflict(originalPath, externalPath) {
log.Printf("Skipping conflict for path: %s", externalPath)
if o.arePathsIdenticalWithExcludeExtensions(externalPath) {
log.Printf("No doc diff detected for path %s, merging the paths", externalPath)
basePaths.Set(externalPath, removeExternalRefs(externalPathData))
} else {
log.Printf("Doc diff detected failing as allowDocsDiff=true is not supported.")
}
err := o.handlePathConflict(originalPath, externalPath)
if err != nil {
return err
}

return errors.PathConflictError{
Entry: externalPath,
}
basePaths.Set(externalPath, removeExternalRefs(externalPathData))
}
}
o.base.Spec.Paths = basePaths
Expand Down Expand Up @@ -172,6 +165,26 @@ func removeExternalRefs(path *openapi3.PathItem) *openapi3.PathItem {
return path
}

// handlePathConflict handles the path conflict by checking if the conflict should be skipped or not.
func (o OasDiff) handlePathConflict(basePath *openapi3.PathItem, basePathName string) error {
if !o.shouldSkipPathConflict(basePath, basePathName) {
return errors.PathConflictError{
Entry: basePathName,
}
}

log.Printf("Skipping conflict for path: %s", basePathName)
if o.arePathsIdenticalWithExcludeExtensions(basePathName) {
log.Printf("No doc diff detected for path %s, merging the paths", basePathName)
return nil
}

log.Printf("Doc diff detected failing as allowDocsDiff=true is not supported.")
return errors.PathConflictError{
Entry: basePathName,
}
}

// shouldSkipConflict checks if the conflict should be skipped.
// The method goes through each path operation and performs the following checks:
// 1. Validates if both paths have same operations, if not, then it returns false.
Expand Down

0 comments on commit ef3b6e6

Please sign in to comment.