Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Master refresh #1361

Merged
merged 42 commits into from
Sep 26, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
42 commits
Select commit Hold shift + click to select a range
03aed8a
Bump docker/build-push-action from 4.1.1 to 4.2.1
dependabot[bot] Sep 11, 2023
9284836
Bump Verify.Xunit from 21.0.0 to 21.1.1
dependabot[bot] Sep 11, 2023
66a7ea2
Merge pull request #1337 from microsoft/dependabot/github_actions/doc…
baywet Sep 11, 2023
6442d76
Merge pull request #1338 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Sep 11, 2023
0e67b93
Bump Microsoft.Windows.Compatibility from 7.0.4 to 7.0.5
dependabot[bot] Sep 12, 2023
9f07c80
Merge pull request #1339 from microsoft/dependabot/nuget/Microsoft.Wi…
baywet Sep 12, 2023
b1d174a
Bump Verify.Xunit from 21.1.1 to 21.1.3
dependabot[bot] Sep 13, 2023
2984d30
Merge pull request #1341 from microsoft/dependabot/nuget/Verify.Xunit…
andrueastman Sep 14, 2023
6814542
Fixes null reference exception. Closes #1342
waldekmastykarz Sep 14, 2023
b6cf619
Merge pull request #1343 from waldekmastykarz/fix-filter-postman
baywet Sep 14, 2023
ee526e7
- enables NRT for main hidi project
baywet Sep 14, 2023
104f5f5
- enables all mode analysis
baywet Sep 14, 2023
c099ebe
- fixes hidi release build
baywet Sep 15, 2023
fa032dd
- removes publish trimmed since it'd break functionality
baywet Sep 18, 2023
4c558a8
Bump xunit.runner.visualstudio from 2.5.0 to 2.5.1
dependabot[bot] Sep 18, 2023
564ed76
Merge pull request #1345 from microsoft/dependabot/nuget/xunit.runner…
baywet Sep 18, 2023
da91427
Bump xunit from 2.5.0 to 2.5.1
dependabot[bot] Sep 18, 2023
51323b8
Merge pull request #1346 from microsoft/dependabot/nuget/xunit-2.5.1
baywet Sep 18, 2023
e4acf09
Bump docker/build-push-action from 4.2.1 to 5.0.0
dependabot[bot] Sep 18, 2023
adbbe34
Bump docker/login-action from 2.2.0 to 3.0.0
dependabot[bot] Sep 18, 2023
6933ada
Merge pull request #1348 from microsoft/dependabot/github_actions/doc…
andrueastman Sep 19, 2023
a82b00f
Merge pull request #1344 from microsoft/feature/NRT
baywet Sep 19, 2023
05bfddb
Merge pull request #1347 from microsoft/dependabot/github_actions/doc…
andrueastman Sep 19, 2023
cca1bb9
- fixes readme path to the correct hidi readme
baywet Sep 19, 2023
b1e0ab2
Merge pull request #1349 from microsoft/butfix/readme-file-path
baywet Sep 19, 2023
5c32301
- adds auto merge dependabot workflow
baywet Sep 19, 2023
65b7e7e
- fixes an issue where executable release would fail because of warn …
baywet Sep 19, 2023
be22996
Merge pull request #1351 from microsoft/bugfix/publish-as-exe
baywet Sep 19, 2023
843c107
Merge pull request #1350 from microsoft/feature/auto-merge
baywet Sep 19, 2023
e07a980
Bump Verify.Xunit from 21.1.3 to 21.1.4
dependabot[bot] Sep 19, 2023
78f53c2
Merge pull request #1354 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Sep 19, 2023
0bb8a93
Bump Verify.Xunit from 21.1.4 to 21.1.5
dependabot[bot] Sep 21, 2023
ac2a8d1
Merge pull request #1356 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Sep 21, 2023
33ff054
Bump Verify.Xunit from 21.1.5 to 21.2.0
dependabot[bot] Sep 25, 2023
ad1460b
Merge pull request #1358 from microsoft/dependabot/nuget/Verify.Xunit…
baywet Sep 25, 2023
73c11c5
Add a DefaultContentType setting to OpenApiReaderSettings
MaggieKimani1 Sep 26, 2023
0720231
Use the setting passed as the default content type if global and loca…
MaggieKimani1 Sep 26, 2023
f359565
Add test to validate
MaggieKimani1 Sep 26, 2023
f80f958
Merge pull request #1359 from microsoft/mk/add-default-content-type-s…
MaggieKimani1 Sep 26, 2023
3d6c85e
Bump lib versions
MaggieKimani1 Sep 26, 2023
b254402
Fix grammatical error in ReadMe
MaggieKimani1 Sep 26, 2023
0ec11c1
Merge pull request #1360 from microsoft/mk/bump-versions
MaggieKimani1 Sep 26, 2023
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/fetch-metadata@v1.6.0
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