コード例 #1
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));
        }
コード例 #2
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
        }
コード例 #3
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
        }
コード例 #4
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));
            }
        }
コード例 #5
0
 public override void Compare(OpenApiString sourceFragment, OpenApiString targetFragment, ComparisonContext comparisonContext)
 {
     Compare(sourceFragment.Value, targetFragment.Value, comparisonContext);
 }
コード例 #6
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
        }
コード例 #7
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();
        }
コード例 #8
0
 public override void Compare(IOpenApiAny sourceFragment, IOpenApiAny targetFragment, ComparisonContext comparisonContext)
 {
     Compare(((OpenApiString)sourceFragment).Value, ((OpenApiString)targetFragment).Value, comparisonContext);
 }
コード例 #9
0
        /// <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)
                    });
                }
            }
        }
コード例 #10
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
        }
コード例 #11
0
        /// <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
        }
コード例 #12
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));
                }
            }
        }
コード例 #13
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)
                });
            }
        }
コード例 #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)
                    });
                }
            }
        }
コード例 #15
0
 /// <summary>
 /// Validates a fragment of <see cref="OpenApiDocument"/>.
 /// </summary>
 /// <param name="sourceFragment">The source fragment.</param>
 /// <param name="targetFragment">The target fragment.</param>
 /// <param name="comparisonContext">Context under which to compare fragment.</param>
 public abstract void Compare(T sourceFragment, T targetFragment, ComparisonContext comparisonContext);
コード例 #16
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)
                    });
                }
            }
        }
コード例 #17
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
        }
コード例 #18
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
        }