Skip to content

Commit

Permalink
Merge pull request #1729 from microsoft/mk/update-packages
Browse files Browse the repository at this point in the history
Update packages
  • Loading branch information
MaggieKimani1 authored Jul 16, 2024
2 parents 4afdd15 + a9075aa commit 5c56379
Show file tree
Hide file tree
Showing 36 changed files with 431 additions and 400 deletions.
622 changes: 286 additions & 336 deletions .azure-pipelines/ci-build.yml

Large diffs are not rendered by default.

2 changes: 1 addition & 1 deletion .github/workflows/auto-merge-dependabot.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ jobs:
steps:
- name: Dependabot metadata
id: metadata
uses: dependabot/fetch-metadata@v2.0.0
uses: dependabot/fetch-metadata@v2.2.0
with:
github-token: "${{ secrets.GITHUB_TOKEN }}"

Expand Down
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@v3.1.0
uses: docker/login-action@v3.2.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@v5.3.0
uses: docker/build-push-action@v6.3.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@v5.3.0
uses: docker/build-push-action@v6.3.0
with:
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.getversion.outputs.version }}
17 changes: 3 additions & 14 deletions .github/workflows/sonarcloud.yml
Original file line number Diff line number Diff line change
Expand Up @@ -52,28 +52,17 @@ jobs:
path: ~/.sonar/cache
key: ${{ runner.os }}-sonar
restore-keys: ${{ runner.os }}-sonar
- name: Cache SonarCloud scanner
id: cache-sonar-scanner
uses: actions/cache@v4
with:
path: ./.sonar/scanner
key: ${{ runner.os }}-sonar-scanner
restore-keys: ${{ runner.os }}-sonar-scanner
- name: Install SonarCloud scanner
if: steps.cache-sonar-scanner.outputs.cache-hit != 'true'
shell: pwsh
run: |
New-Item -Path ./.sonar/scanner -ItemType Directory
dotnet tool update dotnet-sonarscanner --tool-path ./.sonar/scanner
run: dotnet tool install dotnet-sonarscanner --create-manifest-if-needed
- name: Build and analyze
env:
GITHUB_TOKEN: ${{ secrets.GITHUB_TOKEN }} # Needed to get PR information, if any
CollectCoverage: true
CoverletOutputFormat: 'opencover' # https://github.com/microsoft/vstest/issues/4014#issuecomment-1307913682
shell: pwsh
run: |
./.sonar/scanner/dotnet-sonarscanner begin /k:"microsoft_OpenAPI.NET" /o:"microsoft" /d:sonar.login="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="test/**/coverage.opencover.xml"
dotnet tool run dotnet-sonarscanner begin /k:"microsoft_OpenAPI.NET" /o:"microsoft" /d:sonar.token="${{ secrets.SONAR_TOKEN }}" /d:sonar.host.url="https://sonarcloud.io" /d:sonar.cs.opencover.reportsPaths="test/**/coverage.opencover.xml"
dotnet workload restore
dotnet build
dotnet test Microsoft.OpenApi.sln --no-build --verbosity normal /p:CollectCoverage=true /p:CoverletOutputFormat=opencover
./.sonar/scanner/dotnet-sonarscanner end /d:sonar.login="${{ secrets.SONAR_TOKEN }}"
dotnet tool run dotnet-sonarscanner end /d:sonar.token="${{ secrets.SONAR_TOKEN }}"
2 changes: 1 addition & 1 deletion .vscode/launch.json
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi/bin/Debug/net8.0/Microsoft.OpenApi.Hidi.dll",
"args": ["plugin",
"-m","C:\\Users\\darrmi\\src\\github\\microsoft\\openapi.net\\test\\Microsoft.OpenApi.Hidi.Tests\\UtilityFiles\\exampleapimanifest.json",
"-m","${workspaceFolder}/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/exampleapimanifest.json",
"--of","./output"],
"cwd": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi",
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
Expand Down
10 changes: 10 additions & 0 deletions CODE_OF_CONDUCT.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
# Microsoft Open Source Code of Conduct

This project has adopted the [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/).

Resources:

- [Microsoft Open Source Code of Conduct](https://opensource.microsoft.com/codeofconduct/)
- [Microsoft Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/)
- Contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with questions or concerns
- Employees can reach out at [aka.ms/opensource/moderation-support](https://aka.ms/opensource/moderation-support)
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -133,4 +133,4 @@ This project has adopted the [Microsoft Open Source Code of Conduct](https://ope
For more information see the [Code of Conduct FAQ](https://opensource.microsoft.com/codeofconduct/faq/) or
contact [opencode@microsoft.com](mailto:opencode@microsoft.com) with any additional questions or comments.

To provide feedback and ask questions you can use Stack Overflow with the [OpenAPI.NET](https://stackoverflow.com/questions/tagged/openapi.net) tag or use the OpenAPI.NET Slack channel which you can join by registering for the HTTP APIs team at http://slack.httpapis.com.
To provide feedback and ask questions you can use Stack Overflow with the [OpenAPI.NET](https://stackoverflow.com/questions/tagged/openapi.net) tag.
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi.Hidi/Handlers/ValidateCommandHandler.cs
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ public async Task<int> InvokeAsync(InvocationContext context)
try
{
if (hidiOptions.OpenApi is null) throw new InvalidOperationException("OpenApi file is required");
await OpenApiService.ValidateOpenApiDocument(hidiOptions.OpenApi, logger, cancellationToken).ConfigureAwait(false);
return 0;
var isValid = await OpenApiService.ValidateOpenApiDocument(hidiOptions.OpenApi, logger, cancellationToken).ConfigureAwait(false);
return isValid is not false ? 0 : -1;
}
#if RELEASE
#pragma warning disable CA1031 // Do not catch general exception types
Expand Down
6 changes: 3 additions & 3 deletions src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
<Nullable>enable</Nullable>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>1.4.1</Version>
<Version>1.4.6</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
Expand All @@ -34,8 +34,8 @@
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="8.0.0" />
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="8.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
<PackageReference Include="Microsoft.OData.Edm" Version="7.20.0" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.6.1" />
<PackageReference Include="Microsoft.OData.Edm" Version="7.21.3" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.6.7" />
<PackageReference Include="Microsoft.OpenApi.ApiManifest" Version="0.5.0-preview" />
<PackageReference Include="System.CommandLine.Hosting" Version="0.4.0-alpha.22272.1" />
</ItemGroup>
Expand Down
11 changes: 9 additions & 2 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -335,7 +335,8 @@ private static MemoryStream ApplyFilterToCsdl(Stream csdlStream, string entitySe
/// <summary>
/// Implementation of the validate command
/// </summary>
public static async Task ValidateOpenApiDocument(
/// <returns><see langword="true"/> when valid, <see langword="false"/> when invalid and <see langword="null"/> when cancelled</returns>
public static async Task<bool?> ValidateOpenApiDocument(
string openApi,
ILogger logger,
CancellationToken cancellationToken = default)
Expand All @@ -345,11 +346,13 @@ public static async Task ValidateOpenApiDocument(
throw new ArgumentNullException(nameof(openApi));
}

ReadResult? result = null;

try
{
using var stream = await GetStream(openApi, logger, cancellationToken).ConfigureAwait(false);

var result = await ParseOpenApi(openApi, false, logger, stream, cancellationToken).ConfigureAwait(false);
result = await ParseOpenApi(openApi, false, logger, stream, cancellationToken).ConfigureAwait(false);

using (logger.BeginScope("Calculating statistics"))
{
Expand All @@ -371,6 +374,10 @@ public static async Task ValidateOpenApiDocument(
{
throw new InvalidOperationException($"Could not validate the document, reason: {ex.Message}", ex);
}

if (result is null) return null;

return result.OpenApiDiagnostic.Errors.Count == 0;
}

private static async Task<ReadResult> ParseOpenApi(string openApiFile, bool inlineExternal, ILogger logger, Stream stream, CancellationToken cancellationToken = default)
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Hidi/readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ This command accepts the following parameters:
hidi transform --openapi files\People.yml --format yaml --output files\People2.yml --version OpenApi3_0 --filterByCollection Graph-Collection-0017059134807617005.postman_collection.json
3. CSDL--->OpenAPI conversion and filtering
hidi transform --input Files/Todo.xml --output Files/Todo-subset.yml --format yaml --version OpenApi3_0 --filterByOperationIds Todos.Todo.UpdateTodo
hidi transform --csdl Files/Todo.xml --output Files/Todo-subset.yml --format yaml --version OpenApi3_0 --filterByOperationIds Todos.Todo.UpdateTodo
4. CSDL Filtering by EntitySets and Singletons
hidi transform --cs dataverse.csdl --csdlFilter "appointments,opportunities" -o appointmentsAndOpportunities.yaml --ll trace
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.6.14</Version>
<Version>1.6.15</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
Expand All @@ -27,7 +27,7 @@
<PackageReference Include="JsonSchema.Net" Version="4.1.5" />
<PackageReference Include="JsonSchema.Net.OpenApi" Version="1.1.0" />
<PackageReference Include="SharpYaml" Version="2.1.1" />
<PackageReference Include="System.Text.Json" Version="7.0.2" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers" Version="0.4.421302" PrivateAssets="all" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="8.0.4" />
<PackageReference Include="Microsoft.Windows.Compatibility" Version="8.0.7" />
</ItemGroup>
<ItemGroup>
<Resource Include="Themes\Metro\HowToApplyTheme.txt" />
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Extensions/OpenApiTypeMapper.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<TargetFramework>netstandard2.0</TargetFramework>
<LangVersion>Latest</LangVersion>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
<Version>1.6.14</Version>
<Version>1.6.15</Version>
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
<SignAssembly>true</SignAssembly>
<!-- https://github.com/dotnet/sourcelink/blob/main/docs/README.md#embeduntrackedsources -->
Expand All @@ -26,7 +26,7 @@
<PackageReference Include="JsonSchema.Net.OpenApi" Version="1.1.0" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="System.Text.Json" Version="7.0.2" />
<PackageReference Include="System.Text.Json" Version="8.0.4" />
</ItemGroup>

<ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,7 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
/// <exception cref="ArgumentOutOfRangeException">When the source element is not an object</exception>
public static OpenApiDeprecationExtension Parse(OpenApiAny source)
{
if (source.Node is not JsonObject rawObject) throw new ArgumentOutOfRangeException(nameof(source));
if (source.Node is not JsonObject rawObject) return null;
var extension = new OpenApiDeprecationExtension();
if (rawObject.TryGetPropertyValue(nameof(RemovalDate).ToFirstCharacterLowerCase(), out var removalDate) && removalDate is JsonNode removalDateValue)
extension.RemovalDate = removalDateValue.GetValue<DateTimeOffset>();
Expand Down
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// ------------------------------------------------------------
// ------------------------------------------------------------
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License (MIT). See LICENSE in the repo root for license information.
// ------------------------------------------------------------
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -65,7 +65,7 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
/// <exception cref="ArgumentOutOfRangeException">When the source element is not an object</exception>
public static OpenApiEnumValuesDescriptionExtension Parse(OpenApiAny source)
{
if (source.Node is not JsonObject rawObject) throw new ArgumentOutOfRangeException(nameof(source));
if (source.Node is not JsonObject rawObject) return null;
var extension = new OpenApiEnumValuesDescriptionExtension();
if (rawObject.TryGetPropertyValue("values", out var values) && values is JsonArray valuesArray)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
/// <exception cref="ArgumentOutOfRangeException">When the source element is not an object</exception>
public static OpenApiPagingExtension Parse(OpenApiAny source)
{
if (source.Node is not JsonObject rawObject) throw new ArgumentOutOfRangeException(nameof(source));
if (source.Node is not JsonObject rawObject) return null;
var extension = new OpenApiPagingExtension();
if (rawObject.TryGetPropertyValue(nameof(NextLinkName).ToFirstCharacterLowerCase(), out var nextLinkName) && nextLinkName is JsonNode nextLinkNameStr)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
/// <returns>The <see cref="OpenApiPrimaryErrorMessageExtension"/>.</returns>
public static OpenApiPrimaryErrorMessageExtension Parse(OpenApiAny source)
{
if (source.Node is not JsonNode rawObject) throw new ArgumentOutOfRangeException(nameof(source));
if (source.Node is not JsonNode rawObject) return null;
return new()
{
IsPrimaryErrorMessage = rawObject.GetValue<bool>()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,7 @@ public bool? IsReserved
/// <returns></returns>
public static OpenApiReservedParameterExtension Parse(OpenApiAny source)
{
if (source.Node is not JsonNode rawBoolean) throw new ArgumentOutOfRangeException(nameof(source));
if (source.Node is not JsonNode rawBoolean) return null;
return new()
{
IsReserved = rawBoolean.GetValue<bool>()
Expand Down
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi/Properties/SRResource.Designer.cs

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi/Properties/SRResource.resx
Original file line number Diff line number Diff line change
Expand Up @@ -139,7 +139,7 @@
<value>Invalid Reference identifier '{0}'.</value>
</data>
<data name="InvalidReferenceType" xml:space="preserve">
<value>Invalid Reference Type.</value>
<value>Invalid Reference Type '{0}'.</value>
</data>
<data name="LocalReferenceRequiresType" xml:space="preserve">
<value>Local reference must have type specified.</value>
Expand Down
5 changes: 3 additions & 2 deletions src/Microsoft.OpenApi/Reader/V3/OpenApiV3Deserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -170,9 +170,10 @@ public static OpenApiAny LoadAny(ParseNode node, OpenApiDocument hostDocument =

private static IOpenApiExtension LoadExtension(string name, ParseNode node)
{
if (node.Context.ExtensionParsers.TryGetValue(name, out var parser))
if (node.Context.ExtensionParsers.TryGetValue(name, out var parser) && parser(
node.CreateAny(), OpenApiSpecVersion.OpenApi3_0) is { } result)
{
return parser(node.CreateAny(), OpenApiSpecVersion.OpenApi3_0);
return result;
}
else
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@

<ItemGroup>
<PackageReference Include="coverlet.msbuild" Version="6.0.2" PrivateAssets="all" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.9.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.10.0" />
<PackageReference Include="Moq" Version="4.20.70" />
<PackageReference Include="xunit" Version="2.7.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.5.8" PrivateAssets="all" />
<PackageReference Include="xunit" Version="2.9.0" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.8.2" PrivateAssets="all" />
<PackageReference Include="coverlet.collector" Version="6.0.2" PrivateAssets="all" />
</ItemGroup>

Expand Down
25 changes: 25 additions & 0 deletions test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,6 +151,31 @@ public async Task ValidateCommandProcessesOpenApi()
Assert.True(true);
}

[Fact]
public async Task ValidFileReturnsTrue()
{
var isValid = await OpenApiService.ValidateOpenApiDocument(Path.Combine("UtilityFiles", "SampleOpenApi.yml"), _logger);

Assert.True(isValid);
}

[Fact]
public async Task InvalidFileReturnsFalse()
{
var isValid = await OpenApiService.ValidateOpenApiDocument(Path.Combine("UtilityFiles", "InvalidSampleOpenApi.yml"), _logger);

Assert.False(isValid);
}

[Fact]
public async Task CancellingValidationReturnsNull()
{
using var cts = new CancellationTokenSource();
await cts.CancelAsync();
var isValid = await OpenApiService.ValidateOpenApiDocument(Path.Combine("UtilityFiles", "SampleOpenApi.yml"), _logger, cts.Token);

Assert.Null(isValid);
}

[Fact]
public async Task TransformCommandConvertsOpenApi()
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
openapi: 3.0.0
info:
title: Sample OpenApi
version: 1.0.0
paths:
/api/editresource:
get:
operationId: api.ListEditresource
patch:
operationId: api.UpdateEditresource
responses:
'200':
description: OK
/api/viewresource:
get:
operationId: api.ListViewresource
responses:
'200':
description: OK
Loading

0 comments on commit 5c56379

Please sign in to comment.