public override IEnumerable Compare()

in openapi-diff/src/modeler/AutoRest.Swagger/Model/Schema.cs [76:184]


        public override IEnumerable<ComparisonMessage> Compare(
            ComparisonContext<ServiceDefinition> context,
            Schema previous
        )
        {
            var priorSchema = previous;
            if (priorSchema == null)
            {
                throw new ArgumentNullException("priorVersion");
            }
            if (context == null)
            {
                throw new ArgumentNullException("context");
            }



            int referenced = 0;

            var thisSchema = this;

            if (!string.IsNullOrWhiteSpace(thisSchema.Reference))
            {
                thisSchema = FindReferencedSchema(thisSchema.Reference, context.CurrentRoot.Definitions);
                referenced += 1;
                if (thisSchema == null)
                {
                    return context.Messages;
                }
            }
            if (!string.IsNullOrWhiteSpace(priorSchema.Reference))
            {
                priorSchema = FindReferencedSchema(priorSchema.Reference, context.PreviousRoot.Definitions);
                referenced += 1;
                if (priorSchema == null)
                {
                    return context.Messages;
                }
            }

            var thisModelName = thisSchema.XmsClientName ?? Reference ?? "";
            var priorModelName = priorSchema.XmsClientName ?? previous.Reference ?? "";
            if (!thisModelName.Equals(priorModelName))
            {
                context.LogBreakingChange(ComparisonMessages.ReferenceRedirection);
            }

            // Avoid doing the comparison repeatedly by marking for which direction it's already been done.

            if (context.Direction != DataDirection.None && referenced == 2)
            {
                // Comparing two referenced schemas in the context of a parameter or response -- did we already do this?

                if (thisSchema._compareDirection == context.Direction || thisSchema._compareDirection == DataDirection.Both)
                {
                    return new ComparisonMessage[0];
                }
                _compareDirection |= context.Direction;
            }

            if (thisSchema != this || priorSchema != previous)
            {
                if (_visitedSchemas.Contains(priorSchema))
                {
                    return context.Messages;
                }
                _visitedSchemas.AddFirst(priorSchema);
                return thisSchema.Compare(context, priorSchema);
            }

            base.Compare(context, previous);

            if (priorSchema.ReadOnly != ReadOnly)
            {
                context.LogBreakingChange(ComparisonMessages.ReadonlyPropertyChanged, priorSchema.ReadOnly.ToString().ToLower(), ReadOnly.ToString().ToLower());
            }

            if ((priorSchema.Discriminator == null && Discriminator != null) ||
                (priorSchema.Discriminator != null && !priorSchema.Discriminator.Equals(Discriminator)))
            {
                context.LogBreakingChange(ComparisonMessages.DifferentDiscriminator);
            }

            if ((priorSchema.Extends == null && Extends != null) ||
                (priorSchema.Extends != null && !priorSchema.Extends.Equals(Extends)))
            {
                context.LogBreakingChange(ComparisonMessages.DifferentExtends);
            }

            if ((priorSchema.AllOf == null && AllOf != null) ||
                (priorSchema.AllOf != null && AllOf == null))
            {
                context.LogBreakingChange(ComparisonMessages.DifferentAllOf);
            }
            else if (priorSchema.AllOf != null)
            {
                CompareAllOfs(context, priorSchema);
            }

            // Compare each properties of the model
            context.PushProperty("properties");
            CompareProperties(context, priorSchema);
            context.Pop();

            // Compare `required` list of properties of the model
            CompareRequired(context, priorSchema);

            return context.Messages;
        }