From 103f5d22445973e5b299aecc5404e6ffc9824cb1 Mon Sep 17 00:00:00 2001 From: Reuven Date: Tue, 30 Jan 2024 17:02:53 +0200 Subject: [PATCH] documentation --- DELTA.md | 49 +++++++++++++++++++++++++++++++++++++++++++++++++ README.md | 1 + delta/delta.go | 1 + delta/doc.go | 2 +- 4 files changed, 52 insertions(+), 1 deletion(-) create mode 100644 DELTA.md diff --git a/DELTA.md b/DELTA.md new file mode 100644 index 00000000..cfb036cd --- /dev/null +++ b/DELTA.md @@ -0,0 +1,49 @@ +## Delta - a distance function for OpenAPI Spec 3 +Delta calculates a numeric value between 0 and 1 representing the distance between base and revision specs: +``` +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: +``` +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. +For example, 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. +For example, these two commands return the same distance: +``` +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. +The sum of the following distances is always 1: +``` +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 an issue for issues and feature requests. + diff --git a/README.md b/README.md index d883c9a7..f07de405 100644 --- a/README.md +++ b/README.md @@ -36,6 +36,7 @@ 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 index fa32f6dc..b6d2d3b9 100644 --- a/delta/delta.go +++ b/delta/delta.go @@ -6,6 +6,7 @@ import ( 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 diff --git a/delta/doc.go b/delta/doc.go index 2c157ea6..f157c60e 100644 --- a/delta/doc.go +++ b/delta/doc.go @@ -10,7 +10,7 @@ Delta considers both elements of base that are deleted in revision and elements 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. +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