Skip to content

Commit

Permalink
Merge pull request #1366 from SimonCropp/use-some-pattern-matiching
Browse files Browse the repository at this point in the history
use some pattern matching
  • Loading branch information
MaggieKimani1 authored Oct 2, 2023
2 parents a847203 + cf89b4f commit 170ee50
Show file tree
Hide file tree
Showing 8 changed files with 16 additions and 14 deletions.
16 changes: 9 additions & 7 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -510,13 +510,15 @@ private static async Task<Stream> GetStream(string input, ILogger logger, Cancel
var fileInput = new FileInfo(input);
stream = fileInput.OpenRead();
}
catch (Exception ex) when (ex is FileNotFoundException ||
ex is PathTooLongException ||
ex is DirectoryNotFoundException ||
ex is IOException ||
ex is UnauthorizedAccessException ||
ex is SecurityException ||
ex is NotSupportedException)
catch (Exception ex) when (
ex is
FileNotFoundException or
PathTooLongException or
DirectoryNotFoundException or
IOException or
UnauthorizedAccessException or
SecurityException or
NotSupportedException)
{
throw new InvalidOperationException($"Could not open the file at {input}", ex);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -116,7 +116,7 @@ public static IOpenApiAny GetSpecificOpenApiAny(IOpenApiAny openApiAny, OpenApiS
return openApiAny;
}

if (value == null || value == "null")
if (value is null or "null")
{
return new OpenApiNull();
}
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Readers/ParseNodes/ValueNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public override string GetScalarValue()
public override IOpenApiAny CreateAny()
{
var value = GetScalarValue();
return new OpenApiString(value, this._node.Style == ScalarStyle.SingleQuoted || this._node.Style == ScalarStyle.DoubleQuoted || this._node.Style == ScalarStyle.Literal || this._node.Style == ScalarStyle.Folded);
return new OpenApiString(value, this._node.Style is ScalarStyle.SingleQuoted or ScalarStyle.DoubleQuoted or ScalarStyle.Literal or ScalarStyle.Folded);
}
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Readers/ParsingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ internal OpenApiDocument Parse(YamlDocument yamlDocument)

switch (inputVersion)
{
case string version when version == "2.0":
case string and "2.0":
VersionService = new OpenApiV2VersionService(Diagnostic);
doc = VersionService.LoadDocument(RootNode);
this.Diagnostic.SpecificationVersion = OpenApiSpecVersion.OpenApi2_0;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ public OpenApiReference ConvertToOpenApiReference(string reference, ReferenceTyp
};
}

if (type == ReferenceType.Tag || type == ReferenceType.SecurityScheme)
if (type is ReferenceType.Tag or ReferenceType.SecurityScheme)
{
return new OpenApiReference
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@ public OpenApiReference ConvertToOpenApiReference(
var segments = reference.Split('#');
if (segments.Length == 1)
{
if (type == ReferenceType.Tag || type == ReferenceType.SecurityScheme)
if (type is ReferenceType.Tag or ReferenceType.SecurityScheme)
{
return new OpenApiReference
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ public class OpenApiEnumValuesDescriptionExtension : IOpenApiExtension
public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
{
if (writer is null) throw new ArgumentNullException(nameof(writer));
if ((specVersion == OpenApiSpecVersion.OpenApi2_0 || specVersion == OpenApiSpecVersion.OpenApi3_0) &&
if (specVersion is OpenApiSpecVersion.OpenApi2_0 or OpenApiSpecVersion.OpenApi3_0 &&
!string.IsNullOrEmpty(EnumName) &&
ValuesDescriptions.Any())
{ // when we upgrade to 3.1, we don't need to write this extension as JSON schema will support writing enum values
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -274,7 +274,7 @@ private static string WriteAsJson(IOpenApiAny any, bool produceTerseOutput = fal
// Act
var value = new StreamReader(stream).ReadToEnd();

if (any.AnyType == AnyType.Primitive || any.AnyType == AnyType.Null)
if (any.AnyType is AnyType.Primitive or AnyType.Null)
{
return value;
}
Expand Down

0 comments on commit 170ee50

Please sign in to comment.