Skip to content

Commit

Permalink
Merge branch 'vnext' into remove-redundant-CheckArguments
Browse files Browse the repository at this point in the history
  • Loading branch information
baywet authored Oct 24, 2023
2 parents 9937565 + dcc1e83 commit 428b9e4
Show file tree
Hide file tree
Showing 128 changed files with 912 additions and 1,457 deletions.
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Hidi/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public static IList<string> SplitByChar(this string target, char separator)
{
return new List<string>();
}
return target.Split(new char[] { separator }, StringSplitOptions.RemoveEmptyEntries).ToList();
return target.Split(new[] { separator }, StringSplitOptions.RemoveEmptyEntries).ToList();
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,7 @@ private static string SingularizeAndDeduplicateOperationId(IList<string> operati
var lastSegmentIndex = segmentsCount - 1;
var singularizedSegments = new List<string>();

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

Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi.Hidi/Handlers/PluginCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public int Invoke(InvocationContext context)
}
public async Task<int> InvokeAsync(InvocationContext context)
{
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
var hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
var cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));

using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
var logger = loggerFactory.CreateLogger<PluginCommandHandler>();
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi.Hidi/Handlers/ShowCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public int Invoke(InvocationContext context)
}
public async Task<int> InvokeAsync(InvocationContext context)
{
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
var hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
var cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));

using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
var logger = loggerFactory.CreateLogger<ShowCommandHandler>();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,8 @@ public int Invoke(InvocationContext context)
}
public async Task<int> InvokeAsync(InvocationContext context)
{
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
var hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
var cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));

using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
var logger = loggerFactory.CreateLogger<TransformCommandHandler>();
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi.Hidi/Handlers/ValidateCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -26,8 +26,8 @@ public int Invoke(InvocationContext context)
}
public async Task<int> InvokeAsync(InvocationContext context)
{
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
var hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
var cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
var logger = loggerFactory.CreateLogger<ValidateCommandHandler>();
try
Expand Down
5 changes: 1 addition & 4 deletions src/Microsoft.OpenApi.Hidi/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,10 +17,7 @@ public static ILoggerFactory ConfigureLogger(LogLevel logLevel)
return LoggerFactory.Create((builder) =>
{
builder
.AddSimpleConsole(c =>
{
c.IncludeScopes = true;
})
.AddSimpleConsole(c => c.IncludeScopes = true)
#if DEBUG
.AddDebug()
#endif
Expand Down
18 changes: 9 additions & 9 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -66,8 +66,8 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
}

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

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

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

if (options.FilterOptions != null)
{
Expand Down Expand Up @@ -227,7 +227,7 @@ private static async Task<OpenApiDocument> GetOpenApi(HidiOptions options, ILogg
Stream? filteredStream = null;
if (!string.IsNullOrEmpty(options.CsdlFilter))
{
XslCompiledTransform transform = GetFilterTransform();
var transform = GetFilterTransform();
filteredStream = ApplyFilterToCsdl(stream, options.CsdlFilter, transform);
filteredStream.Position = 0;
await stream.DisposeAsync().ConfigureAwait(false);
Expand Down Expand Up @@ -299,7 +299,7 @@ private static Dictionary<string, List<string>> GetRequestUrlsFromManifest(ApiDe
private static XslCompiledTransform GetFilterTransform()
{
XslCompiledTransform transform = new();
Assembly assembly = typeof(OpenApiService).GetTypeInfo().Assembly;
var assembly = typeof(OpenApiService).GetTypeInfo().Assembly;
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.");
using var streamReader = new StreamReader(xslt);
using var textReader = new XmlTextReader(streamReader);
Expand All @@ -310,7 +310,7 @@ private static XslCompiledTransform GetFilterTransform()
private static Stream ApplyFilterToCsdl(Stream csdlStream, string entitySetOrSingleton, XslCompiledTransform transform)
{
using StreamReader inputReader = new(csdlStream, leaveOpen: true);
using XmlReader inputXmlReader = XmlReader.Create(inputReader);
using var inputXmlReader = XmlReader.Create(inputReader);
MemoryStream filteredStream = new();
using StreamWriter writer = new(filteredStream, leaveOpen: true);
XsltArgumentList args = new();
Expand Down Expand Up @@ -363,7 +363,7 @@ public static async Task ValidateOpenApiDocument(
private static async Task<ReadResult> ParseOpenApi(string openApiFile, bool inlineExternal, ILogger logger, Stream stream, CancellationToken cancellationToken = default)
{
ReadResult result;
Stopwatch stopwatch = Stopwatch.StartNew();
var stopwatch = Stopwatch.StartNew();
using (logger.BeginScope("Parsing OpenAPI: {OpenApiFile}", openApiFile))
{
stopwatch.Start();
Expand Down Expand Up @@ -398,7 +398,7 @@ public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl, stri
var edmModel = CsdlReader.Parse(XElement.Parse(csdlText).CreateReader());
settings ??= SettingsUtilities.GetConfiguration();

OpenApiDocument document = edmModel.ConvertToOpenApi(SettingsUtilities.GetOpenApiConvertSettings(settings, metadataVersion));
var document = edmModel.ConvertToOpenApi(SettingsUtilities.GetOpenApiConvertSettings(settings, metadataVersion));
document = FixReferences(document);

return document;
Expand Down Expand Up @@ -725,7 +725,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C
}

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

cancellationToken.ThrowIfCancellationRequested();

Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Hidi/OpenApiSpecVersionHelper.cs
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public static OpenApiSpecVersion TryParseOpenApiSpecVersion(string value)
}
var res = value.Split('.', StringSplitOptions.RemoveEmptyEntries).FirstOrDefault();

if (int.TryParse(res, out int result))
if (int.TryParse(res, out var result))
{
if (result >= 2 && result < 3)
{
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Readers/OpenApiYamlDocumentReader.cs
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ private Task<OpenApiDiagnostic> LoadExternalRefs(OpenApiDocument document, Cance

private void ResolveReferences(OpenApiDiagnostic diagnostic, OpenApiDocument document)
{
List<OpenApiError> errors = new List<OpenApiError>();
var errors = new List<OpenApiError>();

// Resolve References if requested
switch (_settings.ReferenceResolution)
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Readers/ParsingContext.cs
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ internal T ParseFragment<T>(YamlDocument yamlDocument, OpenApiSpecVersion versio
{
var node = ParseNode.Create(this, yamlDocument.RootNode);

T element = default(T);
var element = default(T);

switch (version)
{
Expand Down
18 changes: 6 additions & 12 deletions src/Microsoft.OpenApi.Readers/V2/OpenApiContactDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -17,22 +17,16 @@ internal static partial class OpenApiV2Deserializer
private static FixedFieldMap<OpenApiContact> _contactFixedFields = new()
{
{
"name", (o, n) =>
{
o.Name = n.GetScalarValue();
}
"name",
(o, n) => o.Name = n.GetScalarValue()
},
{
"url", (o, n) =>
{
o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute);
}
"url",
(o, n) => o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute)
},
{
"email", (o, n) =>
{
o.Email = n.GetScalarValue();
}
"email",
(o, n) => o.Email = n.GetScalarValue()
},
};

Expand Down
21 changes: 10 additions & 11 deletions src/Microsoft.OpenApi.Readers/V2/OpenApiDocumentDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,22 +21,21 @@ internal static partial class OpenApiV2Deserializer
private static FixedFieldMap<OpenApiDocument> _openApiFixedFields = new()
{
{
"swagger", (o, n) =>
{
} /* Version is valid field but we already parsed it */
"swagger", (_, _) => {}
/* Version is valid field but we already parsed it */
},
{"info", (o, n) => o.Info = LoadInfo(n)},
{"host", (o, n) => n.Context.SetTempStorage("host", n.GetScalarValue())},
{"basePath", (o, n) => n.Context.SetTempStorage("basePath", n.GetScalarValue())},
{"host", (_, n) => n.Context.SetTempStorage("host", n.GetScalarValue())},
{"basePath", (_, n) => n.Context.SetTempStorage("basePath", n.GetScalarValue())},
{
"schemes", (o, n) => n.Context.SetTempStorage(
"schemes", (_, n) => n.Context.SetTempStorage(
"schemes",
n.CreateSimpleList(
s => s.GetScalarValue()))
},
{
"consumes",
(o, n) =>
(_, n) =>
{
var consumes = n.CreateSimpleList(s => s.GetScalarValue());
if (consumes.Count > 0)
Expand All @@ -46,7 +45,7 @@ internal static partial class OpenApiV2Deserializer
}
},
{
"produces", (o, n) => {
"produces", (_, n) => {
var produces = n.CreateSimpleList(s => s.GetScalarValue());
if (produces.Count > 0)
{
Expand Down Expand Up @@ -138,7 +137,7 @@ private static void MakeServers(IList<OpenApiServer> servers, ParsingContext con
var host = context.GetFromTempStorage<string>("host");
var basePath = context.GetFromTempStorage<string>("basePath");
var schemes = context.GetFromTempStorage<List<string>>("schemes");
Uri defaultUrl = rootNode.Context.BaseUrl;
var defaultUrl = rootNode.Context.BaseUrl;

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

// Create the Server objects
if (schemes != null && schemes.Count > 0)
if (schemes is {Count: > 0})
{
foreach (var scheme in schemes)
{
Expand Down Expand Up @@ -295,7 +294,7 @@ private static void FixRequestBodyReferences(OpenApiDocument doc)
{
// Walk all unresolved parameter references
// if id matches with request body Id, change type
if (doc.Components?.RequestBodies != null && doc.Components?.RequestBodies.Count > 0)
if (doc.Components?.RequestBodies is {Count: > 0})
{
var fixer = new RequestBodyReferenceFixer(doc.Components?.RequestBodies);
var walker = new OpenApiWalker(fixer);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,16 +18,12 @@ internal static partial class OpenApiV2Deserializer
new()
{
{
OpenApiConstants.Description, (o, n) =>
{
o.Description = n.GetScalarValue();
}
OpenApiConstants.Description,
(o, n) => o.Description = n.GetScalarValue()
},
{
OpenApiConstants.Url, (o, n) =>
{
o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute);
}
OpenApiConstants.Url,
(o, n) => o.Url = new(n.GetScalarValue(), UriKind.RelativeOrAbsolute)
},
};

Expand Down
Loading

0 comments on commit 428b9e4

Please sign in to comment.