コード例 #1
0
        /// <summary>
        /// Compares Enum.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="comparisonContext">The context under which to compare the objects.</param>
        internal void Compare <TEnum>(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
                });
            }
        }
コード例 #2
0
        /// <summary>
        /// Executes comparision against source and target <see cref="IOpenApiAny"/>.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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
                });
            }
        }
コード例 #3
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiTag"/>.
        /// </summary>
        /// <param name="sourceTag">The source.</param>
        /// <param name="targetTag">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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 <OpenApiExternalDocs>()
                .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));
        }
コード例 #4
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiServerVariable"/>.
        /// </summary>
        /// <param name="sourceServerVariable">The source.</param>
        /// <param name="targetServerVariable">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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
        }
コード例 #5
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiContact"/>.
        /// </summary>
        /// <param name="sourceContact">The source.</param>
        /// <param name="targetContact">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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));
        }
コード例 #6
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiExternalDocs"/>.
        /// </summary>
        /// <param name="sourceDocs">The source.</param>
        /// <param name="targetDocs">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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));
        }
コード例 #7
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiOAuthFlow"/>.
        /// </summary>
        /// <param name="sourceFlow">The source.</param>
        /// <param name="targetFlow">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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));
        }
コード例 #8
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiSecurityScheme"/>.
        /// </summary>
        /// <param name="sourcecSecurityScheme">The source.</param>
        /// <param name="targetSecurityScheme">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        public override void Compare(
            OpenApiSecurityScheme sourcecSecurityScheme,
            OpenApiSecurityScheme targetSecurityScheme,
            ComparisonContext comparisonContext)
        {
            if (sourcecSecurityScheme == null && targetSecurityScheme == null)
            {
                return;
            }

            if (sourcecSecurityScheme == null || targetSecurityScheme == null)
            {
                comparisonContext.AddOpenApiDifference(
                    new OpenApiDifference
                {
                    OpenApiDifferenceOperation = OpenApiDifferenceOperation.Update,
                    SourceValue = sourcecSecurityScheme,
                    TargetValue = targetSecurityScheme,
                    OpenApiComparedElementType = typeof(OpenApiSecurityScheme),
                    Pointer = comparisonContext.PathString
                });

                return;
            }

            new OpenApiReferenceComparer <OpenApiSecurityScheme>()
            .Compare(sourcecSecurityScheme.Reference, targetSecurityScheme.Reference,
                     comparisonContext);

            WalkAndCompare(comparisonContext, OpenApiConstants.Description,
                           () => Compare(sourcecSecurityScheme.Description, targetSecurityScheme.Description, comparisonContext));

            WalkAndCompare(comparisonContext, OpenApiConstants.Type,
                           () => Compare <SecuritySchemeType>(sourcecSecurityScheme.Type, targetSecurityScheme.Type,
                                                              comparisonContext));

            WalkAndCompare(comparisonContext, OpenApiConstants.Name,
                           () => Compare(sourcecSecurityScheme.Name, targetSecurityScheme.Name, comparisonContext));

            WalkAndCompare(comparisonContext, OpenApiConstants.In,
                           () => Compare <ParameterLocation>(sourcecSecurityScheme.In, targetSecurityScheme.In, comparisonContext));

            WalkAndCompare(comparisonContext, OpenApiConstants.Scheme,
                           () => Compare(sourcecSecurityScheme.Scheme, targetSecurityScheme.Scheme, comparisonContext));

            WalkAndCompare(comparisonContext, OpenApiConstants.BearerFormat,
                           () => Compare(sourcecSecurityScheme.BearerFormat, targetSecurityScheme.BearerFormat,
                                         comparisonContext));

            WalkAndCompare(comparisonContext, OpenApiConstants.OpenIdConnectUrl,
                           () => Compare(sourcecSecurityScheme.OpenIdConnectUrl, targetSecurityScheme.OpenIdConnectUrl,
                                         comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Flows,
                () => comparisonContext
                .GetComparer <OpenApiOAuthFlows>()
                .Compare(sourcecSecurityScheme.Flows, targetSecurityScheme.Flows, comparisonContext));
        }
コード例 #9
0
 /// <summary>
 /// Adds a segment to the context path to enable pointing to the current location in the document.
 /// </summary>
 /// <param name="comparisonContext">The context under which to compare the objects.</param>
 /// <param name="segment">An identifier for the segment.</param>
 /// <param name="openApiDifference">The open api difference to add.</param>
 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();
 }
コード例 #10
0
        /// <summary>
        /// Compares <see cref="IDictionary{TKey,TValue}"/> where TKey is <see cref="string"/> and TValue is
        /// <see cref="string"/>.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="comparisonContext">The context under which to compare the objects.</param>
        internal void Compare(IDictionary <string, string> source, IDictionary <string, string> 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 <string, T>),
                    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)
                });
            }
        }
コード例 #11
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiOAuthFlows"/>.
        /// </summary>
        /// <param name="sourceFlows">The source.</param>
        /// <param name="targetFlows">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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 <OpenApiOAuthFlow>()
                .Compare(sourceFlows.Implicit, targetFlows.Implicit, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Password,
                () => comparisonContext
                .GetComparer <OpenApiOAuthFlow>()
                .Compare(sourceFlows.Password, targetFlows.Password, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.ClientCredentials,
                () => comparisonContext
                .GetComparer <OpenApiOAuthFlow>()
                .Compare(sourceFlows.ClientCredentials, targetFlows.ClientCredentials, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.AuthorizationCode,
                () => comparisonContext
                .GetComparer <OpenApiOAuthFlow>()
                .Compare(sourceFlows.AuthorizationCode, targetFlows.AuthorizationCode, comparisonContext));
        }
コード例 #12
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiMediaType"/>.
        /// </summary>
        /// <param name="sourceMediaType">The source.</param>
        /// <param name="targetMediaType">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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 <OpenApiSchema>()
                .Compare(sourceMediaType.Schema, targetMediaType.Schema, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Encoding,
                () => comparisonContext
                .GetComparer <IDictionary <string, OpenApiEncoding> >()
                .Compare(sourceMediaType.Encoding, sourceMediaType.Encoding, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Examples,
                () => comparisonContext
                .GetComparer <IDictionary <string, OpenApiExample> >()
                .Compare(sourceMediaType.Examples, targetMediaType.Examples, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Example,
                () => comparisonContext
                .GetComparer <IOpenApiAny>()
                .Compare(sourceMediaType.Example, targetMediaType.Example, comparisonContext));
        }
コード例 #13
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiInfo"/>.
        /// </summary>
        /// <param name="sourceInfo">The source.</param>
        /// <param name="targetInfo">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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 <OpenApiContact>()
                .Compare(sourceInfo.Contact, targetInfo.Contact, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.License,
                () => comparisonContext
                .GetComparer <OpenApiLicense>()
                .Compare(sourceInfo.License, targetInfo.License, comparisonContext));
        }
コード例 #14
0
        /// <summary>
        /// Compares <see cref="OpenApiReference"/> object.
        /// </summary>
        /// <param name="sourceReference">The source.</param>
        /// <param name="targetReference">The target.</param>
        /// <param name="comparisonContext">The context under which to compare the objects.</param>
        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 <T>()
            .Compare(source, target, comparisonContext);
        }
コード例 #15
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiEncoding"/>.
        /// </summary>
        /// <param name="sourceEncoding">The source.</param>
        /// <param name="targetEncoding">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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 <ParameterStyle>(sourceEncoding.Style, targetEncoding.Style, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Headers,
                () => comparisonContext
                .GetComparer <IDictionary <string, OpenApiHeader> >()
                .Compare(sourceEncoding.Headers, targetEncoding.Headers, comparisonContext));

            // To Do Compare Extensions
        }
コード例 #16
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiExample"/>.
        /// </summary>
        /// <param name="sourceExample">The source.</param>
        /// <param name="targetExample">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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;
            }

            new OpenApiReferenceComparer <OpenApiExample>()
            .Compare(sourceExample.Reference, targetExample.Reference, comparisonContext);

            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 <IOpenApiAny>()
                .Compare(sourceExample.Value, targetExample.Value, comparisonContext));
        }
コード例 #17
0
        /// <summary>
        /// Compares two string object.
        /// </summary>
        /// <param name="source">The source string.</param>
        /// <param name="target">The target string.</param>
        /// <param name="comparisonContext">The context under which to compare the objects.</param>
        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
                });
            }
        }
コード例 #18
0
        /// <summary>
        /// Compares two boolean object.
        /// </summary>
        /// <param name="source">The source.</param>
        /// <param name="target">The target.</param>
        /// <param name="comparisonContext">The context under which to compare the objects.</param>
        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
                });
            }
        }
コード例 #19
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiRequestBody"/>.
        /// </summary>
        /// <param name="sourceRequestBody">The source.</param>
        /// <param name="targetRequestBody">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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;
            }

            new OpenApiReferenceComparer <OpenApiRequestBody>()
            .Compare(sourceRequestBody.Reference, targetRequestBody.Reference, comparisonContext);

            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 <IDictionary <string, OpenApiMediaType> >()
                .Compare(sourceRequestBody.Content, targetRequestBody.Content, comparisonContext));

            //To Do Compare Extensions
        }
コード例 #20
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiServer"/>.
        /// </summary>
        /// <param name="sourceServer">The source.</param>
        /// <param name="targetServer">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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 <IDictionary <string, OpenApiServerVariable> >()
                .Compare(sourceServer.Variables, sourceServer.Variables, comparisonContext));

            // To Do compare extensions
        }
コード例 #21
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiSchema"/>.
        /// </summary>
        /// <param name="sourceSchema">The source.</param>
        /// <param name="targetSchema">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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.SourceSchemaLoop.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 <OpenApiSchema>()
                    .Compare(sourceSchema.Items, targetSchema.Items, comparisonContext));
            }

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Properties,
                () => comparisonContext
                .GetComparer <IDictionary <string, OpenApiSchema> >()
                .Compare(sourceSchema.Properties,
                         targetSchema.Properties, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.ExternalDocs,
                () => comparisonContext
                .GetComparer <OpenApiExternalDocs>()
                .Compare(sourceSchema.ExternalDocs, targetSchema.ExternalDocs, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Example,
                () => comparisonContext
                .GetComparer <IOpenApiAny>()
                .Compare(sourceSchema.Example, targetSchema.Example, comparisonContext));

            // To Do Compare schema.AllOf
            // To Do Compare schema.AnyOf

            comparisonContext.SourceSchemaLoop.Pop();
            comparisonContext.TargetSchemaLoop.Pop();
        }
コード例 #22
0
        /// <summary>
        /// Executes comparision against based on the order of the list for source and target <see cref="IList{T}"/>
        /// where T is <see cref="IOpenApiSerializable"/>.
        /// </summary>
        /// <param name="sourceFragment">The source.</param>
        /// <param name="targetFragment">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        public override void Compare(
            IList <T> sourceFragment,
            IList <T> 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 <T>),
                    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 <T>()
                                   .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)
                });
            }
        }
コード例 #23
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiParameter"/>.
        /// </summary>
        /// <param name="sourceParameter">The source.</param>
        /// <param name="targetParameter">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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;
            }

            new OpenApiReferenceComparer <OpenApiParameter>()
            .Compare(sourceParameter.Reference, targetParameter.Reference, comparisonContext);

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Content,
                () => comparisonContext
                .GetComparer <IDictionary <string, OpenApiMediaType> >()
                .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 <ParameterStyle>(sourceParameter.Style, targetParameter.Style, comparisonContext));

            WalkAndCompare(comparisonContext, OpenApiConstants.In,
                           () => Compare <ParameterLocation>(sourceParameter.In, targetParameter.In, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Schema,
                () => comparisonContext
                .GetComparer <OpenApiSchema>()
                .Compare(sourceParameter.Schema, targetParameter.Schema, comparisonContext));

            // To Do Compare Examples
            // To Do Compare parameter as IOpenApiExtensible
        }
コード例 #24
0
        /// <summary>
        /// Executes comparision against source and target <see cref="IDictionary{TKey,TValue}"/>
        /// where TKey is<see cref="OperationType"/> and TValue is <see cref="OpenApiOperation"/>.
        /// </summary>
        /// <param name="sourceOperations">The source.</param>
        /// <param name="targetOperations">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        public override void Compare(
            IDictionary <OperationType, OpenApiOperation> sourceOperations,
            IDictionary <OperationType, OpenApiOperation> 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 <OperationType, OpenApiOperation>),
                    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 <OpenApiOperation>()
                                   .Compare(sourceOperation.Value, targetOperations[sourceOperation.Key], comparisonContext));
                }
                else
                {
                    WalkAndAddOpenApiDifference(
                        comparisonContext,
                        sourceOperation.Key.GetDisplayName(),
                        new OpenApiDifference
                    {
                        OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove,
                        SourceValue = sourceOperation.Value,
                        OpenApiComparedElementType = typeof(OpenApiOperation)
                    });
                }
            }
        }
コード例 #25
0
        /// <summary>
        /// Executes comparision against source and target <see cref="IDictionary{TKey, TValue}"/>
        /// where TKey is <see cref="string"/> and TValue is <see cref="IOpenApiSerializable"/>.
        /// </summary>
        /// <param name="sourceFragment">The source.</param>
        /// <param name="targetFragment">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        public override void Compare(
            IDictionary <string, T> sourceFragment,
            IDictionary <string, T> 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 <string, T>),
                    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 <T>()
                                   .Compare(source.Value, targetFragment[source.Key], comparisonContext));
                }
                else
                {
                    WalkAndAddOpenApiDifference(
                        comparisonContext,
                        source.Key,
                        new OpenApiDifference
                    {
                        OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove,
                        SourceValue = source.Value,
                        OpenApiComparedElementType = typeof(T)
                    });
                }
            }
        }
コード例 #26
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiComponents"/>.
        /// </summary>
        /// <param name="sourceComponents">The source.</param>
        /// <param name="targetComponents">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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 <IDictionary <string, OpenApiParameter> >()
                .Compare(sourceComponents.Parameters, targetComponents.Parameters, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.RequestBodies,
                () => comparisonContext
                .GetComparer <IDictionary <string, OpenApiRequestBody> >()
                .Compare(sourceComponents.RequestBodies, targetComponents.RequestBodies, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Responses,
                () => comparisonContext
                .GetComparer <IDictionary <string, OpenApiResponse> >()
                .Compare(sourceComponents.Responses, targetComponents.Responses, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Schemas,
                () => comparisonContext
                .GetComparer <IDictionary <string, OpenApiSchema> >()
                .Compare(sourceComponents.Schemas, targetComponents.Schemas, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Headers,
                () => comparisonContext
                .GetComparer <IDictionary <string, OpenApiHeader> >()
                .Compare(sourceComponents.Headers, targetComponents.Headers, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.SecuritySchemes,
                () => comparisonContext
                .GetComparer <IDictionary <string, OpenApiSecurityScheme> >()
                .Compare(sourceComponents.SecuritySchemes, targetComponents.SecuritySchemes, comparisonContext));

            // To Do compare Examples
            // To Do compare Links
            // To Do compare Callbacks
            // To Do compare Extensions
        }
コード例 #27
0
        /// <summary>
        /// Executes comparision against source and target <see cref="IList{T}"/>
        /// where T is<see cref="OpenApiParameter"/>.
        /// </summary>
        /// <param name="sourceParameters">The source.</param>
        /// <param name="targetParameters">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        public override void Compare(
            IList <OpenApiParameter> sourceParameters,
            IList <OpenApiParameter> 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 <OpenApiParameter>),
                    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 <OpenApiParameter>()
                    .Compare(sourceParameter, targetParameter, comparisonContext));
            }
        }
コード例 #28
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiSecurityRequirement"/>.
        /// </summary>
        /// <param name="sourceSecurityRequirement">The source.</param>
        /// <param name="targetSecurityRequirement">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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 <string>)
                });
            }

            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 <string>)
                    });
                }
                else
                {
                    WalkAndCompare(comparisonContext,
                                   sourceSecurityScheme.Reference.Id,
                                   () => comparisonContext
                                   .GetComparer <OpenApiSecurityScheme>()
                                   .Compare(sourceSecurityScheme, targetSecurityScheme, comparisonContext));
                }
            }
        }
コード例 #29
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiHeader"/>.
        /// </summary>
        /// <param name="sourceHeader">The source.</param>
        /// <param name="targetHeader">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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 <IDictionary <string, OpenApiMediaType> >()
                .Compare(sourceHeader.Content, targetHeader.Content, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Schema,
                () => comparisonContext
                .GetComparer <OpenApiSchema>()
                .Compare(sourceHeader.Schema, targetHeader.Schema, comparisonContext));

            // To do compare example
            // To do compare examples
            // To do compare extensions
        }
コード例 #30
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiResponse"/>.
        /// </summary>
        /// <param name="sourceResponse">The source.</param>
        /// <param name="targetResponse">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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 <IDictionary <string, OpenApiMediaType> >()
                .Compare(sourceResponse.Content, targetResponse.Content, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Headers,
                () => comparisonContext
                .GetComparer <IDictionary <string, OpenApiHeader> >()
                .Compare(sourceResponse.Headers, targetResponse.Headers, comparisonContext));

            // To Do Compare Link
        }