diff --git a/src/lib/Helpers/ParsingHelpers.cs b/src/lib/Helpers/ParsingHelpers.cs index 3f3e1e4..e68750c 100644 --- a/src/lib/Helpers/ParsingHelpers.cs +++ b/src/lib/Helpers/ParsingHelpers.cs @@ -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; @@ -150,12 +152,13 @@ internal static async Task ParseOpenApiAsync(Uri openApiFileUri, boo internal static async Task 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; } diff --git a/src/lib/TypeExtensions/ApiManifestDocumentExtensions.cs b/src/lib/TypeExtensions/ApiManifestDocumentExtensions.cs index 7239218..2f7ce63 100644 --- a/src/lib/TypeExtensions/ApiManifestDocumentExtensions.cs +++ b/src/lib/TypeExtensions/ApiManifestDocumentExtensions.cs @@ -35,7 +35,7 @@ public static async Task 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!); } } diff --git a/src/lib/apimanifest.csproj b/src/lib/apimanifest.csproj index 222c70c..6d42b63 100644 --- a/src/lib/apimanifest.csproj +++ b/src/lib/apimanifest.csproj @@ -3,7 +3,7 @@ netstandard2.0 Microsoft.OpenApi.ApiManifest - 0.5.6 + 0.6.0 preview http://go.microsoft.com/fwlink/?LinkID=288890 https://github.com/Microsoft/OpenApi.ApiManifest @@ -30,16 +30,12 @@ - + runtime; build; native; contentfiles; analyzers; buildtransitive all - - - - + diff --git a/tests/ApiManifest.Tests/Helpers/ParsingHelpersTests.cs b/tests/ApiManifest.Tests/Helpers/ParsingHelpersTests.cs index 2128f3f..46a3cfc 100644 --- a/tests/ApiManifest.Tests/Helpers/ParsingHelpersTests.cs +++ b/tests/ApiManifest.Tests/Helpers/ParsingHelpersTests.cs @@ -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] diff --git a/tests/ApiManifest.Tests/TypeExtensions/OpenApiDocumentExtensionsTests.cs b/tests/ApiManifest.Tests/TypeExtensions/OpenApiDocumentExtensionsTests.cs index 78ee9c2..6021e5b 100644 --- a/tests/ApiManifest.Tests/TypeExtensions/OpenApiDocumentExtensionsTests.cs +++ b/tests/ApiManifest.Tests/TypeExtensions/OpenApiDocumentExtensionsTests.cs @@ -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); } @@ -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); }