Ejemplo n.º 1
0
        public bool Equals(JsonSchema other)
        {
            if (other is null)
            {
                return(false);
            }

            return(Id == other.Id &&
                   (SchemaVersion == null
                        ? other.SchemaVersion == null
                        : SchemaVersion.EqualsWithFragments(other.SchemaVersion)) &&
                   string.Equals(Title, other.Title, StringComparison.Ordinal) &&
                   string.Equals(Description, other.Description, StringComparison.Ordinal) &&
                   Type.HasSameElementsAs(other.Type) &&
                   Enum.HasSameElementsAs(other.Enum) &&
                   (Items == null
                        ? other.Items == null
                        : Items.Equals(other.Items)) &&
                   (Properties == null
                        ? other.Properties == null
                        : Properties.HasSameElementsAs(other.Properties)) &&
                   Required.HasSameElementsAs(other.Required) &&
                   Definitions.HasSameElementsAs(other.Definitions) &&
                   (AdditionalItems == null
                        ? other.AdditionalItems == null
                        : AdditionalItems.Equals(other.AdditionalItems)) &&
                   (AdditionalProperties == null
                        ? other.AdditionalProperties == null
                        : AdditionalProperties.Equals(other.AdditionalProperties)) &&
                   (Dependencies == null
                        ? other.Dependencies == null
                        : Dependencies.HasSameElementsAs(other.Dependencies)) &&
                   (PatternProperties == null
                        ? other.PatternProperties == null
                        : PatternProperties.HasSameElementsAs(other.PatternProperties)) &&
                   (Reference == null
                        ? other.Reference == null
                        : Reference.Equals(other.Reference)) &&
                   Object.Equals(Default, other.Default) &&
                   Pattern == other.Pattern &&
                   MaxLength == other.MaxLength &&
                   MinLength == other.MinLength &&
                   MultipleOf == other.MultipleOf &&
                   Maximum == other.Maximum &&
                   ExclusiveMaximum == other.ExclusiveMaximum &&
                   MinItems == other.MinItems &&
                   MaxItems == other.MaxItems &&
                   UniqueItems == other.UniqueItems &&
                   string.Equals(Format, other.Format, StringComparison.Ordinal) &&
                   (AllOf == null
                        ? other.AllOf == null
                        : AllOf.HasSameElementsAs(other.AllOf)) &&
                   (AnyOf == null
                        ? other.AnyOf == null
                        : AnyOf.HasSameElementsAs(other.AnyOf)) &&
                   (OneOf == null
                        ? other.OneOf == null
                        : OneOf.HasSameElementsAs(other.OneOf)) &&
                   (Not == null
                        ? other.Not == null
                        : Not.Equals(other.Not)));
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Initializes a new instance of the <see cref="JsonSchema"/> class from the
        /// specified instance.
        /// </summary>
        /// <param name="other">
        /// The instance used to initialize the new instance.
        /// </param>
        public JsonSchema(JsonSchema other)
        {
            if (other.Id != null)
            {
                Id = new UriOrFragment(other.Id);
            }

            if (other.SchemaVersion != null)
            {
                SchemaVersion = new Uri(other.SchemaVersion.OriginalString);
            }

            Title       = other.Title;
            Description = other.Description;

            if (other.Type != null)
            {
                Type = new List <SchemaType>(other.Type);
            }

            if (other.Enum != null)
            {
                // A shallow copy is fine for now since Enum will be checked to ensure that it
                // contain only primitive types.
                // But it won't do if we want to pass the JSON Schema validation suite.
                Enum = new List <object>(other.Enum);
            }

            if (other.Items != null)
            {
                Items = new Items(other.Items);
            }

            if (other.Properties != null)
            {
                Properties = new Dictionary <string, JsonSchema>();
                foreach (string key in other.Properties.Keys)
                {
                    Properties.Add(key, new JsonSchema(other.Properties[key]));
                }
            }

            if (other.Required != null)
            {
                Required = new List <string>(other.Required);
            }

            if (other.Definitions != null)
            {
                Definitions = new Dictionary <string, JsonSchema>();
                foreach (string key in other.Definitions.Keys)
                {
                    Definitions.Add(key, new JsonSchema(other.Definitions[key]));
                }
            }

            if (other.AdditionalItems != null)
            {
                AdditionalItems = new AdditionalItems(other.AdditionalItems);
            }

            if (other.AdditionalProperties != null)
            {
                AdditionalProperties = new AdditionalProperties(other.AdditionalProperties);
            }

            if (other.Dependencies != null)
            {
                Dependencies = new Dictionary <string, Dependency>(other.Dependencies);
            }

            if (other.PatternProperties != null)
            {
                PatternProperties = new Dictionary <string, JsonSchema>(other.PatternProperties);
            }

            Default          = other.Default;
            Pattern          = other.Pattern;
            MaxLength        = other.MaxLength;
            MinLength        = other.MinLength;
            Format           = other.Format;
            MultipleOf       = other.MultipleOf;
            Maximum          = other.Maximum;
            ExclusiveMaximum = other.ExclusiveMaximum;
            MinItems         = other.MinItems;
            MaxItems         = other.MaxItems;
            UniqueItems      = other.UniqueItems;

            if (other.Reference != null)
            {
                Reference = new UriOrFragment(other.Reference);
            }

            if (other.AllOf != null)
            {
                AllOf = new List <JsonSchema>(other.AllOf);
            }

            if (other.AnyOf != null)
            {
                AnyOf = new List <JsonSchema>(other.AnyOf);
            }

            if (other.OneOf != null)
            {
                OneOf = new List <JsonSchema>(other.OneOf);
            }

            if (other.Not != null)
            {
                Not = new JsonSchema(other.Not);
            }
        }