-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: better handling of enum changes based on direction
| Enum Change | In Request (path/query/body) | In Response (body) | In Both | |---------------|------------------------------|--------------------|----------| | Value Added | OK | Breaking | Breaking | | Value Removed | Breaking | OK | Breaking |
- Loading branch information
Showing
13 changed files
with
501 additions
and
34 deletions.
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
src/Criteo.OpenApi.Comparator.UTest/OpenApiEnumDirectionTests.cs
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,82 @@ | ||
using System.Collections.Generic; | ||
using System.IO; | ||
using System.Linq; | ||
using System.Reflection; | ||
using Criteo.OpenApi.Comparator.Logging; | ||
using NUnit.Framework; | ||
|
||
namespace Criteo.OpenApi.Comparator.UTest; | ||
|
||
[TestFixture] | ||
public class OpenApiEnumDirectionTests | ||
{ | ||
[TestCase("path_add", "#/paths/~1order~1{path}/post/parameters/0/schema/enum")] | ||
[TestCase("query_add", "#/paths/~1order~1{path}/post/parameters/1/schema/enum")] | ||
[TestCase("body_add", "#/paths/~1order~1{path}/post/requestBody/content/application~1json/schema/properties/foo/enum")] | ||
public void CompareOAS_ShouldReturn_NonBreakingEnumChange_InRequest(string oasName, string jsonRef) | ||
{ | ||
var differences = CompareSpecifications(oasName); | ||
differences.AssertContains(new ExpectedDifference | ||
{ | ||
Rule = ComparisonRules.AddedEnumValue, | ||
Severity = Severity.Warning, | ||
NewJsonRef = jsonRef | ||
}, 1); | ||
} | ||
|
||
[TestCase("response_remove", "#/paths/~1order~1{path}/post/responses/200/content/application~1json/schema/properties/bar/enum")] | ||
public void CompareOAS_ShouldReturn_NonBreakingEnumChange_InResponse(string oasName, string jsonRef) | ||
{ | ||
var differences = CompareSpecifications(oasName); | ||
differences.AssertContains(new ExpectedDifference | ||
{ | ||
Rule = ComparisonRules.RemovedEnumValue, | ||
Severity = Severity.Warning, | ||
NewJsonRef = jsonRef | ||
}, 1); | ||
} | ||
|
||
[TestCase("path_remove", "#/paths/~1order~1{path}/post/parameters/0/schema/enum")] | ||
[TestCase("query_remove", "#/paths/~1order~1{path}/post/parameters/1/schema/enum")] | ||
[TestCase("body_remove", "#/paths/~1order~1{path}/post/requestBody/content/application~1json/schema/properties/foo/enum")] | ||
public void CompareOAS_ShouldReturn_BreakingEnumChange_InRequest(string oasName, string jsonRef) | ||
{ | ||
var differences = CompareSpecifications(oasName); | ||
differences.AssertContains(new ExpectedDifference | ||
{ | ||
Rule = ComparisonRules.RemovedEnumValue, | ||
Severity = Severity.Error, | ||
NewJsonRef = jsonRef, | ||
}, 1); | ||
} | ||
|
||
[TestCase("response_add", "#/paths/~1order~1{path}/post/responses/200/content/application~1json/schema/properties/bar/enum")] | ||
public void CompareOAS_ShouldReturn_BreakingEnumChange_InResponse(string oasName, string jsonRef) | ||
{ | ||
var differences = CompareSpecifications(oasName); | ||
differences.AssertContains(new ExpectedDifference | ||
{ | ||
Rule = ComparisonRules.AddedEnumValue, | ||
Severity = Severity.Error, | ||
NewJsonRef = jsonRef | ||
}, 1); | ||
} | ||
|
||
private static IList<ComparisonMessage> CompareSpecifications(string oasName) | ||
{ | ||
var baseDirectory = Directory | ||
.GetParent(typeof(OpenApiSpecificationsCompareTests).GetTypeInfo().Assembly.Location) | ||
.ToString(); | ||
|
||
var referenceFileName = Path.Combine(baseDirectory, "Resource", "enum_direction", "reference.json"); | ||
var newFileName = Path.Combine(baseDirectory, "Resource", "enum_direction", oasName + ".yaml"); | ||
|
||
var differences = OpenApiComparator | ||
.Compare(File.ReadAllText(referenceFileName), File.ReadAllText(newFileName), strict: true) | ||
.ToList(); | ||
|
||
OpenApiSpecificationsCompareTests.ValidateDifferences(differences); | ||
|
||
return differences; | ||
} | ||
} |
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
42 changes: 42 additions & 0 deletions
42
src/Criteo.OpenApi.Comparator.UTest/Resource/enum_direction/body_add.yaml
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,42 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: My API | ||
version: 0.2.0 | ||
paths: | ||
/order/{path}: | ||
post: | ||
parameters: | ||
- name: path | ||
in: path | ||
required: true | ||
schema: | ||
enum: | ||
- abc | ||
- def | ||
- name: query | ||
in: query | ||
schema: | ||
enum: | ||
- ghi | ||
- jkl | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
foo: | ||
enum: | ||
- zzzzzz | ||
- mno | ||
- pqr | ||
responses: | ||
"200": | ||
description: Successful Response | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
bar: | ||
enum: | ||
- stu | ||
- vwx |
40 changes: 40 additions & 0 deletions
40
src/Criteo.OpenApi.Comparator.UTest/Resource/enum_direction/body_remove.yaml
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,40 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: My API | ||
version: 0.2.0 | ||
paths: | ||
/order/{path}: | ||
post: | ||
parameters: | ||
- name: path | ||
in: path | ||
required: true | ||
schema: | ||
enum: | ||
- abc | ||
- def | ||
- name: query | ||
in: query | ||
schema: | ||
enum: | ||
- ghi | ||
- jkl | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
foo: | ||
enum: | ||
- pqr | ||
responses: | ||
"200": | ||
description: Successful Response | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
bar: | ||
enum: | ||
- stu | ||
- vwx |
42 changes: 42 additions & 0 deletions
42
src/Criteo.OpenApi.Comparator.UTest/Resource/enum_direction/path_add.yaml
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,42 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: My API | ||
version: 0.2.0 | ||
paths: | ||
/order/{path}: | ||
post: | ||
parameters: | ||
- name: path | ||
in: path | ||
required: true | ||
schema: | ||
enum: | ||
- abc | ||
- zzzzzz | ||
- def | ||
- name: query | ||
in: query | ||
schema: | ||
enum: | ||
- ghi | ||
- jkl | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
foo: | ||
enum: | ||
- mno | ||
- pqr | ||
responses: | ||
"200": | ||
description: Successful Response | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
bar: | ||
enum: | ||
- stu | ||
- vwx |
40 changes: 40 additions & 0 deletions
40
src/Criteo.OpenApi.Comparator.UTest/Resource/enum_direction/path_remove.yaml
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,40 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: My API | ||
version: 0.2.0 | ||
paths: | ||
/order/{path}: | ||
post: | ||
parameters: | ||
- name: path | ||
in: path | ||
required: true | ||
schema: | ||
enum: | ||
- abc | ||
- name: query | ||
in: query | ||
schema: | ||
enum: | ||
- ghi | ||
- jkl | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
foo: | ||
enum: | ||
- mno | ||
- pqr | ||
responses: | ||
"200": | ||
description: Successful Response | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
bar: | ||
enum: | ||
- stu | ||
- vwx |
42 changes: 42 additions & 0 deletions
42
src/Criteo.OpenApi.Comparator.UTest/Resource/enum_direction/query_add.yaml
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,42 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: My API | ||
version: 0.2.0 | ||
paths: | ||
/order/{path}: | ||
post: | ||
parameters: | ||
- name: path | ||
in: path | ||
required: true | ||
schema: | ||
enum: | ||
- abc | ||
- def | ||
- name: query | ||
in: query | ||
schema: | ||
enum: | ||
- ghi | ||
- jkl | ||
- zzzzzz | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
foo: | ||
enum: | ||
- mno | ||
- pqr | ||
responses: | ||
"200": | ||
description: Successful Response | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
bar: | ||
enum: | ||
- stu | ||
- vwx |
40 changes: 40 additions & 0 deletions
40
src/Criteo.OpenApi.Comparator.UTest/Resource/enum_direction/query_remove.yaml
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,40 @@ | ||
openapi: 3.0.0 | ||
info: | ||
title: My API | ||
version: 0.2.0 | ||
paths: | ||
/order/{path}: | ||
post: | ||
parameters: | ||
- name: path | ||
in: path | ||
required: true | ||
schema: | ||
enum: | ||
- abc | ||
- def | ||
- name: query | ||
in: query | ||
schema: | ||
enum: | ||
- jkl | ||
requestBody: | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
foo: | ||
enum: | ||
- mno | ||
- pqr | ||
responses: | ||
"200": | ||
description: Successful Response | ||
content: | ||
application/json: | ||
schema: | ||
properties: | ||
bar: | ||
enum: | ||
- stu | ||
- vwx |
48 changes: 48 additions & 0 deletions
48
src/Criteo.OpenApi.Comparator.UTest/Resource/enum_direction/reference.json
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,48 @@ | ||
{ | ||
"openapi": "3.0.0", | ||
"info": { "title": "My API", "version": "0.1.0" }, | ||
"paths": { | ||
"/order/{path}": { | ||
"post": { | ||
"parameters": [ | ||
{ | ||
"name": "path", | ||
"in": "path", | ||
"required": true, | ||
"schema": { "enum": ["abc", "def"] } | ||
}, | ||
{ | ||
"name": "query", | ||
"in": "query", | ||
"schema": { "enum": ["ghi", "jkl"] } | ||
} | ||
], | ||
"requestBody": { | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"properties": { | ||
"foo": { "enum": ["mno", "pqr"] } | ||
} | ||
} | ||
} | ||
} | ||
}, | ||
"responses": { | ||
"200": { | ||
"description": "Successful Response", | ||
"content": { | ||
"application/json": { | ||
"schema": { | ||
"properties": { | ||
"bar": { "enum": ["stu", "vwx"] } | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} | ||
} |
Oops, something went wrong.