-
Notifications
You must be signed in to change notification settings - Fork 68
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Reuven
committed
Jan 22, 2024
1 parent
bc58315
commit 3f532a6
Showing
7 changed files
with
93 additions
and
18 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,16 @@ | ||
/* | ||
Package delta provides a distance function for OpenAPI Spec 3. | ||
The delta is a numeric value representing the distance between base and revision specs. | ||
The delta is a numeric value between 0 and 1 representing the distance between base and revision specs. | ||
For any spec, a: delta(a, a) = 0 | ||
For any two specs, a and b, with no common elements: delta(a, b) = 1 | ||
Symmetric mode: | ||
Delta considers both elements of base that are deleted in revision and elements of base that are added in revision. | ||
For any two specs, a and b: delta(a, b) = delta(b, a) | ||
Asymmetric mode: | ||
Delta only considers elements of base that are deleted in revision but not elements of base that are added in revision. | ||
For any two specs, a and b: Delta(a, b) + Delta(b, a) = 1 | ||
*/ | ||
package delta |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package delta | ||
|
||
import ( | ||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
func getResponsesDelta(asymmetric bool, d *diff.ResponsesDiff) WeightedDelta { | ||
if d.Empty() { | ||
return WeightedDelta{} | ||
} | ||
|
||
added := d.Added.Len() | ||
deleted := d.Deleted.Len() | ||
modified := len(d.Modified) | ||
unchanged := d.Unchanged.Len() | ||
all := added + deleted + modified + unchanged | ||
|
||
// TODO: drill down into modified | ||
modifiedDelta := coefficient * float64(modified) | ||
|
||
return WeightedDelta{ | ||
delta: ratio(asymmetric, added, deleted, modifiedDelta, all), | ||
weight: all, | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters