diff --git a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj index 6dbcbf20f..dad533668 100644 --- a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj +++ b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj @@ -41,6 +41,7 @@ ResXFileCodeGenerator SRResource.Designer.cs + Microsoft.OpenApi diff --git a/src/Microsoft.OpenApi/Properties/SRResource.Designer.cs b/src/Microsoft.OpenApi/Properties/SRResource.Designer.cs index 4e4717e0d..3de246750 100644 --- a/src/Microsoft.OpenApi/Properties/SRResource.Designer.cs +++ b/src/Microsoft.OpenApi/Properties/SRResource.Designer.cs @@ -1,6 +1,7 @@ //------------------------------------------------------------------------------ // // This code was generated by a tool. +// Runtime Version:4.0.30319.42000 // // Changes to this file may cause incorrect behavior and will be lost if // the code is regenerated. @@ -69,25 +70,23 @@ internal static string ActiveScopeNeededForPropertyNameWriting { } /// - /// Looks up a localized string similar to The argument '{0}' is null, empty or consists only of white-space.. + /// Looks up a localized string similar to The argument '{0}' is null.. /// - internal static string ArgumentNullOrWhiteSpace { + internal static string ArgumentNull { get { - return ResourceManager.GetString("ArgumentNullOrWhiteSpace", resourceCulture); + return ResourceManager.GetString("ArgumentNull", resourceCulture); } } - + /// - /// Looks up a localized string similar to The argument '{0}' is null.. + /// Looks up a localized string similar to The argument '{0}' is null, empty or consists only of white-space.. /// - internal static string ArgumentNull - { - get - { - return ResourceManager.GetString("ArgumentNull", resourceCulture); + internal static string ArgumentNullOrWhiteSpace { + get { + return ResourceManager.GetString("ArgumentNullOrWhiteSpace", resourceCulture); } } - + /// /// Looks up a localized string similar to http://localhost/. /// @@ -412,27 +411,5 @@ internal static string WorkspaceRequredForExternalReferenceResolution { return ResourceManager.GetString("WorkspaceRequredForExternalReferenceResolution", resourceCulture); } } - - /// - /// Looks up a localized string similar to The HostDocument is null.. - /// - internal static string HostDocumentIsNull - { - get - { - return ResourceManager.GetString("HostDocumentIsNull", resourceCulture); - } - } - - /// - /// Looks up a localized string similar to The identifier in the referenced element is null or empty .. - /// - internal static string ReferenceIdIsNullOrEmpty - { - get - { - return ResourceManager.GetString("ReferenceIdIsNullOrEmpty", resourceCulture); - } - } } } diff --git a/src/Microsoft.OpenApi/Properties/SRResource.resx b/src/Microsoft.OpenApi/Properties/SRResource.resx index 0effa1d44..6cd1fc2ba 100644 --- a/src/Microsoft.OpenApi/Properties/SRResource.resx +++ b/src/Microsoft.OpenApi/Properties/SRResource.resx @@ -226,9 +226,12 @@ OpenAPI document must be added to an OpenApiWorkspace to be able to resolve external references. - Invalid server variable '{0}'. A value was not provided and no default value was provided. + Invalid server variable '{0}'. A value was not provided and no default value was provided. - Value '{0}' is not a valid value for variable '{1}'. If an enum is provided, it should not be empty and the value provided should exist in the enum + Value '{0}' is not a valid value for variable '{1}'. If an enum is provided, it should not be empty and the value provided should exist in the enum - + + The argument '{0}' is null. + + \ No newline at end of file diff --git a/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs b/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs index 63baab84d..e5078e7e0 100644 --- a/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs +++ b/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs @@ -2,9 +2,9 @@ // Licensed under the MIT license. using System; +using System.Collections.Generic; using System.Linq; using System.Reflection; -using System.Collections.Generic; namespace Microsoft.OpenApi { @@ -150,12 +150,12 @@ public void Add(Type key, List rules) /// Exception thrown when rule already exists. public void Add(Type key, ValidationRule rule) { - if (!_rulesDictionary.ContainsKey(key)) + if (!_rulesDictionary.TryGetValue(key, out var rules)) { - _rulesDictionary[key] = []; + _rulesDictionary[key] = rules = []; } - if (_rulesDictionary[key].Contains(rule)) + if (rules.Contains(rule)) { throw new OpenApiException(SRResource.Validation_RuleAddTwice); } @@ -202,7 +202,7 @@ public void Remove(string ruleName) } // Remove types with no rule - _rulesDictionary = _rulesDictionary.Where(r => r.Value.Any()).ToDictionary(r => r.Key, r => r.Value); + _rulesDictionary = _rulesDictionary.Where(r => r.Value.Count > 0).ToDictionary(r => r.Key, r => r.Value); } /// diff --git a/test/Microsoft.OpenApi.Tests/Validations/ValidationRuleSetTests.cs b/test/Microsoft.OpenApi.Tests/Validations/ValidationRuleSetTests.cs index 80ac348cb..45a2dfcad 100644 --- a/test/Microsoft.OpenApi.Tests/Validations/ValidationRuleSetTests.cs +++ b/test/Microsoft.OpenApi.Tests/Validations/ValidationRuleSetTests.cs @@ -59,7 +59,7 @@ public void RuleSetConstructorsReturnsTheCorrectRules() } [Fact] - public void RemoveValidatioRuleGivenTheValidationRuleWorks() + public void RemoveValidationRuleGivenTheValidationRuleWorks() { // Arrange var ruleSet = new ValidationRuleSet(_rulesDictionary); @@ -162,7 +162,7 @@ public void TryGetValueWorks() ruleSet.TryGetValue(typeof(OpenApiContact), out var validationRules); // Assert - Assert.True(validationRules.Any()); + Assert.True(validationRules.Count > 0); Assert.Contains(_contactValidationRule, validationRules); } @@ -195,7 +195,7 @@ public void GetValidationRuleTypesReturnsAllSupportedTypes() var declaredRuleTypeProperties = typeof(ValidationRuleSet).Assembly.GetTypes() .Where(t => t.IsClass && t != typeof(object) - && t.GetCustomAttributes(typeof(OpenApiRuleAttribute), false).Any()) + && t.GetCustomAttributes(typeof(OpenApiRuleAttribute), false).Length != 0) .SelectMany(t2 => t2.GetProperties(BindingFlags.Static | BindingFlags.Public)) .ToList();