Skip to content

Commit 76dcb45

Browse files
committed
Code quality fixes.
1 parent fe2b6b9 commit 76dcb45

File tree

3 files changed

+13
-11
lines changed

3 files changed

+13
-11
lines changed

src/Microsoft.OpenApi.Hidi/Handlers/PluginCommandHandler.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ public async Task<int> InvokeAsync(InvocationContext context)
2727
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetService(typeof(CancellationToken));
2828

2929
using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
30-
var logger = loggerFactory.CreateLogger<OpenApiService>();
30+
var logger = loggerFactory.CreateLogger("Hidi.PluginCommandHandler");
3131
try
3232
{
3333
await OpenApiService.PluginManifest(hidiOptions, logger, cancellationToken);

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@
3535

3636
namespace Microsoft.OpenApi.Hidi
3737
{
38-
internal class OpenApiService
38+
internal static class OpenApiService
3939
{
4040
/// <summary>
4141
/// Implementation of the transform command
@@ -134,7 +134,7 @@ private static async Task<ApiDependency> FindApiDependency(string apiManifestPat
134134
{
135135
apiManifest = ApiManifestDocument.Load(JsonDocument.Parse(fileStream).RootElement);
136136
}
137-
137+
138138
apiDependency = apiDependencyName != null ? apiManifest.ApiDependencies[apiDependencyName] : apiManifest.ApiDependencies.First().Value;
139139
}
140140

@@ -146,7 +146,7 @@ private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger,
146146
Dictionary<string, List<string>> requestUrls = null;
147147
if (apiDependency != null)
148148
{
149-
requestUrls = GetRequestUrlsFromManifest(apiDependency, document);
149+
requestUrls = GetRequestUrlsFromManifest(apiDependency);
150150
}
151151
else if (postmanCollection != null)
152152
{
@@ -159,7 +159,7 @@ private static OpenApiDocument ApplyFilters(HidiOptions options, ILogger logger,
159159
options.FilterOptions.FilterByTags,
160160
requestUrls,
161161
document,
162-
logger, cancellationToken);
162+
logger);
163163
if (predicate != null)
164164
{
165165
var stopwatch = new Stopwatch();
@@ -242,7 +242,7 @@ private static async Task<OpenApiDocument> GetOpenApi(string openapi, string csd
242242
return document;
243243
}
244244

245-
private static Func<string, OperationType?, OpenApiOperation, bool> FilterOpenApiDocument(string filterbyoperationids, string filterbytags, Dictionary<string, List<string>> requestUrls, OpenApiDocument document, ILogger logger, CancellationToken cancellationToken)
245+
private static Func<string, OperationType?, OpenApiOperation, bool> FilterOpenApiDocument(string filterbyoperationids, string filterbytags, Dictionary<string, List<string>> requestUrls, OpenApiDocument document, ILogger logger)
246246
{
247247
Func<string, OperationType?, OpenApiOperation, bool> predicate = null;
248248

@@ -275,9 +275,9 @@ private static async Task<OpenApiDocument> GetOpenApi(string openapi, string csd
275275
return predicate;
276276
}
277277

278-
private static Dictionary<string, List<string>> GetRequestUrlsFromManifest(ApiDependency apiDependency, OpenApiDocument document)
278+
private static Dictionary<string, List<string>> GetRequestUrlsFromManifest(ApiDependency apiDependency)
279279
{
280-
// Get the request URLs from the API Dependencies in the API manifest that have a baseURL that matches the server URL in the OpenAPI document
280+
// Get the request URLs from the API Dependencies in the API manifest
281281
var requests = apiDependency
282282
.Requests.Where(r => !r.Exclude)
283283
.Select(r=> new { UriTemplate= r.UriTemplate, Method=r.Method } )
@@ -696,18 +696,19 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
696696
writer.WriteLine("</html");
697697
}
698698

699-
internal async static Task PluginManifest(HidiOptions options, ILogger<OpenApiService> logger, CancellationToken cancellationToken)
699+
internal async static Task PluginManifest(HidiOptions options, ILogger logger, CancellationToken cancellationToken)
700700
{
701701
// If ApiManifest is provided, set the referenced OpenAPI document
702702
var apiDependency = await FindApiDependency(options.FilterOptions?.FilterByApiManifest, logger, cancellationToken);
703703
if (apiDependency != null) {
704704
options.OpenApi = apiDependency.ApiDescripionUrl;
705705
}
706706

707-
708707
// Load OpenAPI document
709708
OpenApiDocument document = await GetOpenApi(options.OpenApi, options.Csdl, options.CsdlFilter, options.SettingsConfig, options.InlineExternal, logger, cancellationToken, options.MetadataVersion);
710709

710+
cancellationToken.ThrowIfCancellationRequested();
711+
711712
if (options.FilterOptions != null)
712713
{
713714
document = ApplyFilters(options, logger, apiDependency, null, document, cancellationToken);

src/Microsoft.OpenApi/Services/OpenApiFilterService.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -346,7 +346,8 @@ private static bool AddReferences(OpenApiComponents newComponents, OpenApiCompon
346346
private static string ExtractPath(string url, IList<OpenApiServer> serverList)
347347
{
348348
// if OpenAPI has servers, then see if the url matches one of them
349-
var baseUrl = serverList.Select(s => s.Url.TrimEnd('/')).Where(c => url.Contains(c)).FirstOrDefault();
349+
var baseUrl = serverList.Select(s => s.Url.TrimEnd('/'))
350+
.FirstOrDefault(c => url.Contains(c));
350351

351352
return baseUrl == null ?
352353
new Uri(new Uri("http://localhost/"), url).GetComponents(UriComponents.Path | UriComponents.KeepDelimiter, UriFormat.Unescaped)

0 commit comments

Comments
 (0)