diff --git a/ALLOF.md b/ALLOF.md index 449afdab..690e136f 100644 --- a/ALLOF.md +++ b/ALLOF.md @@ -23,7 +23,7 @@ In order to reduce such false-positives, oasdiff supports the ability to replace oasdiff breaking data/allof/simple.yaml data/allof/revision.yaml --flatten-allof ``` In this case no breaking changes are reported, correctly. -The `--flatten-allof` flag is also supported with `diff`, `changelog`, `delta` and `summary`. +The `--flatten-allof` flag is also supported with `diff`, `changelog` and `summary`. In order to see how oasdiff merges allOf, you can use the dedicated `flatten` command: ``` diff --git a/DELTA.md b/DELTA.md deleted file mode 100644 index eccf6005..00000000 --- a/DELTA.md +++ /dev/null @@ -1,50 +0,0 @@ -## 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. -For example: -``` -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. -The distance between any spec to itself is 0: -``` -oasdiff delta spec.yaml spec.yaml -``` - -### The distance between disjoint specs is 1 -The maximum distance, 1, respresnts the distance between specifications with no common endpoints. -The distance between a spec with no endpoints and another spec with one or more endpoints is 1: -``` -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. -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 -``` - -### 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. -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 -``` - -### Feature status [Beta] -Delta currently considers: -- Endpoints (path+method) - - Parameters - - Schema - - Type - - Responses - -Other elementes of OpenAPI spec are ignored. -Please submit feature requests. - diff --git a/README.md b/README.md index 0c3ca12a..23bb573d 100644 --- a/README.md +++ b/README.md @@ -38,7 +38,6 @@ docker run --rm -t tufin/oasdiff changelog https://raw.githubusercontent.com/Tuf - [Excluding endpoints](#excluding-specific-endpoints) - [Extending breaking changes with custom checks](CUSTOMIZING-CHECKS.md) - Localization: display breaking changes and changelog messages in English or Russian ([please contribute support for your language](https://github.com/Tufin/oasdiff/issues/383)) -- [Measure a numeric distance between a pair of specifications](DELTA.md) ## Install with Go diff --git a/delta/delta.go b/delta/delta.go deleted file mode 100644 index b6d2d3b9..00000000 --- a/delta/delta.go +++ /dev/null @@ -1,39 +0,0 @@ -package delta - -import ( - "github.com/tufin/oasdiff/diff" -) - -const coefficient = 0.5 - -// Get returns a numeric value between 0 and 1 representing the distance between base and revision specs -func Get(asymmetric bool, diffReport *diff.Diff) float64 { - if diffReport.Empty() { - return 0 - } - - return getEndpointsDelta(asymmetric, diffReport.EndpointsDiff) -} - -func ratio(asymmetric bool, added int, deleted int, modifiedDelta float64, all int) float64 { - if asymmetric { - added = 0 - } - - return (float64(added+deleted) + modifiedDelta) / float64(all) -} - -func modifiedLeafDelta(asymmetric bool, modified float64) float64 { - if asymmetric { - return modified / 2 - } - - return modified -} - -func boolToFloat64(b bool) float64 { - if b { - return 1.0 - } - return 0.0 -} diff --git a/delta/delta_test.go b/delta/delta_test.go deleted file mode 100644 index a7b897f5..00000000 --- a/delta/delta_test.go +++ /dev/null @@ -1,230 +0,0 @@ -package delta_test - -import ( - "testing" - - "github.com/getkin/kin-openapi/openapi3" - "github.com/stretchr/testify/require" - "github.com/tufin/oasdiff/delta" - "github.com/tufin/oasdiff/diff" - "github.com/tufin/oasdiff/utils" -) - -func TestEmpty(t *testing.T) { - d := &diff.Diff{} - require.Equal(t, 0.0, delta.Get(false, d)) -} - -func TestEndpointAdded(t *testing.T) { - d := &diff.Diff{ - EndpointsDiff: &diff.EndpointsDiff{ - Added: diff.Endpoints{ - diff.Endpoint{ - Method: "GET", - Path: "/test", - }, - }, - Unchanged: diff.Endpoints{ - diff.Endpoint{ - Method: "POST", - Path: "/test", - }, - }, - }, - } - - require.Equal(t, 0.5, delta.Get(false, d)) - require.Equal(t, 0.0, delta.Get(true, d)) -} - -func TestEndpointDeleted(t *testing.T) { - d := &diff.Diff{ - EndpointsDiff: &diff.EndpointsDiff{ - Deleted: diff.Endpoints{ - diff.Endpoint{ - Method: "GET", - Path: "/test", - }, - }, - Unchanged: diff.Endpoints{ - diff.Endpoint{ - Method: "POST", - Path: "/test", - }, - }, - }, - } - - require.Equal(t, 0.5, delta.Get(false, d)) - require.Equal(t, 0.5, delta.Get(true, d)) -} - -func TestEndpointAddedAndDeleted(t *testing.T) { - d := &diff.Diff{ - EndpointsDiff: &diff.EndpointsDiff{ - Added: diff.Endpoints{ - diff.Endpoint{ - Method: "GET", - Path: "/test", - }, - }, - Deleted: diff.Endpoints{ - diff.Endpoint{ - Method: "POST", - Path: "/test", - }, - }, - }, - } - - require.Equal(t, 1.0, delta.Get(false, d)) - require.Equal(t, 0.5, delta.Get(true, d)) -} - -func TestParameters(t *testing.T) { - d := &diff.Diff{ - EndpointsDiff: &diff.EndpointsDiff{ - Modified: diff.ModifiedEndpoints{ - diff.Endpoint{ - Method: "GET", - Path: "/test", - }: &diff.MethodDiff{ - ParametersDiff: &diff.ParametersDiffByLocation{ - Deleted: diff.ParamNamesByLocation{ - "query": utils.StringList{"a"}, - }, - }, - }, - }, - }, - } - - require.Equal(t, 0.5, delta.Get(false, d)) - require.Equal(t, 0.5, delta.Get(true, d)) -} - -func TestResponses_AddedAndDeleted(t *testing.T) { - d := &diff.Diff{ - EndpointsDiff: &diff.EndpointsDiff{ - Modified: diff.ModifiedEndpoints{ - diff.Endpoint{ - Method: "GET", - Path: "/test", - }: &diff.MethodDiff{ - ResponsesDiff: &diff.ResponsesDiff{ - Added: utils.StringList{"201"}, - Deleted: utils.StringList{"200"}, - }, - }, - }, - }, - } - - require.Equal(t, 0.5, delta.Get(false, d)) - require.Equal(t, 0.25, delta.Get(true, d)) -} - -func TestResponses_Modified(t *testing.T) { - d := &diff.Diff{ - EndpointsDiff: &diff.EndpointsDiff{ - Modified: diff.ModifiedEndpoints{ - diff.Endpoint{ - Method: "GET", - Path: "/test", - }: &diff.MethodDiff{ - ResponsesDiff: &diff.ResponsesDiff{ - Modified: diff.ModifiedResponses{ - "200": &diff.ResponseDiff{ - ContentDiff: &diff.ContentDiff{ - MediaTypeAdded: utils.StringList{"json"}, - }, - }, - }, - }, - }, - }, - }, - } - - require.Equal(t, 0.25, delta.Get(false, d)) - require.Equal(t, 0.125, delta.Get(true, d)) -} - -func TestSchema(t *testing.T) { - d := &diff.Diff{ - EndpointsDiff: &diff.EndpointsDiff{ - Modified: diff.ModifiedEndpoints{ - diff.Endpoint{ - Method: "GET", - Path: "/test", - }: &diff.MethodDiff{ - ParametersDiff: &diff.ParametersDiffByLocation{ - Modified: diff.ParamDiffByLocation{ - "query": diff.ParamDiffs{ - "a": &diff.ParameterDiff{ - SchemaDiff: &diff.SchemaDiff{ - TypeDiff: &diff.ValueDiff{ - From: "integer", - To: "string", - }, - }, - }, - }, - }, - }, - }, - }, - }, - } - - require.Equal(t, 0.25, delta.Get(false, d)) - require.Equal(t, 0.125, delta.Get(true, d)) -} - -func TestSymmetric(t *testing.T) { - specs := utils.StringList{"../data/simple.yaml", "../data/simple1.yaml", "../data/simple2.yaml", "../data/simple3.yaml", "../data/simple4.yaml", "../data/simple5.yaml"} - specPairs := specs.CartesianProduct(specs) - - loader := openapi3.NewLoader() - for _, pair := range specPairs { - s1, err := loader.LoadFromFile(pair.X) - require.NoError(t, err) - - s2, err := loader.LoadFromFile(pair.Y) - require.NoError(t, err) - - d1, err := diff.Get(diff.NewConfig(), s1, s2) - require.NoError(t, err) - - d2, err := diff.Get(diff.NewConfig(), s2, s1) - require.NoError(t, err) - - require.Equal(t, delta.Get(false, d1), delta.Get(false, d2), pair) - } -} - -func TestAsymmetric(t *testing.T) { - specs := utils.StringList{"../data/simple.yaml", "../data/simple1.yaml", "../data/simple2.yaml", "../data/simple3.yaml", "../data/simple4.yaml", "../data/simple5.yaml"} - specPairs := specs.CartesianProduct(specs) - - loader := openapi3.NewLoader() - for _, pair := range specPairs { - s1, err := loader.LoadFromFile(pair.X) - require.NoError(t, err) - - s2, err := loader.LoadFromFile(pair.Y) - require.NoError(t, err) - - d1, err := diff.Get(diff.NewConfig(), s1, s2) - require.NoError(t, err) - asymmetric1 := delta.Get(true, d1) - - d2, err := diff.Get(diff.NewConfig(), s2, s1) - require.NoError(t, err) - asymmetric2 := delta.Get(true, d2) - - symmetric := delta.Get(false, d2) - - require.Equal(t, asymmetric1+asymmetric2, symmetric, pair) - } -} diff --git a/delta/doc.go b/delta/doc.go deleted file mode 100644 index f157c60e..00000000 --- a/delta/doc.go +++ /dev/null @@ -1,16 +0,0 @@ -/* -Package delta provides a distance function for OpenAPI Spec 3. -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 that are missing in base and were added in revision. -For any two specs, a and b: Delta(a, b) + Delta(b, a) = 1 -*/ -package delta diff --git a/delta/endpoints.go b/delta/endpoints.go deleted file mode 100644 index 15eeb5a6..00000000 --- a/delta/endpoints.go +++ /dev/null @@ -1,43 +0,0 @@ -package delta - -import ( - "github.com/tufin/oasdiff/diff" -) - -func getEndpointsDelta(asymmetric bool, d *diff.EndpointsDiff) float64 { - if d.Empty() { - return 0 - } - - added := len(d.Added) - deleted := len(d.Deleted) - modified := len(d.Modified) - unchanged := len(d.Unchanged) - all := added + deleted + modified + unchanged - - modifiedDelta := coefficient * getModifiedEndpointsDelta(asymmetric, d.Modified) - - return ratio(asymmetric, added, deleted, modifiedDelta, all) -} - -func getModifiedEndpointsDelta(asymmetric bool, d diff.ModifiedEndpoints) float64 { - weightedDeltas := make([]*WeightedDelta, len(d)) - i := 0 - for _, methodDiff := range d { - weightedDeltas[i] = NewWeightedDelta(getModifiedEndpointDelta(asymmetric, methodDiff), 1) - i++ - } - return weightedAverage(weightedDeltas) -} - -func getModifiedEndpointDelta(asymmetric bool, d *diff.MethodDiff) float64 { - if d.Empty() { - return 0 - } - - // TODO: consider additional elements of MethodDiff - paramsDelta := getParametersDelta(asymmetric, d.ParametersDiff) - responsesDelta := getResponsesDelta(asymmetric, d.ResponsesDiff) - - return weightedAverage([]*WeightedDelta{paramsDelta, responsesDelta}) -} diff --git a/delta/parameters.go b/delta/parameters.go deleted file mode 100644 index f4f6b6cc..00000000 --- a/delta/parameters.go +++ /dev/null @@ -1,47 +0,0 @@ -package delta - -import ( - "github.com/tufin/oasdiff/diff" -) - -func getParametersDelta(asymmetric bool, d *diff.ParametersDiffByLocation) *WeightedDelta { - if d.Empty() { - return &WeightedDelta{} - } - - added := d.Added.Len() - deleted := d.Deleted.Len() - modified := d.Modified.Len() - unchanged := d.Unchanged.Len() - all := added + deleted + modified + unchanged - - modifiedDelta := coefficient * getModifiedParametersDelta(asymmetric, d.Modified) - - return NewWeightedDelta( - ratio(asymmetric, added, deleted, modifiedDelta, all), - all, - ) -} - -func getModifiedParametersDelta(asymmetric bool, d diff.ParamDiffByLocation) float64 { - weightedDeltas := make([]*WeightedDelta, d.Len()) - i := 0 - for _, paramsDiff := range d { - for _, parameterDiff := range paramsDiff { - weightedDeltas[i] = NewWeightedDelta(getModifiedParameterDelta(asymmetric, parameterDiff), 1) - i++ - } - } - return weightedAverage(weightedDeltas) -} - -func getModifiedParameterDelta(asymmetric bool, d *diff.ParameterDiff) float64 { - if d.Empty() { - return 0.0 - } - - // TODO: consider additional elements of ParameterDiff - schemaDelta := getSchemaDelta(asymmetric, d.SchemaDiff) - - return schemaDelta -} diff --git a/delta/responses.go b/delta/responses.go deleted file mode 100644 index 7c068818..00000000 --- a/delta/responses.go +++ /dev/null @@ -1,22 +0,0 @@ -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 * modifiedLeafDelta(asymmetric, float64(modified)) - - return NewWeightedDelta(ratio(asymmetric, added, deleted, modifiedDelta, all), all) -} diff --git a/delta/schema.go b/delta/schema.go deleted file mode 100644 index 0f57fa75..00000000 --- a/delta/schema.go +++ /dev/null @@ -1,16 +0,0 @@ -package delta - -import ( - "github.com/tufin/oasdiff/diff" -) - -func getSchemaDelta(asymmetric bool, d *diff.SchemaDiff) float64 { - if d.Empty() { - return 0 - } - - // consider additional fields of schema - typeDelta := modifiedLeafDelta(asymmetric, boolToFloat64(!d.TypeDiff.Empty())) - - return typeDelta -} diff --git a/delta/weighted_delta.go b/delta/weighted_delta.go deleted file mode 100644 index fff024c2..00000000 --- a/delta/weighted_delta.go +++ /dev/null @@ -1,26 +0,0 @@ -package delta - -type WeightedDelta struct { - delta float64 - weight int -} - -func NewWeightedDelta(delta float64, weight int) *WeightedDelta { - return &WeightedDelta{ - delta: delta, - weight: weight, - } -} - -func weightedAverage(weightedDeltas []*WeightedDelta) float64 { - dividend := 0.0 - divisor := 0 - for _, weightedDelta := range weightedDeltas { - dividend += weightedDelta.delta * float64(weightedDelta.weight) - divisor += weightedDelta.weight - } - if dividend == 0 { - return 0 - } - return dividend / float64(divisor) -} diff --git a/diff/diff_test.go b/diff/diff_test.go index b61ae47b..145f1d93 100644 --- a/diff/diff_test.go +++ b/diff/diff_test.go @@ -85,10 +85,9 @@ func TestDiff_ModifiedOperation(t *testing.T) { require.NoError(t, err) require.Equal(t, &diff.OperationsDiff{ - Added: utils.StringList{"GET"}, - Deleted: utils.StringList{"POST"}, - Modified: diff.ModifiedOperations{}, - Unchanged: utils.StringList{}, + Added: utils.StringList{"GET"}, + Deleted: utils.StringList{"POST"}, + Modified: diff.ModifiedOperations{}, }, d.PathsDiff.Modified["/api/test"].OperationsDiff) } diff --git a/diff/endpoints_diff.go b/diff/endpoints_diff.go index aaccbfdb..83707f4f 100644 --- a/diff/endpoints_diff.go +++ b/diff/endpoints_diff.go @@ -13,10 +13,9 @@ For example, if there's a new path "/test" with method POST then EndpointsDiff w Or, if path "/test" was modified to include a new methdod, PUT, then EndpointsDiff will describe this as a new endpoint: PUT /test. */ type EndpointsDiff struct { - Added Endpoints `json:"added,omitempty" yaml:"added,omitempty"` - Deleted Endpoints `json:"deleted,omitempty" yaml:"deleted,omitempty"` - Modified ModifiedEndpoints `json:"modified,omitempty" yaml:"modified,omitempty"` - Unchanged Endpoints `json:"unchanged,omitempty" yaml:"unchanged,omitempty"` + Added Endpoints `json:"added,omitempty" yaml:"added,omitempty"` + Deleted Endpoints `json:"deleted,omitempty" yaml:"deleted,omitempty"` + Modified ModifiedEndpoints `json:"modified,omitempty" yaml:"modified,omitempty"` } // Endpoint is a combination of an HTTP method and a Path @@ -38,10 +37,9 @@ func (diff *EndpointsDiff) Empty() bool { func newEndpointsDiff() *EndpointsDiff { return &EndpointsDiff{ - Added: Endpoints{}, - Deleted: Endpoints{}, - Modified: ModifiedEndpoints{}, - Unchanged: Endpoints{}, + Added: Endpoints{}, + Deleted: Endpoints{}, + Modified: ModifiedEndpoints{}, } } @@ -111,13 +109,6 @@ func (diff *EndpointsDiff) addDeletedPath(path string, method string) { }) } -func (diff *EndpointsDiff) addUnchangedPath(path string, method string) { - diff.Unchanged = append(diff.Unchanged, Endpoint{ - Method: method, - Path: path, - }) -} - func (diff *EndpointsDiff) addModifiedPaths(config *Config, state *state, path string, pathItemPair *pathItemPair) error { pathDiff, err := getPathDiff(config, state, pathItemPair) @@ -144,10 +135,6 @@ func (diff *EndpointsDiff) addModifiedPaths(config *Config, state *state, path s }] = methodDiff } - for _, method := range pathDiff.OperationsDiff.Unchanged { - diff.addUnchangedPath(path, method) - } - return nil } diff --git a/diff/operations_diff.go b/diff/operations_diff.go index e053c89c..7cc323b8 100644 --- a/diff/operations_diff.go +++ b/diff/operations_diff.go @@ -11,10 +11,9 @@ import ( // OperationsDiff describes the changes between a pair of operation objects (https://swagger.io/specification/#operation-object) of two path item objects type OperationsDiff struct { - Added utils.StringList `json:"added,omitempty" yaml:"added,omitempty"` - Deleted utils.StringList `json:"deleted,omitempty" yaml:"deleted,omitempty"` - Modified ModifiedOperations `json:"modified,omitempty" yaml:"modified,omitempty"` - Unchanged utils.StringList `json:"unchanged,omitempty" yaml:"unchanged,omitempty"` + Added utils.StringList `json:"added,omitempty" yaml:"added,omitempty"` + Deleted utils.StringList `json:"deleted,omitempty" yaml:"deleted,omitempty"` + Modified ModifiedOperations `json:"modified,omitempty" yaml:"modified,omitempty"` } // Empty indicates whether a change was found in this element @@ -30,10 +29,9 @@ func (operationsDiff *OperationsDiff) Empty() bool { func newOperationsDiff() *OperationsDiff { return &OperationsDiff{ - Added: utils.StringList{}, - Deleted: utils.StringList{}, - Modified: ModifiedOperations{}, - Unchanged: utils.StringList{}, + Added: utils.StringList{}, + Deleted: utils.StringList{}, + Modified: ModifiedOperations{}, } } @@ -107,8 +105,6 @@ func (operationsDiff *OperationsDiff) diffOperation(config *Config, state *state if !diff.Empty() { operationsDiff.Modified[method] = diff - } else { - operationsDiff.Unchanged = append(operationsDiff.Unchanged, method) } return nil diff --git a/diff/parameters_diff_by_location.go b/diff/parameters_diff_by_location.go index 55ee44e1..151f9370 100644 --- a/diff/parameters_diff_by_location.go +++ b/diff/parameters_diff_by_location.go @@ -9,10 +9,9 @@ import ( // ParametersDiffByLocation describes the changes, grouped by param location, between a pair of lists of parameter objects: https://swagger.io/specification/#parameter-object type ParametersDiffByLocation struct { - Added ParamNamesByLocation `json:"added,omitempty" yaml:"added,omitempty"` - Deleted ParamNamesByLocation `json:"deleted,omitempty" yaml:"deleted,omitempty"` - Modified ParamDiffByLocation `json:"modified,omitempty" yaml:"modified,omitempty"` - Unchanged ParamNamesByLocation `json:"unchanged,omitempty" yaml:"unchanged,omitempty"` + Added ParamNamesByLocation `json:"added,omitempty" yaml:"added,omitempty"` + Deleted ParamNamesByLocation `json:"deleted,omitempty" yaml:"deleted,omitempty"` + Modified ParamDiffByLocation `json:"modified,omitempty" yaml:"modified,omitempty"` } // Empty indicates whether a change was found in this element @@ -55,10 +54,9 @@ func lenNested[T utils.StringList | ParamDiffs](mapOfList map[string]T) int { func newParametersDiffByLocation() *ParametersDiffByLocation { return &ParametersDiffByLocation{ - Added: ParamNamesByLocation{}, - Deleted: ParamNamesByLocation{}, - Modified: ParamDiffByLocation{}, - Unchanged: ParamNamesByLocation{}, + Added: ParamNamesByLocation{}, + Deleted: ParamNamesByLocation{}, + Modified: ParamDiffByLocation{}, } } @@ -92,15 +90,6 @@ func (diff *ParametersDiffByLocation) addModifiedParam(param *openapi3.Parameter } } -func (diff *ParametersDiffByLocation) addUnchangedParam(param *openapi3.Parameter) { - - if paramNames, ok := diff.Unchanged[param.In]; ok { - diff.Unchanged[param.In] = append(paramNames, param.Name) - } else { - diff.Unchanged[param.In] = utils.StringList{param.Name} - } -} - func getParametersDiffByLocation(config *Config, state *state, params1, params2 openapi3.Parameters, pathParamsMap PathParamsMap) (*ParametersDiffByLocation, error) { diff, err := getParametersDiffByLocationInternal(config, state, params1, params2, pathParamsMap) if err != nil { @@ -135,9 +124,7 @@ func getParametersDiffByLocationInternal(config *Config, state *state, params1, return nil, err } - if diff.Empty() { - result.addUnchangedParam(param1) - } else { + if !diff.Empty() { result.addModifiedParam(param1, diff) } } else { diff --git a/diff/responses_diff.go b/diff/responses_diff.go index 4d6a678d..9bf35c1c 100644 --- a/diff/responses_diff.go +++ b/diff/responses_diff.go @@ -9,10 +9,9 @@ import ( // ResponsesDiff describes the changes between a pair of sets of response objects: https://swagger.io/specification/#responses-object type ResponsesDiff struct { - Added utils.StringList `json:"added,omitempty" yaml:"added,omitempty"` - Deleted utils.StringList `json:"deleted,omitempty" yaml:"deleted,omitempty"` - Modified ModifiedResponses `json:"modified,omitempty" yaml:"modified,omitempty"` - Unchanged utils.StringList `json:"unchanged,omitempty" yaml:"unchanged,omitempty"` + Added utils.StringList `json:"added,omitempty" yaml:"added,omitempty"` + Deleted utils.StringList `json:"deleted,omitempty" yaml:"deleted,omitempty"` + Modified ModifiedResponses `json:"modified,omitempty" yaml:"modified,omitempty"` } // Empty indicates whether a change was found in this element @@ -31,10 +30,9 @@ type ModifiedResponses map[string]*ResponseDiff func newResponsesDiff() *ResponsesDiff { return &ResponsesDiff{ - Added: utils.StringList{}, - Deleted: utils.StringList{}, - Modified: ModifiedResponses{}, - Unchanged: utils.StringList{}, + Added: utils.StringList{}, + Deleted: utils.StringList{}, + Modified: ModifiedResponses{}, } } @@ -75,9 +73,7 @@ func getResponsesDiffInternal(config *Config, state *state, responses1, response if err != nil { return nil, err } - if diff.Empty() { - result.Unchanged = append(result.Unchanged, responseValue1) - } else { + if !diff.Empty() { result.Modified[responseValue1] = diff } } else { diff --git a/internal/delta.go b/internal/delta.go deleted file mode 100644 index 9e980bef..00000000 --- a/internal/delta.go +++ /dev/null @@ -1,42 +0,0 @@ -package internal - -import ( - "fmt" - "io" - - "github.com/getkin/kin-openapi/openapi3" - "github.com/spf13/cobra" - "github.com/tufin/oasdiff/delta" -) - -func getDeltaCmd() *cobra.Command { - - flags := DeltaFlags{} - - cmd := cobra.Command{ - Use: "delta base revision [flags]", - Short: "Calculate the delta value", - Long: `Calculate a numeric value representing the delta between base and revision specs.` + specHelp, - Args: getParseArgs(&flags), - RunE: getRun(&flags, runDelta), - } - - addCommonDiffFlags(&cmd, &flags) - cmd.PersistentFlags().BoolVarP(&flags.asymmetric, "asymmetric", "", false, "perform asymmetric diff (only elements of base that are missing in revision)") - - return &cmd -} - -func runDelta(flags Flags, stdout io.Writer) (bool, *ReturnError) { - - openapi3.CircularReferenceCounter = flags.getCircularReferenceCounter() - - diffResult, err := calcDiff(flags) - if err != nil { - return false, err - } - - _, _ = fmt.Fprintf(stdout, "%g\n", delta.Get(flags.getAsymmetric(), diffResult.diffReport)) - - return false, nil -} diff --git a/internal/delta_flags.go b/internal/delta_flags.go deleted file mode 100644 index f04d32e7..00000000 --- a/internal/delta_flags.go +++ /dev/null @@ -1,62 +0,0 @@ -package internal - -type DeltaFlags struct { - DiffFlags - asymmetric bool -} - -func (flags *DeltaFlags) getAsymmetric() bool { - return flags.asymmetric -} - -func (flags *DeltaFlags) refComposed() *bool { - return &flags.composed -} - -func (flags *DeltaFlags) refExcludeElements() *[]string { - return &flags.excludeElements -} - -func (flags *DeltaFlags) refMatchPath() *string { - return &flags.matchPath -} - -func (flags *DeltaFlags) refFilterExtension() *string { - return &flags.filterExtension -} - -func (flags *DeltaFlags) refCircularReferenceCounter() *int { - return &flags.circularReferenceCounter -} - -func (flags *DeltaFlags) refPrefixBase() *string { - return &flags.prefixBase -} - -func (flags *DeltaFlags) refPrefixRevision() *string { - return &flags.prefixRevision -} - -func (flags *DeltaFlags) refStripPrefixBase() *string { - return &flags.stripPrefixBase -} - -func (flags *DeltaFlags) refStripPrefixRevision() *string { - return &flags.stripPrefixRevision -} - -func (flags *DeltaFlags) refIncludePathParams() *bool { - return &flags.includePathParams -} - -func (flags *DeltaFlags) refFlattenAllOf() *bool { - return &flags.flattenAllOf -} - -func (flags *DeltaFlags) refFlattenParams() *bool { - return &flags.flattenParams -} - -func (flags *DeltaFlags) refInsensitiveHeaders() *bool { - return &flags.insensitiveHeaders -} diff --git a/internal/run.go b/internal/run.go index 17e12e9e..0dd35f26 100644 --- a/internal/run.go +++ b/internal/run.go @@ -40,7 +40,6 @@ func Run(args []string, stdout io.Writer, stderr io.Writer) int { getFlattenCmd(), getChecksCmd(), getQRCodeCmd(), - getDeltaCmd(), ) return run(rootCmd) diff --git a/internal/run_test.go b/internal/run_test.go index 6a21905c..fd6c4a4d 100644 --- a/internal/run_test.go +++ b/internal/run_test.go @@ -301,7 +301,3 @@ func Test_ColorWithNonTextFormat(t *testing.T) { require.Equal(t, 100, internal.Run(cmdToArgs("oasdiff changelog ../data/allof/simple.yaml ../data/allof/revision.yaml -f yaml --color always"), io.Discard, &stderr)) require.Equal(t, "Error: --color flag is only relevant with 'text' or 'singleline' formats\n", stderr.String()) } - -func Test_Delta(t *testing.T) { - require.Zero(t, internal.Run(cmdToArgs("oasdiff delta ../data/simple1.yaml ../data/simple2.yaml"), io.Discard, io.Discard)) -}