diff --git a/src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs b/src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs index c90b13f20..b5107b743 100644 --- a/src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs +++ b/src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs @@ -47,8 +47,7 @@ public PropertyNode this[string key] { get { - YamlNode node; - if (this._node.Children.TryGetValue(new YamlScalarNode(key), out node)) + if (this._node.Children.TryGetValue(new YamlScalarNode(key), out var node)) { return new PropertyNode(Context, key, node); } @@ -192,9 +191,7 @@ public T GetReferencedObject(ReferenceType referenceType, string referenceId) public string GetReferencePointer() { - YamlNode refNode; - - if (!_node.Children.TryGetValue(new YamlScalarNode("$ref"), out refNode)) + if (!_node.Children.TryGetValue(new YamlScalarNode("$ref"), out var refNode)) { return null; } diff --git a/src/Microsoft.OpenApi.Readers/ParseNodes/PropertyNode.cs b/src/Microsoft.OpenApi.Readers/ParseNodes/PropertyNode.cs index b53c1d405..7927520c7 100644 --- a/src/Microsoft.OpenApi.Readers/ParseNodes/PropertyNode.cs +++ b/src/Microsoft.OpenApi.Readers/ParseNodes/PropertyNode.cs @@ -30,10 +30,7 @@ public void ParseField( IDictionary> fixedFields, IDictionary, Action> patternFields) { - Action fixedFieldMap; - var found = fixedFields.TryGetValue(Name, out fixedFieldMap); - - if (fixedFieldMap != null) + if (fixedFields.TryGetValue(Name, out var fixedFieldMap)) { try { diff --git a/src/Microsoft.OpenApi.Readers/ParsingContext.cs b/src/Microsoft.OpenApi.Readers/ParsingContext.cs index d60b4c10e..781a16ed8 100644 --- a/src/Microsoft.OpenApi.Readers/ParsingContext.cs +++ b/src/Microsoft.OpenApi.Readers/ParsingContext.cs @@ -206,8 +206,7 @@ public void StartObject(string objectName) /// If method returns false a loop was detected and the key is not added. public bool PushLoop(string loopId, string key) { - Stack stack; - if (!_loopStacks.TryGetValue(loopId, out stack)) + if (!_loopStacks.TryGetValue(loopId, out var stack)) { stack = new Stack(); _loopStacks.Add(loopId, stack); diff --git a/src/Microsoft.OpenApi/Services/LoopDetector.cs b/src/Microsoft.OpenApi/Services/LoopDetector.cs index 1a796f60b..2c9618213 100644 --- a/src/Microsoft.OpenApi/Services/LoopDetector.cs +++ b/src/Microsoft.OpenApi/Services/LoopDetector.cs @@ -14,8 +14,7 @@ internal class LoopDetector /// If method returns false a loop was detected and the key is not added. public bool PushLoop(T key) { - Stack stack; - if (!_loopStacks.TryGetValue(typeof(T), out stack)) + if (!_loopStacks.TryGetValue(typeof(T), out var stack)) { stack = new Stack(); _loopStacks.Add(typeof(T), stack); diff --git a/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs b/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs index 249d5affc..5199f82bc 100644 --- a/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs +++ b/src/Microsoft.OpenApi/Validations/ValidationRuleSet.cs @@ -30,8 +30,7 @@ public sealed class ValidationRuleSet : IEnumerable /// Either the rules related to the type, or an empty list. public IList FindRules(Type type) { - IList results = null; - _rules.TryGetValue(type, out results); + _rules.TryGetValue(type, out var results); return results ?? _emptyRules; } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiContactTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiContactTests.cs index 725fd6d82..d3197476f 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiContactTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V2Tests/OpenApiContactTests.cs @@ -22,10 +22,9 @@ public void ParseStringContactFragmentShouldSucceed() } """; var reader = new OpenApiStringReader(); - var diagnostic = new OpenApiDiagnostic(); // Act - var contact = reader.ReadFragment(input, OpenApiSpecVersion.OpenApi2_0, out diagnostic); + var contact = reader.ReadFragment(input, OpenApiSpecVersion.OpenApi2_0, out var diagnostic); // Assert diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic()); diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiContactTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiContactTests.cs index bbd18ee61..c4f08f389 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiContactTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiContactTests.cs @@ -22,10 +22,9 @@ public void ParseStringContactFragmentShouldSucceed() } """; var reader = new OpenApiStringReader(); - var diagnostic = new OpenApiDiagnostic(); // Act - var contact = reader.ReadFragment(input, OpenApiSpecVersion.OpenApi3_0, out diagnostic); + var contact = reader.ReadFragment(input, OpenApiSpecVersion.OpenApi3_0, out var diagnostic); // Assert diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic()); diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs index 05c7fe889..e84b8cbc5 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiSchemaTests.cs @@ -51,10 +51,9 @@ public void ParsePrimitiveSchemaFragmentShouldSucceed() { using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "primitiveSchema.yaml")); var reader = new OpenApiStreamReader(); - var diagnostic = new OpenApiDiagnostic(); // Act - var schema = reader.ReadFragment(stream, OpenApiSpecVersion.OpenApi3_0, out diagnostic); + var schema = reader.ReadFragment(stream, OpenApiSpecVersion.OpenApi3_0, out var diagnostic); // Assert diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic()); @@ -79,10 +78,9 @@ public void ParsePrimitiveStringSchemaFragmentShouldSucceed() } """; var reader = new OpenApiStringReader(); - var diagnostic = new OpenApiDiagnostic(); // Act - var schema = reader.ReadFragment(input, OpenApiSpecVersion.OpenApi3_0, out diagnostic); + var schema = reader.ReadFragment(input, OpenApiSpecVersion.OpenApi3_0, out var diagnostic); // Assert diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic()); @@ -107,10 +105,9 @@ public void ParseExampleStringFragmentShouldSucceed() } """; var reader = new OpenApiStringReader(); - var diagnostic = new OpenApiDiagnostic(); // Act - var openApiAny = reader.ReadFragment(input, OpenApiSpecVersion.OpenApi3_0, out diagnostic); + var openApiAny = reader.ReadFragment(input, OpenApiSpecVersion.OpenApi3_0, out var diagnostic); // Assert diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic()); @@ -138,10 +135,9 @@ public void ParseEnumFragmentShouldSucceed() ] """; var reader = new OpenApiStringReader(); - var diagnostic = new OpenApiDiagnostic(); // Act - var openApiAny = reader.ReadFragment(input, OpenApiSpecVersion.OpenApi3_0, out diagnostic); + var openApiAny = reader.ReadFragment(input, OpenApiSpecVersion.OpenApi3_0, out var diagnostic); // Assert diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic()); @@ -214,10 +210,9 @@ public void ParsePathFragmentShouldSucceed() description: Ok """; var reader = new OpenApiStringReader(); - var diagnostic = new OpenApiDiagnostic(); // Act - var openApiAny = reader.ReadFragment(input, OpenApiSpecVersion.OpenApi3_0, out diagnostic); + var openApiAny = reader.ReadFragment(input, OpenApiSpecVersion.OpenApi3_0, out var diagnostic); // Assert diagnostic.Should().BeEquivalentTo(new OpenApiDiagnostic());