Skip to content

Commit c0b7adc

Browse files
authored
Merge pull request #2460 from martincostello/code-fixes
Code fixes
2 parents 1994320 + 23d0cdf commit c0b7adc

File tree

5 files changed

+25
-44
lines changed

5 files changed

+25
-44
lines changed

src/Microsoft.OpenApi/Microsoft.OpenApi.csproj

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@
4141
<EmbeddedResource Update="Properties\SRResource.resx">
4242
<Generator>ResXFileCodeGenerator</Generator>
4343
<LastGenOutput>SRResource.Designer.cs</LastGenOutput>
44+
<CustomToolNamespace>Microsoft.OpenApi</CustomToolNamespace>
4445
</EmbeddedResource>
4546
</ItemGroup>
4647

src/Microsoft.OpenApi/Properties/SRResource.Designer.cs

Lines changed: 10 additions & 33 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

src/Microsoft.OpenApi/Properties/SRResource.resx

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -226,9 +226,12 @@
226226
<value>OpenAPI document must be added to an OpenApiWorkspace to be able to resolve external references.</value>
227227
</data>
228228
<data name="ParseServerUrlDefaultValueNotAvailable" xml:space="preserve">
229-
<value>Invalid server variable '{0}'. A value was not provided and no default value was provided.</value>
229+
<value>Invalid server variable '{0}'. A value was not provided and no default value was provided.</value>
230230
</data>
231231
<data name="ParseServerUrlValueNotValid" xml:space="preserve">
232-
<value>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>
232+
<value>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>
233233
</data>
234-
</root>
234+
<data name="ArgumentNull" xml:space="preserve">
235+
<value>The argument '{0}' is null.</value>
236+
</data>
237+
</root>

src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,9 @@
22
// Licensed under the MIT license.
33

44
using System;
5+
using System.Collections.Generic;
56
using System.Linq;
67
using System.Reflection;
7-
using System.Collections.Generic;
88

99
namespace Microsoft.OpenApi
1010
{
@@ -150,12 +150,12 @@ public void Add(Type key, List<ValidationRule> rules)
150150
/// <exception cref="OpenApiException">Exception thrown when rule already exists.</exception>
151151
public void Add(Type key, ValidationRule rule)
152152
{
153-
if (!_rulesDictionary.ContainsKey(key))
153+
if (!_rulesDictionary.TryGetValue(key, out var rules))
154154
{
155-
_rulesDictionary[key] = [];
155+
_rulesDictionary[key] = rules = [];
156156
}
157157

158-
if (_rulesDictionary[key].Contains(rule))
158+
if (rules.Contains(rule))
159159
{
160160
throw new OpenApiException(SRResource.Validation_RuleAddTwice);
161161
}
@@ -202,7 +202,7 @@ public void Remove(string ruleName)
202202
}
203203

204204
// Remove types with no rule
205-
_rulesDictionary = _rulesDictionary.Where(r => r.Value.Any()).ToDictionary(r => r.Key, r => r.Value);
205+
_rulesDictionary = _rulesDictionary.Where(r => r.Value.Count > 0).ToDictionary(r => r.Key, r => r.Value);
206206
}
207207

208208
/// <summary>

test/Microsoft.OpenApi.Tests/Validations/ValidationRuleSetTests.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ public void RuleSetConstructorsReturnsTheCorrectRules()
5959
}
6060

6161
[Fact]
62-
public void RemoveValidatioRuleGivenTheValidationRuleWorks()
62+
public void RemoveValidationRuleGivenTheValidationRuleWorks()
6363
{
6464
// Arrange
6565
var ruleSet = new ValidationRuleSet(_rulesDictionary);
@@ -162,7 +162,7 @@ public void TryGetValueWorks()
162162
ruleSet.TryGetValue(typeof(OpenApiContact), out var validationRules);
163163

164164
// Assert
165-
Assert.True(validationRules.Any());
165+
Assert.True(validationRules.Count > 0);
166166
Assert.Contains(_contactValidationRule, validationRules);
167167
}
168168

@@ -195,7 +195,7 @@ public void GetValidationRuleTypesReturnsAllSupportedTypes()
195195
var declaredRuleTypeProperties = typeof(ValidationRuleSet).Assembly.GetTypes()
196196
.Where(t => t.IsClass
197197
&& t != typeof(object)
198-
&& t.GetCustomAttributes(typeof(OpenApiRuleAttribute), false).Any())
198+
&& t.GetCustomAttributes(typeof(OpenApiRuleAttribute), false).Length != 0)
199199
.SelectMany(t2 => t2.GetProperties(BindingFlags.Static | BindingFlags.Public))
200200
.ToList();
201201

0 commit comments

Comments
 (0)