-
Notifications
You must be signed in to change notification settings - Fork 62
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
1 parent
d2e44ea
commit ca3ab5d
Showing
20 changed files
with
240 additions
and
25 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,76 @@ | ||
package checker_test | ||
|
||
import ( | ||
"testing" | ||
|
||
"github.com/stretchr/testify/require" | ||
"github.com/tufin/oasdiff/checker" | ||
"github.com/tufin/oasdiff/diff" | ||
) | ||
|
||
func TestBreaking_Attributes(t *testing.T) { | ||
s1, err := open("../data/attributes/base.yaml") | ||
require.NoError(t, err) | ||
|
||
s2, err := open("../data/attributes/revision.yaml") | ||
require.NoError(t, err) | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) | ||
require.NoError(t, err) | ||
errs := checker.CheckBackwardCompatibility(allChecksConfig().WithAttributes([]string{"x-test"}), d, osm) | ||
require.NotEmpty(t, errs) | ||
require.Len(t, errs, 2) | ||
|
||
require.Equal(t, map[string]any{"x-test": []any{"xyz", float64(456)}}, errs[0].GetAttributes()) | ||
require.Equal(t, map[string]any{"x-test": "abc"}, errs[1].GetAttributes()) | ||
} | ||
|
||
func TestBreaking_AttributesNone(t *testing.T) { | ||
s1, err := open("../data/attributes/base.yaml") | ||
require.NoError(t, err) | ||
|
||
s2, err := open("../data/attributes/revision.yaml") | ||
require.NoError(t, err) | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) | ||
require.NoError(t, err) | ||
errs := checker.CheckBackwardCompatibility(allChecksConfig().WithAttributes([]string{"x-other"}), d, osm) | ||
require.NotEmpty(t, errs) | ||
require.Len(t, errs, 2) | ||
|
||
require.Empty(t, errs[0].GetAttributes()) | ||
require.Empty(t, errs[1].GetAttributes()) | ||
} | ||
|
||
func TestBreaking_AttributesReverse(t *testing.T) { | ||
s1, err := open("../data/attributes/revision.yaml") | ||
require.NoError(t, err) | ||
|
||
s2, err := open("../data/attributes/base.yaml") | ||
require.NoError(t, err) | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) | ||
require.NoError(t, err) | ||
errs := checker.CheckBackwardCompatibility(allChecksConfig().WithAttributes([]string{"x-test"}), d, osm) | ||
require.NotEmpty(t, errs) | ||
require.Len(t, errs, 2) | ||
|
||
require.Equal(t, map[string]any{"x-test": []any{float64(123), float64(456)}}, errs[0].GetAttributes()) | ||
require.Equal(t, map[string]any{"x-test": float64(123)}, errs[1].GetAttributes()) | ||
} | ||
|
||
func TestBreaking_AttributesTwo(t *testing.T) { | ||
s1, err := open("../data/attributes/base.yaml") | ||
require.NoError(t, err) | ||
|
||
s2, err := open("../data/attributes/revision.yaml") | ||
require.NoError(t, err) | ||
|
||
d, osm, err := diff.GetWithOperationsSourcesMap(diff.NewConfig(), s1, s2) | ||
require.NoError(t, err) | ||
errs := checker.CheckBackwardCompatibility(allChecksConfig().WithAttributes([]string{"x-test", "x-test2"}), d, osm) | ||
require.Len(t, errs, 2) | ||
|
||
require.Equal(t, map[string]any{"x-test": []any{"xyz", float64(456)}}, errs[0].GetAttributes()) | ||
require.Equal(t, map[string]any{"x-test": "abc", "x-test2": "def"}, errs[1].GetAttributes()) | ||
} |
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
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,23 @@ | ||
openapi: 3.0.1 | ||
info: | ||
title: Test API | ||
version: v1 | ||
paths: | ||
/partner-api/test/some-method: | ||
get: | ||
x-test: 123 | ||
tags: | ||
- Test | ||
responses: | ||
"200": | ||
description: Success | ||
/partner-api/test/another-method: | ||
get: | ||
x-test: | ||
- 123 | ||
- 456 | ||
tags: | ||
- Test | ||
responses: | ||
"200": | ||
description: Success |
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,24 @@ | ||
openapi: 3.0.1 | ||
info: | ||
title: Test API | ||
version: v1 | ||
paths: | ||
/partner-api/test/some-method: | ||
get: | ||
x-test: "abc" | ||
x-test2: "def" | ||
tags: | ||
- Test | ||
responses: | ||
"201": | ||
description: Success | ||
/partner-api/test/another-method: | ||
get: | ||
x-test: | ||
- "xyz" | ||
- 456 | ||
tags: | ||
- Test | ||
responses: | ||
"201": | ||
description: Success |
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,29 @@ | ||
## Adding custom attributes to changelog entries basing on OpenAPI extension tags | ||
Some people annotate their endpoints with OpenAPI Extension tags, for example: | ||
``` | ||
/restapi/oauth/token: | ||
post: | ||
operationId: getToken | ||
x-audience: Public | ||
summary: ... | ||
requestBody: | ||
... | ||
responses: | ||
... | ||
``` | ||
|
||
Oasdiff can add these attributes to the changelog in JSON or YAML formats as follows: | ||
|
||
``` | ||
❯ oasdiff changelog base.yaml revision.yaml -f yaml --attributes x-audience | ||
- id: new-optional-request-property | ||
text: added the new optional request property ivr_pin | ||
level: 1 | ||
operation: POST | ||
operationId: getToken | ||
path: /restapi/oauth/token | ||
source: new-revision.yaml | ||
section: paths | ||
attributes: | ||
x-audience: Public | ||
``` |
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
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
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 |
---|---|---|
|
@@ -6,6 +6,8 @@ import ( | |
) | ||
|
||
type DiffFlags struct { | ||
CommonFlags | ||
|
||
base *load.Source | ||
revision *load.Source | ||
composed bool | ||
|
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
Oops, something went wrong.