/// <summary>Indicates whether the current object is equal to another object of the same type.</summary> /// <param name="other">An object to compare with this object.</param> /// <returns>true if the current object is equal to the <paramref name="other">other</paramref> parameter; otherwise, false.</returns> public bool Equals(OasSchema other) { if (other is null) return false; if (ReferenceEquals(this, other)) return true; if (JsonType != other.JsonType) return false; if (Format != other.Format) return false; if (Options != other.Options) return false; if (!NumberRange.Equals(other.NumberRange)) return false; if (!ItemsRange.Equals(other.ItemsRange)) return false; if (!LengthRange.Equals(other.LengthRange)) return false; if (!PropertiesRange.Equals(other.PropertiesRange)) return false; if (!ExternalDocumentation.Equals(other.ExternalDocumentation)) return false; if (!StringComparer.Ordinal.Equals(Title, other.Title)) return false; if (!StringComparer.Ordinal.Equals(Description, other.Description)) return false; if (!StringComparer.Ordinal.Equals(Pattern, other.Pattern)) return false; if (!Enum.NullableSetEquals(other.Enum)) return false; if (!AllOf.NullableSetEquals(other.AllOf)) return false; if (!OneOf.NullableSetEquals(other.OneOf)) return false; if (!AnyOf.NullableSetEquals(other.AnyOf)) return false; if (!Not.NullableSetEquals(other.Not)) return false; if (Items != other.Items) return false; if (!Properties.NullableDictionaryEquals(other.Properties)) return false; if (!AdditionalProperties.NullableDictionaryEquals(other.AdditionalProperties)) return false; return true; }
/// <exception cref="InvalidOperationException">Cyclic references detected.</exception> /// <exception cref="InvalidOperationException">The schema reference path has not been resolved.</exception> private JsonSchema4 GetActualSchema(IList <JsonSchema4> checkedSchemas) { if (checkedSchemas.Contains(this)) { throw new InvalidOperationException("Cyclic references detected."); } if (SchemaReferencePath != null && SchemaReference == null) { throw new InvalidOperationException("The schema reference path '" + SchemaReferencePath + "' has not been resolved."); } if (HasSchemaReference) { checkedSchemas.Add(this); if (HasAllOfSchemaReference) { return(AllOf.First().GetActualSchema(checkedSchemas)); } return(SchemaReference.GetActualSchema(checkedSchemas)); } return(this); }
private IEnumerable <Event> TestAllOfGeneratorProcess(Environment env) { var events = Enumerable.Range(0, 10).Select(x => new Timeout(env, env.ToTimeSpan(x), x)); var allOf = new AllOf(env, events); yield return(allOf); Assert.IsTrue(Enumerable.Range(0, 10).SequenceEqual(allOf.Value.Values.OfType <int>())); Assert.AreEqual(9, env.NowD); }
public void TestAllOfEmptyList() { var env = new Environment(); var evt = new AllOf(env, Enumerable.Empty<Event>()); Assert.IsTrue(evt.IsTriggered); Assert.IsFalse(evt.IsProcessed); env.Run(evt); Assert.IsTrue(evt.IsProcessed); Assert.AreEqual(0, env.NowD); }
public void TestAllOfEmptyList() { var env = new Environment(); var evt = new AllOf(env, Enumerable.Empty <Event>()); Assert.IsTrue(evt.IsTriggered); Assert.IsFalse(evt.IsProcessed); env.Run(evt); Assert.IsTrue(evt.IsProcessed); Assert.AreEqual(0, env.NowD); }
public void TestAllOfEmptyList() { var env = new Simulation(); var evt = new AllOf(env, Enumerable.Empty <Event>()); Assert.True(evt.IsTriggered); Assert.False(evt.IsProcessed); env.Run(evt); Assert.True(evt.IsProcessed); Assert.Equal(0, env.NowD); }
/// <summary> /// Add the provided JSON schema as an option for the allOf property of this JSON schema. /// </summary> /// <param name="allOfOption"></param> /// <returns></returns> public JsonSchema AddAllOf(JsonSchema allOfOption) { if (allOfOption == null) { throw new ArgumentNullException(nameof(allOfOption)); } if (AllOf == null) { AllOf = new List <JsonSchema>(); } AllOf.Add(allOfOption); return(this); }
/// <summary> /// Serves as a hash function for a particular type. /// </summary> /// <returns> /// A hash code for the current <see cref="T:System.Object"/>. /// </returns> public override int GetHashCode() { unchecked { var hashCode = Type.GetHashCode(); hashCode = (hashCode * 397) ^ (Id?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Schema?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Comment?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Title?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Description?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Default?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ MultipleOf.GetHashCode(); hashCode = (hashCode * 397) ^ Maximum.GetHashCode(); hashCode = (hashCode * 397) ^ ExclusiveMaximum.GetHashCode(); hashCode = (hashCode * 397) ^ Minimum.GetHashCode(); hashCode = (hashCode * 397) ^ ExclusiveMinimum.GetHashCode(); hashCode = (hashCode * 397) ^ (MaxLength?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (MinLength?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Pattern?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (AdditionalItems?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Items?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (MaxItems?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (MinItems?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (UniqueItems?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Contains?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (AdditionalProperties?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Definitions?.GetCollectionHashCode().GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Properties?.GetCollectionHashCode() ?? 0); hashCode = (hashCode * 397) ^ (PatternProperties?.GetCollectionHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Dependencies?.GetCollectionHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Const?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Enum?.GetCollectionHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Format?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (ContentMediaType?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (ContentEncoding?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (If?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Then?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Else?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (AllOf?.GetCollectionHashCode() ?? 0); hashCode = (hashCode * 397) ^ (AnyOf?.GetCollectionHashCode() ?? 0); hashCode = (hashCode * 397) ^ (OneOf?.GetCollectionHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Not?.GetHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Required?.GetCollectionHashCode() ?? 0); hashCode = (hashCode * 397) ^ (Examples?.GetCollectionHashCode() ?? 0); return(hashCode); } }
private IDictionary <string, JsonSchemaProperty> GetActualProperties(bool includeInherited) #endif { var ignoredSchema = includeInherited ? null : InheritedSchema; var properties = Properties .Union(AllOf.Where(s => s.ActualSchema != ignoredSchema).SelectMany(s => s.ActualSchema.GetActualProperties(false))) .Union(AnyOf.Where(s => s.ActualSchema != ignoredSchema).SelectMany(s => s.ActualSchema.GetActualProperties(true))) .Union(OneOf.Where(s => s.ActualSchema != ignoredSchema).SelectMany(s => s.ActualSchema.GetActualProperties(true))) .ToList(); // Collapse all duplicated properties, checking that the duplicated ones are compatible var duplicatedProperties = properties .GroupBy(p => p.Key) .Where(g => g.Count() > 1) .Select(g => g.ToList()) .ToList(); var invalidDuplicates = new List <string>(); foreach (var duped in duplicatedProperties) { // Make sure all the properties are the same type as each other so they are compatible primitive types var toKeep = duped[0].Value; if (duped.Any(dupe => dupe.Value.Type != toKeep.Type)) { invalidDuplicates.Add(duped[0].Key); continue; } // All good, so remove the duplicates here foreach (var c in duped.Skip(1)) { properties.Remove(c); } } if (invalidDuplicates.Count > 0) { throw new InvalidOperationException("The properties " + string.Join(", ", invalidDuplicates.Select(key => "'" + key + "'")) + " are defined multiple times and are not the same type."); } #if !LEGACY return(new ReadOnlyDictionary <string, JsonSchemaProperty>(properties.ToDictionary(p => p.Key, p => p.Value))); #else return(new Dictionary <string, JsonSchemaProperty>(properties.ToDictionary(p => p.Key, p => p.Value))); #endif }
private void CompareAllOfs(ComparisonContext <ServiceDefinition> context, Schema priorSchema) { var different = 0; foreach (var schema in priorSchema.AllOf) { if (!AllOf.Select(s => s.Reference).ToArray().Contains(schema.Reference)) { different += 1; } } foreach (var schema in AllOf) { if (!priorSchema.AllOf.Select(s => s.Reference).ToArray().Contains(schema.Reference)) { different += 1; } } if (different > 0) { context.LogBreakingChange(ComparisonMessages.DifferentAllOf); } }
/// <summary> /// Converts an object to a <see cref="JsonValue"/>. /// </summary> /// <param name="serializer">The <see cref="JsonSerializer"/> instance to use for additional serialization of values.</param> /// <returns>The <see cref="JsonValue"/> representation of the object.</returns> public virtual JsonValue ToJson(JsonSerializer serializer) { var json = new JsonObject(); if (Id != null) { json["id"] = Id; } if (!string.IsNullOrWhiteSpace(Schema)) { json["$schema"] = Schema; } if (Title != null) { json["title"] = Title; } if (!string.IsNullOrWhiteSpace(Description)) { json["description"] = Description; } if (Default != null) { json["default"] = Default; } if (MultipleOf.HasValue) { json["multipleOf"] = MultipleOf; } if (Maximum.HasValue) { json["maximum"] = Maximum; } if (ExclusiveMaximum.HasValue) { json["exclusiveMaximum"] = ExclusiveMaximum; } if (Minimum.HasValue) { json["minimum"] = Minimum; } if (ExclusiveMinimum.HasValue) { json["exclusiveMinimum"] = ExclusiveMinimum; } if (MaxLength.HasValue) { json["maxLength"] = MaxLength; } if (MinLength.HasValue) { json["minLength"] = MinLength; } if (Pattern != null) { json["pattern"] = Pattern; } if (AdditionalItems != null) { json["additionalItems"] = AdditionalItems.ToJson(serializer); } if (Items != null) { json["items"] = Items.ToJson(serializer); } if (MaxItems.HasValue) { json["maxItems"] = MinItems; } if (MinItems.HasValue) { json["minItems"] = MinItems; } if (UniqueItems ?? false) { json["uniqueItems"] = UniqueItems; } if (MaxProperties.HasValue) { json["maxProperties"] = MaxProperties; } if (MinProperties.HasValue) { json["minProperties"] = MinProperties; } if (Required != null) { var array = Required.ToJson(); array.Array.EqualityStandard = ArrayEquality.ContentsEqual; json["required"] = array; } if (AdditionalProperties != null) { json["additionalProperties"] = AdditionalProperties.ToJson(serializer); } if (Definitions != null) { json["definitions"] = Definitions.ToJson(serializer); } if (Properties != null) { json["properties"] = Properties.ToJson(serializer); } if (PatternProperties != null && PatternProperties.Any()) { json["patternProperties"] = PatternProperties.ToDictionary(kvp => kvp.Key.ToString(), kvp => kvp.Value).ToJson(serializer); } if (Dependencies != null && Dependencies.Any()) { var jsonDependencies = new JsonObject(); foreach (var dependency in Dependencies) { jsonDependencies[dependency.PropertyName] = dependency.GetJsonData(); } json["dependencies"] = jsonDependencies; } if (Enum != null) { var array = Enum.ToJson(serializer); array.Array.EqualityStandard = ArrayEquality.ContentsEqual; json["enum"] = Enum.ToJson(serializer); } if (Type != JsonSchemaType.NotDefined) { var array = Type.ToJson(); if (array.Type == JsonValueType.Array) { array.Array.EqualityStandard = ArrayEquality.ContentsEqual; } json["type"] = array; } if (AllOf != null) { var array = AllOf.Select(s => s.ToJson(serializer)).ToJson(); array.EqualityStandard = ArrayEquality.ContentsEqual; json["allOf"] = array; } if (AnyOf != null) { var array = AnyOf.Select(s => s.ToJson(serializer)).ToJson(); array.EqualityStandard = ArrayEquality.ContentsEqual; json["anyOf"] = array; } if (OneOf != null) { var array = OneOf.Select(s => s.ToJson(serializer)).ToJson(); array.EqualityStandard = ArrayEquality.ContentsEqual; json["oneOf"] = array; } if (Not != null) { json["not"] = Not.ToJson(serializer); } if (Format != null) { json["format"] = Format.Key; } if (ExtraneousDetails != null) { foreach (var kvp in ExtraneousDetails.Where(kvp => !_definedProperties.Contains(kvp.Key))) { json[kvp.Key] = kvp.Value; } } return(json); }
public IElement GetInstance(Node node) { return(AllOf.GetInstance(node)); }
private IEnumerable<Event> TestAllOfGeneratorProcess(Environment env) { var events = Enumerable.Range(0, 10).Select(x => new Timeout(env, env.ToTimeSpan(x), x)); var allOf = new AllOf(env, events); yield return allOf; Assert.IsTrue(Enumerable.Range(0, 10).SequenceEqual(allOf.Value.Values.OfType<int>())); Assert.AreEqual(9, env.NowD); }
private async Task <string> UpdateMessageWithSearchResultsAsync(string teamsMessageTemplate, AlertConfiguration alertConfiguration, AllOf condition, int conditionIndex) { IQueryResultFetcher queryResultFetcher = _queryResultFetcherFabric.CreateQueryResultFetcher(condition.LinkToSearchResultsApi); var result = await queryResultFetcher.FetchLogQueryResultsAsync(condition.LinkToSearchResultsApi, alertConfiguration.Context.ToString()); foreach (var table in result.Tables) { var tableIndex = Array.IndexOf(result.Tables, table) + 1; foreach (var row in table.Rows) { var rowIndex = Array.IndexOf(table.Rows, row) + 1; var columns = table.Columns.Select(c => c.Name).ToArray(); foreach (var column in columns) { teamsMessageTemplate = teamsMessageTemplate .Replace($"[[$.data.alertContext.SearchResults[{conditionIndex}].Tables[{tableIndex}].Rows[{rowIndex}].{column}]]", row[Array.IndexOf(columns, column)], StringComparison.InvariantCultureIgnoreCase); } } } return(teamsMessageTemplate); }
/// <summary> /// Indicates whether the current object is equal to another object of the same type. /// </summary> /// <returns> /// true if the current object is equal to the <paramref name="other"/> parameter; otherwise, false. /// </returns> /// <param name="other">An object to compare with this object.</param> public virtual bool Equals(IJsonSchema other) { var schema = other as JsonSchema04; if (ReferenceEquals(null, schema)) { return(false); } if (ReferenceEquals(this, schema)) { return(true); } if (Id != schema.Id) { return(false); } if (Schema != schema.Schema) { return(false); } if (Title != schema.Title) { return(false); } if (Description != schema.Description) { return(false); } if (!Equals(Default, schema.Default)) { return(false); } if (MultipleOf != schema.MultipleOf) { return(false); } if (Maximum != schema.Maximum) { return(false); } if (ExclusiveMaximum != schema.ExclusiveMaximum) { return(false); } if (Minimum != schema.Minimum) { return(false); } if (ExclusiveMinimum != schema.ExclusiveMinimum) { return(false); } if (MaxLength != schema.MaxLength) { return(false); } if (MinLength != schema.MinLength) { return(false); } if (Pattern != schema.Pattern) { return(false); } if (!Equals(AdditionalItems, schema.AdditionalItems)) { return(false); } if (!Equals(Items, schema.Items)) { return(false); } if (MaxItems != schema.MaxItems) { return(false); } if (MinItems != schema.MinItems) { return(false); } if (UniqueItems != schema.UniqueItems) { return(false); } if (!Equals(AdditionalProperties, schema.AdditionalProperties)) { return(false); } if (!Definitions.ContentsEqual(schema.Definitions)) { return(false); } if (!Properties.ContentsEqual(schema.Properties)) { return(false); } if (!PatternProperties.ContentsEqual(PatternProperties)) { return(false); } if (!Dependencies.ContentsEqual(schema.Dependencies)) { return(false); } if (!Enum.ContentsEqual(schema.Enum)) { return(false); } if (!Equals(Type, schema.Type)) { return(false); } if (!AllOf.ContentsEqual(schema.AllOf)) { return(false); } if (!AnyOf.ContentsEqual(schema.AnyOf)) { return(false); } if (!OneOf.ContentsEqual(schema.OneOf)) { return(false); } if (!Equals(Not, schema.Not)) { return(false); } if (!Equals(Format, schema.Format)) { return(false); } if (!Required.ContentsEqual(schema.Required)) { return(false); } return(Dependencies.ContentsEqual(schema.Dependencies)); }
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))); }
public IElement GetInstance(string value) { return(AllOf.GetInstance(value)); }