Skip to content
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

Test PR codium #33

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
Original file line number Diff line number Diff line change
Expand Up @@ -15,14 +15,15 @@
<Authors>Criteo</Authors>
<Company>Criteo</Company>
<Copyright>Copyright (c) Criteo Technology. All rights reserved.</Copyright>
<Version>0.7.3</Version>
<Version>1.0.0</Version>
<PackageProjectUrl>https://github.com/criteo/openapi-comparator</PackageProjectUrl>
<RepositoryUrl>https://github.com/criteo/openapi-comparator</RepositoryUrl>
<PackageTags>Criteo, OpenApi, OpenApi-Comparator, OpenApi-Diff, Swagger</PackageTags>
<PackageLicenseExpression>Apache-2.0</PackageLicenseExpression>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackAsTool>true</PackAsTool>
<ToolCommandName>openapi-compare</ToolCommandName>
<PackageOutputPath>./nupkg</PackageOutputPath>
<PackageReadmeFile>Readme.md</PackageReadmeFile>
</PropertyGroup>
<ItemGroup>
Expand Down
32 changes: 30 additions & 2 deletions src/Criteo.OpenApi.Comparator.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,8 @@
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text.Json;

namespace Criteo.OpenApi.Comparator.Cli
Expand Down Expand Up @@ -45,15 +47,41 @@ public static int Main(string[] args)
}

private static bool TryReadFile(string path, out string fileContent)
{
bool readOk = TryReadDistantFile(path, out fileContent);
if (!readOk)
{
TryReadLocalFile(path, out fileContent);

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

It would be beneficial to add a null check for fileContent after trying to read from both a distant URL and a local file. This can prevent potential NullReferenceExceptions in the future. [medium]

}
return readOk;
}

private static bool TryReadDistantFile(string url, out string fileContent)
{
try
{
using HttpClient wc = new HttpClient();
fileContent = wc.GetStringAsync(url).Result;

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider using async/await for the HttpClient.GetStringAsync(url) call to avoid blocking the thread. This can improve the performance of your application. [important]

return true;
}
catch (Exception e)
{
Console.WriteLine($"File not found for: {url} with the message {e.Message}");
fileContent = null;
return false;
}
}

private static bool TryReadLocalFile(string path, out string fileContent)
{
try
{
fileContent = File.ReadAllText(path);
return true;
}
catch (FileNotFoundException)
catch (FileNotFoundException f)
{
Console.WriteLine($"File not found for: {path}.");
Console.WriteLine($"File not found for: {path} with the message {f.Message}");
fileContent = null;
return false;
}
Expand Down