Skip to content

Commit 9c3668c

Browse files
authored
Merge pull request #1382 from SimonCropp/remove-redundant-casts
remove redundant casts
2 parents 4bf34d3 + 0252298 commit 9c3668c

File tree

5 files changed

+16
-20
lines changed

5 files changed

+16
-20
lines changed

src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,9 +60,9 @@ public OpenApiDocument Read(Stream input, out OpenApiDiagnostic diagnostic)
6060
public async Task<ReadResult> ReadAsync(Stream input, CancellationToken cancellationToken = default)
6161
{
6262
MemoryStream bufferedStream;
63-
if (input is MemoryStream)
63+
if (input is MemoryStream stream)
6464
{
65-
bufferedStream = (MemoryStream)input;
65+
bufferedStream = stream;
6666
}
6767
else
6868
{

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -50,16 +50,16 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
5050
return newObject;
5151
}
5252

53-
if (!(openApiAny is OpenApiString))
53+
if (openApiAny is not OpenApiString apiString)
5454
{
5555
return openApiAny;
5656
}
5757

58-
var value = ((OpenApiString)openApiAny).Value;
58+
var value = apiString.Value;
5959
var type = schema?.Type;
6060
var format = schema?.Format;
6161

62-
if (((OpenApiString)openApiAny).IsExplicit())
62+
if (apiString.IsExplicit())
6363
{
6464
// More narrow type detection for explicit strings, only check types that are passed as strings
6565
if (schema == null)
@@ -113,7 +113,7 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
113113
}
114114
}
115115

116-
return openApiAny;
116+
return apiString;
117117
}
118118

119119
if (value is null or "null")
@@ -247,7 +247,7 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
247247

248248
if (type == "string")
249249
{
250-
return openApiAny;
250+
return apiString;
251251
}
252252

253253
if (type == "boolean")
@@ -262,7 +262,7 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
262262
// If data conflicts with the given type, return a string.
263263
// This converter is used in the parser, so it does not perform any validations,
264264
// but the validator can be used to validate whether the data and given type conflicts.
265-
return openApiAny;
265+
return apiString;
266266
}
267267
}
268268
}

src/Microsoft.OpenApi/Extensions/OpenAPIWriterExtensions.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,9 +11,9 @@ internal static class OpenAPIWriterExtensions
1111
/// <returns></returns>
1212
internal static OpenApiWriterSettings GetSettings(this IOpenApiWriter openApiWriter)
1313
{
14-
if (openApiWriter is OpenApiWriterBase)
14+
if (openApiWriter is OpenApiWriterBase @base)
1515
{
16-
return ((OpenApiWriterBase)openApiWriter).Settings;
16+
return @base.Settings;
1717
}
1818
return new OpenApiWriterSettings();
1919
}

src/Microsoft.OpenApi/Models/OpenApiParameter.cs

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -411,10 +411,10 @@ public void SerializeAsV2WithoutReference(IOpenApiWriter writer)
411411
{
412412
Style = In switch
413413
{
414-
ParameterLocation.Query => (ParameterStyle?)ParameterStyle.Form,
415-
ParameterLocation.Header => (ParameterStyle?)ParameterStyle.Simple,
416-
ParameterLocation.Path => (ParameterStyle?)ParameterStyle.Simple,
417-
ParameterLocation.Cookie => (ParameterStyle?)ParameterStyle.Form,
414+
ParameterLocation.Query => ParameterStyle.Form,
415+
ParameterLocation.Header => ParameterStyle.Simple,
416+
ParameterLocation.Path => ParameterStyle.Simple,
417+
ParameterLocation.Cookie => ParameterStyle.Form,
418418
_ => (ParameterStyle?)ParameterStyle.Simple,
419419
};
420420

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

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -75,16 +75,14 @@ public static void ValidateDataTypeMismatch(
7575
}
7676

7777
// If value is not a string and also not an object, there is a data mismatch.
78-
if (!(value is OpenApiObject))
78+
if (value is not OpenApiObject anyObject)
7979
{
8080
context.CreateWarning(
8181
ruleName,
8282
DataTypeMismatchedErrorMessage);
8383
return;
8484
}
8585

86-
var anyObject = (OpenApiObject)value;
87-
8886
foreach (var key in anyObject.Keys)
8987
{
9088
context.Enter(key);
@@ -115,16 +113,14 @@ public static void ValidateDataTypeMismatch(
115113
}
116114

117115
// If value is not a string and also not an array, there is a data mismatch.
118-
if (!(value is OpenApiArray))
116+
if (value is not OpenApiArray anyArray)
119117
{
120118
context.CreateWarning(
121119
ruleName,
122120
DataTypeMismatchedErrorMessage);
123121
return;
124122
}
125123

126-
var anyArray = (OpenApiArray)value;
127-
128124
for (int i = 0; i < anyArray.Count; i++)
129125
{
130126
context.Enter(i.ToString());

0 commit comments

Comments
 (0)