Skip to content

Commit e6bec55

Browse files
authored
Merge pull request #1417 from SimonCropp/use-some-var
use some var
2 parents 8c17b0c + e397649 commit e6bec55

File tree

60 files changed

+169
-172
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

60 files changed

+169
-172
lines changed

src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -122,7 +122,7 @@ private static string SingularizeAndDeduplicateOperationId(IList<string> operati
122122
var lastSegmentIndex = segmentsCount - 1;
123123
var singularizedSegments = new List<string>();
124124

125-
for (int x = 0; x < segmentsCount; x++)
125+
for (var x = 0; x < segmentsCount; x++)
126126
{
127127
var segment = operationIdSegments[x].Singularize(inputIsKnownToBePlural: false);
128128

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public int Invoke(InvocationContext context)
2424
}
2525
public async Task<int> InvokeAsync(InvocationContext context)
2626
{
27-
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
28-
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
27+
var hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
28+
var cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
2929

3030
using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
3131
var logger = loggerFactory.CreateLogger<PluginCommandHandler>();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public int Invoke(InvocationContext context)
2424
}
2525
public async Task<int> InvokeAsync(InvocationContext context)
2626
{
27-
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
28-
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
27+
var hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
28+
var cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
2929

3030
using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
3131
var logger = loggerFactory.CreateLogger<ShowCommandHandler>();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,8 +24,8 @@ public int Invoke(InvocationContext context)
2424
}
2525
public async Task<int> InvokeAsync(InvocationContext context)
2626
{
27-
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
28-
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
27+
var hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
28+
var cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
2929

3030
using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
3131
var logger = loggerFactory.CreateLogger<TransformCommandHandler>();

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -26,8 +26,8 @@ public int Invoke(InvocationContext context)
2626
}
2727
public async Task<int> InvokeAsync(InvocationContext context)
2828
{
29-
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
30-
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
29+
var hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
30+
var cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
3131
using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
3232
var logger = loggerFactory.CreateLogger<ValidateCommandHandler>();
3333
try

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 9 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -66,8 +66,8 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
6666
}
6767

6868
// Default to yaml and OpenApiVersion 3 during csdl to OpenApi conversion
69-
OpenApiFormat openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiFormat.Yaml);
70-
OpenApiSpecVersion openApiVersion = options.Version != null ? TryParseOpenApiSpecVersion(options.Version) : OpenApiSpecVersion.OpenApi3_0;
69+
var openApiFormat = options.OpenApiFormat ?? (!string.IsNullOrEmpty(options.OpenApi) ? GetOpenApiFormat(options.OpenApi, logger) : OpenApiFormat.Yaml);
70+
var openApiVersion = options.Version != null ? TryParseOpenApiSpecVersion(options.Version) : OpenApiSpecVersion.OpenApi3_0;
7171

7272
// If ApiManifest is provided, set the referenced OpenAPI document
7373
var apiDependency = await FindApiDependency(options.FilterOptions.FilterByApiManifest, logger, cancellationToken).ConfigureAwait(false);
@@ -85,7 +85,7 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
8585
}
8686

8787
// Load OpenAPI document
88-
OpenApiDocument document = await GetOpenApi(options, logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false);
88+
var document = await GetOpenApi(options, logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false);
8989

9090
if (options.FilterOptions != null)
9191
{
@@ -227,7 +227,7 @@ private static async Task<OpenApiDocument> GetOpenApi(HidiOptions options, ILogg
227227
Stream? filteredStream = null;
228228
if (!string.IsNullOrEmpty(options.CsdlFilter))
229229
{
230-
XslCompiledTransform transform = GetFilterTransform();
230+
var transform = GetFilterTransform();
231231
filteredStream = ApplyFilterToCsdl(stream, options.CsdlFilter, transform);
232232
filteredStream.Position = 0;
233233
await stream.DisposeAsync().ConfigureAwait(false);
@@ -299,7 +299,7 @@ private static Dictionary<string, List<string>> GetRequestUrlsFromManifest(ApiDe
299299
private static XslCompiledTransform GetFilterTransform()
300300
{
301301
XslCompiledTransform transform = new();
302-
Assembly assembly = typeof(OpenApiService).GetTypeInfo().Assembly;
302+
var assembly = typeof(OpenApiService).GetTypeInfo().Assembly;
303303
using var xslt = assembly.GetManifestResourceStream("Microsoft.OpenApi.Hidi.CsdlFilter.xslt") ?? throw new InvalidOperationException("Could not find the Microsoft.OpenApi.Hidi.CsdlFilter.xslt file in the assembly. Check build configuration.");
304304
using var streamReader = new StreamReader(xslt);
305305
using var textReader = new XmlTextReader(streamReader);
@@ -310,7 +310,7 @@ private static XslCompiledTransform GetFilterTransform()
310310
private static Stream ApplyFilterToCsdl(Stream csdlStream, string entitySetOrSingleton, XslCompiledTransform transform)
311311
{
312312
using StreamReader inputReader = new(csdlStream, leaveOpen: true);
313-
using XmlReader inputXmlReader = XmlReader.Create(inputReader);
313+
using var inputXmlReader = XmlReader.Create(inputReader);
314314
MemoryStream filteredStream = new();
315315
using StreamWriter writer = new(filteredStream, leaveOpen: true);
316316
XsltArgumentList args = new();
@@ -363,7 +363,7 @@ public static async Task ValidateOpenApiDocument(
363363
private static async Task<ReadResult> ParseOpenApi(string openApiFile, bool inlineExternal, ILogger logger, Stream stream, CancellationToken cancellationToken = default)
364364
{
365365
ReadResult result;
366-
Stopwatch stopwatch = Stopwatch.StartNew();
366+
var stopwatch = Stopwatch.StartNew();
367367
using (logger.BeginScope("Parsing OpenAPI: {OpenApiFile}", openApiFile))
368368
{
369369
stopwatch.Start();
@@ -398,7 +398,7 @@ public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl, stri
398398
var edmModel = CsdlReader.Parse(XElement.Parse(csdlText).CreateReader());
399399
settings ??= SettingsUtilities.GetConfiguration();
400400

401-
OpenApiDocument document = edmModel.ConvertToOpenApi(SettingsUtilities.GetOpenApiConvertSettings(settings, metadataVersion));
401+
var document = edmModel.ConvertToOpenApi(SettingsUtilities.GetOpenApiConvertSettings(settings, metadataVersion));
402402
document = FixReferences(document);
403403

404404
return document;
@@ -725,7 +725,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C
725725
}
726726

727727
// Load OpenAPI document
728-
OpenApiDocument document = await GetOpenApi(options, logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false);
728+
var document = await GetOpenApi(options, logger, options.MetadataVersion, cancellationToken).ConfigureAwait(false);
729729

730730
cancellationToken.ThrowIfCancellationRequested();
731731

src/Microsoft.OpenApi.Hidi/OpenApiSpecVersionHelper.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ public static OpenApiSpecVersion TryParseOpenApiSpecVersion(string value)
1616
}
1717
var res = value.Split('.', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();
1818

19-
if (int.TryParse(res, out int result))
19+
if (int.TryParse(res, out var result))
2020
{
2121
if (result >= 2 && result < 3)
2222
{

src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ private Task<OpenApiDiagnostic> LoadExternalRefs(OpenApiDocument document, Cance
152152

153153
private void ResolveReferences(OpenApiDiagnostic diagnostic, OpenApiDocument document)
154154
{
155-
List<OpenApiError> errors = new List<OpenApiError>();
155+
var errors = new List<OpenApiError>();
156156

157157
// Resolve References if requested
158158
switch (_settings.ReferenceResolution)

src/Microsoft.OpenApi.Readers/ParsingContext.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@ internal T ParseFragment<T>(YamlDocument yamlDocument, OpenApiSpecVersion versio
8989
{
9090
var node = ParseNode.Create(this, yamlDocument.RootNode);
9191

92-
T element = default(T);
92+
var element = default(T);
9393

9494
switch (version)
9595
{

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ private static void MakeServers(IList<OpenApiServer> servers, ParsingContext con
138138
var host = context.GetFromTempStorage<string>("host");
139139
var basePath = context.GetFromTempStorage<string>("basePath");
140140
var schemes = context.GetFromTempStorage<List<string>>("schemes");
141-
Uri defaultUrl = rootNode.Context.BaseUrl;
141+
var defaultUrl = rootNode.Context.BaseUrl;
142142

143143
// so we don't default to the document path when a host is provided
144144
if (string.IsNullOrEmpty(basePath) && !string.IsNullOrEmpty(host))
@@ -172,7 +172,7 @@ private static void MakeServers(IList<OpenApiServer> servers, ParsingContext con
172172
}
173173

174174
// Create the Server objects
175-
if (schemes != null && schemes.Count > 0)
175+
if (schemes is {Count: > 0})
176176
{
177177
foreach (var scheme in schemes)
178178
{
@@ -295,7 +295,7 @@ private static void FixRequestBodyReferences(OpenApiDocument doc)
295295
{
296296
// Walk all unresolved parameter references
297297
// if id matches with request body Id, change type
298-
if (doc.Components?.RequestBodies != null && doc.Components?.RequestBodies.Count > 0)
298+
if (doc.Components?.RequestBodies is {Count: > 0})
299299
{
300300
var fixer = new RequestBodyReferenceFixer(doc.Components?.RequestBodies);
301301
var walker = new OpenApiWalker(fixer);

0 commit comments

Comments
 (0)