コード例 #1
0
ファイル: HeaderDiff.cs プロジェクト: LimeFlight/openapi-diff
        protected override ChangedHeaderBO ComputeDiff(OpenApiHeader left, OpenApiHeader right,
                                                       DiffContextBO context)
        {
            left  = RefPointer.ResolveRef(_leftComponents, left, left.Reference?.ReferenceV3);
            right = RefPointer.ResolveRef(_rightComponents, right, right.Reference?.ReferenceV3);

            var changedHeader =
                new ChangedHeaderBO(left, right, context)
            {
                Required    = GetBooleanDiff(left.Required, right.Required),
                Deprecated  = !left.Deprecated && right.Deprecated,
                Style       = left.Style != right.Style,
                Explode     = GetBooleanDiff(left.Explode, right.Explode),
                Description = _openApiDiff
                              .MetadataDiff
                              .Diff(left.Description, right.Description, context),
                Schema = _openApiDiff
                         .SchemaDiff
                         .Diff(left.Schema, right.Schema, context.CopyWithRequired(true)),
                Content = _openApiDiff
                          .ContentDiff
                          .Diff(left.Content, right.Content, context),
                Extensions = _openApiDiff
                             .ExtensionsDiff
                             .Diff(left.Extensions, right.Extensions, context)
            };

            return(ChangedUtils.IsChanged(changedHeader));
        }
コード例 #2
0
 public static OpenApiParameter Contains(OpenApiComponents components, List <OpenApiParameter> parameters,
                                         OpenApiParameter parameter)
 {
     return(parameters
            .FirstOrDefault(x =>
                            Same(RefPointer.ResolveRef(components, x, x.Reference?.ReferenceV3), parameter)));
 }
コード例 #3
0
        protected override ChangedRequestBodyBO ComputeDiff(OpenApiRequestBody left,
                                                            OpenApiRequestBody right,
                                                            DiffContextBO context)
        {
            Dictionary <string, OpenApiMediaType> oldRequestContent = null;
            Dictionary <string, OpenApiMediaType> newRequestContent = null;
            OpenApiRequestBody oldRequestBody = null;
            OpenApiRequestBody newRequestBody = null;

            if (left != null)
            {
                oldRequestBody =
                    RefPointer.ResolveRef(
                        _openApiDiff.OldSpecOpenApi.Components, left, left.Reference?.ReferenceV3);
                if (oldRequestBody.Content != null)
                {
                    oldRequestContent = (Dictionary <string, OpenApiMediaType>)oldRequestBody.Content;
                }
            }

            if (right != null)
            {
                newRequestBody =
                    RefPointer.ResolveRef(
                        _openApiDiff.NewSpecOpenApi.Components, right, right.Reference?.ReferenceV3);
                if (newRequestBody.Content != null)
                {
                    newRequestContent = (Dictionary <string, OpenApiMediaType>)newRequestBody.Content;
                }
            }

            var leftRequired =
                oldRequestBody != null && oldRequestBody.Required;
            var rightRequired =
                newRequestBody != null && newRequestBody.Required;

            var changedRequestBody =
                new ChangedRequestBodyBO(oldRequestBody, newRequestBody, context)
            {
                ChangeRequired = leftRequired != rightRequired,
                Description    = _openApiDiff
                                 .MetadataDiff
                                 .Diff(
                    oldRequestBody?.Description,
                    newRequestBody?.Description,
                    context),
                Content = _openApiDiff
                          .ContentDiff
                          .Diff(oldRequestContent, newRequestContent, context),
                Extensions = _openApiDiff
                             .ExtensionsDiff
                             .Diff(GetExtensions(left), GetExtensions(right), context)
            };

            return(ChangedUtils.IsChanged(changedRequestBody));
        }
コード例 #4
0
        private static KeyValuePair <string, OpenApiSchema> ResolveComposedSchema(OpenApiComponents components, OpenApiSchema schema)
        {
            var allOfSchemaList = schema.AllOf.ToList();

            if (!allOfSchemaList.Any())
            {
                return(new KeyValuePair <string, OpenApiSchema>(string.Empty, null));
            }

            // Get combined schema name
            var refName = "allOfCombined-";

            allOfSchemaList
            .ForEach(x => refName += x.Reference?.ReferenceV3);

            // If the same refName was already created before
            if (components.Schemas.TryGetValue(refName, out var composedSchema))
            {
                return(new KeyValuePair <string, OpenApiSchema>(refName, composedSchema));
            }

            //// Add combined schema name with empty schema
            //components.Schemas.Add(refName, new OpenApiSchema());

            // Construct combined schema
            var allOfCombinedSchema = new OpenApiSchema();

            allOfCombinedSchema = AddSchema(allOfCombinedSchema, schema);
            foreach (var t in allOfSchemaList)
            {
                var allOfSchema = t;
                allOfSchema =
                    RefPointer.ResolveRef(components, allOfSchema, allOfSchema.Reference?.ReferenceV3);

                var result = ResolveComposedSchema(components, allOfSchema);

                if (result.Value != null)
                {
                    allOfSchema = result.Value;
                }

                allOfCombinedSchema = AddSchema(allOfCombinedSchema, allOfSchema);
            }

            // Set correct combined schema
            components.Schemas[refName] = allOfCombinedSchema;

            return(new KeyValuePair <string, OpenApiSchema>(refName, allOfCombinedSchema));
        }
コード例 #5
0
        private static Dictionary <string, OpenApiSchema> GetSchema(OpenApiComponents components,
                                                                    Dictionary <string, string> mapping)
        {
            var result = new Dictionary <string, OpenApiSchema>();

            foreach (var map in mapping)
            {
                result.Add(map.Key, refPointer.ResolveRef(components, new OpenApiSchema(), map.Value));
            }
            return(result);
        }
コード例 #6
0
        protected override ChangedResponseBO ComputeDiff(OpenApiResponse left,
                                                         OpenApiResponse right, DiffContextBO context)
        {
            left  = RefPointer.ResolveRef(_leftComponents, left, left.Reference?.ReferenceV3);
            right = RefPointer.ResolveRef(_rightComponents, right, right.Reference?.ReferenceV3);

            var changedResponse = new ChangedResponseBO(left, right, context)
            {
                Description = _openApiDiff
                              .MetadataDiff
                              .Diff(left.Description, right.Description, context),
                Content = _openApiDiff
                          .ContentDiff
                          .Diff(left.Content, right.Content, context),
                Headers = _openApiDiff
                          .HeadersDiff
                          .Diff(left.Headers, right.Headers, context),
                Extensions = _openApiDiff
                             .ExtensionsDiff
                             .Diff(left.Extensions, right.Extensions, context)
            };

            return(ChangedUtils.IsChanged(changedResponse));
        }
コード例 #7
0
 private static OpenApiSchema Resolve(OpenApiSchema schema)
 {
     return(RefPointer.ResolveRef(_diff.NewSpecOpenApi.Components, schema, schema.Reference?.ReferenceV3));
 }