Skip to content

Commit

Permalink
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: show component path for referenced schemas
Browse files Browse the repository at this point in the history
NextFire committed Jul 12, 2024
1 parent 0891232 commit 86271a2
Showing 42 changed files with 257 additions and 238 deletions.
Original file line number Diff line number Diff line change
@@ -29,6 +29,7 @@ public class OpenApiSpecificationsCompareTests
{
private static readonly JsonSerializerOptions serializerOptions = new()
{
WriteIndented = true,
Converters = { new JsonStringEnumConverter() }
};

@@ -43,11 +44,13 @@ public void CompareOAS(string testcase)
var differences = OpenApiComparator
.Compare(File.ReadAllText(oldFileName), File.ReadAllText(newFileName));

var expectedDifferencesText = File.ReadAllText(diffFileName);
var expectedDifferences = JsonSerializer
.Deserialize<ComparisonMessageModel[]>(File.ReadAllText(diffFileName), serializerOptions);
.Deserialize<ComparisonMessageModel[]>(expectedDifferencesText, serializerOptions);

Assert.That(differences,
Is.EquivalentTo(expectedDifferences).Using<ComparisonMessage, ComparisonMessageModel>(Comparer));
Is.EquivalentTo(expectedDifferences).Using<ComparisonMessage, ComparisonMessageModel>(Comparer),
$"Expected differences:\n{expectedDifferencesText}\nActual differences:\n{JsonSerializer.Serialize(differences, serializerOptions)}");
}

private static IEnumerable<string> TestCases()
Original file line number Diff line number Diff line change
@@ -2,17 +2,17 @@
{
"Severity": "Warning",
"Message": "The new version adds an \u0027additionalProperties\u0027 element.",
"OldJsonRef": "#/paths/~1api~1Parameters/get/responses/200/content/application~1json/schema/additionalProperties",
"NewJsonRef": "#/paths/~1api~1Parameters/get/responses/200/content/application~1json/schema/additionalProperties",
"OldJsonRef": "#/components/schemas/Pet/additionalProperties",
"NewJsonRef": "#/components/schemas/Pet/additionalProperties",
"Id": 1021,
"Code": "AddedAdditionalProperties",
"Mode": "Addition"
},
{
"Severity": "Warning",
"Message": "The new version adds an \u0027additionalProperties\u0027 element.",
"OldJsonRef": "#/schemas/Pet/additionalProperties",
"NewJsonRef": "#/schemas/Pet/additionalProperties",
"OldJsonRef": "#/components/schemas/Pet/additionalProperties",
"NewJsonRef": "#/components/schemas/Pet/additionalProperties",
"Id": 1021,
"Code": "AddedAdditionalProperties",
"Mode": "Addition"
Original file line number Diff line number Diff line change
@@ -2,53 +2,53 @@
{
"Severity": "Warning",
"Message": "The new version is adding enum value(s) \u0027Microsoft.OpenApi.Any.OpenApiString\u0027 from the old version.",
"OldJsonRef": "#/paths/~1api~1Parameters/put/responses/200/content/application~1json/schema/properties/petType/enum",
"NewJsonRef": "#/paths/~1api~1Parameters/put/responses/200/content/application~1json/schema/properties/petType/enum",
"OldJsonRef": "#/components/schemas/Pet/properties/petType/enum",
"NewJsonRef": "#/components/schemas/Pet/properties/petType/enum",
"Id": 1020,
"Code": "AddedEnumValue",
"Mode": "Addition"
},
{
"Severity": "Info",
"Message": "The new version has a less constraining \u0027enum\u0027 value than the previous one.",
"OldJsonRef": "#/paths/~1api~1Parameters/put/responses/200/content/application~1json/schema/properties/petType/enum",
"NewJsonRef": "#/paths/~1api~1Parameters/put/responses/200/content/application~1json/schema/properties/petType/enum",
"OldJsonRef": "#/components/schemas/Pet/properties/petType/enum",
"NewJsonRef": "#/components/schemas/Pet/properties/petType/enum",
"Id": 1037,
"Code": "ConstraintIsWeaker",
"Mode": "Update"
},
{
"Severity": "Info",
"Message": "The new version has a less constraining \u0027enum\u0027 value than the previous one.",
"OldJsonRef": "#/paths/~1api~1Parameters/put/responses/200/content/application~1json/schema/properties/accountType/enum",
"NewJsonRef": "#/paths/~1api~1Parameters/put/responses/200/content/application~1json/schema/properties/accountType/enum",
"OldJsonRef": "#/components/schemas/Pet/properties/accountType/enum",
"NewJsonRef": "#/components/schemas/Pet/properties/accountType/enum",
"Id": 1037,
"Code": "ConstraintIsWeaker",
"Mode": "Update"
},
{
"Severity": "Warning",
"Message": "The new version is adding enum value(s) \u0027Microsoft.OpenApi.Any.OpenApiString\u0027 from the old version.",
"OldJsonRef": "#/schemas/Pet/properties/petType/enum",
"NewJsonRef": "#/schemas/Pet/properties/petType/enum",
"OldJsonRef": "#/components/schemas/Pet/properties/petType/enum",
"NewJsonRef": "#/components/schemas/Pet/properties/petType/enum",
"Id": 1020,
"Code": "AddedEnumValue",
"Mode": "Addition"
},
{
"Severity": "Info",
"Message": "The new version has a less constraining \u0027enum\u0027 value than the previous one.",
"OldJsonRef": "#/schemas/Pet/properties/petType/enum",
"NewJsonRef": "#/schemas/Pet/properties/petType/enum",
"OldJsonRef": "#/components/schemas/Pet/properties/petType/enum",
"NewJsonRef": "#/components/schemas/Pet/properties/petType/enum",
"Id": 1037,
"Code": "ConstraintIsWeaker",
"Mode": "Update"
},
{
"Severity": "Info",
"Message": "The new version has a less constraining \u0027enum\u0027 value than the previous one.",
"OldJsonRef": "#/schemas/Pet/properties/accountType/enum",
"NewJsonRef": "#/schemas/Pet/properties/accountType/enum",
"OldJsonRef": "#/components/schemas/Pet/properties/accountType/enum",
"NewJsonRef": "#/components/schemas/Pet/properties/accountType/enum",
"Id": 1037,
"Code": "ConstraintIsWeaker",
"Mode": "Update"
Original file line number Diff line number Diff line change
@@ -2,17 +2,17 @@
{
"Severity": "Warning",
"Message": "The new version has a new optional property \u0027message\u0027 that was not found in the old version.",
"OldJsonRef": "#/paths/~1api~1Parameters/put/parameters/0/schema/properties/message",
"NewJsonRef": "#/paths/~1api~1Parameters/put/parameters/0/schema/properties/message",
"OldJsonRef": "#/components/parameters/skipParam/schema/properties/message",
"NewJsonRef": "#/components/parameters/skipParam/schema/properties/message",
"Id": 1045,
"Code": "AddedOptionalProperty",
"Mode": "Addition"
},
{
"Severity": "Warning",
"Message": "The new version has a new optional property \u0027end\u0027 that was not found in the old version.",
"OldJsonRef": "#/paths/~1api~1Parameters/put/parameters/1/schema/properties/end",
"NewJsonRef": "#/paths/~1api~1Parameters/put/parameters/1/schema/properties/end",
"OldJsonRef": "#/components/parameters/limitParam/schema/properties/end",
"NewJsonRef": "#/components/parameters/limitParam/schema/properties/end",
"Id": 1045,
"Code": "AddedOptionalProperty",
"Mode": "Addition"
Original file line number Diff line number Diff line change
@@ -2,17 +2,17 @@
{
"Severity": "Warning",
"Message": "The new version has a new property \u0027petType\u0027 in response that was not found in the old version.",
"OldJsonRef": "#/paths/~1pets/get/responses/200/content/application~1json/schema/items/properties/petType",
"NewJsonRef": "#/paths/~1pets/get/responses/200/content/application~1json/schema/items/properties/petType",
"OldJsonRef": "#/components/schemas/Pet/properties/petType",
"NewJsonRef": "#/components/schemas/Pet/properties/petType",
"Id": 1041,
"Code": "AddedPropertyInResponse",
"Mode": "Addition"
},
{
"Severity": "Warning",
"Message": "The new version has a new property \u0027petAge\u0027 in response that was not found in the old version.",
"OldJsonRef": "#/paths/~1pets/get/responses/200/content/application~1json/schema/items/properties/petAge",
"NewJsonRef": "#/paths/~1pets/get/responses/200/content/application~1json/schema/items/properties/petAge",
"OldJsonRef": "#/components/schemas/Pet/properties/petAge",
"NewJsonRef": "#/components/schemas/Pet/properties/petAge",
"Id": 1041,
"Code": "AddedPropertyInResponse",
"Mode": "Addition"
@@ -29,8 +29,8 @@
{
"Severity": "Warning",
"Message": "The new version has a new property \u0027message\u0027 in response that was not found in the old version.",
"OldJsonRef": "#/paths/~1pets/get/responses/500/content/application~1json/schema/properties/message",
"NewJsonRef": "#/paths/~1pets/get/responses/500/content/application~1json/schema/properties/message",
"OldJsonRef": "#/components/responses/InternalErrorResponse/content/application~1json/schema/properties/message",
"NewJsonRef": "#/components/responses/InternalErrorResponse/content/application~1json/schema/properties/message",
"Id": 1041,
"Code": "AddedPropertyInResponse",
"Mode": "Addition"
Original file line number Diff line number Diff line change
@@ -2,8 +2,8 @@
{
"Severity": "Info",
"Message": "The new version has a new read-only property \u0027petType\u0027 in response that was not found in the old version.",
"OldJsonRef": "#/paths/~1pets/get/responses/200/content/application~1json/schema/items/properties/petType",
"NewJsonRef": "#/paths/~1pets/get/responses/200/content/application~1json/schema/items/properties/petType",
"OldJsonRef": "#/components/schemas/Pet/properties/petType",
"NewJsonRef": "#/components/schemas/Pet/properties/petType",
"Id": 1040,
"Code": "AddedReadOnlyPropertyInResponse",
"Mode": "Addition"
@@ -20,8 +20,8 @@
{
"Severity": "Info",
"Message": "The new version has a new read-only property \u0027message\u0027 in response that was not found in the old version.",
"OldJsonRef": "#/paths/~1pets/get/responses/500/content/application~1json/schema/properties/message",
"NewJsonRef": "#/paths/~1pets/get/responses/500/content/application~1json/schema/properties/message",
"OldJsonRef": "#/components/responses/InternalErrorResponse/content/application~1json/schema/properties/message",
"NewJsonRef": "#/components/responses/InternalErrorResponse/content/application~1json/schema/properties/message",
"Id": 1040,
"Code": "AddedReadOnlyPropertyInResponse",
"Mode": "Addition"
Original file line number Diff line number Diff line change
@@ -20,8 +20,8 @@
{
"Severity": "Warning",
"Message": "The new version has new required property \u0027petType\u0027 that was not found in the old version.",
"OldJsonRef": "#/schemas/Pet",
"NewJsonRef": "#/schemas/Pet",
"OldJsonRef": "#/components/schemas/Pet",
"NewJsonRef": "#/components/schemas/Pet",
"Id": 1034,
"Code": "AddedRequiredProperty",
"Mode": "Addition"
Original file line number Diff line number Diff line change
@@ -2,26 +2,26 @@
{
"Severity": "Warning",
"Message": "The \u0027constant\u0027 status changed from the old version to the new.",
"OldJsonRef": "#/paths/~1api~1Parameters/put/parameters/1/enum",
"NewJsonRef": "#/paths/~1api~1Parameters/put/parameters/1/enum",
"OldJsonRef": "#/components/parameters/limitParam/enum",
"NewJsonRef": "#/components/parameters/limitParam/enum",
"Id": 1016,
"Code": "ConstantStatusHasChanged",
"Mode": "Update"
},
{
"Severity": "Warning",
"Message": "The new version is adding enum value(s) \u0027Microsoft.OpenApi.Any.OpenApiString, Microsoft.OpenApi.Any.OpenApiString\u0027 from the old version.",
"OldJsonRef": "#/paths/~1api~1Parameters/put/parameters/1/schema/enum",
"NewJsonRef": "#/paths/~1api~1Parameters/put/parameters/1/schema/enum",
"OldJsonRef": "#/components/parameters/limitParam/schema/enum",
"NewJsonRef": "#/components/parameters/limitParam/schema/enum",
"Id": 1020,
"Code": "AddedEnumValue",
"Mode": "Addition"
},
{
"Severity": "Info",
"Message": "The new version has a less constraining \u0027enum\u0027 value than the previous one.",
"OldJsonRef": "#/paths/~1api~1Parameters/put/parameters/1/schema/enum",
"NewJsonRef": "#/paths/~1api~1Parameters/put/parameters/1/schema/enum",
"OldJsonRef": "#/components/parameters/limitParam/schema/enum",
"NewJsonRef": "#/components/parameters/limitParam/schema/enum",
"Id": 1037,
"Code": "ConstraintIsWeaker",
"Mode": "Update"
Original file line number Diff line number Diff line change
@@ -2,44 +2,44 @@
{
"Severity": "Warning",
"Message": "The new version has a different \u0027pattern\u0027 value than the previous one.",
"OldJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/accessKey/pattern",
"NewJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/accessKey/pattern",
"OldJsonRef": "#/components/schemas/limitParam/properties/accessKey/pattern",
"NewJsonRef": "#/components/schemas/limitParam/properties/accessKey/pattern",
"Id": 1036,
"Code": "ConstraintChanged",
"Mode": "Update"
},
{
"Severity": "Warning",
"Message": "The new version has a different \u0027uniqueItems\u0027 value than the previous one.",
"OldJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/redirectUrl/uniqueItems",
"NewJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/redirectUrl/uniqueItems",
"OldJsonRef": "#/components/schemas/limitParam/properties/redirectUrl/uniqueItems",
"NewJsonRef": "#/components/schemas/limitParam/properties/redirectUrl/uniqueItems",
"Id": 1036,
"Code": "ConstraintChanged",
"Mode": "Update"
},
{
"Severity": "Warning",
"Message": "The new version is removing enum value(s) \u0027Microsoft.OpenApi.Any.OpenApiString\u0027 from the old version.",
"OldJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/constrainsItems/enum",
"NewJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/constrainsItems/enum",
"OldJsonRef": "#/components/schemas/limitParam/properties/constrainsItems/enum",
"NewJsonRef": "#/components/schemas/limitParam/properties/constrainsItems/enum",
"Id": 1019,
"Code": "RemovedEnumValue",
"Mode": "Removal"
},
{
"Severity": "Warning",
"Message": "The new version is adding enum value(s) \u0027Microsoft.OpenApi.Any.OpenApiString\u0027 from the old version.",
"OldJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/constrainsItems/enum",
"NewJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/constrainsItems/enum",
"OldJsonRef": "#/components/schemas/limitParam/properties/constrainsItems/enum",
"NewJsonRef": "#/components/schemas/limitParam/properties/constrainsItems/enum",
"Id": 1020,
"Code": "AddedEnumValue",
"Mode": "Addition"
},
{
"Severity": "Info",
"Message": "The new version has a different \u0027enum\u0027 value than the previous one.",
"OldJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/constrainsItems/enum",
"NewJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/constrainsItems/enum",
"OldJsonRef": "#/components/schemas/limitParam/properties/constrainsItems/enum",
"NewJsonRef": "#/components/schemas/limitParam/properties/constrainsItems/enum",
"Id": 1036,
"Code": "ConstraintChanged",
"Mode": "Update"
Original file line number Diff line number Diff line change
@@ -2,53 +2,53 @@
{
"Severity": "Warning",
"Message": "The new version has a more constraining \u0027maximum\u0027 value than the previous one.",
"OldJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/minLimit/maximum",
"NewJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/minLimit/maximum",
"OldJsonRef": "#/components/schemas/limitParam/properties/minLimit/maximum",
"NewJsonRef": "#/components/schemas/limitParam/properties/minLimit/maximum",
"Id": 1024,
"Code": "ConstraintIsStronger",
"Mode": "Update"
},
{
"Severity": "Warning",
"Message": "The new version has a more constraining \u0027minimum\u0027 value than the previous one.",
"OldJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/exclusiveMin/minimum",
"NewJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/exclusiveMin/minimum",
"OldJsonRef": "#/components/schemas/limitParam/properties/exclusiveMin/minimum",
"NewJsonRef": "#/components/schemas/limitParam/properties/exclusiveMin/minimum",
"Id": 1024,
"Code": "ConstraintIsStronger",
"Mode": "Update"
},
{
"Severity": "Warning",
"Message": "The new version has a more constraining \u0027maxLength\u0027 value than the previous one.",
"OldJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/maxTextSize/maxLength",
"NewJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/maxTextSize/maxLength",
"OldJsonRef": "#/components/schemas/limitParam/properties/maxTextSize/maxLength",
"NewJsonRef": "#/components/schemas/limitParam/properties/maxTextSize/maxLength",
"Id": 1024,
"Code": "ConstraintIsStronger",
"Mode": "Update"
},
{
"Severity": "Warning",
"Message": "The new version has a more constraining \u0027minLength\u0027 value than the previous one.",
"OldJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/minTextSize/minLength",
"NewJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/minTextSize/minLength",
"OldJsonRef": "#/components/schemas/limitParam/properties/minTextSize/minLength",
"NewJsonRef": "#/components/schemas/limitParam/properties/minTextSize/minLength",
"Id": 1024,
"Code": "ConstraintIsStronger",
"Mode": "Update"
},
{
"Severity": "Warning",
"Message": "The new version has a more constraining \u0027maxItems\u0027 value than the previous one.",
"OldJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/redirectUrl/maxItems",
"NewJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/redirectUrl/maxItems",
"OldJsonRef": "#/components/schemas/limitParam/properties/redirectUrl/maxItems",
"NewJsonRef": "#/components/schemas/limitParam/properties/redirectUrl/maxItems",
"Id": 1024,
"Code": "ConstraintIsStronger",
"Mode": "Update"
},
{
"Severity": "Warning",
"Message": "The new version has a more constraining \u0027minItems\u0027 value than the previous one.",
"OldJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/redirectUrl/minItems",
"NewJsonRef": "#/paths/~1pets/get/parameters/0/schema/properties/redirectUrl/minItems",
"OldJsonRef": "#/components/schemas/limitParam/properties/redirectUrl/minItems",
"NewJsonRef": "#/components/schemas/limitParam/properties/redirectUrl/minItems",
"Id": 1024,
"Code": "ConstraintIsStronger",
"Mode": "Update"
Loading

0 comments on commit 86271a2

Please sign in to comment.