Skip to content

Code fixes #2460

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 2 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@
<EmbeddedResource Update="Properties\SRResource.resx">
<Generator>ResXFileCodeGenerator</Generator>
<LastGenOutput>SRResource.Designer.cs</LastGenOutput>
<CustomToolNamespace>Microsoft.OpenApi</CustomToolNamespace>
</EmbeddedResource>
</ItemGroup>

Expand Down
43 changes: 10 additions & 33 deletions src/Microsoft.OpenApi/Properties/SRResource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

9 changes: 6 additions & 3 deletions src/Microsoft.OpenApi/Properties/SRResource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -226,9 +226,12 @@
<value>OpenAPI document must be added to an OpenApiWorkspace to be able to resolve external references.</value>
</data>
<data name="ParseServerUrlDefaultValueNotAvailable" xml:space="preserve">
<value>Invalid server variable '{0}'. A value was not provided and no default value was provided.</value>
<value>Invalid server variable '{0}'. A value was not provided and no default value was provided.</value>
</data>
<data name="ParseServerUrlValueNotValid" xml:space="preserve">
<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>
<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>
</data>
</root>
<data name="ArgumentNull" xml:space="preserve">
<value>The argument '{0}' is null.</value>
</data>
</root>
10 changes: 5 additions & 5 deletions src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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
{
Expand Down Expand Up @@ -150,12 +150,12 @@ public void Add(Type key, List<ValidationRule> rules)
/// <exception cref="OpenApiException">Exception thrown when rule already exists.</exception>
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);
}
Expand Down Expand Up @@ -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);
}

/// <summary>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,7 @@ public void RuleSetConstructorsReturnsTheCorrectRules()
}

[Fact]
public void RemoveValidatioRuleGivenTheValidationRuleWorks()
public void RemoveValidationRuleGivenTheValidationRuleWorks()
{
// Arrange
var ruleSet = new ValidationRuleSet(_rulesDictionary);
Expand Down Expand Up @@ -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);
}

Expand Down Expand Up @@ -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();

Expand Down