Skip to content

Commit 11cfc7d

Browse files
Merge pull request #1361 from microsoft/vnext
Master refresh
2 parents acd7652 + 0ec11c1 commit 11cfc7d

Some content is hidden

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

41 files changed

+363
-207
lines changed

.azure-pipelines/ci-build.yml

+1-1
Original file line numberDiff line numberDiff line change
@@ -216,7 +216,7 @@ stages:
216216
displayName: publish Hidi as executable
217217
inputs:
218218
command: 'publish'
219-
arguments: -c Release --runtime win-x64 /p:PublishSingleFile=true --self-contained --output $(Build.ArtifactStagingDirectory)/Microsoft.OpenApi.Hidi-v$(hidiversion) -p:PublishTrimmed=true
219+
arguments: -c Release --runtime win-x64 /p:PublishSingleFile=true /p:PackAsTool=false --self-contained --output $(Build.ArtifactStagingDirectory)/Microsoft.OpenApi.Hidi-v$(hidiversion)
220220
projects: 'src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj'
221221
publishWebProjects: False
222222
zipAfterPublish: false
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,32 @@
1+
name: Auto-merge dependabot updates
2+
3+
on:
4+
pull_request:
5+
branches: [ main ]
6+
7+
permissions:
8+
pull-requests: write
9+
contents: write
10+
11+
jobs:
12+
13+
dependabot-merge:
14+
15+
runs-on: ubuntu-latest
16+
17+
if: ${{ github.actor == 'dependabot[bot]' }}
18+
19+
steps:
20+
- name: Dependabot metadata
21+
id: metadata
22+
uses: dependabot/[email protected]
23+
with:
24+
github-token: "${{ secrets.GITHUB_TOKEN }}"
25+
26+
- name: Enable auto-merge for Dependabot PRs
27+
# Only if version bump is not a major version change
28+
if: ${{steps.metadata.outputs.update-type != 'version-update:semver-major'}}
29+
run: gh pr merge --auto --merge "$PR_URL"
30+
env:
31+
PR_URL: ${{github.event.pull_request.html_url}}
32+
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}

.github/workflows/docker.yml

+3-3
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ jobs:
1717
- name: Check out the repo
1818
uses: actions/checkout@v4
1919
- name: Login to GitHub package feed
20-
uses: docker/login-action@v2.2.0
20+
uses: docker/login-action@v3.0.0
2121
with:
2222
username: ${{ secrets.ACR_USERNAME }}
2323
password: ${{ secrets.ACR_PASSWORD }}
@@ -30,13 +30,13 @@ jobs:
3030
id: getversion
3131
- name: Push to GitHub Packages - Nightly
3232
if: ${{ github.ref == 'refs/heads/vnext' }}
33-
uses: docker/build-push-action@v4.1.1
33+
uses: docker/build-push-action@v5.0.0
3434
with:
3535
push: true
3636
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly
3737
- name: Push to GitHub Packages - Release
3838
if: ${{ github.ref == 'refs/heads/master' }}
39-
uses: docker/build-push-action@v4.1.1
39+
uses: docker/build-push-action@v5.0.0
4040
with:
4141
push: true
4242
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.getversion.outputs.version }}

.vscode/settings.json

+5-1
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,9 @@
33
"activityBar.background": "#03323C",
44
"titleBar.activeBackground": "#054754",
55
"titleBar.activeForeground": "#F0FCFE"
6-
}
6+
},
7+
"cSpell.words": [
8+
"csdl",
9+
"Hidi"
10+
]
711
}

README.md

+1-1
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ var document = new OpenApiDocument
7373
};
7474
```
7575

76-
Reading and writing a OpenAPI description
76+
Reading and writing an OpenAPI description
7777

7878
```C#
7979
var httpClient = new HttpClient

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

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

+6-3
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

+4-6
Original file line numberDiff line numberDiff line change
@@ -88,7 +88,7 @@ public override void Visit(OpenApiOperation operation)
8888
private static string ResolveVerbSegmentInOpertationId(string operationId)
8989
{
9090
var charPos = operationId.LastIndexOf('.', operationId.Length - 1);
91-
if (operationId.Contains('_') || charPos < 0)
91+
if (operationId.Contains('_', StringComparison.OrdinalIgnoreCase) || charPos < 0)
9292
return operationId;
9393
var newOperationId = new StringBuilder(operationId);
9494
newOperationId[charPos] = '_';
@@ -99,7 +99,7 @@ private static string ResolveVerbSegmentInOpertationId(string operationId)
9999
private static string ResolvePutOperationId(string operationId)
100100
{
101101
return operationId.Contains(DefaultPutPrefix, StringComparison.OrdinalIgnoreCase) ?
102-
operationId.Replace(DefaultPutPrefix, PowerShellPutPrefix) : operationId;
102+
operationId.Replace(DefaultPutPrefix, PowerShellPutPrefix, StringComparison.Ordinal) : operationId;
103103
}
104104

105105
private static string ResolveByRefOperationId(string operationId)
@@ -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

+11-2
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,26 +25,34 @@ 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>();
3132
try
3233
{
33-
await OpenApiService.PluginManifest(hidiOptions, logger, cancellationToken);
34+
await OpenApiService.PluginManifest(hidiOptions, logger, cancellationToken).ConfigureAwait(false);
3435

3536
return 0;
3637
}
38+
#if RELEASE
39+
#pragma warning disable CA1031 // Do not catch general exception types
40+
#endif
3741
catch (Exception ex)
3842
{
3943
#if DEBUG
4044
logger.LogCritical(ex, "Command failed");
4145
throw; // so debug tools go straight to the source of the exception when attached
4246
#else
47+
#pragma warning disable CA2254
4348
logger.LogCritical(ex.Message);
49+
#pragma warning restore CA2254
4450
return 1;
4551
#endif
4652
}
53+
#if RELEASE
54+
#pragma warning restore CA1031 // Do not catch general exception types
55+
#endif
4756
}
4857
}
4958
}

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

+11-2
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,26 +25,34 @@ 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>();
3132
try
3233
{
33-
await OpenApiService.ShowOpenApiDocument(hidiOptions, logger, cancellationToken);
34+
await OpenApiService.ShowOpenApiDocument(hidiOptions, logger, cancellationToken).ConfigureAwait(false);
3435

3536
return 0;
3637
}
38+
#if RELEASE
39+
#pragma warning disable CA1031 // Do not catch general exception types
40+
#endif
3741
catch (Exception ex)
3842
{
3943
#if DEBUG
4044
logger.LogCritical(ex, "Command failed");
4145
throw; // so debug tools go straight to the source of the exception when attached
4246
#else
47+
#pragma warning disable CA2254
4348
logger.LogCritical( ex.Message);
49+
#pragma warning restore CA2254
4450
return 1;
4551
#endif
4652
}
53+
#if RELEASE
54+
#pragma warning restore CA1031 // Do not catch general exception types
55+
#endif
4756
}
4857
}
4958
}

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

+11-2
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,26 +25,34 @@ 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>();
3132
try
3233
{
33-
await OpenApiService.TransformOpenApiDocument(hidiOptions, logger, cancellationToken);
34+
await OpenApiService.TransformOpenApiDocument(hidiOptions, logger, cancellationToken).ConfigureAwait(false);
3435

3536
return 0;
3637
}
38+
#if RELEASE
39+
#pragma warning disable CA1031 // Do not catch general exception types
40+
#endif
3741
catch (Exception ex)
3842
{
3943
#if DEBUG
4044
logger.LogCritical(ex, "Command failed");
4145
throw; // so debug tools go straight to the source of the exception when attached
4246
#else
47+
#pragma warning disable CA2254
4348
logger.LogCritical( ex.Message);
49+
#pragma warning restore CA2254
4450
return 1;
4551
#endif
4652
}
53+
#if RELEASE
54+
#pragma warning restore CA1031 // Do not catch general exception types
55+
#endif
4756
}
4857
}
4958
}

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

+13-3
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,24 +27,33 @@ 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
{
34-
await OpenApiService.ValidateOpenApiDocument(hidiOptions.OpenApi, logger, cancellationToken);
35+
if (hidiOptions.OpenApi is null) throw new InvalidOperationException("OpenApi file is required");
36+
await OpenApiService.ValidateOpenApiDocument(hidiOptions.OpenApi, logger, cancellationToken).ConfigureAwait(false);
3537
return 0;
3638
}
39+
#if RELEASE
40+
#pragma warning disable CA1031 // Do not catch general exception types
41+
#endif
3742
catch (Exception ex)
3843
{
3944
#if DEBUG
4045
logger.LogCritical(ex, "Command failed");
4146
throw; // so debug tools go straight to the source of the exception when attached
4247
#else
43-
logger.LogCritical( ex.Message);
48+
#pragma warning disable CA2254
49+
logger.LogCritical(ex.Message);
50+
#pragma warning restore CA2254
4451
return 1;
4552
#endif
4653
}
54+
#if RELEASE
55+
#pragma warning restore CA1031 // Do not catch general exception types
56+
#endif
4757
}
4858
}
4959
}

src/Microsoft.OpenApi.Hidi/Logger.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
namespace Microsoft.OpenApi.Hidi
77
{
8-
public class Logger
8+
public static class Logger
99
{
1010
public static ILoggerFactory ConfigureLogger(LogLevel logLevel)
1111
{

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

+12-2
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>
@@ -15,7 +17,7 @@
1517
<PackageId>Microsoft.OpenApi.Hidi</PackageId>
1618
<ToolCommandName>hidi</ToolCommandName>
1719
<PackageOutputPath>./../../artifacts</PackageOutputPath>
18-
<Version>1.2.9</Version>
20+
<Version>1.3.0</Version>
1921
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
2022
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
2123
<PackageTags>OpenAPI .NET</PackageTags>
@@ -26,6 +28,10 @@
2628
<SignAssembly>true</SignAssembly>
2729
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
2830
<EmbedUntrackedSources>true</EmbedUntrackedSources>
31+
<NoWarn>$(NoWarn);NU5048;NU5104;CA1848;</NoWarn>
32+
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
33+
<PackageReadmeFile>readme.md</PackageReadmeFile>
34+
<AnalysisMode>All</AnalysisMode>
2935
</PropertyGroup>
3036

3137
<ItemGroup>
@@ -62,4 +68,8 @@
6268
</ItemGroup>
6369
<!-- End Unit test Internals -->
6470

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

0 commit comments

Comments
 (0)