Skip to content

Commit ee526e7

Browse files
committed
- enables NRT for main hidi project
1 parent b6cf619 commit ee526e7

File tree

23 files changed

+150
-105
lines changed

23 files changed

+150
-105
lines changed

.vscode/settings.json

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,8 @@
33
"activityBar.background": "#03323C",
44
"titleBar.activeBackground": "#054754",
55
"titleBar.activeForeground": "#F0FCFE"
6-
}
6+
},
7+
"cSpell.words": [
8+
"Hidi"
9+
]
710
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,13 @@ internal static class OpenApiExtensibleExtensions
1212
/// <param name="extensions">A dictionary of <see cref="IOpenApiExtension"/>.</param>
1313
/// <param name="extensionKey">The key corresponding to the <see cref="IOpenApiExtension"/>.</param>
1414
/// <returns>A <see cref="string"/> value matching the provided extensionKey. Return null when extensionKey is not found. </returns>
15-
public static string GetExtension(this IDictionary<string, IOpenApiExtension> extensions, string extensionKey)
15+
internal static string GetExtension(this IDictionary<string, IOpenApiExtension> extensions, string extensionKey)
1616
{
1717
if (extensions.TryGetValue(extensionKey, out var value) && value is OpenApiString castValue)
1818
{
1919
return castValue.Value;
2020
}
21-
return default;
21+
return string.Empty;
2222
}
2323
}
2424
}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -12,13 +12,16 @@ internal static class StringExtensions
1212
/// <summary>
1313
/// Checks if the specified searchValue is equal to the target string based on the specified <see cref="StringComparison"/>.
1414
/// </summary>
15-
/// <param name="target">The target string to commpare to.</param>
15+
/// <param name="target">The target string to compare to.</param>
1616
/// <param name="searchValue">The search string to seek.</param>
1717
/// <param name="comparison">The <see cref="StringComparison"/> to use. This defaults to <see cref="StringComparison.OrdinalIgnoreCase"/>.</param>
1818
/// <returns>true if the searchValue parameter occurs within this string; otherwise, false.</returns>
19-
public static bool IsEquals(this string target, string searchValue, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
19+
public static bool IsEquals(this string? target, string? searchValue, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
2020
{
21-
if (string.IsNullOrWhiteSpace(target) || string.IsNullOrWhiteSpace(searchValue))
21+
if (string.IsNullOrWhiteSpace(target) && string.IsNullOrWhiteSpace(searchValue))
22+
{
23+
return true;
24+
} else if (string.IsNullOrWhiteSpace(target))
2225
{
2326
return false;
2427
}

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

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -191,19 +191,17 @@ private void AddAdditionalPropertiesToSchema(OpenApiSchema schema)
191191

192192
private static void ResolveOneOfSchema(OpenApiSchema schema)
193193
{
194-
if (schema.OneOf?.Any() ?? false)
194+
if (schema.OneOf?.FirstOrDefault() is {} newSchema)
195195
{
196-
var newSchema = schema.OneOf.FirstOrDefault();
197196
schema.OneOf = null;
198197
FlattenSchema(schema, newSchema);
199198
}
200199
}
201200

202201
private static void ResolveAnyOfSchema(OpenApiSchema schema)
203202
{
204-
if (schema.AnyOf?.Any() ?? false)
203+
if (schema.AnyOf?.FirstOrDefault() is {} newSchema)
205204
{
206-
var newSchema = schema.AnyOf.FirstOrDefault();
207205
schema.AnyOf = null;
208206
FlattenSchema(schema, newSchema);
209207
}

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.CommandLine.Invocation;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.Extensions.DependencyInjection;
89
using Microsoft.Extensions.Logging;
910
using Microsoft.OpenApi.Hidi.Options;
1011

@@ -24,7 +25,7 @@ public int Invoke(InvocationContext context)
2425
public async Task<int> InvokeAsync(InvocationContext context)
2526
{
2627
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
27-
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetService(typeof(CancellationToken));
28+
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
2829

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.CommandLine.Invocation;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.Extensions.DependencyInjection;
89
using Microsoft.Extensions.Logging;
910
using Microsoft.OpenApi.Hidi.Options;
1011

@@ -24,7 +25,7 @@ public int Invoke(InvocationContext context)
2425
public async Task<int> InvokeAsync(InvocationContext context)
2526
{
2627
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
27-
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetService(typeof(CancellationToken));
28+
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
2829

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

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

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.CommandLine.Invocation;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.Extensions.DependencyInjection;
89
using Microsoft.Extensions.Logging;
910
using Microsoft.OpenApi.Hidi.Options;
1011

@@ -24,7 +25,7 @@ public int Invoke(InvocationContext context)
2425
public async Task<int> InvokeAsync(InvocationContext context)
2526
{
2627
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
27-
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetService(typeof(CancellationToken));
28+
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
2829

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

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

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,7 @@
55
using System.CommandLine.Invocation;
66
using System.Threading;
77
using System.Threading.Tasks;
8+
using Microsoft.Extensions.DependencyInjection;
89
using Microsoft.Extensions.Logging;
910
using Microsoft.OpenApi.Hidi.Options;
1011

@@ -26,11 +27,12 @@ public int Invoke(InvocationContext context)
2627
public async Task<int> InvokeAsync(InvocationContext context)
2728
{
2829
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
29-
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetService(typeof(CancellationToken));
30+
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
3031
using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
3132
var logger = loggerFactory.CreateLogger<ValidateCommandHandler>();
3233
try
3334
{
35+
if (hidiOptions.OpenApi is null) throw new InvalidOperationException("OpenApi file is required");
3436
await OpenApiService.ValidateOpenApiDocument(hidiOptions.OpenApi, logger, cancellationToken);
3537
return 0;
3638
}

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

Lines changed: 10 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,10 @@
33
<PropertyGroup>
44
<OutputType>Exe</OutputType>
55
<TargetFramework>net7.0</TargetFramework>
6-
<LangVersion>9.0</LangVersion>
6+
<LangVersion>latest</LangVersion>
7+
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
78
<PackAsTool>true</PackAsTool>
9+
<Nullable>enable</Nullable>
810
<PackageIconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</PackageIconUrl>
911
<PackageProjectUrl>https://github.com/Microsoft/OpenAPI.NET</PackageProjectUrl>
1012
<PackageLicenseExpression>MIT</PackageLicenseExpression>
@@ -26,6 +28,9 @@
2628
<SignAssembly>true</SignAssembly>
2729
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
2830
<EmbedUntrackedSources>true</EmbedUntrackedSources>
31+
<NoWarn>NU5048</NoWarn>
32+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
33+
<PackageReadmeFile>readme.md</PackageReadmeFile>
2934
</PropertyGroup>
3035

3136
<ItemGroup>
@@ -62,4 +67,8 @@
6267
</ItemGroup>
6368
<!-- End Unit test Internals -->
6469

70+
<ItemGroup>
71+
<None Include="../../readme.md" Pack="true" PackagePath="" />
72+
</ItemGroup>
73+
6574
</Project>

0 commit comments

Comments
 (0)