Skip to content

Commit 6b3343c

Browse files
committed
Address code scanning alerts
1 parent 128c1fa commit 6b3343c

File tree

6 files changed

+17
-17
lines changed

6 files changed

+17
-17
lines changed

src/Microsoft.OpenApi.Readers/ParseNodes/MapNode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,7 +135,7 @@ public override Dictionary<string, T> CreateSimpleMap<T>(Func<ValueNode, T> map)
135135
JsonValue valueNode = n.Value is JsonValue value ? value
136136
: throw new OpenApiReaderException($"Expected scalar while parsing {typeof(T).Name}", Context);
137137

138-
return (key, value: map(new ValueNode(Context, (JsonValue)n.Value)));
138+
return (key, value: map(new ValueNode(Context, valueNode)));
139139
} finally {
140140
Context.EndObject();
141141
}

src/Microsoft.OpenApi.Readers/V2/OpenApiV2Deserializer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ private static void ProcessAnyFields<T>(
4848
{
4949
mapNode.Context.StartObject(anyFieldName);
5050
var anyFieldValue = anyFieldMap[anyFieldName].PropertyGetter(domainObject);
51-
var anyFieldSchema = anyFieldMap[anyFieldName].SchemaGetter(domainObject);
5251

5352
if(anyFieldValue == null)
5453
{

src/Microsoft.OpenApi.Readers/V3/OpenApiV3Deserializer.cs

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,6 @@ private static void ProcessAnyFields<T>(
4848
mapNode.Context.StartObject(anyFieldName);
4949

5050
var any = anyFieldMap[anyFieldName].PropertyGetter(domainObject);
51-
var schema = anyFieldMap[anyFieldName].SchemaGetter(domainObject);
5251

5352
if (any == null)
5453
{

src/Microsoft.OpenApi/Models/OpenApiRequestBody.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -192,7 +192,7 @@ internal OpenApiBodyParameter ConvertToBodyParameter()
192192
if (bodyParameter.Extensions.ContainsKey(OpenApiConstants.BodyName))
193193
{
194194
var bodyName = bodyParameter.Extensions[OpenApiConstants.BodyName] as OpenApiAny;
195-
bodyParameter.Name = string.IsNullOrEmpty(bodyName.Node.ToString()) ? "body" : bodyName.Node.ToString();
195+
bodyParameter.Name = string.IsNullOrEmpty(bodyName?.Node.ToString()) ? "body" : bodyName.Node.ToString();
196196
bodyParameter.Extensions.Remove(OpenApiConstants.BodyName);
197197
}
198198
return bodyParameter;

src/Microsoft.OpenApi/Validations/Rules/RuleHelpers.cs

Lines changed: 14 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -86,21 +86,23 @@ public static void ValidateDataTypeMismatch(
8686
}
8787

8888
var anyObject = value as JsonObject;
89-
89+
9090
foreach (var property in anyObject)
9191
{
92-
context.Enter(property.Key);
93-
94-
if (schema.Properties != null && schema.Properties.ContainsKey(property.Key))
95-
{
96-
ValidateDataTypeMismatch(context, ruleName, anyObject[property.Key], schema.Properties[property.Key]);
97-
}
98-
else
92+
if (anyObject != null)
9993
{
100-
ValidateDataTypeMismatch(context, ruleName, anyObject[property.Key], schema.AdditionalProperties);
101-
}
102-
103-
context.Exit();
94+
context.Enter(property.Key);
95+
if (schema.Properties.TryGetValue(property.Key, out var propertyValue))
96+
{
97+
ValidateDataTypeMismatch(context, ruleName, anyObject[property.Key], propertyValue);
98+
}
99+
else
100+
{
101+
ValidateDataTypeMismatch(context, ruleName, anyObject[property.Key], schema.AdditionalProperties);
102+
}
103+
104+
context.Exit();
105+
}
104106
}
105107

106108
return;

test/Microsoft.OpenApi.Tests/Models/OpenApiDocumentTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System;

0 commit comments

Comments
 (0)