Skip to content

Commit

Permalink
Merge pull request #1361 from microsoft/vnext
Browse files Browse the repository at this point in the history
Master refresh
  • Loading branch information
MaggieKimani1 authored Sep 26, 2023
2 parents acd7652 + 0ec11c1 commit 11cfc7d
Show file tree
Hide file tree
Showing 41 changed files with 363 additions and 207 deletions.
2 changes: 1 addition & 1 deletion .azure-pipelines/ci-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -216,7 +216,7 @@ stages:
displayName: publish Hidi as executable
inputs:
command: 'publish'
arguments: -c Release --runtime win-x64 /p:PublishSingleFile=true --self-contained --output $(Build.ArtifactStagingDirectory)/Microsoft.OpenApi.Hidi-v$(hidiversion) -p:PublishTrimmed=true
arguments: -c Release --runtime win-x64 /p:PublishSingleFile=true /p:PackAsTool=false --self-contained --output $(Build.ArtifactStagingDirectory)/Microsoft.OpenApi.Hidi-v$(hidiversion)
projects: 'src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj'
publishWebProjects: False
zipAfterPublish: false
Expand Down
32 changes: 32 additions & 0 deletions .github/workflows/auto-merge-dependabot.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
name: Auto-merge dependabot updates

on:
pull_request:
branches: [ main ]

permissions:
pull-requests: write
contents: write

jobs:

dependabot-merge:

runs-on: ubuntu-latest

if: ${{ github.actor == 'dependabot[bot]' }}

steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/[email protected]
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

- name: Enable auto-merge for Dependabot PRs
# Only if version bump is not a major version change
if: ${{steps.metadata.outputs.update-type != 'version-update:semver-major'}}
run: gh pr merge --auto --merge "$PR_URL"
env:
PR_URL: ${{github.event.pull_request.html_url}}
GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}}
6 changes: 3 additions & 3 deletions .github/workflows/docker.yml
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ jobs:
- name: Check out the repo
uses: actions/checkout@v4
- name: Login to GitHub package feed
uses: docker/login-action@v2.2.0
uses: docker/login-action@v3.0.0
with:
username: ${{ secrets.ACR_USERNAME }}
password: ${{ secrets.ACR_PASSWORD }}
Expand All @@ -30,13 +30,13 @@ jobs:
id: getversion
- name: Push to GitHub Packages - Nightly
if: ${{ github.ref == 'refs/heads/vnext' }}
uses: docker/build-push-action@v4.1.1
uses: docker/build-push-action@v5.0.0
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly
- name: Push to GitHub Packages - Release
if: ${{ github.ref == 'refs/heads/master' }}
uses: docker/build-push-action@v4.1.1
uses: docker/build-push-action@v5.0.0
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.getversion.outputs.version }}
6 changes: 5 additions & 1 deletion .vscode/settings.json
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,9 @@
"activityBar.background": "#03323C",
"titleBar.activeBackground": "#054754",
"titleBar.activeForeground": "#F0FCFE"
}
},
"cSpell.words": [
"csdl",
"Hidi"
]
}
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ var document = new OpenApiDocument
};
```

Reading and writing a OpenAPI description
Reading and writing an OpenAPI description

```C#
var httpClient = new HttpClient
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,13 @@ internal static class OpenApiExtensibleExtensions
/// <param name="extensions">A dictionary of <see cref="IOpenApiExtension"/>.</param>
/// <param name="extensionKey">The key corresponding to the <see cref="IOpenApiExtension"/>.</param>
/// <returns>A <see cref="string"/> value matching the provided extensionKey. Return null when extensionKey is not found. </returns>
public static string GetExtension(this IDictionary<string, IOpenApiExtension> extensions, string extensionKey)
internal static string GetExtension(this IDictionary<string, IOpenApiExtension> extensions, string extensionKey)
{
if (extensions.TryGetValue(extensionKey, out var value) && value is OpenApiString castValue)
{
return castValue.Value;
}
return default;
return string.Empty;
}
}
}
9 changes: 6 additions & 3 deletions src/Microsoft.OpenApi.Hidi/Extensions/StringExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ internal static class StringExtensions
/// <summary>
/// Checks if the specified searchValue is equal to the target string based on the specified <see cref="StringComparison"/>.
/// </summary>
/// <param name="target">The target string to commpare to.</param>
/// <param name="target">The target string to compare to.</param>
/// <param name="searchValue">The search string to seek.</param>
/// <param name="comparison">The <see cref="StringComparison"/> to use. This defaults to <see cref="StringComparison.OrdinalIgnoreCase"/>.</param>
/// <returns>true if the searchValue parameter occurs within this string; otherwise, false.</returns>
public static bool IsEquals(this string target, string searchValue, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
public static bool IsEquals(this string? target, string? searchValue, StringComparison comparison = StringComparison.OrdinalIgnoreCase)
{
if (string.IsNullOrWhiteSpace(target) || string.IsNullOrWhiteSpace(searchValue))
if (string.IsNullOrWhiteSpace(target) && string.IsNullOrWhiteSpace(searchValue))
{
return true;
} else if (string.IsNullOrWhiteSpace(target))
{
return false;
}
Expand Down
10 changes: 4 additions & 6 deletions src/Microsoft.OpenApi.Hidi/Formatters/PowerShellFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public override void Visit(OpenApiOperation operation)
private static string ResolveVerbSegmentInOpertationId(string operationId)
{
var charPos = operationId.LastIndexOf('.', operationId.Length - 1);
if (operationId.Contains('_') || charPos < 0)
if (operationId.Contains('_', StringComparison.OrdinalIgnoreCase) || charPos < 0)
return operationId;
var newOperationId = new StringBuilder(operationId);
newOperationId[charPos] = '_';
Expand All @@ -99,7 +99,7 @@ private static string ResolveVerbSegmentInOpertationId(string operationId)
private static string ResolvePutOperationId(string operationId)
{
return operationId.Contains(DefaultPutPrefix, StringComparison.OrdinalIgnoreCase) ?
operationId.Replace(DefaultPutPrefix, PowerShellPutPrefix) : operationId;
operationId.Replace(DefaultPutPrefix, PowerShellPutPrefix, StringComparison.Ordinal) : operationId;
}

private static string ResolveByRefOperationId(string operationId)
Expand Down Expand Up @@ -191,19 +191,17 @@ private void AddAdditionalPropertiesToSchema(OpenApiSchema schema)

private static void ResolveOneOfSchema(OpenApiSchema schema)
{
if (schema.OneOf?.Any() ?? false)
if (schema.OneOf?.FirstOrDefault() is {} newSchema)
{
var newSchema = schema.OneOf.FirstOrDefault();
schema.OneOf = null;
FlattenSchema(schema, newSchema);
}
}

private static void ResolveAnyOfSchema(OpenApiSchema schema)
{
if (schema.AnyOf?.Any() ?? false)
if (schema.AnyOf?.FirstOrDefault() is {} newSchema)
{
var newSchema = schema.AnyOf.FirstOrDefault();
schema.AnyOf = null;
FlattenSchema(schema, newSchema);
}
Expand Down
13 changes: 11 additions & 2 deletions src/Microsoft.OpenApi.Hidi/Handlers/PluginCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.CommandLine.Invocation;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Hidi.Options;

Expand All @@ -24,26 +25,34 @@ public int Invoke(InvocationContext context)
public async Task<int> InvokeAsync(InvocationContext context)
{
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetService(typeof(CancellationToken));
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));

using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
var logger = loggerFactory.CreateLogger<PluginCommandHandler>();
try
{
await OpenApiService.PluginManifest(hidiOptions, logger, cancellationToken);
await OpenApiService.PluginManifest(hidiOptions, logger, cancellationToken).ConfigureAwait(false);

return 0;
}
#if RELEASE
#pragma warning disable CA1031 // Do not catch general exception types
#endif
catch (Exception ex)
{
#if DEBUG
logger.LogCritical(ex, "Command failed");
throw; // so debug tools go straight to the source of the exception when attached
#else
#pragma warning disable CA2254
logger.LogCritical(ex.Message);
#pragma warning restore CA2254
return 1;
#endif
}
#if RELEASE
#pragma warning restore CA1031 // Do not catch general exception types
#endif
}
}
}
13 changes: 11 additions & 2 deletions src/Microsoft.OpenApi.Hidi/Handlers/ShowCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.CommandLine.Invocation;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Hidi.Options;

Expand All @@ -24,26 +25,34 @@ public int Invoke(InvocationContext context)
public async Task<int> InvokeAsync(InvocationContext context)
{
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetService(typeof(CancellationToken));
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));

using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
var logger = loggerFactory.CreateLogger<ShowCommandHandler>();
try
{
await OpenApiService.ShowOpenApiDocument(hidiOptions, logger, cancellationToken);
await OpenApiService.ShowOpenApiDocument(hidiOptions, logger, cancellationToken).ConfigureAwait(false);

return 0;
}
#if RELEASE
#pragma warning disable CA1031 // Do not catch general exception types
#endif
catch (Exception ex)
{
#if DEBUG
logger.LogCritical(ex, "Command failed");
throw; // so debug tools go straight to the source of the exception when attached
#else
#pragma warning disable CA2254
logger.LogCritical( ex.Message);
#pragma warning restore CA2254
return 1;
#endif
}
#if RELEASE
#pragma warning restore CA1031 // Do not catch general exception types
#endif
}
}
}
13 changes: 11 additions & 2 deletions src/Microsoft.OpenApi.Hidi/Handlers/TransformCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.CommandLine.Invocation;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Hidi.Options;

Expand All @@ -24,26 +25,34 @@ public int Invoke(InvocationContext context)
public async Task<int> InvokeAsync(InvocationContext context)
{
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetService(typeof(CancellationToken));
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));

using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
var logger = loggerFactory.CreateLogger<TransformCommandHandler>();
try
{
await OpenApiService.TransformOpenApiDocument(hidiOptions, logger, cancellationToken);
await OpenApiService.TransformOpenApiDocument(hidiOptions, logger, cancellationToken).ConfigureAwait(false);

return 0;
}
#if RELEASE
#pragma warning disable CA1031 // Do not catch general exception types
#endif
catch (Exception ex)
{
#if DEBUG
logger.LogCritical(ex, "Command failed");
throw; // so debug tools go straight to the source of the exception when attached
#else
#pragma warning disable CA2254
logger.LogCritical( ex.Message);
#pragma warning restore CA2254
return 1;
#endif
}
#if RELEASE
#pragma warning restore CA1031 // Do not catch general exception types
#endif
}
}
}
16 changes: 13 additions & 3 deletions src/Microsoft.OpenApi.Hidi/Handlers/ValidateCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
using System.CommandLine.Invocation;
using System.Threading;
using System.Threading.Tasks;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.Extensions.Logging;
using Microsoft.OpenApi.Hidi.Options;

Expand All @@ -26,24 +27,33 @@ public int Invoke(InvocationContext context)
public async Task<int> InvokeAsync(InvocationContext context)
{
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetService(typeof(CancellationToken));
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetRequiredService(typeof(CancellationToken));
using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
var logger = loggerFactory.CreateLogger<ValidateCommandHandler>();
try
{
await OpenApiService.ValidateOpenApiDocument(hidiOptions.OpenApi, logger, cancellationToken);
if (hidiOptions.OpenApi is null) throw new InvalidOperationException("OpenApi file is required");
await OpenApiService.ValidateOpenApiDocument(hidiOptions.OpenApi, logger, cancellationToken).ConfigureAwait(false);
return 0;
}
#if RELEASE
#pragma warning disable CA1031 // Do not catch general exception types
#endif
catch (Exception ex)
{
#if DEBUG
logger.LogCritical(ex, "Command failed");
throw; // so debug tools go straight to the source of the exception when attached
#else
logger.LogCritical( ex.Message);
#pragma warning disable CA2254
logger.LogCritical(ex.Message);
#pragma warning restore CA2254
return 1;
#endif
}
#if RELEASE
#pragma warning restore CA1031 // Do not catch general exception types
#endif
}
}
}
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Hidi/Logger.cs
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

namespace Microsoft.OpenApi.Hidi
{
public class Logger
public static class Logger
{
public static ILoggerFactory ConfigureLogger(LogLevel logLevel)
{
Expand Down
14 changes: 12 additions & 2 deletions src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,10 @@
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net7.0</TargetFramework>
<LangVersion>9.0</LangVersion>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<PackAsTool>true</PackAsTool>
<Nullable>enable</Nullable>
<PackageIconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</PackageIconUrl>
<PackageProjectUrl>https://github.com/Microsoft/OpenAPI.NET</PackageProjectUrl>
<PackageLicenseExpression>MIT</PackageLicenseExpression>
Expand All @@ -15,7 +17,7 @@
<PackageId>Microsoft.OpenApi.Hidi</PackageId>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>1.2.9</Version>
<Version>1.3.0</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand All @@ -26,6 +28,10 @@
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
<EmbedUntrackedSources>true</EmbedUntrackedSources>
<NoWarn>$(NoWarn);NU5048;NU5104;CA1848;</NoWarn>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
<PackageReadmeFile>readme.md</PackageReadmeFile>
<AnalysisMode>All</AnalysisMode>
</PropertyGroup>

<ItemGroup>
Expand Down Expand Up @@ -62,4 +68,8 @@
</ItemGroup>
<!-- End Unit test Internals -->

<ItemGroup>
<None Include="./readme.md" Pack="true" PackagePath="" />
</ItemGroup>

</Project>
Loading

0 comments on commit 11cfc7d

Please sign in to comment.