diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 000000000..0d20a9b46 --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,27 @@ +{ + "version": "0.2.0", + "configurations": [ + { + // Use IntelliSense to find out which attributes exist for C# debugging + // Use hover for the description of the existing attributes + // For further information visit https://github.com/OmniSharp/omnisharp-vscode/blob/master/debugger-launchjson.md + "name": ".NET Core Launch (console)", + "type": "coreclr", + "request": "launch", + "preLaunchTask": "build", + // If you have changed target frameworks, make sure to update the program path. + "program": "${workspaceFolder}/src/Microsoft.OpenApi.Tool/bin/Debug/netcoreapp3.1/Microsoft.OpenApi.Tool.dll", + "args": [], + "cwd": "${workspaceFolder}/src/Microsoft.OpenApi.Tool", + // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console + "console": "internalConsole", + "stopAtEntry": false + }, + { + "name": ".NET Core Attach", + "type": "coreclr", + "request": "attach", + "processId": "${command:pickProcess}" + } + ] +} \ No newline at end of file diff --git a/src/Microsoft.OpenApi/Services/ComparisonContext.cs b/src/Microsoft.OpenApi/Services/ComparisonContext.cs deleted file mode 100644 index 42acf5bda..000000000 --- a/src/Microsoft.OpenApi/Services/ComparisonContext.cs +++ /dev/null @@ -1,87 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// A class encapsulating the comparision context. - /// - public class ComparisonContext - { - private readonly IList _openApiDifferences = new List(); - private readonly Stack _path = new Stack(); - internal readonly OpenApiDocument SourceDocument; - internal readonly Stack SourceSchemaLoop = new Stack(); - internal readonly OpenApiDocument TargetDocument; - internal readonly Stack TargetSchemaLoop = new Stack(); - internal OpenApiComparerFactory OpenApiComparerFactory; - - /// - /// Creates instance of . - /// - public ComparisonContext( - OpenApiComparerFactory openApiComparerFactory, - OpenApiDocument sourceDocument, - OpenApiDocument targetDocument) - { - OpenApiComparerFactory = openApiComparerFactory; - SourceDocument = sourceDocument; - TargetDocument = targetDocument; - } - - /// - /// Gets the list of open api differences. - /// - public IEnumerable OpenApiDifferences => _openApiDifferences; - - /// - /// Pointer to the source of difference in the document. - /// - public string PathString => "#/" + string.Join("/", _path.Reverse()); - - /// - /// Adds an open api difference. - /// - /// The open api difference to add. - public void AddOpenApiDifference(OpenApiDifference openApiDifference) - { - if (openApiDifference == null) - { - throw Error.ArgumentNull(nameof(openApiDifference)); - } - - _openApiDifferences.Add(openApiDifference); - } - - /// - /// Allow Rule to indicate difference occured at a deeper context level. - /// - /// Identifier for the context. - public void Enter(string segment) - { - _path.Push(segment); - } - - /// - /// Exit from path context level. Enter and Exit calls should be matched. - /// - public void Exit() - { - _path.Pop(); - } - - /// - /// Gets the comparer instance for the requested type. - /// - /// Type of requested comparer. - /// Comparer instance to use when comparing requested type. - internal OpenApiComparerBase GetComparer() - { - return OpenApiComparerFactory.GetComparer(); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiAnyComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiAnyComparer.cs deleted file mode 100644 index 886f4313d..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiAnyComparer.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System; -using System.IO; -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Writers; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiAnyComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - IOpenApiAny source, - IOpenApiAny target, - ComparisonContext comparisonContext) - { - if (source == null && target == null) - { - return; - } - - if (source == null || target == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = source, - TargetValue = target, - OpenApiComparedElementType = typeof(IOpenApiAny), - Pointer = comparisonContext.PathString - }); - - return; - } - - var sourceStringWriter = new StringWriter(); - var sourceWriter = new OpenApiJsonWriter(sourceStringWriter); - - source.Write(sourceWriter, OpenApiSpecVersion.OpenApi3_0); - var sourceValue = sourceStringWriter.GetStringBuilder().ToString(); - - var targetStringWriter = new StringWriter(); - var targetWriter = new OpenApiJsonWriter(targetStringWriter); - - target.Write(targetWriter, OpenApiSpecVersion.OpenApi3_0); - var targetValue = targetStringWriter.GetStringBuilder().ToString(); - - if (string.Compare(sourceValue, targetValue, StringComparison.InvariantCulture) != 0) - { - comparisonContext.AddOpenApiDifference(new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(IOpenApiAny), - SourceValue = source, - TargetValue = target, - Pointer = comparisonContext.PathString - }); - } - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiComparer.cs deleted file mode 100644 index cfe73e65e..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiComparer.cs +++ /dev/null @@ -1,36 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Class containing logic to get differences between two s. - /// - public static class OpenApiComparer - { - /// - /// Compares two s and returns a list of differences. - /// - public static IEnumerable Compare(OpenApiDocument source, OpenApiDocument target) - { - if (source == null) - { - throw Error.ArgumentNull(nameof(source)); - } - - if (target == null) - { - throw Error.ArgumentNull(nameof(target)); - } - - var comparisonContext = new ComparisonContext(new OpenApiComparerFactory(), source, target); - - new OpenApiDocumentComparer().Compare(source, target, comparisonContext); - - return comparisonContext.OpenApiDifferences; - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiComparerBase.cs b/src/Microsoft.OpenApi/Services/OpenApiComparerBase.cs deleted file mode 100644 index 53762688b..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiComparerBase.cs +++ /dev/null @@ -1,263 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System; -using System.Collections.Generic; -using System.Linq; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing parts of class. - /// - /// Type of class to compare. - public abstract class OpenApiComparerBase - { - /// - /// Validates a fragment of . - /// - /// The source fragment. - /// The target fragment. - /// Context under which to compare fragment. - public abstract void Compare(T sourceFragment, T targetFragment, ComparisonContext comparisonContext); - - /// - /// Compares two string object. - /// - /// The source string. - /// The target string. - /// The context under which to compare the objects. - internal void Compare(string source, string target, ComparisonContext comparisonContext) - { - if (string.IsNullOrWhiteSpace(source) && string.IsNullOrWhiteSpace(target)) - { - return; - } - - if (string.Compare(source, target, StringComparison.CurrentCultureIgnoreCase) != 0) - { - comparisonContext.AddOpenApiDifference(new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = source, - TargetValue = target, - Pointer = comparisonContext.PathString - }); - } - } - - /// - /// Compares two Uri object. - /// - /// The source. - /// The target. - /// The context under which to compare the objects. - internal void Compare(Uri source, Uri target, ComparisonContext comparisonContext) - { - if (source == null && target == null) - { - return; - } - - if (source != target) - { - comparisonContext.AddOpenApiDifference(new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(Uri), - SourceValue = source, - TargetValue = target, - Pointer = comparisonContext.PathString - }); - } - } - - /// - /// Compares two boolean object. - /// - /// The source. - /// The target. - /// The context under which to compare the objects. - internal void Compare(bool? source, bool? target, ComparisonContext comparisonContext) - { - if (source == null && target == null) - { - return; - } - - if (source != target) - { - comparisonContext.AddOpenApiDifference(new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(bool?), - SourceValue = source, - TargetValue = target, - Pointer = comparisonContext.PathString - }); - } - } - - /// - /// Compares two decimal object. - /// - /// The source. - /// The target. - /// The context under which to compare the objects. - internal void Compare(decimal? source, decimal? target, ComparisonContext comparisonContext) - { - if (source == null && target == null) - { - return; - } - - if (source != target) - { - comparisonContext.AddOpenApiDifference(new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(decimal?), - SourceValue = source, - TargetValue = target, - Pointer = comparisonContext.PathString - }); - } - } - - /// - /// Compares Enum. - /// - /// The source. - /// The target. - /// The context under which to compare the objects. - internal void Compare(Enum source, Enum target, ComparisonContext comparisonContext) - { - if (source == null && target == null) - { - return; - } - - if (source == null || target == null) - { - comparisonContext.AddOpenApiDifference(new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(TEnum), - SourceValue = source, - TargetValue = target, - Pointer = comparisonContext.PathString - }); - - return; - } - - if (!source.Equals(target)) - { - comparisonContext.AddOpenApiDifference(new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(TEnum), - SourceValue = source, - TargetValue = target, - Pointer = comparisonContext.PathString - }); - } - } - - /// - /// Compares where TKey is and TValue is - /// . - /// - /// The source. - /// The target. - /// The context under which to compare the objects. - internal void Compare(IDictionary source, IDictionary target, - ComparisonContext comparisonContext) - { - if (source == null && target == null) - { - return; - } - - if (source == null || target == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = source, - TargetValue = target, - OpenApiComparedElementType = typeof(IDictionary), - Pointer = comparisonContext.PathString - }); - - return; - } - - var newKeysInTarget = target.Keys.Except(source.Keys).ToList(); - - foreach (var newKeyInTarget in newKeysInTarget) - { - WalkAndAddOpenApiDifference( - comparisonContext, - newKeyInTarget, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - TargetValue = target[newKeyInTarget], - OpenApiComparedElementType = typeof(string) - }); - } - - var removedKeysFromSource = source.Keys.Except(target.Keys).ToList(); - - foreach (var removedKeyFromSource in removedKeysFromSource) - { - WalkAndAddOpenApiDifference( - comparisonContext, - removedKeyFromSource, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - SourceValue = source[removedKeyFromSource], - OpenApiComparedElementType = typeof(string) - }); - } - } - - /// - /// Adds a segment to the context path to enable pointing to the current location in the document. - /// - /// The context under which to compare the objects. - /// An identifier for the segment. - /// The open api difference to add. - internal void WalkAndAddOpenApiDifference( - ComparisonContext comparisonContext, - string segment, - OpenApiDifference openApiDifference) - { - comparisonContext.Enter(segment.Replace("~", "~0").Replace("/", "~1")); - openApiDifference.Pointer = comparisonContext.PathString; - comparisonContext.AddOpenApiDifference(openApiDifference); - comparisonContext.Exit(); - } - - /// - /// Adds a segment to the context path to enable pointing to the current location in the document. - /// - /// The context under which to compare the objects. - /// An identifier for the segment. - /// An action that compares objects within the context. - protected virtual void WalkAndCompare( - ComparisonContext comparisonContext, - string segment, - Action compare) - { - comparisonContext.Enter(segment.Replace("~", "~0").Replace("/", "~1")); - compare(); - comparisonContext.Exit(); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiComparerFactory.cs b/src/Microsoft.OpenApi/Services/OpenApiComparerFactory.cs deleted file mode 100644 index 5ff7b6481..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiComparerFactory.cs +++ /dev/null @@ -1,105 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System; -using System.Collections.Generic; -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for registering specific comparer instances and encapsulates default comparers. - /// - public class OpenApiComparerFactory - { - private static readonly Dictionary TypeToDefaultComparerMap = new Dictionary - { - {typeof(OpenApiPaths), new OpenApiPathsComparer()}, - {typeof(OpenApiPathItem), new OpenApiPathItemComparer()}, - {typeof(OpenApiOperation), new OpenApiOperationComparer()}, - {typeof(IDictionary), new OpenApiOperationsComparer()}, - {typeof(IList), new OpenApiParametersComparer()}, - {typeof(OpenApiParameter), new OpenApiParameterComparer()}, - {typeof(OpenApiSchema), new OpenApiSchemaComparer()}, - {typeof(OpenApiMediaType), new OpenApiMediaTypeComparer()}, - {typeof(IDictionary), new OpenApiDictionaryComparer()}, - {typeof(IDictionary), new OpenApiDictionaryComparer()}, - {typeof(IDictionary), new OpenApiDictionaryComparer()}, - {typeof(IDictionary), new OpenApiDictionaryComparer()}, - { - typeof(IDictionary), - new OpenApiDictionaryComparer() - }, - {typeof(IDictionary), new OpenApiDictionaryComparer()}, - {typeof(IDictionary), new OpenApiDictionaryComparer()}, - {typeof(IDictionary), new OpenApiDictionaryComparer()}, - { - typeof(IDictionary), - new OpenApiDictionaryComparer() - }, - {typeof(OpenApiHeader), new OpenApiHeaderComparer()}, - {typeof(OpenApiRequestBody), new OpenApiRequestBodyComparer()}, - {typeof(OpenApiResponse), new OpenApiResponseComparer()}, - {typeof(OpenApiComponents), new OpenApiComponentsComparer()}, - {typeof(OpenApiEncoding), new OpenApiEncodingComparer()}, - {typeof(IList), new OpenApiServersComparer()}, - {typeof(OpenApiServer), new OpenApiServerComparer()}, - {typeof(OpenApiServerVariable), new OpenApiServerVariableComparer()}, - {typeof(OpenApiOAuthFlow), new OpenApiOAuthFlowComparer()}, - {typeof(OpenApiOAuthFlows), new OpenApiOAuthFlowsComparer()}, - {typeof(OpenApiSecurityRequirement), new OpenApiSecurityRequirementComparer()}, - {typeof(OpenApiInfo), new OpenApiInfoComparer()}, - {typeof(OpenApiContact), new OpenApiContactComparer()}, - {typeof(OpenApiLicense), new OpenApiLicenseComparer()}, - {typeof(IList), new OpenApiOrderedListComparer()}, - {typeof(IList), new OpenApiOrderedListComparer()}, - {typeof(OpenApiExternalDocs), new OpenApiExternalDocsComparer()}, - {typeof(OpenApiTag), new OpenApiTagComparer()}, - {typeof(OpenApiSecurityScheme), new OpenApiSecuritySchemeComparer()}, - {typeof(OpenApiExample), new OpenApiExampleComparer()}, - {typeof(IDictionary), new OpenApiDictionaryComparer()}, - {typeof(IOpenApiAny), new OpenApiAnyComparer()} - }; - - private readonly Dictionary _typeToComparerMap = new Dictionary(); - - /// - /// Adds a comparer instance to this registry. - /// - /// Type of the comparer instance. - /// Instance of to register. - protected void AddComparer(OpenApiComparerBase comparer) - { - if (comparer == null) - { - throw new ArgumentNullException(nameof(comparer)); - } - - _typeToComparerMap.Add(typeof(T), comparer); - } - - /// - /// Gets a registered comparer instance for the requested type. - /// - /// Type of the comparer. - /// The comparer instance corresponding to the type requested. - internal OpenApiComparerBase GetComparer() - { - var requestedComparerType = typeof(T); - - if (_typeToComparerMap.TryGetValue(requestedComparerType, out object comparerInstance)) - { - return (OpenApiComparerBase)comparerInstance; - } - - if (!TypeToDefaultComparerMap.TryGetValue(requestedComparerType, out comparerInstance)) - { - throw Error.NotSupported( - $"No comparer is registered for type {requestedComparerType.Name}."); - } - - return (OpenApiComparerBase)comparerInstance; - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiComponentsComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiComponentsComparer.cs deleted file mode 100644 index 2dd397ef7..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiComponentsComparer.cs +++ /dev/null @@ -1,98 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiComponentsComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiComponents sourceComponents, - OpenApiComponents targetComponents, - ComparisonContext comparisonContext) - { - if (sourceComponents == null && targetComponents == null) - { - return; - } - - if (sourceComponents == null || targetComponents == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceComponents, - TargetValue = targetComponents, - OpenApiComparedElementType = typeof(OpenApiComponents), - Pointer = comparisonContext.PathString - }); - - return; - } - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Parameters, - () => comparisonContext - .GetComparer>() - .Compare(sourceComponents.Parameters, targetComponents.Parameters, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.RequestBodies, - () => comparisonContext - .GetComparer>() - .Compare(sourceComponents.RequestBodies, targetComponents.RequestBodies, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Responses, - () => comparisonContext - .GetComparer>() - .Compare(sourceComponents.Responses, targetComponents.Responses, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Schemas, - () => comparisonContext - .GetComparer>() - .Compare(sourceComponents.Schemas, targetComponents.Schemas, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Headers, - () => comparisonContext - .GetComparer>() - .Compare(sourceComponents.Headers, targetComponents.Headers, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.SecuritySchemes, - () => comparisonContext - .GetComparer>() - .Compare(sourceComponents.SecuritySchemes, targetComponents.SecuritySchemes, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Examples, - () => comparisonContext - .GetComparer>() - .Compare(sourceComponents.Examples, targetComponents.Examples, comparisonContext)); - - // To Do compare Links - // To Do compare Callbacks - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiContactComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiContactComparer.cs deleted file mode 100644 index 1c0626ade..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiContactComparer.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiContactComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiContact sourceContact, - OpenApiContact targetContact, - ComparisonContext comparisonContext) - { - if (sourceContact == null && targetContact == null) - { - return; - } - - if (sourceContact == null || targetContact == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceContact, - TargetValue = targetContact, - OpenApiComparedElementType = typeof(OpenApiContact), - Pointer = comparisonContext.PathString - }); - - return; - } - - WalkAndCompare(comparisonContext, OpenApiConstants.Name, - () => Compare(sourceContact.Name, targetContact.Name, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Email, - () => Compare(sourceContact.Email, targetContact.Email, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Url, - () => Compare(sourceContact.Url, targetContact.Url, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiDictionaryComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiDictionaryComparer.cs deleted file mode 100644 index 89e9c7431..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiDictionaryComparer.cs +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using Microsoft.OpenApi.Interfaces; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing where TKey is - /// and TValue is . - /// - public class OpenApiDictionaryComparer : OpenApiComparerBase> - where T : IOpenApiSerializable - { - /// - /// Executes comparision against source and target - /// where TKey is and TValue is . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - IDictionary sourceFragment, - IDictionary targetFragment, - ComparisonContext comparisonContext) - { - if (sourceFragment == null && targetFragment == null) - { - return; - } - - if (sourceFragment == null || targetFragment == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceFragment, - TargetValue = targetFragment, - OpenApiComparedElementType = typeof(IDictionary), - Pointer = comparisonContext.PathString - }); - - return; - } - - var newKeysInTarget = targetFragment.Keys.Except(sourceFragment.Keys).ToList(); - - foreach (var newKeyInTarget in newKeysInTarget) - { - WalkAndAddOpenApiDifference( - comparisonContext, - newKeyInTarget, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - TargetValue = targetFragment[newKeyInTarget], - OpenApiComparedElementType = typeof(T) - }); - } - - foreach (var source in sourceFragment) - { - if (targetFragment.Keys.Contains(source.Key)) - { - WalkAndCompare(comparisonContext, source.Key, - () => comparisonContext - .GetComparer() - .Compare(source.Value, targetFragment[source.Key], comparisonContext)); - } - else - { - WalkAndAddOpenApiDifference( - comparisonContext, - source.Key, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - SourceValue = source.Value, - OpenApiComparedElementType = typeof(T) - }); - } - } - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiDifference.cs b/src/Microsoft.OpenApi/Services/OpenApiDifference.cs deleted file mode 100644 index bd6262c5b..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiDifference.cs +++ /dev/null @@ -1,39 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Difference point between two . - /// - public class OpenApiDifference - { - /// - /// The type of the element for which difference found. - /// - public Type OpenApiComparedElementType { get; set; } - - /// - /// The open api difference operation. - /// - public OpenApiDifferenceOperation OpenApiDifferenceOperation { get; set; } - - /// - /// Pointer to the location of the difference. - /// - public string Pointer { get; set; } - - /// - /// The source value. - /// - public object SourceValue { get; set; } - - /// - /// The target value. - /// - public object TargetValue { get; set; } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiDifferenceOperation.cs b/src/Microsoft.OpenApi/Services/OpenApiDifferenceOperation.cs deleted file mode 100644 index 896c0a4d3..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiDifferenceOperation.cs +++ /dev/null @@ -1,19 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -namespace Microsoft.OpenApi.Services -{ -#pragma warning disable CS1591 // Missing XML comment for publicly visible type or member - - /// - /// The open api difference operation. - /// - public enum OpenApiDifferenceOperation - { - Add, - Remove, - Update - } -#pragma warning restore CS1591 // Missing XML comment for publicly visible type or member - -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiDocumentComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiDocumentComparer.cs deleted file mode 100644 index 7ac8786b7..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiDocumentComparer.cs +++ /dev/null @@ -1,76 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiDocumentComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiDocument sourceDocument, - OpenApiDocument targetDocument, - ComparisonContext comparisonContext) - { - WalkAndCompare( - comparisonContext, - OpenApiConstants.Paths, - () => comparisonContext - .GetComparer() - .Compare(sourceDocument.Paths, targetDocument.Paths, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Components, - () => comparisonContext - .GetComparer() - .Compare(sourceDocument.Components, targetDocument.Components, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Components, - () => comparisonContext - .GetComparer>() - .Compare(sourceDocument.Servers, targetDocument.Servers, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Info, - () => comparisonContext - .GetComparer() - .Compare(sourceDocument.Info, targetDocument.Info, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Security, - () => comparisonContext - .GetComparer>() - .Compare(sourceDocument.SecurityRequirements, targetDocument.SecurityRequirements, - comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Tags, - () => comparisonContext - .GetComparer>() - .Compare(sourceDocument.Tags, targetDocument.Tags, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.ExternalDocs, - () => comparisonContext - .GetComparer() - .Compare(sourceDocument.ExternalDocs, targetDocument.ExternalDocs, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiEncodingComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiEncodingComparer.cs deleted file mode 100644 index ed7349299..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiEncodingComparer.cs +++ /dev/null @@ -1,65 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiEncodingComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiEncoding sourceEncoding, - OpenApiEncoding targetEncoding, - ComparisonContext comparisonContext) - { - if (sourceEncoding == null && targetEncoding == null) - { - return; - } - - if (sourceEncoding == null || targetEncoding == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceEncoding, - TargetValue = targetEncoding, - OpenApiComparedElementType = typeof(OpenApiEncoding), - Pointer = comparisonContext.PathString - }); - - return; - } - - WalkAndCompare(comparisonContext, OpenApiConstants.ContentType, - () => Compare(sourceEncoding.ContentType, targetEncoding.ContentType, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Explode, - () => Compare(sourceEncoding.Explode, targetEncoding.Explode, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.AllowReserved, - () => Compare(sourceEncoding.AllowReserved, targetEncoding.AllowReserved, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Style, - () => Compare(sourceEncoding.Style, targetEncoding.Style, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Headers, - () => comparisonContext - .GetComparer>() - .Compare(sourceEncoding.Headers, targetEncoding.Headers, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiExampleComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiExampleComparer.cs deleted file mode 100644 index aa9d33b06..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiExampleComparer.cs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiExampleComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiExample sourceExample, - OpenApiExample targetExample, - ComparisonContext comparisonContext) - { - if (sourceExample == null && targetExample == null) - { - return; - } - - if (sourceExample == null || targetExample == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceExample, - TargetValue = targetExample, - OpenApiComparedElementType = typeof(OpenApiExample), - Pointer = comparisonContext.PathString - }); - - return; - } - - if (sourceExample.Reference != null - && targetExample.Reference != null - && sourceExample.Reference.Id != targetExample.Reference.Id) - { - WalkAndAddOpenApiDifference( - comparisonContext, - OpenApiConstants.DollarRef, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceExample.Reference, - TargetValue = targetExample.Reference, - OpenApiComparedElementType = typeof(OpenApiReference) - }); - - return; - } - - if (sourceExample.Reference != null) - { - sourceExample = (OpenApiExample)comparisonContext.SourceDocument.ResolveReference( - sourceExample.Reference); - } - - if (targetExample.Reference != null) - { - targetExample = (OpenApiExample)comparisonContext.TargetDocument.ResolveReference( - targetExample.Reference); - } - - WalkAndCompare(comparisonContext, OpenApiConstants.Description, - () => Compare(sourceExample.Description, targetExample.Description, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Summary, - () => Compare(sourceExample.Summary, targetExample.Summary, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.ExternalValue, - () => Compare(sourceExample.ExternalValue, targetExample.ExternalValue, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Value, - () => comparisonContext - .GetComparer() - .Compare(sourceExample.Value, targetExample.Value, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiExternalDocsComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiExternalDocsComparer.cs deleted file mode 100644 index b5eea40e4..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiExternalDocsComparer.cs +++ /dev/null @@ -1,48 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiExternalDocsComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare(OpenApiExternalDocs sourceDocs, OpenApiExternalDocs targetDocs, - ComparisonContext comparisonContext) - { - if (sourceDocs == null && targetDocs == null) - { - return; - } - - if (sourceDocs == null || targetDocs == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceDocs, - TargetValue = targetDocs, - OpenApiComparedElementType = typeof(OpenApiExternalDocs), - Pointer = comparisonContext.PathString - }); - return; - } - - WalkAndCompare(comparisonContext, OpenApiConstants.Description, - () => Compare(sourceDocs.Description, targetDocs.Description, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Url, - () => Compare(sourceDocs.Url, targetDocs.Url, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiHeaderComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiHeaderComparer.cs deleted file mode 100644 index f80fa977c..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiHeaderComparer.cs +++ /dev/null @@ -1,123 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiHeaderComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiHeader sourceHeader, - OpenApiHeader targetHeader, - ComparisonContext comparisonContext) - { - if (sourceHeader == null && targetHeader == null) - { - return; - } - - if (sourceHeader == null || targetHeader == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceHeader, - TargetValue = targetHeader, - OpenApiComparedElementType = typeof(OpenApiHeader), - Pointer = comparisonContext.PathString - }); - - return; - } - - if (sourceHeader.Reference != null - && targetHeader.Reference != null - && sourceHeader.Reference.Id != targetHeader.Reference.Id) - { - WalkAndAddOpenApiDifference( - comparisonContext, - OpenApiConstants.DollarRef, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceHeader.Reference, - TargetValue = targetHeader.Reference, - OpenApiComparedElementType = typeof(OpenApiReference) - }); - - return; - } - - if (sourceHeader.Reference != null) - { - sourceHeader = (OpenApiHeader)comparisonContext.SourceDocument.ResolveReference( - sourceHeader.Reference); - } - - if (targetHeader.Reference != null) - { - targetHeader = (OpenApiHeader)comparisonContext.TargetDocument.ResolveReference( - targetHeader.Reference); - } - - WalkAndCompare(comparisonContext, OpenApiConstants.Description, - () => Compare(sourceHeader.Description, targetHeader.Description, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Required, - () => Compare(sourceHeader.Required, targetHeader.Required, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Deprecated, - () => Compare(sourceHeader.Deprecated, targetHeader.Deprecated, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.AllowEmptyValue, - () => Compare(sourceHeader.AllowEmptyValue, targetHeader.AllowEmptyValue, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Explode, - () => Compare(sourceHeader.Explode, targetHeader.Explode, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.AllowReserved, - () => Compare(sourceHeader.AllowReserved, targetHeader.AllowReserved, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Content, - () => comparisonContext - .GetComparer>() - .Compare(sourceHeader.Content, targetHeader.Content, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Schema, - () => comparisonContext - .GetComparer() - .Compare(sourceHeader.Schema, targetHeader.Schema, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Examples, - () => comparisonContext - .GetComparer>() - .Compare(sourceHeader.Examples, targetHeader.Examples, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Example, - () => comparisonContext - .GetComparer() - .Compare(sourceHeader.Example, targetHeader.Example, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiInfoComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiInfoComparer.cs deleted file mode 100644 index 0d391ed82..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiInfoComparer.cs +++ /dev/null @@ -1,71 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiInfoComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiInfo sourceInfo, - OpenApiInfo targetInfo, - ComparisonContext comparisonContext) - { - if (sourceInfo == null && targetInfo == null) - { - return; - } - - if (sourceInfo == null || targetInfo == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceInfo, - TargetValue = targetInfo, - OpenApiComparedElementType = typeof(OpenApiInfo), - Pointer = comparisonContext.PathString - }); - - return; - } - - WalkAndCompare(comparisonContext, OpenApiConstants.Title, - () => Compare(sourceInfo.Title, targetInfo.Title, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Description, - () => Compare(sourceInfo.Description, targetInfo.Description, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.TermsOfService, - () => Compare(sourceInfo.TermsOfService, targetInfo.TermsOfService, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Version, - () => Compare(sourceInfo.Version, targetInfo.Version, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Contact, - () => comparisonContext - .GetComparer() - .Compare(sourceInfo.Contact, targetInfo.Contact, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.License, - () => comparisonContext - .GetComparer() - .Compare(sourceInfo.License, targetInfo.License, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiLicenseComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiLicenseComparer.cs deleted file mode 100644 index ad0b06e17..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiLicenseComparer.cs +++ /dev/null @@ -1,51 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiLicenseComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiLicense sourceLicense, - OpenApiLicense targetLicense, - ComparisonContext comparisonContext) - { - if (sourceLicense == null && targetLicense == null) - { - return; - } - - if (sourceLicense == null || targetLicense == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceLicense, - TargetValue = targetLicense, - OpenApiComparedElementType = typeof(OpenApiLicense), - Pointer = comparisonContext.PathString - }); - - return; - } - - WalkAndCompare(comparisonContext, OpenApiConstants.Name, - () => Compare(sourceLicense.Name, targetLicense.Name, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Url, - () => Compare(sourceLicense.Url, targetLicense.Url, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiMediaTypeComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiMediaTypeComparer.cs deleted file mode 100644 index 69767e88e..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiMediaTypeComparer.cs +++ /dev/null @@ -1,75 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiMediaTypeComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiMediaType sourceMediaType, - OpenApiMediaType targetMediaType, - ComparisonContext comparisonContext) - { - if (sourceMediaType == null && targetMediaType == null) - { - return; - } - - if (sourceMediaType == null || targetMediaType == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceMediaType, - TargetValue = targetMediaType, - OpenApiComparedElementType = typeof(OpenApiMediaType), - Pointer = comparisonContext.PathString - }); - - return; - } - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Schema, - () => comparisonContext - .GetComparer() - .Compare(sourceMediaType.Schema, targetMediaType.Schema, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Encoding, - () => comparisonContext - .GetComparer>() - .Compare(sourceMediaType.Encoding, sourceMediaType.Encoding, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Examples, - () => comparisonContext - .GetComparer>() - .Compare(sourceMediaType.Examples, targetMediaType.Examples, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Example, - () => comparisonContext - .GetComparer() - .Compare(sourceMediaType.Example, targetMediaType.Example, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiOAuthFlowComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiOAuthFlowComparer.cs deleted file mode 100644 index 56bcfd47d..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiOAuthFlowComparer.cs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiOAuthFlowComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare(OpenApiOAuthFlow sourceFlow, OpenApiOAuthFlow targetFlow, - ComparisonContext comparisonContext) - { - if (sourceFlow == null && targetFlow == null) - { - return; - } - - if (sourceFlow == null || targetFlow == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceFlow, - TargetValue = targetFlow, - OpenApiComparedElementType = typeof(OpenApiOAuthFlow), - Pointer = comparisonContext.PathString - }); - - return; - } - - WalkAndCompare(comparisonContext, OpenApiConstants.AuthorizationUrl, - () => Compare(sourceFlow.AuthorizationUrl, targetFlow.AuthorizationUrl, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.TokenUrl, - () => Compare(sourceFlow.TokenUrl, targetFlow.TokenUrl, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.RefreshUrl, - () => Compare(sourceFlow.RefreshUrl, targetFlow.RefreshUrl, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Scopes, - () => Compare(sourceFlow.Scopes, targetFlow.Scopes, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiOAuthFlowsComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiOAuthFlowsComparer.cs deleted file mode 100644 index 8856107d3..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiOAuthFlowsComparer.cs +++ /dev/null @@ -1,73 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiOAuthFlowsComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiOAuthFlows sourceFlows, - OpenApiOAuthFlows targetFlows, - ComparisonContext comparisonContext) - { - if (sourceFlows == null && targetFlows == null) - { - return; - } - - if (sourceFlows == null || targetFlows == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceFlows, - TargetValue = targetFlows, - OpenApiComparedElementType = typeof(OpenApiOAuthFlows), - Pointer = comparisonContext.PathString - }); - - return; - } - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Implicit, - () => comparisonContext - .GetComparer() - .Compare(sourceFlows.Implicit, targetFlows.Implicit, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Password, - () => comparisonContext - .GetComparer() - .Compare(sourceFlows.Password, targetFlows.Password, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.ClientCredentials, - () => comparisonContext - .GetComparer() - .Compare(sourceFlows.ClientCredentials, targetFlows.ClientCredentials, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.AuthorizationCode, - () => comparisonContext - .GetComparer() - .Compare(sourceFlows.AuthorizationCode, targetFlows.AuthorizationCode, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiOperationComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiOperationComparer.cs deleted file mode 100644 index 64e38cff4..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiOperationComparer.cs +++ /dev/null @@ -1,96 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiOperationComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiOperation sourceOperation, - OpenApiOperation targetOperation, - ComparisonContext comparisonContext) - { - if (sourceOperation == null && targetOperation == null) - { - return; - } - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Summary, - () => Compare(sourceOperation?.Summary, targetOperation?.Summary, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Summary, - () => Compare(sourceOperation?.Description, targetOperation?.Description, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.OperationId, - () => Compare(sourceOperation?.OperationId, targetOperation?.OperationId, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Deprecated, - () => Compare(sourceOperation?.Deprecated, targetOperation?.Deprecated, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Parameters, - () => comparisonContext - .GetComparer>() - .Compare(sourceOperation?.Parameters, targetOperation?.Parameters, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.RequestBody, - () => comparisonContext - .GetComparer() - .Compare(sourceOperation?.RequestBody, targetOperation?.RequestBody, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Responses, - () => comparisonContext - .GetComparer>() - .Compare(sourceOperation?.Responses, targetOperation?.Responses, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Servers, - () => comparisonContext - .GetComparer>() - .Compare(sourceOperation?.Servers, targetOperation?.Servers, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Tags, - () => comparisonContext - .GetComparer>() - .Compare(sourceOperation?.Tags, targetOperation?.Tags, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Security, - () => comparisonContext - .GetComparer>() - .Compare(sourceOperation?.Security, targetOperation?.Security, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.ExternalDocs, - () => comparisonContext - .GetComparer() - .Compare(sourceOperation?.ExternalDocs, targetOperation?.ExternalDocs, comparisonContext)); - - // Compare CallBack - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiOperationsComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiOperationsComparer.cs deleted file mode 100644 index 78b8e0aa1..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiOperationsComparer.cs +++ /dev/null @@ -1,88 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using Microsoft.OpenApi.Extensions; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of - /// where TKey is and TValue is . - /// - public class OpenApiOperationsComparer : OpenApiComparerBase> - { - /// - /// Executes comparision against source and target - /// where TKey is and TValue is . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - IDictionary sourceOperations, - IDictionary targetOperations, - ComparisonContext comparisonContext) - { - if (sourceOperations == null && targetOperations == null) - { - return; - } - - if (sourceOperations == null || targetOperations == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceOperations, - TargetValue = targetOperations, - OpenApiComparedElementType = typeof(IDictionary), - Pointer = comparisonContext.PathString - }); - - return; - } - - var newOperationKeysInTarget = targetOperations.Keys.Except(sourceOperations.Keys).ToList(); - - foreach (var newOperationKeyInTarget in newOperationKeysInTarget) - { - WalkAndAddOpenApiDifference( - comparisonContext, - newOperationKeyInTarget.GetDisplayName(), - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - TargetValue = targetOperations[newOperationKeyInTarget], - OpenApiComparedElementType = typeof(OpenApiOperation) - }); - } - - foreach (var sourceOperation in sourceOperations) - { - if (targetOperations.Keys.Contains(sourceOperation.Key)) - { - WalkAndCompare(comparisonContext, sourceOperation.Key.GetDisplayName(), - () => comparisonContext - .GetComparer() - .Compare(sourceOperation.Value, targetOperations[sourceOperation.Key], comparisonContext)); - } - else - { - WalkAndAddOpenApiDifference( - comparisonContext, - sourceOperation.Key.GetDisplayName(), - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - SourceValue = sourceOperation.Value, - OpenApiComparedElementType = typeof(OpenApiOperation) - }); - } - } - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiOrderedListComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiOrderedListComparer.cs deleted file mode 100644 index b4ac53a5c..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiOrderedListComparer.cs +++ /dev/null @@ -1,90 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using Microsoft.OpenApi.Interfaces; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing where T is . - /// - public class OpenApiOrderedListComparer : OpenApiComparerBase> where T : IOpenApiSerializable - { - /// - /// Executes comparision against based on the order of the list for source and target - /// where T is . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - IList sourceFragment, - IList targetFragment, - ComparisonContext comparisonContext) - { - if (sourceFragment == null && targetFragment == null) - { - return; - } - - if (sourceFragment == null || targetFragment == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceFragment, - TargetValue = sourceFragment, - OpenApiComparedElementType = typeof(IList), - Pointer = comparisonContext.PathString - }); - - return; - } - - for (var i = 0; i < sourceFragment.Count; i++) - { - if (i >= targetFragment.Count) - { - WalkAndAddOpenApiDifference( - comparisonContext, - i.ToString(), - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - SourceValue = sourceFragment[i], - OpenApiComparedElementType = typeof(T) - }); - } - else - { - WalkAndCompare(comparisonContext, - i.ToString(), - () => comparisonContext - .GetComparer() - .Compare(sourceFragment[i], targetFragment[i], comparisonContext)); - } - } - - if (targetFragment.Count <= sourceFragment.Count) - { - return; - } - - // Loop through remaining elements in target that are not in source. - for (var i = sourceFragment.Count; i < targetFragment.Count; i++) - { - WalkAndAddOpenApiDifference( - comparisonContext, - i.ToString(), - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - TargetValue = targetFragment[i], - OpenApiComparedElementType = typeof(T) - }); - } - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiParameterComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiParameterComparer.cs deleted file mode 100644 index 1a9958e92..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiParameterComparer.cs +++ /dev/null @@ -1,132 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiParameterComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiParameter sourceParameter, - OpenApiParameter targetParameter, - ComparisonContext comparisonContext) - { - if (sourceParameter == null && targetParameter == null) - { - return; - } - - if (sourceParameter == null || targetParameter == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceParameter, - TargetValue = targetParameter, - OpenApiComparedElementType = typeof(OpenApiParameter), - Pointer = comparisonContext.PathString - }); - - return; - } - - if (sourceParameter.Reference != null - && targetParameter.Reference != null - && sourceParameter.Reference.Id != targetParameter.Reference.Id) - { - WalkAndAddOpenApiDifference( - comparisonContext, - OpenApiConstants.DollarRef, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceParameter.Reference, - TargetValue = targetParameter.Reference, - OpenApiComparedElementType = typeof(OpenApiReference) - }); - - return; - } - - if (sourceParameter.Reference != null) - { - sourceParameter = (OpenApiParameter)comparisonContext.SourceDocument.ResolveReference( - sourceParameter.Reference); - } - - if (targetParameter.Reference != null) - { - targetParameter = (OpenApiParameter)comparisonContext.TargetDocument.ResolveReference( - targetParameter.Reference); - } - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Content, - () => comparisonContext - .GetComparer>() - .Compare(sourceParameter.Content, targetParameter.Content, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Description, - () => Compare(sourceParameter.Description, targetParameter.Description, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Required, - () => Compare(sourceParameter.Required, targetParameter.Required, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Name, - () => Compare(sourceParameter.Name, targetParameter.Name, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Deprecated, - () => Compare(sourceParameter.Deprecated, targetParameter.Deprecated, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.AllowEmptyValue, - () => Compare(sourceParameter.AllowEmptyValue, targetParameter.AllowEmptyValue, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Explode, - () => Compare(sourceParameter.Explode, targetParameter.Explode, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.AllowReserved, - () => Compare(sourceParameter.AllowReserved, targetParameter.AllowReserved, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Style, - () => Compare(sourceParameter.Style, targetParameter.Style, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.In, - () => Compare(sourceParameter.In, targetParameter.In, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Schema, - () => comparisonContext - .GetComparer() - .Compare(sourceParameter.Schema, targetParameter.Schema, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Examples, - () => comparisonContext - .GetComparer>() - .Compare(sourceParameter.Examples, targetParameter.Examples, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Example, - () => comparisonContext - .GetComparer() - .Compare(sourceParameter.Example, targetParameter.Example, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiParametersComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiParametersComparer.cs deleted file mode 100644 index 81fd8905f..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiParametersComparer.cs +++ /dev/null @@ -1,101 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of - /// where T is. - /// - public class OpenApiParametersComparer : OpenApiComparerBase> - { - /// - /// Executes comparision against source and target - /// where T is. - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - IList sourceParameters, - IList targetParameters, - ComparisonContext comparisonContext) - { - if (sourceParameters == null && targetParameters == null) - { - return; - } - - if (sourceParameters == null || targetParameters == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceParameters, - TargetValue = targetParameters, - OpenApiComparedElementType = typeof(IList), - Pointer = comparisonContext.PathString - }); - - return; - } - - var removedParameters = sourceParameters?.Where( - sourceParam => !targetParameters.Any( - targetParam => sourceParam.Name == targetParam.Name && sourceParam.In == targetParam.In)).ToList(); - - for (var i = removedParameters.Count - 1; i >= 0; i--) - { - WalkAndAddOpenApiDifference( - comparisonContext, - sourceParameters.IndexOf(removedParameters[i]).ToString(), - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - SourceValue = removedParameters[i], - OpenApiComparedElementType = typeof(OpenApiParameter) - }); - } - - var newParametersInTarget = targetParameters?.Where( - targetParam => !sourceParameters.Any( - sourceParam => sourceParam.Name == targetParam.Name && sourceParam.In == targetParam.In)).ToList(); - - foreach (var newParameterInTarget in newParametersInTarget) - { - WalkAndAddOpenApiDifference( - comparisonContext, - targetParameters.IndexOf(newParameterInTarget).ToString(), - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - TargetValue = newParameterInTarget, - OpenApiComparedElementType = typeof(OpenApiParameter) - }); - } - - foreach (var sourceParameter in sourceParameters) - { - var targetParameter = targetParameters - .FirstOrDefault(param => param.Name == sourceParameter.Name && param.In == sourceParameter.In); - - if (targetParameter == null) - { - continue; - } - - WalkAndCompare( - comparisonContext, - targetParameters.IndexOf(targetParameter).ToString(), - () => comparisonContext - .GetComparer() - .Compare(sourceParameter, targetParameter, comparisonContext)); - } - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiPathItemComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiPathItemComparer.cs deleted file mode 100644 index 8e33dc8be..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiPathItemComparer.cs +++ /dev/null @@ -1,58 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiPathItemComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiPathItem sourcePathItem, - OpenApiPathItem targetPathItem, - ComparisonContext comparisonContext) - { - if (sourcePathItem == null && targetPathItem == null) - { - return; - } - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Summary, - () => Compare(sourcePathItem?.Summary, targetPathItem?.Description, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Description, - () => Compare(sourcePathItem?.Description, targetPathItem?.Description, comparisonContext)); - - comparisonContext.GetComparer>() - .Compare(sourcePathItem?.Operations, targetPathItem?.Operations, comparisonContext); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Parameters, - () => comparisonContext - .GetComparer>() - .Compare(sourcePathItem?.Parameters, targetPathItem?.Parameters, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Servers, - () => comparisonContext - .GetComparer>() - .Compare(sourcePathItem?.Servers, targetPathItem?.Servers, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiPathsComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiPathsComparer.cs deleted file mode 100644 index 83b0f58df..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiPathsComparer.cs +++ /dev/null @@ -1,86 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Linq; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiPathsComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiPaths sourcePaths, - OpenApiPaths targetPaths, - ComparisonContext comparisonContext) - { - if (sourcePaths == null && targetPaths == null) - { - return; - } - - if (sourcePaths == null || targetPaths == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourcePaths, - TargetValue = targetPaths, - OpenApiComparedElementType = typeof(OpenApiPaths), - Pointer = comparisonContext.PathString - }); - - return; - } - - var newPathKeysInTarget = targetPaths.Keys.Except(sourcePaths?.Keys).ToList(); - - foreach (var newPathKeyInTarget in newPathKeysInTarget) - { - WalkAndAddOpenApiDifference( - comparisonContext, - newPathKeyInTarget, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - TargetValue = targetPaths[newPathKeyInTarget], - OpenApiComparedElementType = typeof(OpenApiPathItem) - }); - } - - foreach (var sourcePathKey in sourcePaths.Keys) - { - if (targetPaths.ContainsKey(sourcePathKey)) - { - WalkAndCompare( - comparisonContext, - sourcePathKey, - () => comparisonContext - .GetComparer() - .Compare(sourcePaths[sourcePathKey], targetPaths[sourcePathKey], comparisonContext)); - } - else - { - WalkAndAddOpenApiDifference( - comparisonContext, - sourcePathKey, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - SourceValue = sourcePaths[sourcePathKey], - OpenApiComparedElementType = typeof(OpenApiPathItem) - }); - } - } - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiReferenceComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiReferenceComparer.cs deleted file mode 100644 index c3909b986..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiReferenceComparer.cs +++ /dev/null @@ -1,72 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using Microsoft.OpenApi.Interfaces; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiReferenceComparer : OpenApiComparerBase where T : IOpenApiReferenceable - { - /// - /// Compares object. - /// - /// The source. - /// The target. - /// The context under which to compare the objects. - public override void Compare( - OpenApiReference sourceReference, - OpenApiReference targetReference, - ComparisonContext comparisonContext) - { - if (sourceReference == null && targetReference == null) - { - return; - } - - if (sourceReference == null || targetReference == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceReference, - TargetValue = targetReference, - OpenApiComparedElementType = typeof(OpenApiReference), - Pointer = comparisonContext.PathString - }); - - return; - } - - if (sourceReference.Id != targetReference.Id || sourceReference.Type != targetReference.Type) - { - WalkAndAddOpenApiDifference( - comparisonContext, - OpenApiConstants.DollarRef, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceReference, - TargetValue = targetReference, - OpenApiComparedElementType = typeof(OpenApiReference) - }); - - return; - } - - var source = (T)comparisonContext.SourceDocument.ResolveReference( - sourceReference); - - var target = (T)comparisonContext.TargetDocument.ResolveReference( - targetReference); - - comparisonContext - .GetComparer() - .Compare(source, target, comparisonContext); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiRequestBodyComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiRequestBodyComparer.cs deleted file mode 100644 index dc6d5a297..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiRequestBodyComparer.cs +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiRequestBodyComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiRequestBody sourceRequestBody, - OpenApiRequestBody targetRequestBody, - ComparisonContext comparisonContext) - { - if (sourceRequestBody == null && targetRequestBody == null) - { - return; - } - - if (sourceRequestBody == null || targetRequestBody == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceRequestBody, - TargetValue = targetRequestBody, - OpenApiComparedElementType = typeof(OpenApiRequestBody), - Pointer = comparisonContext.PathString - }); - - return; - } - - if (sourceRequestBody.Reference != null - && targetRequestBody.Reference != null - && sourceRequestBody.Reference.Id != targetRequestBody.Reference.Id) - { - WalkAndAddOpenApiDifference( - comparisonContext, - OpenApiConstants.DollarRef, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceRequestBody.Reference, - TargetValue = targetRequestBody.Reference, - OpenApiComparedElementType = typeof(OpenApiReference) - }); - - return; - } - - if (sourceRequestBody.Reference != null) - { - sourceRequestBody = (OpenApiRequestBody)comparisonContext.SourceDocument.ResolveReference( - sourceRequestBody.Reference); - } - - if (targetRequestBody.Reference != null) - { - targetRequestBody = (OpenApiRequestBody)comparisonContext.TargetDocument.ResolveReference( - targetRequestBody.Reference); - } - - WalkAndCompare(comparisonContext, OpenApiConstants.Description, - () => Compare(sourceRequestBody.Description, targetRequestBody.Description, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Required, - () => Compare(sourceRequestBody.Required, targetRequestBody.Required, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Content, - () => comparisonContext - .GetComparer>() - .Compare(sourceRequestBody.Content, targetRequestBody.Content, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiResponseComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiResponseComparer.cs deleted file mode 100644 index 1b5af7170..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiResponseComparer.cs +++ /dev/null @@ -1,95 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiResponseComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiResponse sourceResponse, - OpenApiResponse targetResponse, - ComparisonContext comparisonContext) - { - if (sourceResponse == null && targetResponse == null) - { - return; - } - - if (sourceResponse == null || targetResponse == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceResponse, - TargetValue = targetResponse, - OpenApiComparedElementType = typeof(OpenApiResponse), - Pointer = comparisonContext.PathString - }); - - return; - } - - if (sourceResponse.Reference != null - && targetResponse.Reference != null - && sourceResponse.Reference.Id != targetResponse.Reference.Id) - { - WalkAndAddOpenApiDifference( - comparisonContext, - OpenApiConstants.DollarRef, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceResponse.Reference, - TargetValue = targetResponse.Reference, - OpenApiComparedElementType = typeof(OpenApiReference) - }); - - return; - } - - if (sourceResponse.Reference != null) - { - sourceResponse = (OpenApiResponse)comparisonContext.SourceDocument.ResolveReference( - sourceResponse.Reference); - } - - if (targetResponse.Reference != null) - { - targetResponse = (OpenApiResponse)comparisonContext.TargetDocument.ResolveReference( - targetResponse.Reference); - } - - WalkAndCompare(comparisonContext, OpenApiConstants.Description, - () => Compare(sourceResponse.Description, targetResponse.Description, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Content, - () => comparisonContext - .GetComparer>() - .Compare(sourceResponse.Content, targetResponse.Content, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Headers, - () => comparisonContext - .GetComparer>() - .Compare(sourceResponse.Headers, targetResponse.Headers, comparisonContext)); - - // To Do Compare Link - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiSchemaComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiSchemaComparer.cs deleted file mode 100644 index bbee51f41..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiSchemaComparer.cs +++ /dev/null @@ -1,177 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiSchemaComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiSchema sourceSchema, - OpenApiSchema targetSchema, - ComparisonContext comparisonContext) - { - if (sourceSchema == null && targetSchema == null) - { - return; - } - - if (sourceSchema == null || targetSchema == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceSchema, - TargetValue = targetSchema, - OpenApiComparedElementType = typeof(OpenApiSchema), - Pointer = comparisonContext.PathString - }); - - return; - } - - if (comparisonContext.SourceSchemaLoop.Contains(sourceSchema) - || comparisonContext.TargetSchemaLoop.Contains(targetSchema)) - { - return; // Loop detected, this schema has already been walked. - } - - comparisonContext.SourceSchemaLoop.Push(sourceSchema); - comparisonContext.TargetSchemaLoop.Push(targetSchema); - - if (sourceSchema.Reference != null - && targetSchema.Reference != null - && sourceSchema.Reference.Id != targetSchema.Reference.Id) - { - WalkAndAddOpenApiDifference( - comparisonContext, - OpenApiConstants.DollarRef, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceSchema.Reference?.Id, - TargetValue = targetSchema.Reference?.Id, - OpenApiComparedElementType = typeof(string) - }); - - return; - } - - if (sourceSchema.Reference != null) - { - sourceSchema = (OpenApiSchema)comparisonContext.SourceDocument.ResolveReference( - sourceSchema.Reference); - } - - if (targetSchema.Reference != null) - { - targetSchema = (OpenApiSchema)comparisonContext.TargetDocument.ResolveReference( - targetSchema.Reference); - } - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Title, - () => Compare(sourceSchema.Title, targetSchema.Title, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Maximum, - () => Compare(sourceSchema.Maximum, targetSchema.Maximum, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.MultipleOf, - () => Compare(sourceSchema.MultipleOf, targetSchema.MultipleOf, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.ExclusiveMaximum, - () => Compare(sourceSchema.ExclusiveMaximum, targetSchema.ExclusiveMaximum, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Minimum, - () => Compare(sourceSchema.Minimum, targetSchema.Minimum, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.ExclusiveMinimum, - () => Compare(sourceSchema.ExclusiveMinimum, targetSchema.ExclusiveMinimum, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.MaxLength, - () => Compare(sourceSchema.MaxLength, targetSchema.MaxLength, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.MinLength, - () => Compare(sourceSchema.MinLength, targetSchema.MinLength, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.MaxItems, - () => Compare(sourceSchema.MaxItems, targetSchema.MaxItems, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.MinItems, - () => Compare(sourceSchema.MinItems, targetSchema.MinItems, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Format, - () => Compare(sourceSchema.Format, targetSchema.Format, comparisonContext)); - - if (sourceSchema.Type != targetSchema.Type) - { - WalkAndAddOpenApiDifference( - comparisonContext, - OpenApiConstants.Type, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceSchema.Type, - TargetValue = targetSchema.Type, - OpenApiComparedElementType = typeof(string) - }); - - return; - } - - if (sourceSchema.Items != null && targetSchema.Items != null) - { - WalkAndCompare( - comparisonContext, - OpenApiConstants.Items, - () => comparisonContext - .GetComparer() - .Compare(sourceSchema.Items, targetSchema.Items, comparisonContext)); - } - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Properties, - () => comparisonContext - .GetComparer>() - .Compare(sourceSchema.Properties, - targetSchema.Properties, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.ExternalDocs, - () => comparisonContext - .GetComparer() - .Compare(sourceSchema.ExternalDocs, targetSchema.ExternalDocs, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Example, - () => comparisonContext - .GetComparer() - .Compare(sourceSchema.Example, targetSchema.Example, comparisonContext)); - - // To Do Compare schema.AllOf - // To Do Compare schema.AnyOf - - comparisonContext.SourceSchemaLoop.Pop(); - comparisonContext.TargetSchemaLoop.Pop(); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiSecurityRequirementComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiSecurityRequirementComparer.cs deleted file mode 100644 index 0753aecb7..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiSecurityRequirementComparer.cs +++ /dev/null @@ -1,92 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiSecurityRequirementComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiSecurityRequirement sourceSecurityRequirement, - OpenApiSecurityRequirement targetSecurityRequirement, - ComparisonContext comparisonContext) - { - if (sourceSecurityRequirement == null && targetSecurityRequirement == null) - { - return; - } - - if (sourceSecurityRequirement == null || targetSecurityRequirement == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceSecurityRequirement, - TargetValue = targetSecurityRequirement, - OpenApiComparedElementType = typeof(OpenApiSecurityRequirement), - Pointer = comparisonContext.PathString - }); - - return; - } - - var newSecuritySchemesInTarget = targetSecurityRequirement.Keys - .Where(targetReq => sourceSecurityRequirement.Keys.All( - sourceReq => sourceReq.Reference.Id != targetReq.Reference.Id)).ToList(); - - foreach (var newSecuritySchemeInTarget in newSecuritySchemesInTarget) - { - WalkAndAddOpenApiDifference( - comparisonContext, - newSecuritySchemeInTarget.Reference.Id, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - TargetValue = targetSecurityRequirement[newSecuritySchemeInTarget], - OpenApiComparedElementType = typeof(IList) - }); - } - - foreach (var sourceSecurityScheme in sourceSecurityRequirement.Keys) - { - var targetSecurityScheme = - targetSecurityRequirement.Keys.FirstOrDefault( - i => i.Reference.Id == sourceSecurityScheme.Reference.Id); - - if (targetSecurityScheme == null) - { - WalkAndAddOpenApiDifference( - comparisonContext, - sourceSecurityScheme.Reference.Id, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - SourceValue = sourceSecurityRequirement[sourceSecurityScheme], - OpenApiComparedElementType = typeof(IList) - }); - } - else - { - WalkAndCompare(comparisonContext, - sourceSecurityScheme.Reference.Id, - () => comparisonContext - .GetComparer() - .Compare(sourceSecurityScheme, targetSecurityScheme, comparisonContext)); - } - } - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiSecuritySchemeComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiSecuritySchemeComparer.cs deleted file mode 100644 index 68781f241..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiSecuritySchemeComparer.cs +++ /dev/null @@ -1,106 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiSecuritySchemeComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiSecurityScheme sourceSecurityScheme, - OpenApiSecurityScheme targetSecurityScheme, - ComparisonContext comparisonContext) - { - if (sourceSecurityScheme == null && targetSecurityScheme == null) - { - return; - } - - if (sourceSecurityScheme == null || targetSecurityScheme == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceSecurityScheme, - TargetValue = targetSecurityScheme, - OpenApiComparedElementType = typeof(OpenApiSecurityScheme), - Pointer = comparisonContext.PathString - }); - - return; - } - - if (sourceSecurityScheme.Reference != null - && targetSecurityScheme.Reference != null - && sourceSecurityScheme.Reference.Id != targetSecurityScheme.Reference.Id) - { - WalkAndAddOpenApiDifference( - comparisonContext, - OpenApiConstants.DollarRef, - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceSecurityScheme.Reference, - TargetValue = targetSecurityScheme.Reference, - OpenApiComparedElementType = typeof(OpenApiReference) - }); - - return; - } - - if (sourceSecurityScheme.Reference != null) - { - sourceSecurityScheme = (OpenApiSecurityScheme)comparisonContext.SourceDocument.ResolveReference( - sourceSecurityScheme.Reference); - } - - if (targetSecurityScheme.Reference != null) - { - targetSecurityScheme = (OpenApiSecurityScheme)comparisonContext.TargetDocument.ResolveReference( - targetSecurityScheme.Reference); - } - - WalkAndCompare(comparisonContext, OpenApiConstants.Description, - () => Compare(sourceSecurityScheme.Description, targetSecurityScheme.Description, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Type, - () => Compare(sourceSecurityScheme.Type, targetSecurityScheme.Type, - comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Name, - () => Compare(sourceSecurityScheme.Name, targetSecurityScheme.Name, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.In, - () => Compare(sourceSecurityScheme.In, targetSecurityScheme.In, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Scheme, - () => Compare(sourceSecurityScheme.Scheme, targetSecurityScheme.Scheme, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.BearerFormat, - () => Compare(sourceSecurityScheme.BearerFormat, targetSecurityScheme.BearerFormat, - comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.OpenIdConnectUrl, - () => Compare(sourceSecurityScheme.OpenIdConnectUrl, targetSecurityScheme.OpenIdConnectUrl, - comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Flows, - () => comparisonContext - .GetComparer() - .Compare(sourceSecurityScheme.Flows, targetSecurityScheme.Flows, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiServerComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiServerComparer.cs deleted file mode 100644 index 4ceabd768..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiServerComparer.cs +++ /dev/null @@ -1,59 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiServerComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiServer sourceServer, - OpenApiServer targetServer, - ComparisonContext comparisonContext) - { - if (sourceServer == null && targetServer == null) - { - return; - } - - if (sourceServer == null || targetServer == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceServer, - TargetValue = targetServer, - OpenApiComparedElementType = typeof(OpenApiServer), - Pointer = comparisonContext.PathString - }); - - return; - } - - WalkAndCompare(comparisonContext, OpenApiConstants.Description, - () => Compare(sourceServer.Description, targetServer.Description, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Url, - () => Compare(sourceServer.Url, targetServer.Url, comparisonContext)); - - WalkAndCompare( - comparisonContext, - OpenApiConstants.Variables, - () => comparisonContext - .GetComparer>() - .Compare(sourceServer.Variables, sourceServer.Variables, comparisonContext)); - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiServerVariableComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiServerVariableComparer.cs deleted file mode 100644 index 348366c6e..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiServerVariableComparer.cs +++ /dev/null @@ -1,54 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiServerVariableComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - OpenApiServerVariable sourceServerVariable, - OpenApiServerVariable targetServerVariable, - ComparisonContext comparisonContext) - { - if (sourceServerVariable == null && targetServerVariable == null) - { - return; - } - - if (sourceServerVariable == null || targetServerVariable == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceServerVariable, - TargetValue = targetServerVariable, - OpenApiComparedElementType = typeof(OpenApiServerVariable), - Pointer = comparisonContext.PathString - }); - - return; - } - - WalkAndCompare(comparisonContext, OpenApiConstants.Description, - () => Compare(sourceServerVariable.Description, targetServerVariable.Description, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Default, - () => Compare(sourceServerVariable.Default, targetServerVariable.Default, comparisonContext)); - - // To Do compare enum - // To Do compare extensions - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiServersComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiServersComparer.cs deleted file mode 100644 index 7428338cd..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiServersComparer.cs +++ /dev/null @@ -1,99 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of - /// where T is. - /// - public class OpenApiServersComparer : OpenApiComparerBase> - { - /// - /// Executes comparision against source and target - /// where T is. - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare( - IList sourceServers, - IList targetServers, - ComparisonContext comparisonContext) - { - if (sourceServers == null && targetServers == null) - { - return; - } - - if (sourceServers == null || targetServers == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceServers, - TargetValue = targetServers, - OpenApiComparedElementType = typeof(IList), - Pointer = comparisonContext.PathString - }); - - return; - } - - var removedServers = sourceServers.Where( - sourceServer => targetServers.All(targetServer => sourceServer.Url != targetServer.Url)).ToList(); - - for (var i = removedServers.Count - 1; i >= 0; i--) - { - WalkAndAddOpenApiDifference( - comparisonContext, - removedServers.IndexOf(removedServers[i]).ToString(), - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - SourceValue = removedServers[i], - OpenApiComparedElementType = typeof(OpenApiServer) - }); - } - - var newServersInTarget = targetServers.Where( - targetServer => sourceServers.All(sourceServer => sourceServer.Url != targetServer.Url)).ToList(); - - foreach (var newServerInTarget in newServersInTarget) - { - WalkAndAddOpenApiDifference( - comparisonContext, - targetServers.IndexOf(newServerInTarget).ToString(), - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - TargetValue = newServerInTarget, - OpenApiComparedElementType = typeof(OpenApiServer) - }); - } - - foreach (var sourceServer in sourceServers) - { - var targetServer = targetServers - .FirstOrDefault(server => server.Url == sourceServer.Url); - - if (targetServer == null) - { - continue; - } - - WalkAndCompare( - comparisonContext, - targetServers.IndexOf(targetServer).ToString(), - () => comparisonContext - .GetComparer() - .Compare(sourceServer, targetServer, comparisonContext)); - } - } - } -} diff --git a/src/Microsoft.OpenApi/Services/OpenApiTagComparer.cs b/src/Microsoft.OpenApi/Services/OpenApiTagComparer.cs deleted file mode 100644 index bc9eb1d5d..000000000 --- a/src/Microsoft.OpenApi/Services/OpenApiTagComparer.cs +++ /dev/null @@ -1,55 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using Microsoft.OpenApi.Models; - -namespace Microsoft.OpenApi.Services -{ - /// - /// Defines behavior for comparing properties of . - /// - public class OpenApiTagComparer : OpenApiComparerBase - { - /// - /// Executes comparision against source and target . - /// - /// The source. - /// The target. - /// Context under which to compare the source and target. - public override void Compare(OpenApiTag sourceTag, OpenApiTag targetTag, ComparisonContext comparisonContext) - { - if (sourceTag == null && targetTag == null) - { - return; - } - - if (sourceTag == null || targetTag == null) - { - comparisonContext.AddOpenApiDifference( - new OpenApiDifference - { - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - SourceValue = sourceTag, - TargetValue = targetTag, - OpenApiComparedElementType = typeof(OpenApiTag), - Pointer = comparisonContext.PathString - }); - - return; - } - - WalkAndCompare( - comparisonContext, - OpenApiConstants.ExternalDocs, - () => comparisonContext - .GetComparer() - .Compare(sourceTag.ExternalDocs, targetTag.ExternalDocs, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Description, - () => Compare(sourceTag.Description, targetTag.Description, comparisonContext)); - - WalkAndCompare(comparisonContext, OpenApiConstants.Name, - () => Compare(sourceTag.Name, targetTag.Name, comparisonContext)); - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 1c74ffab7..b50592076 100755 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -934,15 +934,6 @@ namespace Microsoft.OpenApi.Models } namespace Microsoft.OpenApi.Services { - public class ComparisonContext - { - public ComparisonContext(Microsoft.OpenApi.Services.OpenApiComparerFactory openApiComparerFactory, Microsoft.OpenApi.Models.OpenApiDocument sourceDocument, Microsoft.OpenApi.Models.OpenApiDocument targetDocument) { } - public System.Collections.Generic.IEnumerable OpenApiDifferences { get; } - public string PathString { get; } - public void AddOpenApiDifference(Microsoft.OpenApi.Services.OpenApiDifference openApiDifference) { } - public void Enter(string segment) { } - public void Exit() { } - } public class CurrentKeys { public CurrentKeys() { } @@ -958,199 +949,11 @@ namespace Microsoft.OpenApi.Services public string Response { get; set; } public string ServerVariable { get; } } - public class OpenApiAnyComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiAnyComparer() { } - public override void Compare(Microsoft.OpenApi.Any.IOpenApiAny source, Microsoft.OpenApi.Any.IOpenApiAny target, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public static class OpenApiComparer - { - public static System.Collections.Generic.IEnumerable Compare(Microsoft.OpenApi.Models.OpenApiDocument source, Microsoft.OpenApi.Models.OpenApiDocument target) { } - } - public abstract class OpenApiComparerBase - { - protected OpenApiComparerBase() { } - public abstract void Compare(T sourceFragment, T targetFragment, Microsoft.OpenApi.Services.ComparisonContext comparisonContext); - protected virtual void WalkAndCompare(Microsoft.OpenApi.Services.ComparisonContext comparisonContext, string segment, System.Action compare) { } - } - public class OpenApiComparerFactory - { - public OpenApiComparerFactory() { } - protected void AddComparer(Microsoft.OpenApi.Services.OpenApiComparerBase comparer) { } - } - public class OpenApiComponentsComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiComponentsComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiComponents sourceComponents, Microsoft.OpenApi.Models.OpenApiComponents targetComponents, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiContactComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiContactComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiContact sourceContact, Microsoft.OpenApi.Models.OpenApiContact targetContact, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiDictionaryComparer : Microsoft.OpenApi.Services.OpenApiComparerBase> - where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable - { - public OpenApiDictionaryComparer() { } - public override void Compare(System.Collections.Generic.IDictionary sourceFragment, System.Collections.Generic.IDictionary targetFragment, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiDifference - { - public OpenApiDifference() { } - public System.Type OpenApiComparedElementType { get; set; } - public Microsoft.OpenApi.Services.OpenApiDifferenceOperation OpenApiDifferenceOperation { get; set; } - public string Pointer { get; set; } - public object SourceValue { get; set; } - public object TargetValue { get; set; } - } - public enum OpenApiDifferenceOperation - { - Add = 0, - Remove = 1, - Update = 2, - } - public class OpenApiDocumentComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiDocumentComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiDocument sourceDocument, Microsoft.OpenApi.Models.OpenApiDocument targetDocument, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiEncodingComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiEncodingComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiEncoding sourceEncoding, Microsoft.OpenApi.Models.OpenApiEncoding targetEncoding, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiExampleComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiExampleComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiExample sourceExample, Microsoft.OpenApi.Models.OpenApiExample targetExample, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiExternalDocsComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiExternalDocsComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiExternalDocs sourceDocs, Microsoft.OpenApi.Models.OpenApiExternalDocs targetDocs, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiHeaderComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiHeaderComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiHeader sourceHeader, Microsoft.OpenApi.Models.OpenApiHeader targetHeader, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiInfoComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiInfoComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiInfo sourceInfo, Microsoft.OpenApi.Models.OpenApiInfo targetInfo, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiLicenseComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiLicenseComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiLicense sourceLicense, Microsoft.OpenApi.Models.OpenApiLicense targetLicense, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiMediaTypeComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiMediaTypeComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiMediaType sourceMediaType, Microsoft.OpenApi.Models.OpenApiMediaType targetMediaType, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiOAuthFlowComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiOAuthFlowComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiOAuthFlow sourceFlow, Microsoft.OpenApi.Models.OpenApiOAuthFlow targetFlow, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiOAuthFlowsComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiOAuthFlowsComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiOAuthFlows sourceFlows, Microsoft.OpenApi.Models.OpenApiOAuthFlows targetFlows, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiOperationComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiOperationComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiOperation sourceOperation, Microsoft.OpenApi.Models.OpenApiOperation targetOperation, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiOperationsComparer : Microsoft.OpenApi.Services.OpenApiComparerBase> - { - public OpenApiOperationsComparer() { } - public override void Compare(System.Collections.Generic.IDictionary sourceOperations, System.Collections.Generic.IDictionary targetOperations, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiOrderedListComparer : Microsoft.OpenApi.Services.OpenApiComparerBase> - where T : Microsoft.OpenApi.Interfaces.IOpenApiSerializable - { - public OpenApiOrderedListComparer() { } - public override void Compare(System.Collections.Generic.IList sourceFragment, System.Collections.Generic.IList targetFragment, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiParameterComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiParameterComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiParameter sourceParameter, Microsoft.OpenApi.Models.OpenApiParameter targetParameter, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiParametersComparer : Microsoft.OpenApi.Services.OpenApiComparerBase> - { - public OpenApiParametersComparer() { } - public override void Compare(System.Collections.Generic.IList sourceParameters, System.Collections.Generic.IList targetParameters, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiPathItemComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiPathItemComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiPathItem sourcePathItem, Microsoft.OpenApi.Models.OpenApiPathItem targetPathItem, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiPathsComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiPathsComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiPaths sourcePaths, Microsoft.OpenApi.Models.OpenApiPaths targetPaths, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiReferenceComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - where T : Microsoft.OpenApi.Interfaces.IOpenApiReferenceable - { - public OpenApiReferenceComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiReference sourceReference, Microsoft.OpenApi.Models.OpenApiReference targetReference, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } public class OpenApiReferenceError : Microsoft.OpenApi.Models.OpenApiError { public OpenApiReferenceError(Microsoft.OpenApi.Exceptions.OpenApiException exception) { } public OpenApiReferenceError(Microsoft.OpenApi.Models.OpenApiReference reference, string message) { } } - public class OpenApiRequestBodyComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiRequestBodyComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiRequestBody sourceRequestBody, Microsoft.OpenApi.Models.OpenApiRequestBody targetRequestBody, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiResponseComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiResponseComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiResponse sourceResponse, Microsoft.OpenApi.Models.OpenApiResponse targetResponse, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiSchemaComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiSchemaComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiSchema sourceSchema, Microsoft.OpenApi.Models.OpenApiSchema targetSchema, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiSecurityRequirementComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiSecurityRequirementComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiSecurityRequirement sourceSecurityRequirement, Microsoft.OpenApi.Models.OpenApiSecurityRequirement targetSecurityRequirement, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiSecuritySchemeComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiSecuritySchemeComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiSecurityScheme sourceSecurityScheme, Microsoft.OpenApi.Models.OpenApiSecurityScheme targetSecurityScheme, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiServerComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiServerComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiServer sourceServer, Microsoft.OpenApi.Models.OpenApiServer targetServer, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiServerVariableComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiServerVariableComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiServerVariable sourceServerVariable, Microsoft.OpenApi.Models.OpenApiServerVariable targetServerVariable, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiServersComparer : Microsoft.OpenApi.Services.OpenApiComparerBase> - { - public OpenApiServersComparer() { } - public override void Compare(System.Collections.Generic.IList sourceServers, System.Collections.Generic.IList targetServers, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } - public class OpenApiTagComparer : Microsoft.OpenApi.Services.OpenApiComparerBase - { - public OpenApiTagComparer() { } - public override void Compare(Microsoft.OpenApi.Models.OpenApiTag sourceTag, Microsoft.OpenApi.Models.OpenApiTag targetTag, Microsoft.OpenApi.Services.ComparisonContext comparisonContext) { } - } public abstract class OpenApiVisitorBase { protected OpenApiVisitorBase() { } diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiComparerTestCases.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiComparerTestCases.cs deleted file mode 100644 index ca2b1cb9f..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiComparerTestCases.cs +++ /dev/null @@ -1,2417 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System; -using System.Collections.Generic; -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; - -namespace Microsoft.OpenApi.Tests.Services -{ - internal static class OpenApiComparerTestCases - { - public static IEnumerable GetTestCasesForOpenApiComparerShouldSucceed() - { - // New and removed paths - yield return new object[] - { - "New And Removed Paths", - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - } - } - } - } - } - }, - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/newPath", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - } - } - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/paths/~1newPath", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiPathItem), - SourceValue = null, - TargetValue = new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - } - } - } - }, - new OpenApiDifference - { - Pointer = "#/paths/~1test", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiPathItem), - TargetValue = null, - SourceValue = new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - } - } - } - } - } - }; - - // New and removed operations - yield return new object[] - { - "New And Removed Operations", - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - }, - { - OperationType.Post, new OpenApiOperation() - } - } - } - } - } - }, - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - }, - { - OperationType.Patch, new OpenApiOperation() - } - } - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/paths/~1test/patch", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiOperation), - SourceValue = null, - TargetValue = new OpenApiOperation() - }, - new OpenApiDifference - { - Pointer = "#/paths/~1test/post", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiOperation), - TargetValue = null, - SourceValue = new OpenApiOperation() - } - } - }; - - // Empty target document paths - yield return new object[] - { - "Empty target document", - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - } - } - } - } - } - }, - new OpenApiDocument(), - new List - { - new OpenApiDifference - { - Pointer = "#/paths", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiPaths), - SourceValue = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - } - } - } - } - }, - TargetValue = null - } - } - }; - - // Empty source document - yield return new object[] - { - "Empty source document", - new OpenApiDocument(), - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/newPath", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - } - } - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/paths", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiPaths), - SourceValue = null, - TargetValue = new OpenApiPaths - { - { - "/newPath", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - } - } - } - } - } - } - } - }; - - // Empty target operations - yield return new object[] - { - "Empty target operations", - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - }, - { - OperationType.Post, new OpenApiOperation() - } - } - } - } - } - }, - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary() - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/paths/~1test/get", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiOperation), - TargetValue = null, - SourceValue = new OpenApiOperation() - }, - new OpenApiDifference - { - Pointer = "#/paths/~1test/post", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiOperation), - TargetValue = null, - SourceValue = new OpenApiOperation() - } - } - }; - - // Empty source operations - yield return new object[] - { - "Empty source operations", - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary() - } - } - } - }, - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - }, - { - OperationType.Patch, new OpenApiOperation() - } - } - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/paths/~1test/get", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiOperation), - SourceValue = null, - TargetValue = new OpenApiOperation() - }, - new OpenApiDifference - { - Pointer = "#/paths/~1test/patch", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiOperation), - SourceValue = null, - TargetValue = new OpenApiOperation() - } - } - }; - - // Identical source and target - yield return new object[] - { - "Identical source and target documents", - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - }, - { - OperationType.Post, new OpenApiOperation() - } - } - } - } - } - }, - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - }, - { - OperationType.Post, new OpenApiOperation() - } - } - } - } - } - }, - new List() - }; - - // Differences in summary and description - yield return new object[] - { - "Differences in summary and description", - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - }, - { - OperationType.Post, new OpenApiOperation() - } - } - } - } - } - }, - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "updated", - Description = "updated", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation() - }, - { - OperationType.Post, new OpenApiOperation() - } - } - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/paths/~1test/summary", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "test", - TargetValue = "updated" - }, - new OpenApiDifference - { - Pointer = "#/paths/~1test/description", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "test", - TargetValue = "updated" - } - } - }; - - // Differences in schema - yield return new object[] - { - "Differences in schema", - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation - { - Parameters = new List - { - new OpenApiParameter - { - Name = "Test Parameter", - In = ParameterLocation.Path, - Schema = new OpenApiSchema - { - Title = "title1", - MultipleOf = 3, - Maximum = 42, - ExclusiveMinimum = true, - Minimum = 10, - Default = new OpenApiInteger(15), - Type = "integer", - - Nullable = true, - ExternalDocs = new OpenApiExternalDocs - { - Url = new Uri("http://example.com/externalDocs") - }, - - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - } - } - } - }, - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - }, - Example = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - }, - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation - { - Parameters = new List - { - new OpenApiParameter - { - Name = "Test Parameter", - In = ParameterLocation.Path, - Schema = new OpenApiSchema - { - Title = "title1", - MultipleOf = 3, - Maximum = 42, - ExclusiveMinimum = true, - Minimum = 10, - Default = new OpenApiInteger(15), - Type = "integer", - - Nullable = true, - ExternalDocs = new OpenApiExternalDocs - { - Url = new Uri("http://example.com/externalDocs") - }, - - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - } - } - } - }, - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - }, - Example = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["relupdate"] = new OpenApiString("sampleRel1") - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/paths/~1test/get/parameters/0/schema/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = "#/paths/~1test/get/parameters/0/schema/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/paths/~1test/get/parameters/0/schema/properties/property6/properties/property6/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = - "#/paths/~1test/get/parameters/0/schema/properties/property6/properties/property6/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/paths/~1test/get/parameters/0/schema/properties/property6/properties/property6/example", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(IOpenApiAny), - SourceValue = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - }, - TargetValue = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["relupdate"] = new OpenApiString("sampleRel1") - } - } - } - }, - new OpenApiDifference - { - Pointer = "#/paths/~1test/get/parameters/0/schema/example", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(IOpenApiAny), - SourceValue = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - }, - TargetValue = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["relupdate"] = new OpenApiString("sampleRel1") - } - } - } - }, - new OpenApiDifference - { - Pointer = "#/components/schemas/schemaObject1/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = "#/components/schemas/schemaObject1/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/components/schemas/schemaObject1/properties/property6/properties/property6/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = - "#/components/schemas/schemaObject1/properties/property6/properties/property6/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/components/schemas/schemaObject1/properties/property6/properties/property6/example", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(IOpenApiAny), - SourceValue = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - }, - TargetValue = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["relupdate"] = new OpenApiString("sampleRel1") - } - } - } - }, - new OpenApiDifference - { - Pointer = "#/components/schemas/schemaObject1/example", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(IOpenApiAny), - SourceValue = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - }, - TargetValue = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["relupdate"] = new OpenApiString("sampleRel1") - } - } - } - }, - new OpenApiDifference - { - Pointer = - "#/components/schemas/schemaObject2/properties/property6/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = - "#/components/schemas/schemaObject2/properties/property6/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = "#/components/schemas/schemaObject2/properties/property6/example", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(IOpenApiAny), - SourceValue = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - }, - TargetValue = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["relupdate"] = new OpenApiString("sampleRel1") - } - } - } - } - } - }; - - // Differences in request and response - yield return new object[] - { - "Differences in request and response", - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation - { - RequestBody = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/xml"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - }, - Examples = new Dictionary - { - { - "example1", new OpenApiExample - { - Reference = new OpenApiReference - { - Id = "example1", - Type = ReferenceType.Example - } - } - } - } - } - } - }, - Responses = new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "An updated complex object array response", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - } - } - } - } - } - } - } - }, - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - Examples = new Dictionary - { - ["example1"] = new OpenApiExample - { - Value = new OpenApiObject - { - ["versions"] = new OpenApiArray - { - new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - } - } - }, - ["example3"] = new OpenApiExample - { - Value = new OpenApiObject - { - ["versions"] = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - } - } - } - } - }, - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation - { - RequestBody = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/xml"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - }, - Examples = new Dictionary - { - { - "example1", new OpenApiExample - { - Reference = new OpenApiReference - { - Id = "example1", - Type = ReferenceType.Example - } - } - } - } - } - } - }, - Responses = new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "An updated complex object array response", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - }, - { - "400", - new OpenApiResponse - { - Description = "An updated complex object array response", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - } - } - } - } - } - } - } - } - }, - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - Examples = new Dictionary - { - ["example1"] = new OpenApiExample - { - Value = new OpenApiObject - { - ["versions"] = new OpenApiArray - { - new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["relupdate"] = new OpenApiString("sampleRel1") - } - } - } - } - } - }, - ["example3"] = new OpenApiExample - { - Value = new OpenApiObject - { - ["versions"] = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - } - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/paths/~1test/get/requestBody/content/application~1xml/schema/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = "#/paths/~1test/get/requestBody/content/application~1xml/schema/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/paths/~1test/get/requestBody/content/application~1xml/schema/properties/property6/properties/property6/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = - "#/paths/~1test/get/requestBody/content/application~1xml/schema/properties/property6/properties/property6/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = "#/paths/~1test/get/requestBody/content/application~1xml/examples/example1/value", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(IOpenApiAny), - SourceValue = new OpenApiObject - { - ["versions"] = new OpenApiArray - { - new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - } - }, - TargetValue = new OpenApiObject - { - ["versions"] = new OpenApiArray - { - new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["relupdate"] = new OpenApiString("sampleRel1") - } - } - } - } - } - }, - new OpenApiDifference - { - Pointer = "#/paths/~1test/get/responses/400", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiResponse), - SourceValue = null, - TargetValue = new OpenApiResponse - { - Description = "An updated complex object array response", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - } - }, - new OpenApiDifference - { - Pointer = - "#/paths/~1test/get/responses/200/content/application~1json/schema/items/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = - "#/paths/~1test/get/responses/200/content/application~1json/schema/items/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/paths/~1test/get/responses/200/content/application~1json/schema/items/properties/property6/properties/property6/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = - "#/paths/~1test/get/responses/200/content/application~1json/schema/items/properties/property6/properties/property6/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = "#/components/schemas/schemaObject1/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = "#/components/schemas/schemaObject1/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/components/schemas/schemaObject1/properties/property6/properties/property6/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = - "#/components/schemas/schemaObject1/properties/property6/properties/property6/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/components/schemas/schemaObject2/properties/property6/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = - "#/components/schemas/schemaObject2/properties/property6/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = "#/components/examples/example1/value", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(IOpenApiAny), - SourceValue = new OpenApiObject - { - ["versions"] = new OpenApiArray - { - new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - } - }, - TargetValue = new OpenApiObject - { - ["versions"] = new OpenApiArray - { - new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["relupdate"] = new OpenApiString("sampleRel1") - } - } - } - } - } - } - } - }; - - // Differences in tags and security requirements - yield return new object[] - { - "Differences in tags and security requirements", - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation - { - RequestBody = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/xml"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - Responses = new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "An updated complex object array response", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - } - }, - Security = new List - { - new OpenApiSecurityRequirement - { - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "scheme1" - } - } - ] = new List() - } - } - } - } - } - } - } - }, - Tags = new List - { - new OpenApiTag - { - Description = "test description", - Name = "Tag1", - ExternalDocs = new OpenApiExternalDocs - { - Description = "test description", - Url = new Uri("http://localhost/doc") - } - }, - new OpenApiTag - { - Description = "test description", - Name = "Tag2", - ExternalDocs = new OpenApiExternalDocs - { - Description = "test description", - Url = new Uri("http://localhost/doc") - } - } - }, - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - SecuritySchemes = new Dictionary - { - { - "scheme1", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test", - Flows = new OpenApiOAuthFlows - { - Implicit = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/1") - }, - AuthorizationCode = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/2") - } - } - } - }, - { - "scheme2", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test" - } - }, - { - "scheme3", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test" - } - } - } - }, - SecurityRequirements = new List - { - new OpenApiSecurityRequirement - { - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "scheme1" - } - } - ] = new List() - }, - new OpenApiSecurityRequirement - { - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "scheme2" - } - } - ] = new List() - }, - new OpenApiSecurityRequirement - { - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "scheme3" - } - } - ] = new List() - } - } - }, - new OpenApiDocument - { - Paths = new OpenApiPaths - { - { - "/test", new OpenApiPathItem - { - Summary = "test", - Description = "test", - Operations = new Dictionary - { - { - OperationType.Get, new OpenApiOperation - { - RequestBody = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/xml"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - Responses = new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "An updated complex object array response", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - } - }, - Security = new List - { - new OpenApiSecurityRequirement - { - { - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "scheme1" - } - }, - new List() - } - }, - new OpenApiSecurityRequirement - { - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "scheme4" - } - } - ] = new List() - } - } - } - } - } - } - } - }, - Tags = new List - { - new OpenApiTag - { - Description = "test description updated", - Name = "Tag1", - ExternalDocs = new OpenApiExternalDocs - { - Description = "test description", - Url = new Uri("http://localhost/doc") - } - } - }, - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - SecuritySchemes = new Dictionary - { - { - "scheme1", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test", - Flows = new OpenApiOAuthFlows - { - Implicit = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/3") - }, - ClientCredentials = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/2") - } - } - } - }, - { - "scheme2", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test" - } - }, - { - "scheme4", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test" - } - } - } - }, - SecurityRequirements = new List - { - new OpenApiSecurityRequirement - { - { - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "scheme1" - } - }, - new List() - }, - { - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "scheme2" - } - }, - new List() - } - }, - new OpenApiSecurityRequirement - { - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "scheme4" - } - } - ] = new List() - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/paths/~1test/get/security/0/scheme1/flows/implicit/authorizationUrl", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(Uri), - SourceValue = new Uri("http://localhost/1"), - TargetValue = new Uri("http://localhost/3") - }, - new OpenApiDifference - { - Pointer = - "#/paths/~1test/get/security/0/scheme1/flows/clientCredentials", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiOAuthFlow), - SourceValue = null, - TargetValue = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/2") - } - }, - new OpenApiDifference - { - Pointer = "#/paths/~1test/get/security/0/scheme1/flows/authorizationCode", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiOAuthFlow), - SourceValue = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/2") - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/paths/~1test/get/security/1", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSecurityRequirement), - SourceValue = null, - TargetValue = new OpenApiSecurityRequirement - { - { - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "scheme4" - } - }, - new List() - } - } - }, - new OpenApiDifference - { - Pointer = - "#/components/securitySchemes/scheme4", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSecurityScheme), - SourceValue = null, - TargetValue = new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test", - Reference = new OpenApiReference() - { - Type = ReferenceType.SecurityScheme, - Id = "scheme4" - } - } - }, - new OpenApiDifference - { - Pointer = "#/components/securitySchemes/scheme1/flows/implicit/authorizationUrl", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(Uri), - SourceValue = new Uri("http://localhost/1"), - TargetValue = new Uri("http://localhost/3") - }, - new OpenApiDifference - { - Pointer = - "#/components/securitySchemes/scheme1/flows/clientCredentials", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiOAuthFlow), - SourceValue = null, - TargetValue = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/2") - } - }, - new OpenApiDifference - { - Pointer = "#/components/securitySchemes/scheme1/flows/authorizationCode", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiOAuthFlow), - SourceValue = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/2") - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/components/securitySchemes/scheme3", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSecurityScheme), - SourceValue = new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test", - Reference = new OpenApiReference() - { - Type = ReferenceType.SecurityScheme, - Id = "scheme3" - } - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = "#/security/0/scheme2", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(IList), - SourceValue = null, - TargetValue = new List() - }, - new OpenApiDifference - { - Pointer = "#/security/0/scheme1/flows/implicit/authorizationUrl", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(Uri), - SourceValue = new Uri("http://localhost/1"), - TargetValue = new Uri("http://localhost/3") - }, - new OpenApiDifference - { - Pointer = - "#/security/0/scheme1/flows/clientCredentials", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiOAuthFlow), - SourceValue = null, - TargetValue = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/2") - } - }, - new OpenApiDifference - { - Pointer = "#/security/0/scheme1/flows/authorizationCode", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiOAuthFlow), - SourceValue = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/2") - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = "#/security/1/scheme4", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(IList), - SourceValue = null, - TargetValue = new List() - }, - new OpenApiDifference - { - Pointer = - "#/security/1/scheme2", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(IList), - SourceValue = new List(), - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/security/2", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSecurityRequirement), - SourceValue = new OpenApiSecurityRequirement - { - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "scheme3" - } - } - ] = new List() - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = "#/tags/0/description", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "test description", - TargetValue = "test description updated" - }, - new OpenApiDifference - { - Pointer = "#/tags/1", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiTag), - SourceValue = new OpenApiTag - { - Description = "test description", - Name = "Tag2", - ExternalDocs = new OpenApiExternalDocs - { - Description = "test description", - Url = new Uri("http://localhost/doc") - } - }, - TargetValue = null - } - } - }; - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiComparerTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiComparerTests.cs deleted file mode 100644 index 5f21c6b7d..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiComparerTests.cs +++ /dev/null @@ -1,89 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Microsoft.OpenApi.Interfaces; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.OpenApi.Tests.Services -{ - [Collection("DefaultSettings")] - public class OpenApiComparerTests - { - private readonly ITestOutputHelper _output; - - public OpenApiComparerTests(ITestOutputHelper output) - { - _output = output; - } - - [Theory] - [MemberData( - nameof(OpenApiComparerTestCases.GetTestCasesForOpenApiComparerShouldSucceed), - MemberType = typeof(OpenApiComparerTestCases))] - public void OpenApiComparerShouldSucceed( - string testCaseName, - OpenApiDocument source, - OpenApiDocument target, - List expectedDifferences) - { - _output.WriteLine(testCaseName); - - // Ensure that all references are corrected to mirror what happens in the MapNode. - new OpenApiWalker(new SelfReferenceFixer()).Walk(source); - new OpenApiWalker(new SelfReferenceFixer()).Walk(target); - - var differences = OpenApiComparer.Compare(source, target).ToList(); - - var actualPaths = differences.Select(x => x.Pointer).ToList(); - var expectedPaths = expectedDifferences.Select(x => x.Pointer).ToList(); - - differences.Count().Should().Be(expectedDifferences.Count); - - differences.Should().BeEquivalentTo(expectedDifferences); - } - - /// - /// MapNode adds a self-reference for all IOpenApiReferenceable instances. - /// This visitor mimics that behavior for C# created objects. - /// - internal class SelfReferenceFixer : OpenApiVisitorBase - { - public override void Visit(OpenApiComponents components) - { - UpdateNullReferences(components.Schemas, ReferenceType.Schema); - UpdateNullReferences(components.Responses, ReferenceType.Response); - UpdateNullReferences(components.Parameters, ReferenceType.Parameter); - UpdateNullReferences(components.Examples, ReferenceType.Example); - UpdateNullReferences(components.RequestBodies, ReferenceType.RequestBody); - UpdateNullReferences(components.Headers, ReferenceType.Header); - UpdateNullReferences(components.SecuritySchemes, ReferenceType.SecurityScheme); - UpdateNullReferences(components.Links, ReferenceType.Link); - UpdateNullReferences(components.Callbacks, ReferenceType.Callback); - } - - private void UpdateNullReferences(IDictionary mapping, ReferenceType referenceType) - where T : IOpenApiReferenceable - { - foreach (var kvp in mapping) - { - var element = kvp.Value; - - if (!element.UnresolvedReference && (element.Reference == null)) - { - element.Reference = new OpenApiReference() - { - Id = kvp.Key, - Type = referenceType, - }; - } - } - } - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiComponentsTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiComponentsTests.cs deleted file mode 100644 index 221661bff..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiComponentsTests.cs +++ /dev/null @@ -1,908 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.OpenApi.Tests.Services -{ - [Collection("DefaultSettings")] - public class OpenApiComponentsTests - { - private readonly ITestOutputHelper _output; - - private readonly OpenApiDocument _sourceDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - private readonly OpenApiDocument _targetDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - public OpenApiComponentsTests(ITestOutputHelper output) - { - _output = output; - } - - public static IEnumerable GetTestCasesForOpenApiComponentsComparerShouldSucceed() - { - // Differences in schema and request body - yield return new object[] - { - "Differences in schema and request body", - new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - }, - new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/requestBodies/requestBody1/content/application~1json/schema/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = "#/requestBodies/requestBody1/content/application~1json/schema/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/requestBodies/requestBody1/content/application~1json/schema/properties/property6/properties/property6/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = - "#/requestBodies/requestBody1/content/application~1json/schema/properties/property6/properties/property6/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = "#/schemas/schemaObject1/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = "#/schemas/schemaObject1/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/schemas/schemaObject1/properties/property6/properties/property6/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = - "#/schemas/schemaObject1/properties/property6/properties/property6/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = "#/schemas/schemaObject2/properties/property6/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = "#/schemas/schemaObject2/properties/property6/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/schemas/schemaObject2/properties/property6/properties/property6/properties/property6/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = - "#/schemas/schemaObject2/properties/property6/properties/property6/properties/property6/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - } - } - }; - - // New schema and request body - yield return new object[] - { - "New schema and request body", - new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - } - } - }, - new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/requestBodies/requestBody2", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiRequestBody), - SourceValue = null, - TargetValue = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - } - }, - new OpenApiDifference - { - Pointer = - "#/schemas/schemaObject2", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - } - } - } - } - } - }; - - // New, removed and updated examples - yield return new object[] - { - "New, removed and updated examples", - new OpenApiComponents - { - Examples = new Dictionary - { - ["example1"] = new OpenApiExample - { - Value = new OpenApiObject - { - ["versions"] = new OpenApiArray - { - new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - } - } - }, - ["example3"] = new OpenApiExample - { - Value = new OpenApiObject - { - ["versions"] = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - } - } - } - }, - new OpenApiComponents - { - Examples = new Dictionary - { - ["example2"] = new OpenApiExample - { - Value = new OpenApiObject - { - ["versions"] = new OpenApiArray - { - new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - } - } - }, - ["example3"] = new OpenApiExample - { - Value = new OpenApiObject - { - ["versions"] = new OpenApiArray - { - new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - } - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/examples/example2", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiExample), - SourceValue = null, - TargetValue = new OpenApiExample - { - Value = new OpenApiObject - { - ["versions"] = new OpenApiArray - { - new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - } - } - } - }, - new OpenApiDifference - { - Pointer = "#/examples/example1", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiExample), - SourceValue = new OpenApiExample - { - Value = new OpenApiObject - { - ["versions"] = new OpenApiArray - { - new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - } - } - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = "#/examples/example3/value", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(IOpenApiAny), - SourceValue = new OpenApiObject - { - ["versions"] = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - }, - TargetValue = new OpenApiObject - { - ["versions"] = new OpenApiArray - { - new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - } - } - } - } - }; - } - - [Theory] - [MemberData(nameof(GetTestCasesForOpenApiComponentsComparerShouldSucceed))] - public void OpenApiComponentsComparerShouldSucceed( - string testCaseName, - OpenApiComponents source, - OpenApiComponents target, - List expectedDifferences) - { - _output.WriteLine(testCaseName); - - var comparisonContext = new ComparisonContext(new OpenApiComparerFactory(), _sourceDocument, - _targetDocument); - var comparer = new OpenApiComponentsComparer(); - comparer.Compare(source, target, comparisonContext); - - var differences = comparisonContext.OpenApiDifferences.ToList(); - - differences.Count().Should().Be(expectedDifferences.Count); - - differences.Should().BeEquivalentTo(expectedDifferences); - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiEncodingComparerTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiEncodingComparerTests.cs deleted file mode 100644 index a18749623..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiEncodingComparerTests.cs +++ /dev/null @@ -1,360 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.OpenApi.Tests.Services -{ - [Collection("DefaultSettings")] - public class OpenApiEncodingComparerTests - { - private readonly ITestOutputHelper _output; - - private readonly OpenApiDocument _sourceDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - private readonly OpenApiDocument _targetDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - public OpenApiEncodingComparerTests(ITestOutputHelper output) - { - _output = output; - } - - public static IEnumerable GetTestCasesForOpenApiEncodingComparerShouldSucceed() - { - // Differences in ContentType,Style,Explode and AllowReserved - yield return new object[] - { - "Differences in ContentType,Style,Explode and AllowReserved", - new OpenApiEncoding - { - ContentType = "image/png, image/jpeg", - Style = ParameterStyle.Simple, - Explode = true, - AllowReserved = true - }, - new OpenApiEncoding - { - ContentType = "image/jpeg", - Style = ParameterStyle.Form, - Explode = false, - AllowReserved = false - }, - new List - { - new OpenApiDifference - { - Pointer = "#/contentType", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - TargetValue = "image/jpeg", - SourceValue = "image/png, image/jpeg" - }, - new OpenApiDifference - { - Pointer = "#/explode", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(bool?), - TargetValue = false, - SourceValue = true - }, - new OpenApiDifference - { - Pointer = "#/allowReserved", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(bool?), - TargetValue = false, - SourceValue = true - }, - new OpenApiDifference - { - Pointer = "#/style", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(ParameterStyle), - TargetValue = ParameterStyle.Form, - SourceValue = ParameterStyle.Simple - } - } - }; - - // Null source - yield return new object[] - { - "Null source", - null, - new OpenApiEncoding - { - ContentType = "image/jpeg", - Style = ParameterStyle.Form, - Explode = false, - AllowReserved = false - }, - new List - { - new OpenApiDifference - { - Pointer = "#/", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiEncoding), - SourceValue = null, - TargetValue = new OpenApiEncoding - { - ContentType = "image/jpeg", - Style = ParameterStyle.Form, - Explode = false, - AllowReserved = false - } - } - } - }; - - // Null target - yield return new object[] - { - "Null target", - new OpenApiEncoding - { - ContentType = "image/jpeg", - Style = ParameterStyle.Form, - Explode = false, - AllowReserved = false - }, - null, - new List - { - new OpenApiDifference - { - Pointer = "#/", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiEncoding), - TargetValue = null, - SourceValue = new OpenApiEncoding - { - ContentType = "image/jpeg", - Style = ParameterStyle.Form, - Explode = false, - AllowReserved = false - } - } - } - }; - } - - - [Theory] - [MemberData(nameof(GetTestCasesForOpenApiEncodingComparerShouldSucceed))] - public void OpenApiEncodingComparerShouldSucceed( - string testCaseName, - OpenApiEncoding source, - OpenApiEncoding target, - List expectedDifferences) - { - _output.WriteLine(testCaseName); - - var comparisonContext = new ComparisonContext(new OpenApiComparerFactory(), _sourceDocument, - _targetDocument); - var comparer = new OpenApiEncodingComparer(); - comparer.Compare(source, target, comparisonContext); - - var differences = comparisonContext.OpenApiDifferences.ToList(); - differences.Count().Should().Be(expectedDifferences.Count); - - differences.Should().BeEquivalentTo(expectedDifferences); - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiExampleComparerTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiExampleComparerTests.cs deleted file mode 100644 index 716c75783..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiExampleComparerTests.cs +++ /dev/null @@ -1,461 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.OpenApi.Tests.Services -{ - [Collection("DefaultSettings")] - public class OpenApiExampleComparerTests - { - private readonly ITestOutputHelper _output; - - private readonly OpenApiDocument _sourceDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - private readonly OpenApiDocument _targetDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - public OpenApiExampleComparerTests(ITestOutputHelper output) - { - _output = output; - } - - public static IEnumerable GetTestCasesForOpenApiExampleComparerShouldSucceed() - { - yield return new object[] - { - "Differences in description, summary and external value", - new OpenApiExample - { - Description = "Test description", - Summary = "Test summary", - ExternalValue = "http://localhost/1" - }, - new OpenApiExample - { - Description = "Test description updated", - Summary = "Test summary updated", - ExternalValue = "http://localhost/2" - }, - new List - { - new OpenApiDifference - { - Pointer = "#/description", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "Test description", - TargetValue = "Test description updated" - }, - new OpenApiDifference - { - Pointer = "#/summary", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "Test summary", - TargetValue = "Test summary updated" - }, - new OpenApiDifference - { - Pointer = "#/externalValue", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "http://localhost/1", - TargetValue = "http://localhost/2" - } - } - }; - - yield return new object[] - { - "Null source", - null, - new OpenApiExample - { - Description = "Test description", - Summary = "Test summary", - ExternalValue = "http://localhost/1" - }, - new List - { - new OpenApiDifference - { - Pointer = "#/", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiExample), - SourceValue = null, - TargetValue = new OpenApiExample - { - Description = "Test description", - Summary = "Test summary", - ExternalValue = "http://localhost/1" - } - } - } - }; - - yield return new object[] - { - "Null target", - new OpenApiExample - { - Description = "Test description", - Summary = "Test summary", - ExternalValue = "http://localhost/1" - }, - null, - new List - { - new OpenApiDifference - { - Pointer = "#/", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiExample), - TargetValue = null, - SourceValue = new OpenApiExample - { - Description = "Test description", - Summary = "Test summary", - ExternalValue = "http://localhost/1" - } - } - } - }; - - yield return new object[] - { - "Difference in value", - new OpenApiExample - { - Description = "Test description", - Summary = "Test summary", - Value = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - }, - new OpenApiExample - { - Description = "Test description", - Summary = "Test summary", - Value = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["relUpdated"] = new OpenApiString("sampleRel1") - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/value", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(IOpenApiAny), - TargetValue = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["relUpdated"] = new OpenApiString("sampleRel1") - } - } - }, - SourceValue = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - } - } - }; - - yield return new object[] - { - "No differences", - new OpenApiExample - { - Description = "Test description", - Summary = "Test summary", - Value = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - }, - new OpenApiExample - { - Description = "Test description", - Summary = "Test summary", - Value = new OpenApiObject - { - ["status"] = new OpenApiString("Status1"), - ["id"] = new OpenApiString("v1"), - ["links"] = new OpenApiArray - { - new OpenApiObject - { - ["href"] = new OpenApiString("http://example.com/1"), - ["rel"] = new OpenApiString("sampleRel1") - } - } - } - }, - new List() - }; - } - - [Theory] - [MemberData(nameof(GetTestCasesForOpenApiExampleComparerShouldSucceed))] - public void OpenApiExampleComparerShouldSucceed( - string testCaseName, - OpenApiExample source, - OpenApiExample target, - List expectedDifferences) - { - _output.WriteLine(testCaseName); - - var comparisonContext = new ComparisonContext(new OpenApiComparerFactory(), _sourceDocument, - _targetDocument); - var comparer = new OpenApiExampleComparer(); - comparer.Compare(source, target, comparisonContext); - - var differences = comparisonContext.OpenApiDifferences.ToList(); - differences.Count().Should().Be(expectedDifferences.Count); - - differences.Should().BeEquivalentTo(expectedDifferences); - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiInfoComparerTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiInfoComparerTests.cs deleted file mode 100644 index 1e99cde10..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiInfoComparerTests.cs +++ /dev/null @@ -1,297 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System; -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.OpenApi.Tests.Services -{ - [Collection("DefaultSettings")] - public class OpenApiInfoComparerTests - { - private readonly ITestOutputHelper _output; - - private readonly OpenApiDocument _sourceDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - private readonly OpenApiDocument _targetDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - public OpenApiInfoComparerTests(ITestOutputHelper output) - { - _output = output; - } - - public static IEnumerable GetTestCasesForOpenApiInfoComparerShouldSucceed() - { - yield return new object[] - { - "Differences in title, description, version and tos", - new OpenApiInfo - { - Title = "Test title", - Description = "Test description", - Version = "Test version", - TermsOfService = new Uri("http://localhost/1") - }, - new OpenApiInfo - { - Title = "Test title updated", - Description = "Test description updated", - Version = "Test version updated", - TermsOfService = new Uri("http://localhost/2") - }, - new List - { - new OpenApiDifference - { - Pointer = "#/title", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - TargetValue = "Test title updated", - SourceValue = "Test title" - }, - new OpenApiDifference - { - Pointer = "#/description", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - TargetValue = "Test description updated", - SourceValue = "Test description" - }, - new OpenApiDifference - { - Pointer = "#/termsOfService", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(Uri), - TargetValue = new Uri("http://localhost/2"), - SourceValue = new Uri("http://localhost/1") - }, - new OpenApiDifference - { - Pointer = "#/version", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - TargetValue = "Test version updated", - SourceValue = "Test version" - } - } - }; - } - - [Theory] - [MemberData(nameof(GetTestCasesForOpenApiInfoComparerShouldSucceed))] - public void OpenApiInfoComparerShouldSucceed( - string testCaseName, - OpenApiInfo source, - OpenApiInfo target, - List expectedDifferences) - { - _output.WriteLine(testCaseName); - - var comparisonContext = new ComparisonContext(new OpenApiComparerFactory(), _sourceDocument, - _targetDocument); - var comparer = new OpenApiInfoComparer(); - comparer.Compare(source, target, comparisonContext); - - var differences = comparisonContext.OpenApiDifferences.ToList(); - differences.Count().Should().Be(expectedDifferences.Count); - - differences.Should().BeEquivalentTo(expectedDifferences); - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiParameterComparerTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiParameterComparerTests.cs deleted file mode 100644 index a2455bbae..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiParameterComparerTests.cs +++ /dev/null @@ -1,477 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.OpenApi.Tests.Services -{ - [Collection("DefaultSettings")] - public class OpenApiParameterComparerTests - { - private readonly ITestOutputHelper _output; - - private readonly OpenApiDocument _sourceDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - private readonly OpenApiDocument _targetDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - public OpenApiParameterComparerTests(ITestOutputHelper output) - { - _output = output; - } - - public static IEnumerable GetTestCasesForOpenApiParameterComparerShouldSucceed() - { - // Source and Target are null - yield return new object[] - { - "Source and Target are null", - null, - null, - new List() - }; - - // Source is null - yield return new object[] - { - "Source is null", - null, - new OpenApiParameter - { - Name = "pathParam", - In = ParameterLocation.Path - }, - new List - { - new OpenApiDifference - { - Pointer = "#/", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiParameter), - SourceValue = null, - TargetValue = new OpenApiParameter - { - Name = "pathParam", - In = ParameterLocation.Path - } - } - } - }; - - // Target is null - yield return new object[] - { - "Target is null", - new OpenApiParameter - { - Name = "pathParam", - In = ParameterLocation.Path - }, - null, - new List - { - new OpenApiDifference - { - Pointer = "#/", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiParameter), - TargetValue = null, - SourceValue = new OpenApiParameter - { - Name = "pathParam", - In = ParameterLocation.Path - } - } - } - }; - - // Differences in target and source - yield return new object[] - { - "Differences in target and source", - new OpenApiParameter - { - Name = "pathParam", - Description = "Sample path parameter description", - In = ParameterLocation.Path, - Required = true, - AllowEmptyValue = true, - AllowReserved = true, - Style = ParameterStyle.Form, - Deprecated = false, - Explode = false, - Schema = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - }, - new OpenApiParameter - { - Name = "pathParamUpdate", - Description = "Updated Sample path parameter description", - In = ParameterLocation.Query, - Required = false, - AllowEmptyValue = false, - AllowReserved = false, - Style = ParameterStyle.Label, - Deprecated = true, - Explode = true, - Schema = new OpenApiSchema - { - Type = "bool", - MaxLength = 15 - }, - Content = - { - ["text/plain"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/content/text~1plain", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiMediaType), - TargetValue = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - }, - SourceValue = null - }, - new OpenApiDifference - { - Pointer = "#/content/application~1json", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiMediaType), - SourceValue = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = "#/description", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "Sample path parameter description", - TargetValue = "Updated Sample path parameter description" - }, - new OpenApiDifference - { - Pointer = "#/required", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(bool?), - TargetValue = false, - SourceValue = true - }, - new OpenApiDifference - { - Pointer = "#/name", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "pathParam", - TargetValue = "pathParamUpdate" - }, - new OpenApiDifference - { - Pointer = "#/deprecated", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(bool?), - TargetValue = true, - SourceValue = false - }, - new OpenApiDifference - { - Pointer = "#/allowEmptyValue", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(bool?), - TargetValue = false, - SourceValue = true - }, - new OpenApiDifference - { - Pointer = "#/explode", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(bool?), - TargetValue = true, - SourceValue = false - }, - new OpenApiDifference - { - Pointer = "#/allowReserved", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(bool?), - TargetValue = false, - SourceValue = true - }, - new OpenApiDifference - { - Pointer = "#/style", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(ParameterStyle), - SourceValue = ParameterStyle.Form, - TargetValue = ParameterStyle.Label - }, - new OpenApiDifference - { - Pointer = "#/in", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(ParameterLocation), - SourceValue = ParameterLocation.Path, - TargetValue = ParameterLocation.Query - }, - - new OpenApiDifference - { - Pointer = "#/schema/type", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "string", - TargetValue = "bool" - } - } - }; - } - - [Theory] - [MemberData(nameof(GetTestCasesForOpenApiParameterComparerShouldSucceed))] - public void OpenApiParameterComparerShouldSucceed( - string testCaseName, - OpenApiParameter source, - OpenApiParameter target, - List expectedDifferences) - { - _output.WriteLine(testCaseName); - - var comparisonContext = new ComparisonContext(new OpenApiComparerFactory(), _sourceDocument, - _targetDocument); - var comparer = new OpenApiParameterComparer(); - comparer.Compare(source, target, comparisonContext); - - var differences = comparisonContext.OpenApiDifferences.ToList(); - differences.Count().Should().Be(expectedDifferences.Count); - - differences.Should().BeEquivalentTo(expectedDifferences); - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiParametersComparerTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiParametersComparerTests.cs deleted file mode 100644 index 6d7c2129a..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiParametersComparerTests.cs +++ /dev/null @@ -1,432 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.OpenApi.Tests.Services -{ - [Collection("DefaultSettings")] - public class OpenApiParametersComparerTests - { - private readonly ITestOutputHelper _output; - - private readonly OpenApiDocument _sourceDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - private readonly OpenApiDocument _targetDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - public OpenApiParametersComparerTests(ITestOutputHelper output) - { - _output = output; - } - - public static IEnumerable GetTestCasesForOpenApiParametersComparerShouldSucceed() - { - // Source and Target are null - yield return new object[] - { - "Source and Target are null", - null, - null, - new List() - }; - - // Source and Target are empty - yield return new object[] - { - "Source and Target are null", - new List(), - new List(), - new List() - }; - - // Source is null - yield return new object[] - { - "Source is null", - null, - new List - { - new OpenApiParameter - { - Name = "pathParam1", - In = ParameterLocation.Path - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(IList), - SourceValue = null, - TargetValue = new List - { - new OpenApiParameter - { - Name = "pathParam1", - In = ParameterLocation.Path - } - } - } - } - }; - - // Target is null - yield return new object[] - { - "Target is null", - new List - { - new OpenApiParameter - { - Name = "pathParam1", - In = ParameterLocation.Path - } - }, - null, - new List - { - new OpenApiDifference - { - Pointer = "#/", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(IList), - TargetValue = null, - SourceValue = new List - { - new OpenApiParameter - { - Name = "pathParam1", - In = ParameterLocation.Path - } - } - } - } - }; - - // New, Removed and Updated Parameters - yield return new object[] - { - "New, Removed and Updated Parameters", - new List - { - new OpenApiParameter - { - Name = "pathParam1", - In = ParameterLocation.Path - }, - new OpenApiParameter - { - Name = "pathParam2", - In = ParameterLocation.Path - }, - new OpenApiParameter - { - Name = "pathParam3", - In = ParameterLocation.Path, - Description = "Sample path parameter description" - }, - new OpenApiParameter - { - Name = "queryParam1", - In = ParameterLocation.Query - }, - new OpenApiParameter - { - Name = "queryParam2", - In = ParameterLocation.Query - } - }, - new List - { - new OpenApiParameter - { - Name = "queryParam1", - In = ParameterLocation.Query - }, - new OpenApiParameter - { - Name = "pathParam1", - In = ParameterLocation.Path - }, - new OpenApiParameter - { - Name = "queryParam3", - In = ParameterLocation.Query - }, - new OpenApiParameter - { - Name = "pathParam3", - In = ParameterLocation.Path, - Description = "Updated Sample path parameter description" - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/4", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiParameter), - TargetValue = null, - SourceValue = new OpenApiParameter - { - Name = "queryParam2", - In = ParameterLocation.Query - } - }, - new OpenApiDifference - { - Pointer = "#/1", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiParameter), - TargetValue = null, - SourceValue = new OpenApiParameter - { - Name = "pathParam2", - In = ParameterLocation.Path - } - }, - new OpenApiDifference - { - Pointer = "#/2", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiParameter), - SourceValue = null, - TargetValue = new OpenApiParameter - { - Name = "queryParam3", - In = ParameterLocation.Query - } - }, - new OpenApiDifference - { - Pointer = "#/3/description", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "Sample path parameter description", - TargetValue = "Updated Sample path parameter description" - } - } - }; - } - - [Theory] - [MemberData(nameof(GetTestCasesForOpenApiParametersComparerShouldSucceed))] - public void OpenApiParametersComparerShouldSucceed( - string testCaseName, - IList source, - IList target, - List expectedDifferences) - { - _output.WriteLine(testCaseName); - - var comparisonContext = new ComparisonContext(new OpenApiComparerFactory(), _sourceDocument, - _targetDocument); - var comparer = new OpenApiParametersComparer(); - comparer.Compare(source, target, comparisonContext); - - var differences = comparisonContext.OpenApiDifferences.ToList(); - differences.Count().Should().Be(expectedDifferences.Count); - - differences.Should().BeEquivalentTo(expectedDifferences); - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiRequestBodyComparerTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiRequestBodyComparerTests.cs deleted file mode 100644 index 957708e8c..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiRequestBodyComparerTests.cs +++ /dev/null @@ -1,587 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.OpenApi.Tests.Services -{ - [Collection("DefaultSettings")] - public class OpenApiRequestBodyComparerTests - { - private readonly ITestOutputHelper _output; - - private readonly OpenApiDocument _sourceDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - private readonly OpenApiDocument _targetDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - public OpenApiRequestBodyComparerTests(ITestOutputHelper output) - { - _output = output; - } - - public static IEnumerable GetTestCasesForOpenApiRequestBodyComparerShouldSucceed() - { - // Differences in description and Required - yield return new object[] - { - "Differences in description and Required", - new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - }, - new OpenApiRequestBody - { - Description = "udpated description", - Required = false, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/description", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - TargetValue = "udpated description", - SourceValue = "description" - }, - new OpenApiDifference - { - Pointer = "#/required", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(bool?), - TargetValue = false, - SourceValue = true - } - } - }; - - // Differences in Content - yield return new object[] - { - "Differences in Content", - new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - }, - new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/xml"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/content/application~1xml", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiMediaType), - SourceValue = null, - TargetValue = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - }, - new OpenApiDifference - { - Pointer = "#/content/application~1json", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiMediaType), - TargetValue = null, - SourceValue = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - } - }; - - // Null source - yield return new object[] - { - "Null source", - null, - new OpenApiRequestBody - { - Description = "udpated description", - Required = false, - Content = - { - ["application/xml"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiRequestBody), - SourceValue = null, - TargetValue = new OpenApiRequestBody - { - Description = "udpated description", - Required = false, - Content = - { - ["application/xml"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - } - } - } - }; - - // Null target - yield return new object[] - { - "Null target", - new OpenApiRequestBody - { - Description = "udpated description", - Required = false, - Content = - { - ["application/xml"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - }, - null, - new List - { - new OpenApiDifference - { - Pointer = "#/", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiRequestBody), - SourceValue = new OpenApiRequestBody - { - Description = "udpated description", - Required = false, - Content = - { - ["application/xml"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - }, - TargetValue = null - } - } - }; - - // Differences in reference id - yield return new object[] - { - "Differences in reference id", - new OpenApiRequestBody - { - Reference = new OpenApiReference - { - Id = "Id", - Type = ReferenceType.RequestBody - }, - - Description = "description", - Required = true - }, - new OpenApiRequestBody - { - Reference = new OpenApiReference - { - Id = "NewId", - Type = ReferenceType.RequestBody - }, - - Description = "description", - Required = true - }, - new List - { - new OpenApiDifference - { - Pointer = "#/$ref", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiReference), - TargetValue = new OpenApiReference - { - Id = "NewId", - Type = ReferenceType.RequestBody - }, - SourceValue = new OpenApiReference - { - Id = "Id", - Type = ReferenceType.RequestBody - } - } - } - }; - - // Differences in schema - yield return new object[] - { - "Differences in schema", - new OpenApiRequestBody - { - Reference = new OpenApiReference - { - Id = "requestBody1", - Type = ReferenceType.RequestBody - }, - - Description = "description", - Required = true - }, - new OpenApiRequestBody - { - Reference = new OpenApiReference - { - Id = "requestBody1", - Type = ReferenceType.RequestBody - }, - - Description = "description", - Required = true - }, - new List - { - new OpenApiDifference - { - Pointer = "#/content/application~1json/schema/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = "#/content/application~1json/schema/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/content/application~1json/schema/properties/property6/properties/property6/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = - "#/content/application~1json/schema/properties/property6/properties/property6/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - } - } - }; - } - - [Theory] - [MemberData(nameof(GetTestCasesForOpenApiRequestBodyComparerShouldSucceed))] - public void OpenApiRequestBodyComparerShouldSucceed( - string testCaseName, - OpenApiRequestBody source, - OpenApiRequestBody target, - List expectedDifferences) - { - _output.WriteLine(testCaseName); - - var comparisonContext = new ComparisonContext(new OpenApiComparerFactory(), _sourceDocument, - _targetDocument); - var comparer = new OpenApiRequestBodyComparer(); - comparer.Compare(source, target, comparisonContext); - - var differences = comparisonContext.OpenApiDifferences.ToList(); - - differences.Count().Should().Be(expectedDifferences.Count); - - differences.Should().BeEquivalentTo(expectedDifferences); - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiResponsesComparerTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiResponsesComparerTests.cs deleted file mode 100644 index 7cbf858b3..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiResponsesComparerTests.cs +++ /dev/null @@ -1,818 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.OpenApi.Tests.Services -{ - [Collection("DefaultSettings")] - public class OpenApiResponsesComparerTests - { - private readonly ITestOutputHelper _output; - - private readonly OpenApiDocument _sourceDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - Responses = new Dictionary - { - ["responseObject1"] = new OpenApiResponse - { - Description = "description", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["responseObject2"] = new OpenApiResponse - { - Description = "description", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - private readonly OpenApiDocument _targetDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - Responses = new Dictionary - { - ["responseObject1"] = new OpenApiResponse - { - Description = "description", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["responseObject2"] = new OpenApiResponse - { - Description = "description", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - public OpenApiResponsesComparerTests(ITestOutputHelper output) - { - _output = output; - } - - public static IEnumerable GetTestCasesForOpenApiResponsesComparerShouldSucceed() - { - // Differences in description - yield return new object[] - { - "Differences in description", - new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "A complex object array response", - Content = - { - ["text/plain"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - } - } - }, - new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "An updated complex object array response", - Content = - { - ["text/plain"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "string" - } - } - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/200/description", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "A complex object array response", - TargetValue = "An updated complex object array response" - } - } - }; - - // New response code - yield return new object[] - { - "New response code", - new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "A complex object array response", - Content = - { - ["text/plain"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - } - }, - new OpenApiResponses - { - { - "400", - new OpenApiResponse - { - Description = "An updated complex object array response", - Content = - { - ["text/plain"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/400", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiResponse), - SourceValue = null, - TargetValue = new OpenApiResponse - { - Description = "An updated complex object array response", - Content = - { - ["text/plain"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - }, - new OpenApiDifference - { - Pointer = "#/200", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiResponse), - TargetValue = null, - SourceValue = new OpenApiResponse - { - Description = "A complex object array response", - Content = - { - ["text/plain"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - } - } - }; - - // Differences in Content - yield return new object[] - { - "Differences in Content", - new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "A complex object array response", - Content = - { - ["text/plain"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - } - }, - new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "A complex object array response", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/200/content/application~1json", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiMediaType), - SourceValue = null, - TargetValue = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - new OpenApiDifference - { - Pointer = "#/200/content/text~1plain", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiMediaType), - TargetValue = null, - SourceValue = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - }; - - // Null source - yield return new object[] - { - "Null source", - null, - new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "An updated complex object array response", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(IDictionary), - SourceValue = null, - TargetValue = new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "An updated complex object array response", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - } - } - } - } - }; - - // Null target - yield return new object[] - { - "Null target", - new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "An updated complex object array response", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - } - }, - null, - new List - { - new OpenApiDifference - { - Pointer = "#/", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(IDictionary), - TargetValue = null, - SourceValue = new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "An updated complex object array response", - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Type = "array", - Items = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - } - } - } - } - } - } - }; - - // Differences in reference id - yield return new object[] - { - "Differences in reference id", - new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "A complex object array response", - Reference = new OpenApiReference - { - Id = "responseObject1", - Type = ReferenceType.Response - } - } - } - }, - new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "A complex object array response", - Reference = new OpenApiReference - { - Id = "responseObject2", - Type = ReferenceType.Response - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/200/$ref", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiReference), - SourceValue = new OpenApiReference - { - Id = "responseObject1", - Type = ReferenceType.Response - }, - TargetValue = new OpenApiReference - { - Id = "responseObject2", - Type = ReferenceType.Response - } - } - } - }; - - // Differences in schema - yield return new object[] - { - "Differences in schema", - new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "A complex object array response", - Reference = new OpenApiReference - { - Id = "responseObject1", - Type = ReferenceType.Response - } - } - } - }, - new OpenApiResponses - { - { - "200", - new OpenApiResponse - { - Description = "A complex object array response", - Reference = new OpenApiReference - { - Id = "responseObject1", - Type = ReferenceType.Response - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/200/content/application~1json/schema/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = "#/200/content/application~1json/schema/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - }, - new OpenApiDifference - { - Pointer = - "#/200/content/application~1json/schema/properties/property6/properties/property6/properties/property5", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = null, - TargetValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - } - }, - new OpenApiDifference - { - Pointer = - "#/200/content/application~1json/schema/properties/property6/properties/property6/properties/property7", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiSchema), - SourceValue = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - TargetValue = null - } - } - }; - } - - [Theory] - [MemberData(nameof(GetTestCasesForOpenApiResponsesComparerShouldSucceed))] - public void OpenApiResponsesComparerShouldSucceed( - string testCaseName, - OpenApiResponses source, - OpenApiResponses target, - List expectedDifferences) - { - _output.WriteLine(testCaseName); - - var comparisonContext = new ComparisonContext(new OpenApiComparerFactory(), _sourceDocument, - _targetDocument); - var comparer = new OpenApiDictionaryComparer(); - comparer.Compare(source, target, comparisonContext); - - var differences = comparisonContext.OpenApiDifferences.ToList(); - - differences.Count().Should().Be(expectedDifferences.Count); - - differences.Should().BeEquivalentTo(expectedDifferences); - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiSecurityRequirementComparerTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiSecurityRequirementComparerTests.cs deleted file mode 100644 index 840b74bea..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiSecurityRequirementComparerTests.cs +++ /dev/null @@ -1,289 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.OpenApi.Tests.Services -{ - [Collection("DefaultSettings")] - public class OpenApiSecurityRequirementComparerTests - { - private readonly ITestOutputHelper _output; - - private readonly OpenApiDocument _sourceDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - SecuritySchemes = new Dictionary - { - { - "scheme1", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test" - } - }, - { - "scheme2", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test" - } - }, - { - "scheme3", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test" - } - } - } - } - }; - - private readonly OpenApiDocument _targetDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - SecuritySchemes = new Dictionary - { - { - "scheme1", new OpenApiSecurityScheme - { - Description = "Test Updated", - Name = "Test" - } - }, - { - "scheme2", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test" - } - }, - { - "scheme4", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test" - } - } - } - } - }; - - public OpenApiSecurityRequirementComparerTests(ITestOutputHelper output) - { - _output = output; - } - - public static IEnumerable GetTestCasesForOpenApiSecurityRequirementComparerShouldSucceed() - { - yield return new object[] - { - "New Removed And updated schemes", - new OpenApiSecurityRequirement - { - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference {Type = ReferenceType.SecurityScheme, Id = "scheme1"} - } - ] = new List - { - "scope1", - "scope2", - "scope3" - }, - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference {Type = ReferenceType.SecurityScheme, Id = "scheme2"} - } - ] = new List - { - "scope4", - "scope5" - }, - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference {Type = ReferenceType.SecurityScheme, Id = "scheme3"} - } - ] = new List() - }, - new OpenApiSecurityRequirement - { - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference {Type = ReferenceType.SecurityScheme, Id = "scheme1"} - } - ] = new List - { - "scope1", - "scope2", - "scope3" - }, - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference {Type = ReferenceType.SecurityScheme, Id = "scheme2"} - } - ] = new List - { - "scope4", - "scope5" - }, - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference {Type = ReferenceType.SecurityScheme, Id = "scheme4"} - } - ] = new List() - }, - new List - { - new OpenApiDifference - { - Pointer = "#/scheme4", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(IList), - SourceValue = null, - TargetValue = new List() - }, - new OpenApiDifference - { - Pointer = "#/scheme1/description", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "Test", - TargetValue = "Test Updated" - }, - new OpenApiDifference - { - Pointer = "#/scheme3", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(IList), - SourceValue = new List(), - TargetValue = null - } - } - }; - - yield return new object[] - { - "Source and target are null", - null, - null, - new List() - }; - - yield return new object[] - { - "Source is null", - null, - new OpenApiSecurityRequirement - { - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference {Type = ReferenceType.SecurityScheme, Id = "scheme1"} - } - ] = new List() - }, - new List - { - new OpenApiDifference - { - Pointer = "#/", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiSecurityRequirement), - SourceValue = null, - TargetValue = new OpenApiSecurityRequirement - { - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "scheme1" - } - } - ] = new List() - } - } - } - }; - - yield return new object[] - { - "Target is null", - new OpenApiSecurityRequirement - { - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference {Type = ReferenceType.SecurityScheme, Id = "scheme1"} - } - ] = new List() - }, - null, - new List - { - new OpenApiDifference - { - Pointer = "#/", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiSecurityRequirement), - SourceValue = new OpenApiSecurityRequirement - { - [ - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Type = ReferenceType.SecurityScheme, - Id = "scheme1" - } - } - ] = new List() - }, - TargetValue = null - } - } - }; - } - - [Theory] - [MemberData(nameof(GetTestCasesForOpenApiSecurityRequirementComparerShouldSucceed))] - public void OpenApiSecurityRequirementComparerShouldSucceed( - string testCaseName, - OpenApiSecurityRequirement source, - OpenApiSecurityRequirement target, - List expectedDifferences) - - - { - _output.WriteLine(testCaseName); - - var comparisonContext = new ComparisonContext(new OpenApiComparerFactory(), _sourceDocument, - _targetDocument); - var comparer = new OpenApiSecurityRequirementComparer(); - comparer.Compare(source, target, comparisonContext); - - var differences = comparisonContext.OpenApiDifferences.ToList(); - - differences.Count().Should().Be(expectedDifferences.Count); - - differences.Should().BeEquivalentTo(expectedDifferences); - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiSecuritySchemeComparerTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiSecuritySchemeComparerTests.cs deleted file mode 100644 index 6a8ac60e8..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiSecuritySchemeComparerTests.cs +++ /dev/null @@ -1,308 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System; -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.OpenApi.Tests.Services -{ - [Collection("DefaultSettings")] - public class OpenApiSecuritySchemeComparerTests - { - private readonly ITestOutputHelper _output; - - private readonly OpenApiDocument _sourceDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - SecuritySchemes = new Dictionary - { - { - "scheme1", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test", - Flows = new OpenApiOAuthFlows - { - Implicit = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/1") - }, - AuthorizationCode = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/2") - } - } - } - }, - { - "scheme2", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test" - } - }, - { - "scheme3", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test" - } - } - } - } - }; - - private readonly OpenApiDocument _targetDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - SecuritySchemes = new Dictionary - { - { - "scheme1", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test", - Flows = new OpenApiOAuthFlows - { - Implicit = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/3") - }, - ClientCredentials = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/2") - } - } - } - }, - { - "scheme2", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test" - } - }, - { - "scheme4", new OpenApiSecurityScheme - { - Description = "Test", - Name = "Test" - } - } - } - } - }; - - public OpenApiSecuritySchemeComparerTests(ITestOutputHelper output) - { - _output = output; - } - - public static IEnumerable GetTestCasesForOpenApiSecuritySchemeComparerShouldSucceed() - { - yield return new object[] - { - "Updated Type, Description, Name, In, BearerFormat, OpenIdConnectUrl", - new OpenApiSecurityScheme - { - Type = SecuritySchemeType.ApiKey, - Description = "Test Description", - Name = "Test Name", - In = ParameterLocation.Path, - OpenIdConnectUrl = new Uri("http://localhost:1"), - BearerFormat = "Test Format" - }, - new OpenApiSecurityScheme - { - Type = SecuritySchemeType.Http, - Description = "Test Description Updated", - Name = "Test Name Updated", - Scheme = "basic" - }, - new List - { - new OpenApiDifference - { - Pointer = "#/description", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "Test Description", - TargetValue = "Test Description Updated" - }, - new OpenApiDifference - { - Pointer = "#/type", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(SecuritySchemeType), - SourceValue = SecuritySchemeType.ApiKey, - TargetValue = SecuritySchemeType.Http - }, - new OpenApiDifference - { - Pointer = "#/name", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "Test Name", - TargetValue = "Test Name Updated" - }, - new OpenApiDifference - { - Pointer = "#/in", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(ParameterLocation), - SourceValue = ParameterLocation.Path, - TargetValue = ParameterLocation.Query - }, - new OpenApiDifference - { - Pointer = "#/scheme", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = null, - TargetValue = "basic" - }, - new OpenApiDifference - { - Pointer = "#/bearerFormat", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "Test Format", - TargetValue = null - }, - new OpenApiDifference - { - Pointer = "#/openIdConnectUrl", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(Uri), - SourceValue = new Uri("http://localhost:1"), - TargetValue = null - } - } - }; - - yield return new object[] - { - "Difference in reference id", - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Id = "scheme1", - Type = ReferenceType.SecurityScheme - } - }, - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Id = "scheme2", - Type = ReferenceType.SecurityScheme - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/$ref", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiReference), - SourceValue = new OpenApiReference - { - Id = "scheme1", - Type = ReferenceType.SecurityScheme - }, - TargetValue = new OpenApiReference - { - Id = "scheme2", - Type = ReferenceType.SecurityScheme - } - } - } - }; - - yield return new object[] - { - "New, Removed and Updated OAuthFlows", - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Id = "scheme1", - Type = ReferenceType.SecurityScheme - } - }, - new OpenApiSecurityScheme - { - Reference = new OpenApiReference - { - Id = "scheme1", - Type = ReferenceType.SecurityScheme - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/flows/implicit/authorizationUrl", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(Uri), - SourceValue = new Uri("http://localhost/1"), - TargetValue = new Uri("http://localhost/3") - }, - new OpenApiDifference - { - Pointer = "#/flows/clientCredentials", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiOAuthFlow), - SourceValue = null, - TargetValue = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/2") - } - }, - new OpenApiDifference - { - Pointer = "#/flows/authorizationCode", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(OpenApiOAuthFlow), - SourceValue = new OpenApiOAuthFlow - { - AuthorizationUrl = new Uri("http://localhost/2") - }, - TargetValue = null - } - } - }; - } - - [Theory] - [MemberData(nameof(GetTestCasesForOpenApiSecuritySchemeComparerShouldSucceed))] - public void OpenApiSecuritySchemeComparerShouldSucceed( - string testCaseName, - OpenApiSecurityScheme source, - OpenApiSecurityScheme target, - List expectedDifferences) - { - _output.WriteLine(testCaseName); - - var comparisonContext = new ComparisonContext(new OpenApiComparerFactory(), _sourceDocument, - _targetDocument); - var comparer = new OpenApiSecuritySchemeComparer(); - comparer.Compare(source, target, comparisonContext); - - var differences = comparisonContext.OpenApiDifferences.ToList(); - - differences.Count().Should().Be(expectedDifferences.Count); - - differences.Should().BeEquivalentTo(expectedDifferences); - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiServerVariableComparerTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiServerVariableComparerTests.cs deleted file mode 100644 index 4b2e17dc2..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiServerVariableComparerTests.cs +++ /dev/null @@ -1,287 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.OpenApi.Tests.Services -{ - [Collection("DefaultSettings")] - public class OpenApiServerVariableComparerTests - { - private readonly ITestOutputHelper _output; - - private readonly OpenApiDocument _sourceDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - private readonly OpenApiDocument _targetDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - public OpenApiServerVariableComparerTests(ITestOutputHelper output) - { - _output = output; - } - - public static IEnumerable GetTestCasesForOpenApiServerVariableComparerShouldSucceed() - { - // Differences in default and description - yield return new object[] - { - "Differences in default and description", - new OpenApiServerVariable - { - Default = "8443", - Enum = new List - { - "8443", - "443" - }, - Description = "test description" - }, - new OpenApiServerVariable - { - Default = "1003", - Enum = new List - { - "8443", - "443" - }, - Description = "test description updated" - }, - new List - { - new OpenApiDifference - { - Pointer = "#/description", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "test description", - TargetValue = "test description updated" - }, - new OpenApiDifference - { - Pointer = "#/default", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "8443", - TargetValue = "1003" - } - } - }; - } - - [Theory] - [MemberData(nameof(GetTestCasesForOpenApiServerVariableComparerShouldSucceed))] - public void OpenApiServerVariableComparerShouldSucceed( - string testCaseName, - OpenApiServerVariable source, - OpenApiServerVariable target, - List expectedDifferences) - { - _output.WriteLine(testCaseName); - - var comparisonContext = new ComparisonContext(new OpenApiComparerFactory(), _sourceDocument, - _targetDocument); - var comparer = new OpenApiServerVariableComparer(); - comparer.Compare(source, target, comparisonContext); - - var differences = comparisonContext.OpenApiDifferences.ToList(); - differences.Count().Should().Be(expectedDifferences.Count); - - differences.Should().BeEquivalentTo(expectedDifferences); - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiServersComparerTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiServersComparerTests.cs deleted file mode 100644 index ea7eb8096..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiServersComparerTests.cs +++ /dev/null @@ -1,517 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.OpenApi.Tests.Services -{ - [Collection("DefaultSettings")] - public class OpenApiServersComparerTests - { - private readonly ITestOutputHelper _output; - - private readonly OpenApiDocument _sourceDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - private readonly OpenApiDocument _targetDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - public OpenApiServersComparerTests(ITestOutputHelper output) - { - _output = output; - } - - public static IEnumerable GetTestCasesForOpenApiServersComparerShouldSucceed() - { - // Differences in description - yield return new object[] - { - "Differences in description", - new List - { - new OpenApiServer - { - Description = "description1", - Url = "https://{username}.example.com:{port}/{basePath}", - Variables = new Dictionary - { - ["username"] = new OpenApiServerVariable - { - Default = "unknown", - Description = "variableDescription1" - }, - ["port"] = new OpenApiServerVariable - { - Default = "8443", - Description = "variableDescription2", - Enum = new List - { - "443", - "8443" - } - }, - ["basePath"] = new OpenApiServerVariable - { - Default = "v1" - } - } - } - }, - new List - { - new OpenApiServer - { - Description = "description2", - Url = "https://{username}.example.com:{port}/{basePath}", - Variables = new Dictionary - { - ["username"] = new OpenApiServerVariable - { - Default = "unknown", - Description = "variableDescription1" - }, - ["port"] = new OpenApiServerVariable - { - Default = "8443", - Description = "variableDescription2", - Enum = new List - { - "443", - "8443" - } - }, - ["basePath"] = new OpenApiServerVariable - { - Default = "v1" - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/0/description", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "description1", - TargetValue = "description2" - } - } - }; - - // New and Removed server - yield return new object[] - { - "New and Removed server", - new List - { - new OpenApiServer - { - Description = "description1", - Url = "https://{username}.example.com:{port}/{basePath}", - Variables = new Dictionary - { - ["username"] = new OpenApiServerVariable - { - Default = "unknown", - Description = "variableDescription1" - }, - ["port"] = new OpenApiServerVariable - { - Default = "8443", - Description = "variableDescription2", - Enum = new List - { - "443", - "8443" - } - }, - ["basePath"] = new OpenApiServerVariable - { - Default = "v1" - } - } - } - }, - new List - { - new OpenApiServer - { - Description = "description1", - Url = "https://{username}.example.com:{port}/test", - Variables = new Dictionary - { - ["username"] = new OpenApiServerVariable - { - Default = "unknown", - Description = "variableDescription1" - }, - ["port"] = new OpenApiServerVariable - { - Default = "8443", - Description = "variableDescription2", - Enum = new List - { - "443", - "8443" - } - }, - ["basePath"] = new OpenApiServerVariable - { - Default = "v1" - } - } - }, - new OpenApiServer - { - Description = "description3", - Url = "https://{username}.example.com:{port}/{basePath}/test", - Variables = new Dictionary - { - ["username"] = new OpenApiServerVariable - { - Default = "unknown", - Description = "variableDescription1" - }, - ["port"] = new OpenApiServerVariable - { - Default = "8443", - Description = "variableDescription2", - Enum = new List - { - "443", - "8443" - } - }, - ["basePath"] = new OpenApiServerVariable - { - Default = "v1" - } - } - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/0", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove, - OpenApiComparedElementType = typeof(OpenApiServer), - TargetValue = null, - SourceValue = new OpenApiServer - { - Description = "description1", - Url = "https://{username}.example.com:{port}/{basePath}", - Variables = new Dictionary - { - ["username"] = new OpenApiServerVariable - { - Default = "unknown", - Description = "variableDescription1" - }, - ["port"] = new OpenApiServerVariable - { - Default = "8443", - Description = "variableDescription2", - Enum = new List - { - "443", - "8443" - } - }, - ["basePath"] = new OpenApiServerVariable - { - Default = "v1" - } - } - } - }, - new OpenApiDifference - { - Pointer = "#/0", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiServer), - SourceValue = null, - TargetValue = new OpenApiServer - { - Description = "description1", - Url = "https://{username}.example.com:{port}/test", - Variables = new Dictionary - { - ["username"] = new OpenApiServerVariable - { - Default = "unknown", - Description = "variableDescription1" - }, - ["port"] = new OpenApiServerVariable - { - Default = "8443", - Description = "variableDescription2", - Enum = new List - { - "443", - "8443" - } - }, - ["basePath"] = new OpenApiServerVariable - { - Default = "v1" - } - } - } - }, - new OpenApiDifference - { - Pointer = "#/1", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Add, - OpenApiComparedElementType = typeof(OpenApiServer), - SourceValue = null, - TargetValue = new OpenApiServer - { - Description = "description3", - Url = "https://{username}.example.com:{port}/{basePath}/test", - Variables = new Dictionary - { - ["username"] = new OpenApiServerVariable - { - Default = "unknown", - Description = "variableDescription1" - }, - ["port"] = new OpenApiServerVariable - { - Default = "8443", - Description = "variableDescription2", - Enum = new List - { - "443", - "8443" - } - }, - ["basePath"] = new OpenApiServerVariable - { - Default = "v1" - } - } - } - } - } - }; - } - - [Theory] - [MemberData(nameof(GetTestCasesForOpenApiServersComparerShouldSucceed))] - public void OpenApiServersComparerShouldSucceed( - string testCaseName, - IList source, - IList target, - List expectedDifferences) - { - _output.WriteLine(testCaseName); - - var comparisonContext = new ComparisonContext(new OpenApiComparerFactory(), _sourceDocument, - _targetDocument); - var comparer = new OpenApiServersComparer(); - comparer.Compare(source, target, comparisonContext); - - var differences = comparisonContext.OpenApiDifferences.ToList(); - differences.Count().Should().Be(expectedDifferences.Count); - - differences.Should().BeEquivalentTo(expectedDifferences); - } - } -} diff --git a/test/Microsoft.OpenApi.Tests/Services/OpenApiTagComparerTests.cs b/test/Microsoft.OpenApi.Tests/Services/OpenApiTagComparerTests.cs deleted file mode 100644 index 1d4cd391d..000000000 --- a/test/Microsoft.OpenApi.Tests/Services/OpenApiTagComparerTests.cs +++ /dev/null @@ -1,304 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT license. - -using System; -using System.Collections.Generic; -using System.Linq; -using FluentAssertions; -using Microsoft.OpenApi.Models; -using Microsoft.OpenApi.Services; -using Xunit; -using Xunit.Abstractions; - -namespace Microsoft.OpenApi.Tests.Services -{ - [Collection("DefaultSettings")] - public class OpenApiTagComparerTests - { - private readonly ITestOutputHelper _output; - - private readonly OpenApiDocument _sourceDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property7"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - private readonly OpenApiDocument _targetDocument = new OpenApiDocument - { - Components = new OpenApiComponents - { - Schemas = new Dictionary - { - ["schemaObject1"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject2" - } - } - } - }, - ["schemaObject2"] = new OpenApiSchema - { - Properties = new Dictionary - { - ["property2"] = new OpenApiSchema - { - Type = "integer" - }, - ["property5"] = new OpenApiSchema - { - Type = "string", - MaxLength = 15 - }, - ["property6"] = new OpenApiSchema - { - Reference = new OpenApiReference - { - Type = ReferenceType.Schema, - Id = "schemaObject1" - } - } - } - } - }, - RequestBodies = new Dictionary - { - ["requestBody1"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - }, - ["requestBody2"] = new OpenApiRequestBody - { - Description = "description", - Required = true, - Content = - { - ["application/json"] = new OpenApiMediaType - { - Schema = new OpenApiSchema - { - Reference = new OpenApiReference - { - Id = "schemaObject1", - Type = ReferenceType.Schema - } - } - } - } - } - } - } - }; - - public OpenApiTagComparerTests(ITestOutputHelper output) - { - _output = output; - } - - public static IEnumerable GetTestCasesForOpenApiTagComparerShouldSucceed() - { - // Differences in name, description and external docs - yield return new object[] - { - "Differences in name, description and external docs", - new OpenApiTag - { - Description = "test description", - Name = "test name", - ExternalDocs = new OpenApiExternalDocs - { - Description = "test description", - Url = new Uri("http://localhost/doc") - } - }, - new OpenApiTag - { - Description = "test description updated", - Name = "test name updated", - ExternalDocs = new OpenApiExternalDocs - { - Description = "test description updated", - Url = new Uri("http://localhost/updated") - } - }, - new List - { - new OpenApiDifference - { - Pointer = "#/externalDocs/description", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "test description", - TargetValue = "test description updated" - }, - new OpenApiDifference - { - Pointer = "#/externalDocs/url", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(Uri), - SourceValue = new Uri("http://localhost/doc"), - TargetValue = new Uri("http://localhost/updated") - }, - new OpenApiDifference - { - Pointer = "#/description", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "test description", - TargetValue = "test description updated" - }, - new OpenApiDifference - { - Pointer = "#/name", - OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update, - OpenApiComparedElementType = typeof(string), - SourceValue = "test name", - TargetValue = "test name updated" - } - } - }; - } - - [Theory] - [MemberData(nameof(GetTestCasesForOpenApiTagComparerShouldSucceed))] - public void OpenApiTagServerVariableComparerShouldSucceed( - string testCaseName, - OpenApiTag source, - OpenApiTag target, - List expectedDifferences) - { - _output.WriteLine(testCaseName); - - var comparisonContext = new ComparisonContext(new OpenApiComparerFactory(), _sourceDocument, - _targetDocument); - var comparer = new OpenApiTagComparer(); - comparer.Compare(source, target, comparisonContext); - - var differences = comparisonContext.OpenApiDifferences.ToList(); - differences.Count().Should().Be(expectedDifferences.Count); - - differences.Should().BeEquivalentTo(expectedDifferences); - } - } -}