Skip to content

Commit 1bec222

Browse files
authored
Merge pull request #1445 from microsoft/vnext
Release new versions of OpenAPI.NET libraries
2 parents 2ade929 + 51890ee commit 1bec222

File tree

285 files changed

+3066
-4193
lines changed

Some content is hidden

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

285 files changed

+3066
-4193
lines changed

.editorconfig

+1-1
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ csharp_prefer_braces = true:silent
8484
csharp_style_deconstructed_variable_declaration = true:suggestion
8585
csharp_prefer_simple_default_expression = true:suggestion
8686
csharp_style_pattern_local_over_anonymous_function = true:suggestion
87-
csharp_style_inlined_variable_declaration = true:suggestion
87+
csharp_style_inlined_variable_declaration = true:error
8888
###############################
8989
# C# Formatting Rules #
9090
###############################

src/Microsoft.OpenApi.Hidi/Extensions/StringExtensions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,7 @@ public static IList<string> SplitByChar(this string target, char separator)
4040
{
4141
return new List<string>();
4242
}
43-
return target.Split(new char[] { separator }, StringSplitOptions.RemoveEmptyEntries).ToList();
43+
return target.Split(new[] { separator }, StringSplitOptions.RemoveEmptyEntries).ToList();
4444
}
4545
}
4646
}

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

+4-4
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

@@ -163,10 +163,10 @@ private static IList<OpenApiParameter> ResolveFunctionParameters(IList<OpenApiPa
163163
// Replace content with a schema object of type array
164164
// for structured or collection-valued function parameters
165165
parameter.Content = null;
166-
parameter.Schema = new OpenApiSchema
166+
parameter.Schema = new()
167167
{
168168
Type = "array",
169-
Items = new OpenApiSchema
169+
Items = new()
170170
{
171171
Type = "string"
172172
}
@@ -179,7 +179,7 @@ private void AddAdditionalPropertiesToSchema(OpenApiSchema schema)
179179
{
180180
if (schema != null && !_schemaLoop.Contains(schema) && "object".Equals(schema.Type, StringComparison.OrdinalIgnoreCase))
181181
{
182-
schema.AdditionalProperties = new OpenApiSchema { Type = "object" };
182+
schema.AdditionalProperties = new() { Type = "object" };
183183

184184
/* Because 'additionalProperties' are now being walked,
185185
* we need a way to keep track of visited schemas to avoid

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

+2-2
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

+2-2
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

+2-2
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

+2-2
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/Logger.cs

+1-4
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,7 @@ public static ILoggerFactory ConfigureLogger(LogLevel logLevel)
1717
return LoggerFactory.Create((builder) =>
1818
{
1919
builder
20-
.AddSimpleConsole(c =>
21-
{
22-
c.IncludeScopes = true;
23-
})
20+
.AddSimpleConsole(c => c.IncludeScopes = true)
2421
#if DEBUG
2522
.AddDebug()
2623
#endif

src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj

+2-2
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
<Nullable>enable</Nullable>
1010
<ToolCommandName>hidi</ToolCommandName>
1111
<PackageOutputPath>./../../artifacts</PackageOutputPath>
12-
<Version>1.3.1</Version>
12+
<Version>1.3.2</Version>
1313
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
1414
<SignAssembly>true</SignAssembly>
1515
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
@@ -35,7 +35,7 @@
3535
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="7.0.0" />
3636
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
3737
<PackageReference Include="Microsoft.OData.Edm" Version="7.18.0" />
38-
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.5.0-preview5" />
38+
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.5.0-preview7" />
3939
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.0-preview" />
4040
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
4141
</ItemGroup>

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

+17-17
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ public static async Task TransformOpenApiDocument(HidiOptions options, ILogger l
5353
if (options.Output == null)
5454
{
5555
var inputExtension = GetInputPathExtension(options.OpenApi, options.Csdl);
56-
options.Output = new FileInfo($"./output{inputExtension}");
56+
options.Output = new($"./output{inputExtension}");
5757
};
5858

5959
if (options.CleanOutput && options.Output.Exists)
@@ -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
{
@@ -194,7 +194,7 @@ private static void WriteOpenApi(HidiOptions options, OpenApiFormat openApiForma
194194

195195
IOpenApiWriter writer = openApiFormat switch
196196
{
197-
OpenApiFormat.Json => options.TerseOutput ? new OpenApiJsonWriter(textWriter, settings, options.TerseOutput) : new OpenApiJsonWriter(textWriter, settings, false),
197+
OpenApiFormat.Json => options.TerseOutput ? new(textWriter, settings, options.TerseOutput) : new OpenApiJsonWriter(textWriter, settings, false),
198198
OpenApiFormat.Yaml => new OpenApiYamlWriter(textWriter, settings),
199199
_ => throw new ArgumentException("Unknown format"),
200200
};
@@ -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,16 +363,16 @@ 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();
370370

371-
result = await new OpenApiStreamReader(new OpenApiReaderSettings
372-
{
371+
result = await new OpenApiStreamReader(new()
372+
{
373373
LoadExternalRefs = inlineExternal,
374374
BaseUrl = openApiFile.StartsWith("http", StringComparison.OrdinalIgnoreCase) ?
375-
new Uri(openApiFile) :
375+
new(openApiFile) :
376376
new Uri("file://" + new FileInfo(openApiFile).DirectoryName + Path.DirectorySeparatorChar)
377377
}
378378
).ReadAsync(stream, cancellationToken).ConfigureAwait(false);
@@ -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;
@@ -459,7 +459,7 @@ private static Dictionary<string, List<string>> EnumerateJsonDocument(JsonElemen
459459
}
460460
else
461461
{
462-
paths.Add(path, new List<string> {method});
462+
paths.Add(path, new() {method});
463463
}
464464
}
465465
else
@@ -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

@@ -741,7 +741,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C
741741
outputFolder.Create();
742742
}
743743
// Write OpenAPI to Output folder
744-
options.Output = new FileInfo(Path.Combine(options.OutputFolder, "openapi.json"));
744+
options.Output = new(Path.Combine(options.OutputFolder, "openapi.json"));
745745
options.TerseOutput = true;
746746
WriteOpenApi(options, OpenApiFormat.Json, OpenApiSpecVersion.OpenApi3_0, document, logger);
747747

@@ -762,7 +762,7 @@ internal static async Task PluginManifest(HidiOptions options, ILogger logger, C
762762
// Write OpenAIPluginManifest to Output folder
763763
var manifestFile = new FileInfo(Path.Combine(options.OutputFolder, "ai-plugin.json"));
764764
using var file = new FileStream(manifestFile.FullName, FileMode.Create);
765-
using var jsonWriter = new Utf8JsonWriter(file, new JsonWriterOptions { Indented = true });
765+
using var jsonWriter = new Utf8JsonWriter(file, new() { Indented = true });
766766
manifest.Write(jsonWriter);
767767
await jsonWriter.FlushAsync(cancellationToken).ConfigureAwait(false);
768768
}

src/Microsoft.OpenApi.Hidi/OpenApiSpecVersionHelper.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -16,9 +16,9 @@ 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
{
21-
if (result >= 2 && result < 3)
21+
if (result is >= 2 and < 3)
2222
{
2323
return OpenApiSpecVersion.OpenApi2_0;
2424
}

src/Microsoft.OpenApi.Hidi/Options/HidiOptions.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -53,7 +53,7 @@ private void ParseHidiOptions(ParseResult parseResult, CommandOptions options)
5353
LogLevel = parseResult.GetValueForOption(options.LogLevelOption);
5454
InlineLocal = parseResult.GetValueForOption(options.InlineLocalOption);
5555
InlineExternal = parseResult.GetValueForOption(options.InlineExternalOption);
56-
FilterOptions = new FilterOptions
56+
FilterOptions = new()
5757
{
5858
FilterByOperationIds = parseResult.GetValueForOption(options.FilterByOperationIdsOption),
5959
FilterByTags = parseResult.GetValueForOption(options.FilterByTagsOption),

src/Microsoft.OpenApi.Readers/Interface/IStreamLoader.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ public interface IStreamLoader
1717
/// Use Uri to locate data and convert into an input object.
1818
/// </summary>
1919
/// <param name="uri">Identifier of some source of an OpenAPI Description</param>
20-
/// <returns>A data objext that can be processed by a reader to generate an <see cref="OpenApiDocument"/></returns>
20+
/// <returns>A data object that can be processed by a reader to generate an <see cref="OpenApiDocument"/></returns>
2121
Task<Stream> LoadAsync(Uri uri);
2222

2323
/// <summary>

src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@
33
<TargetFramework>netstandard2.0</TargetFramework>
44
<LangVersion>latest</LangVersion>
55
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
6-
<Version>1.6.9</Version>
6+
<Version>1.6.10</Version>
77
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
88
<SignAssembly>true</SignAssembly>
99
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->

src/Microsoft.OpenApi.Readers/OpenApiDiagnostic.cs

+2-2
Original file line numberDiff line numberDiff line change
@@ -39,12 +39,12 @@ public void AppendDiagnostic(OpenApiDiagnostic diagnosticToAdd, string fileNameT
3939
foreach (var err in diagnosticToAdd.Errors)
4040
{
4141
var errMsgWithFileName = fileNameIsSupplied ? $"[File: {fileNameToAdd}] {err.Message}" : err.Message;
42-
Errors.Add(new OpenApiError(err.Pointer, errMsgWithFileName));
42+
Errors.Add(new(err.Pointer, errMsgWithFileName));
4343
}
4444
foreach (var warn in diagnosticToAdd.Warnings)
4545
{
4646
var warnMsgWithFileName = fileNameIsSupplied ? $"[File: {fileNameToAdd}] {warn.Message}" : warn.Message;
47-
Warnings.Add(new OpenApiError(warn.Pointer, warnMsgWithFileName));
47+
Warnings.Add(new(warn.Pointer, warnMsgWithFileName));
4848
}
4949
}
5050
}

src/Microsoft.OpenApi.Readers/OpenApiReaderSettings.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -50,7 +50,7 @@ public class OpenApiReaderSettings
5050
/// <summary>
5151
/// Dictionary of parsers for converting extensions into strongly typed classes
5252
/// </summary>
53-
public Dictionary<string, Func<IOpenApiAny, OpenApiSpecVersion, IOpenApiExtension>> ExtensionParsers { get; set; } = new Dictionary<string, Func<IOpenApiAny, OpenApiSpecVersion, IOpenApiExtension>>();
53+
public Dictionary<string, Func<IOpenApiAny, OpenApiSpecVersion, IOpenApiExtension>> ExtensionParsers { get; set; } = new();
5454

5555
/// <summary>
5656
/// Rules to use for validating OpenAPI specification. If none are provided a default set of rules are applied.

src/Microsoft.OpenApi.Readers/OpenApiStreamReader.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -68,7 +68,7 @@ public async Task<ReadResult> ReadAsync(Stream input, CancellationToken cancella
6868
{
6969
// Buffer stream so that OpenApiTextReaderReader can process it synchronously
7070
// YamlDocument doesn't support async reading.
71-
bufferedStream = new MemoryStream();
71+
bufferedStream = new();
7272
await input.CopyToAsync(bufferedStream, 81920, cancellationToken);
7373
bufferedStream.Position = 0;
7474
}

0 commit comments

Comments
 (0)