From 5f540f2c6d1b44640850de1034637106c4564e3e Mon Sep 17 00:00:00 2001 From: Reuven Harrison Date: Mon, 26 Feb 2024 12:40:40 +0200 Subject: [PATCH] fix params len (#496) Co-authored-by: Reuven --- DELTA.md | 9 +++++---- delta/parameters.go | 2 +- 2 files changed, 6 insertions(+), 5 deletions(-) diff --git a/DELTA.md b/DELTA.md index 62d26dc8..8d9cae32 100644 --- a/DELTA.md +++ b/DELTA.md @@ -1,5 +1,6 @@ ## Delta - a distance function for OpenAPI Spec 3 [Beta] -Delta calculates a numeric value between 0 and 1 representing the distance between base and revision specs: +Delta calculates a numeric value between 0 and 1 representing the distance between base and revision specs. +For example: ``` oasdiff delta base.yaml revision.yaml ``` @@ -7,7 +8,7 @@ oasdiff delta base.yaml revision.yaml ### The distance between identical specs is 0 The minimum distance, 0, respresnts the distance between specifications with identical endpoints. -For example the distance between any spec to itself is 0: +For example, the distance between any spec to itself is 0: ``` oasdiff delta spec.yaml spec.yaml ``` @@ -22,7 +23,7 @@ oasdiff delta empty-spec.yaml non-empty-spec.yaml ### Symmetric mode By default, delta is symmetric and takes into account both elements of base that are deleted in revision and elements of base that are added in revision. -For example, these two commands return the same distance: +For example, the symmetric distance between any two specs is the same regardless of the order of the given specs: ``` oasdiff delta base.yaml revision.yaml oasdiff delta revision.yaml base.yaml @@ -30,7 +31,7 @@ oasdiff delta revision.yaml base.yaml ### Asymmetric mode It is also possible to calculate an asymmetric distance which takes into account elements of base that were deleted in revision but ignores elements that are missing in base and were added in revision. -The sum of the following distances is always 1: +For examples, for any two specs the sum of the asymmetric distances is their symmetric distance: ``` oasdiff delta base.yaml revision.yaml --asymmetric oasdiff delta revision.yaml base.yaml --asymmetric diff --git a/delta/parameters.go b/delta/parameters.go index e581b794..f4f6b6cc 100644 --- a/delta/parameters.go +++ b/delta/parameters.go @@ -24,7 +24,7 @@ func getParametersDelta(asymmetric bool, d *diff.ParametersDiffByLocation) *Weig } func getModifiedParametersDelta(asymmetric bool, d diff.ParamDiffByLocation) float64 { - weightedDeltas := make([]*WeightedDelta, len(d)) + weightedDeltas := make([]*WeightedDelta, d.Len()) i := 0 for _, paramsDiff := range d { for _, parameterDiff := range paramsDiff {