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

chore: migrates to OpenAPI.net 2.0 feat: adds support for OAS 3.1 #124

Merged
merged 3 commits into from
Jan 2, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
9 changes: 6 additions & 3 deletions src/lib/Helpers/ParsingHelpers.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Reader;
using Microsoft.OpenApi.Readers;
using System.Diagnostics;
using System.Text.Json;
Expand Down Expand Up @@ -150,12 +152,13 @@ internal static async Task<ReadResult> ParseOpenApiAsync(Uri openApiFileUri, boo

internal static async Task<ReadResult> ParseOpenApiAsync(Stream stream, Uri openApiFileUri, bool inlineExternal, CancellationToken cancellationToken)
{
ReadResult result = await new OpenApiStreamReader(new OpenApiReaderSettings
OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yaml, new OpenApiYamlReader());
OpenApiReaderRegistry.RegisterReader(OpenApiConstants.Yml, new OpenApiYamlReader());
ReadResult result = await OpenApiDocument.LoadAsync(stream, settings: new OpenApiReaderSettings
{
LoadExternalRefs = inlineExternal,
BaseUrl = openApiFileUri
}
).ReadAsync(stream, cancellationToken).ConfigureAwait(false);
}, cancellationToken: cancellationToken).ConfigureAwait(false);

return result;
}
Expand Down
2 changes: 1 addition & 1 deletion src/lib/TypeExtensions/ApiManifestDocumentExtensions.cs
Original file line number Diff line number Diff line change
Expand Up @@ -35,7 +35,7 @@ public static async Task<OpenAIPluginManifest> ToOpenAIPluginManifestAsync(this
var result = await ParsingHelpers.ParseOpenApiAsync(new Uri(apiDependency!.ApiDescriptionUrl), false, cancellationToken).ConfigureAwait(false);
if (string.IsNullOrWhiteSpace(openApiPath))
openApiPath = apiDependency.ApiDescriptionUrl;
return apiManifestDocument.ToOpenAIPluginManifest(result.OpenApiDocument, logoUrl, legalInfoUrl, openApiPath!);
return apiManifestDocument.ToOpenAIPluginManifest(result.Document, logoUrl, legalInfoUrl, openApiPath!);
}
}

Expand Down
10 changes: 3 additions & 7 deletions src/lib/apimanifest.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
<PackageId>Microsoft.OpenApi.ApiManifest</PackageId>
<VersionPrefix>0.5.6</VersionPrefix>
<VersionPrefix>0.6.0</VersionPrefix>
<VersionSuffix>preview</VersionSuffix>
<PackageIconUrl>http://go.microsoft.com/fwlink/?LinkID=288890</PackageIconUrl>
<PackageProjectUrl>https://github.com/Microsoft/OpenApi.ApiManifest</PackageProjectUrl>
Expand All @@ -30,16 +30,12 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.OpenApi.Readers" Version="1.6.23" />
<PackageReference Include="Microsoft.OpenApi.Readers" Version="2.0.0-preview4" />
<PackageReference Include="Microsoft.VisualStudio.Threading.Analyzers" Version="17.12.19">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<!-- The target application is the one which will resolve the correct version.
When the version range is updated to > 8.0.4 in the future, remove the GHSA suppression -->
<PackageReference Include="System.Text.Json" Version="[6.0,)" />
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-hh2w-p6rv-4g7w" />
<NuGetAuditSuppress Include="https://github.com/advisories/GHSA-8g4q-xg66-9fp4" />
<PackageReference Include="System.Text.Json" Version="[8.0.5,)" />
</ItemGroup>

</Project>
4 changes: 2 additions & 2 deletions tests/ApiManifest.Tests/Helpers/ParsingHelpersTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -119,8 +119,8 @@ public async Task ParseOpenApiAsync()
var testOpenApiFilePath = Path.Combine(".", "TestFiles", "testOpenApi.yaml");
using var stream = File.OpenRead(testOpenApiFilePath);
var results = await ParsingHelpers.ParseOpenApiAsync(stream, new Uri("https://contoso.com/openapi.yaml"), false, CancellationToken.None);
Assert.Empty(results.OpenApiDiagnostic.Errors);
Assert.NotNull(results.OpenApiDocument);
Assert.Empty(results.Diagnostic.Errors);
Assert.NotNull(results.Document);
}

[Fact]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,9 @@ public void ToApiManifestWithValidDocumentReturnsApiManifestDocument()
Assert.Equal("GraphAPI", apiManifest.ApiDependencies.First().Key);
Assert.Equal(apiDescriptionUrl, apiManifest.ApiDependencies.First().Value.ApiDescriptionUrl);
Assert.Equal(exampleDocument.Info.Version, apiManifest.ApiDependencies.First().Value.ApiDescriptionVersion);
Assert.Equal(exampleDocument.Servers.First().Url, apiManifest.ApiDependencies.First().Value.ApiDeploymentBaseUrl);
Assert.NotNull(exampleDocument.Servers);
Assert.NotEmpty(exampleDocument.Servers);
Assert.Equal(exampleDocument.Servers[0].Url, apiManifest.ApiDependencies.First().Value.ApiDeploymentBaseUrl);
Assert.Equal(exampleDocument.Paths.Count, apiManifest.ApiDependencies.First().Value.Requests.Count);
}

Expand All @@ -87,7 +89,9 @@ public void ToApiManifestWithValidDocumentAndApiDependencyNameReturnsApiManifest
Assert.Equal(apiDependencyName, apiManifest.ApiDependencies.First().Key);
Assert.Equal(apiDescriptionUrl, apiManifest.ApiDependencies.First().Value.ApiDescriptionUrl);
Assert.Equal(exampleDocument.Info.Version, apiManifest.ApiDependencies.First().Value.ApiDescriptionVersion);
Assert.Equal(exampleDocument.Servers.First().Url, apiManifest.ApiDependencies.First().Value.ApiDeploymentBaseUrl);
Assert.NotNull(exampleDocument.Servers);
Assert.NotEmpty(exampleDocument.Servers);
Assert.Equal(exampleDocument.Servers[0].Url, apiManifest.ApiDependencies.First().Value.ApiDeploymentBaseUrl);
Assert.Equal(exampleDocument.Paths.Count, apiManifest.ApiDependencies.First().Value.Requests.Count);
}

Expand Down
Loading