/// <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));
        }
        /// <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));
        }
示例#3
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));
        }
        /// <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));
        }
        /// <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));
        }
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiDocument"/>.
        /// </summary>
        /// <param name="sourceDocument">The source.</param>
        /// <param name="targetDocument">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        public override void Compare(
            OpenApiDocument sourceDocument,
            OpenApiDocument targetDocument,
            ComparisonContext comparisonContext)
        {
            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Paths,
                () => comparisonContext
                .GetComparer <OpenApiPaths>()
                .Compare(sourceDocument.Paths, targetDocument.Paths, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Components,
                () => comparisonContext
                .GetComparer <OpenApiComponents>()
                .Compare(sourceDocument.Components, targetDocument.Components, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Components,
                () => comparisonContext
                .GetComparer <IList <OpenApiServer> >()
                .Compare(sourceDocument.Servers, targetDocument.Servers, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Info,
                () => comparisonContext
                .GetComparer <OpenApiInfo>()
                .Compare(sourceDocument.Info, targetDocument.Info, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Security,
                () => comparisonContext
                .GetComparer <IList <OpenApiSecurityRequirement> >()
                .Compare(sourceDocument.SecurityRequirements, targetDocument.SecurityRequirements,
                         comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Tags,
                () => comparisonContext
                .GetComparer <IList <OpenApiTag> >()
                .Compare(sourceDocument.Tags, targetDocument.Tags, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.ExternalDocs,
                () => comparisonContext
                .GetComparer <OpenApiExternalDocs>()
                .Compare(sourceDocument.ExternalDocs, targetDocument.ExternalDocs, comparisonContext));
        }
示例#7
0
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiPathItem"/>.
        /// </summary>
        /// <param name="sourcePathItem">The source.</param>
        /// <param name="targetPathItem">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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 <IDictionary <OperationType, OpenApiOperation> >()
            .Compare(sourcePathItem?.Operations, targetPathItem?.Operations, comparisonContext);

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Parameters,
                () => comparisonContext
                .GetComparer <IList <OpenApiParameter> >()
                .Compare(sourcePathItem?.Parameters, targetPathItem?.Parameters, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Servers,
                () => comparisonContext
                .GetComparer <IList <OpenApiServer> >()
                .Compare(sourcePathItem?.Servers, targetPathItem?.Servers, comparisonContext));

            // To Do Compare Extensions
        }
示例#8
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);
        }
        /// <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
        }
示例#10
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));
        }
示例#11
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
        }
示例#12
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
        }
        /// <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();
        }
示例#14
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)
                    });
                }
            }
        }
        /// <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)
                });
            }
        }
        /// <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
        }
        /// <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));
                }
            }
        }
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiOperation"/>.
        /// </summary>
        /// <param name="sourceOperation">The source.</param>
        /// <param name="targetOperation">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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 <IList <OpenApiParameter> >()
                           .Compare(sourceOperation?.Parameters, targetOperation?.Parameters, comparisonContext));

            WalkAndCompare(comparisonContext, OpenApiConstants.RequestBody,
                           () => comparisonContext
                           .GetComparer <OpenApiRequestBody>()
                           .Compare(sourceOperation?.RequestBody, targetOperation?.RequestBody, comparisonContext));

            WalkAndCompare(comparisonContext, OpenApiConstants.Responses,
                           () => comparisonContext
                           .GetComparer <IDictionary <string, OpenApiResponse> >()
                           .Compare(sourceOperation?.Responses, targetOperation?.Responses, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Servers,
                () => comparisonContext
                .GetComparer <IList <OpenApiServer> >()
                .Compare(sourceOperation?.Servers, targetOperation?.Servers, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Tags,
                () => comparisonContext
                .GetComparer <IList <OpenApiTag> >()
                .Compare(sourceOperation?.Tags, targetOperation?.Tags, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.Security,
                () => comparisonContext
                .GetComparer <IList <OpenApiSecurityRequirement> >()
                .Compare(sourceOperation?.Security, targetOperation?.Security, comparisonContext));

            WalkAndCompare(
                comparisonContext,
                OpenApiConstants.ExternalDocs,
                () => comparisonContext
                .GetComparer <OpenApiExternalDocs>()
                .Compare(sourceOperation?.ExternalDocs, targetOperation?.ExternalDocs, comparisonContext));

            // Compare CallBack
        }
示例#19
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)
                    });
                }
            }
        }
示例#20
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
        }
示例#21
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));
            }
        }
示例#22
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
        }
示例#23
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
        }
        /// <summary>
        /// Executes comparision against source and target <see cref="OpenApiPaths"/>.
        /// </summary>
        /// <param name="sourcePaths">The source.</param>
        /// <param name="targetPaths">The target.</param>
        /// <param name="comparisonContext">Context under which to compare the source and target.</param>
        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 <OpenApiPathItem>()
                        .Compare(sourcePaths[sourcePathKey], targetPaths[sourcePathKey], comparisonContext));
                }
                else
                {
                    WalkAndAddOpenApiDifference(
                        comparisonContext,
                        sourcePathKey,
                        new OpenApiDifference
                    {
                        OpenApiDifferenceOperation = OpenApiDifferenceOperation.Remove,
                        SourceValue = sourcePaths[sourcePathKey],
                        OpenApiComparedElementType = typeof(OpenApiPathItem)
                    });
                }
            }
        }