From 2a22cd16b348440639463ac0a337eb80bbf50e5d Mon Sep 17 00:00:00 2001 From: Darrel Miller Date: Wed, 11 May 2022 16:38:18 -0400 Subject: [PATCH 01/36] Configure CSDL via settings --- .../Microsoft.OpenApi.Hidi.csproj | 1 + src/Microsoft.OpenApi.Hidi/OpenApiService.cs | 47 ++++++++++++------- src/Microsoft.OpenApi.Hidi/Program.cs | 17 +++++++ 3 files changed, 49 insertions(+), 16 deletions(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index 52d0b3c1e..aaa081c05 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -47,6 +47,7 @@ + diff --git a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs index 584087ea7..4c24c0b4c 100644 --- a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs +++ b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs @@ -28,6 +28,7 @@ using System.Xml; using System.Runtime.CompilerServices; using System.Reflection; +using Microsoft.Extensions.Configuration; namespace Microsoft.OpenApi.Hidi { @@ -98,6 +99,7 @@ CancellationToken cancellationToken stream = ApplyFilter(csdl, csdlFilter, transform); stream.Position = 0; } + document = await ConvertCsdlToOpenApi(stream); stopwatch.Stop(); logger.LogTrace("{timestamp}ms: Generated OpenAPI with {paths} paths.", stopwatch.ElapsedMilliseconds, document.Paths.Count); @@ -321,6 +323,14 @@ public static async Task ValidateOpenApiDocument( } + internal static IConfiguration GetConfiguration() + { + IConfiguration config = new ConfigurationBuilder() + .AddJsonFile("appsettings.json",true) + .Build(); + return config; + } + /// /// Converts CSDL to OpenAPI /// @@ -332,23 +342,28 @@ public static async Task ConvertCsdlToOpenApi(Stream csdl) var csdlText = await reader.ReadToEndAsync(); var edmModel = CsdlReader.Parse(XElement.Parse(csdlText).CreateReader()); - var settings = new OpenApiConvertSettings() + var config = GetConfiguration(); + OpenApiConvertSettings settings = config.GetSection("OpenApiConvertSettings").Get(); + if (settings == null) { - AddSingleQuotesForStringParameters = true, - AddEnumDescriptionExtension = true, - DeclarePathParametersOnPathItem = true, - EnableKeyAsSegment = true, - EnableOperationId = true, - ErrorResponsesAsDefault = false, - PrefixEntityTypeNameBeforeKey = true, - TagDepth = 2, - EnablePagination = true, - EnableDiscriminatorValue = false, - EnableDerivedTypesReferencesForRequestBody = false, - EnableDerivedTypesReferencesForResponses = false, - ShowRootPath = false, - ShowLinks = false - }; + settings = new OpenApiConvertSettings() + { + AddSingleQuotesForStringParameters = true, + AddEnumDescriptionExtension = true, + DeclarePathParametersOnPathItem = true, + EnableKeyAsSegment = true, + EnableOperationId = true, + ErrorResponsesAsDefault = false, + PrefixEntityTypeNameBeforeKey = true, + TagDepth = 2, + EnablePagination = true, + EnableDiscriminatorValue = false, + EnableDerivedTypesReferencesForRequestBody = false, + EnableDerivedTypesReferencesForResponses = false, + ShowRootPath = false, + ShowLinks = false + }; + } OpenApiDocument document = edmModel.ConvertToOpenApi(settings); document = FixReferences(document); diff --git a/src/Microsoft.OpenApi.Hidi/Program.cs b/src/Microsoft.OpenApi.Hidi/Program.cs index 80a4c2e14..09a9061ac 100644 --- a/src/Microsoft.OpenApi.Hidi/Program.cs +++ b/src/Microsoft.OpenApi.Hidi/Program.cs @@ -3,9 +3,15 @@ using System; using System.CommandLine; +using System.CommandLine.Builder; +using System.CommandLine.Hosting; +using System.CommandLine.Parsing; + using System.IO; using System.Threading; using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; +using Microsoft.Extensions.Hosting; using Microsoft.Extensions.Logging; namespace Microsoft.OpenApi.Hidi @@ -92,9 +98,20 @@ static async Task Main(string[] args) rootCommand.Add(transformCommand); rootCommand.Add(validateCommand); + // Parse the incoming args and invoke the handler await rootCommand.InvokeAsync(args); + + //await new CommandLineBuilder(rootCommand) + // .UseHost(_ => Host.CreateDefaultBuilder(), + // host => { + // var config = host.Services.GetRequiredService(); + // }) + // .UseDefaults() + // .Build() + // .InvokeAsync(args); + //// Wait for logger to write messages to the console before exiting await Task.Delay(10); } From 168a58b1fcd4749d6603938f2538c3bee880946f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 25 Oct 2022 21:12:12 +0000 Subject: [PATCH 02/36] Bump Microsoft.OData.Edm from 7.12.4 to 7.12.5 Bumps Microsoft.OData.Edm from 7.12.4 to 7.12.5. --- updated-dependencies: - dependency-name: Microsoft.OData.Edm dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index c77e30194..37c7d3b42 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -42,7 +42,7 @@ - + From 93d9108d0400d0278a0bae83fbafb14d9ff2577a Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 Oct 2022 21:10:37 +0000 Subject: [PATCH 03/36] Bump Verify.Xunit from 18.0.0 to 18.1.1 Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 18.0.0 to 18.1.1. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/compare/18.0.0...18.1.1) --- updated-dependencies: - dependency-name: Verify.Xunit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj index d1f97f6f3..79beda1ad 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -20,7 +20,7 @@ - + all From aa87e77c140c382c844a99417bc7c1e0af7e157b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Fri, 28 Oct 2022 21:10:43 +0000 Subject: [PATCH 04/36] Bump Microsoft.Windows.Compatibility from 6.0.0 to 6.0.1 Bumps [Microsoft.Windows.Compatibility](https://github.com/dotnet/runtime) from 6.0.0 to 6.0.1. - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](https://github.com/dotnet/runtime/compare/v6.0.0...v6.0.1) --- updated-dependencies: - dependency-name: Microsoft.Windows.Compatibility dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../Microsoft.OpenApi.Workbench.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj index a47b5af48..6b83bdbca 100644 --- a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj +++ b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj @@ -10,7 +10,7 @@ all - + From 807dc2f98c26991234420213aaec462a4a139755 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 31 Oct 2022 21:05:58 +0000 Subject: [PATCH 05/36] Bump mathieudutour/github-tag-action from 6.0 to 6.1 Bumps [mathieudutour/github-tag-action](https://github.com/mathieudutour/github-tag-action) from 6.0 to 6.1. - [Release notes](https://github.com/mathieudutour/github-tag-action/releases) - [Commits](https://github.com/mathieudutour/github-tag-action/compare/v6.0...v6.1) --- updated-dependencies: - dependency-name: mathieudutour/github-tag-action dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .github/workflows/ci-cd.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index b972c9848..b394e018b 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -49,7 +49,7 @@ jobs: - if: steps.conditionals_handler.outputs.is_default_branch == 'true' name: Bump GH tag id: tag_generator - uses: mathieudutour/github-tag-action@v6.0 + uses: mathieudutour/github-tag-action@v6.1 with: github_token: ${{ secrets.GITHUB_TOKEN }} default_bump: false From b89ebc28b4613e4724c87acafd3209212c878ae7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 31 Oct 2022 21:12:01 +0000 Subject: [PATCH 06/36] Bump coverlet.collector from 3.1.2 to 3.2.0 Bumps [coverlet.collector](https://github.com/coverlet-coverage/coverlet) from 3.1.2 to 3.2.0. - [Release notes](https://github.com/coverlet-coverage/coverlet/releases) - [Commits](https://github.com/coverlet-coverage/coverlet/commits/v3.2.0) --- updated-dependencies: - dependency-name: coverlet.collector dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../Microsoft.OpenApi.Hidi.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj b/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj index 1a4002daa..2c53d82da 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj +++ b/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj @@ -16,7 +16,7 @@ runtime; build; native; contentfiles; analyzers; buildtransitive all - + runtime; build; native; contentfiles; analyzers; buildtransitive all From 5429810a87def5416b94a2d9620fa7d1b9bb0a30 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 31 Oct 2022 21:12:08 +0000 Subject: [PATCH 07/36] Bump Verify.Xunit from 18.1.1 to 18.2.0 Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 18.1.1 to 18.2.0. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/compare/18.1.1...18.2.0) --- updated-dependencies: - dependency-name: Verify.Xunit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj index 79beda1ad..251fe1a4b 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -20,7 +20,7 @@ - + all From 236a8873938bf56f372ca9510645221ea7b25179 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 21:11:27 +0000 Subject: [PATCH 08/36] Bump Microsoft.OpenApi.OData from 1.2.0-preview5 to 1.2.0-preview6 Bumps [Microsoft.OpenApi.OData](https://github.com/Microsoft/OpenAPI.NET.OData) from 1.2.0-preview5 to 1.2.0-preview6. - [Release notes](https://github.com/Microsoft/OpenAPI.NET.OData/releases) - [Commits](https://github.com/Microsoft/OpenAPI.NET.OData/commits) --- updated-dependencies: - dependency-name: Microsoft.OpenApi.OData dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index 37c7d3b42..e133b37cf 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -43,7 +43,7 @@ - + From 05a1fd8ee3f6eb011d92d0f02931b2bbdc2e0ee7 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 2 Nov 2022 21:11:32 +0000 Subject: [PATCH 09/36] Bump Verify.Xunit from 18.2.0 to 18.3.0 Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 18.2.0 to 18.3.0. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/compare/18.2.0...18.3.0) --- updated-dependencies: - dependency-name: Verify.Xunit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj index 251fe1a4b..33dd48253 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -20,7 +20,7 @@ - + all From 2b13d3f71f049df68fa0432e212f4c9ad3e683c1 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Thu, 3 Nov 2022 12:35:53 +0300 Subject: [PATCH 10/36] Remove return statement to eliminate NullReference exception --- src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs index 40b40e85a..1e729f30a 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs @@ -105,7 +105,6 @@ public OpenApiReference ConvertToOpenApiReference( catch (OpenApiException ex) { Diagnostic.Errors.Add(new OpenApiError(ex)); - return null; } } // Where fragments point into a non-OpenAPI document, the id will be the complete fragment identifier From e210137335bc20027df5ac7b111c396fef2c1fd6 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 7 Nov 2022 11:30:04 +0300 Subject: [PATCH 11/36] Add a settingsFile parameter that allows one to input a path to the settingsfile --- .../Handlers/TransformCommandHandler.cs | 4 +- src/Microsoft.OpenApi.Hidi/OpenApiService.cs | 57 ++++++++++--------- src/Microsoft.OpenApi.Hidi/Program.cs | 5 ++ 3 files changed, 38 insertions(+), 28 deletions(-) diff --git a/src/Microsoft.OpenApi.Hidi/Handlers/TransformCommandHandler.cs b/src/Microsoft.OpenApi.Hidi/Handlers/TransformCommandHandler.cs index e8d9431de..696837d3f 100644 --- a/src/Microsoft.OpenApi.Hidi/Handlers/TransformCommandHandler.cs +++ b/src/Microsoft.OpenApi.Hidi/Handlers/TransformCommandHandler.cs @@ -21,6 +21,7 @@ internal class TransformCommandHandler : ICommandHandler public Option VersionOption { get; set; } public Option FormatOption { get; set; } public Option TerseOutputOption { get; set; } + public Option SettingsFileOption { get; set; } public Option LogLevelOption { get; set; } public Option FilterByOperationIdsOption { get; set; } public Option FilterByTagsOption { get; set; } @@ -42,6 +43,7 @@ public async Task InvokeAsync(InvocationContext context) string? version = context.ParseResult.GetValueForOption(VersionOption); OpenApiFormat? format = context.ParseResult.GetValueForOption(FormatOption); bool terseOutput = context.ParseResult.GetValueForOption(TerseOutputOption); + string settingsFile = context.ParseResult.GetValueForOption(SettingsFileOption); LogLevel logLevel = context.ParseResult.GetValueForOption(LogLevelOption); bool inlineLocal = context.ParseResult.GetValueForOption(InlineLocalOption); bool inlineExternal = context.ParseResult.GetValueForOption(InlineExternalOption); @@ -54,7 +56,7 @@ public async Task InvokeAsync(InvocationContext context) var logger = loggerFactory.CreateLogger(); try { - await OpenApiService.TransformOpenApiDocument(openapi, csdl, csdlFilter, output, cleanOutput, version, format, terseOutput, logLevel, inlineLocal, inlineExternal, filterbyoperationids, filterbytags, filterbycollection, cancellationToken); + await OpenApiService.TransformOpenApiDocument(openapi, csdl, csdlFilter, output, cleanOutput, version, format, terseOutput, settingsFile, logLevel, inlineLocal, inlineExternal, filterbyoperationids, filterbytags, filterbycollection, cancellationToken); return 0; } diff --git a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs index e6603d62d..488db08cf 100644 --- a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs +++ b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs @@ -45,6 +45,7 @@ public static async Task TransformOpenApiDocument( string? version, OpenApiFormat? format, bool terseOutput, + string settingsFile, LogLevel logLevel, bool inlineLocal, bool inlineExternal, @@ -100,7 +101,7 @@ CancellationToken cancellationToken stream.Position = 0; } - document = await ConvertCsdlToOpenApi(stream); + document = await ConvertCsdlToOpenApi(stream, settingsFile); stopwatch.Stop(); logger.LogTrace("{timestamp}ms: Generated OpenAPI with {paths} paths.", stopwatch.ElapsedMilliseconds, document.Paths.Count); } @@ -306,11 +307,14 @@ public static async Task ValidateOpenApiDocument( } } - internal static IConfiguration GetConfiguration() + public static IConfiguration GetConfiguration(string settingsFile) { + settingsFile ??= "appsettings.json"; + IConfiguration config = new ConfigurationBuilder() - .AddJsonFile("appsettings.json",true) + .AddJsonFile(settingsFile, true) .Build(); + return config; } @@ -319,37 +323,36 @@ internal static IConfiguration GetConfiguration() /// /// The CSDL stream. /// An OpenAPI document. - public static async Task ConvertCsdlToOpenApi(Stream csdl) + public static async Task ConvertCsdlToOpenApi(Stream csdl, string settingsFile = null) { using var reader = new StreamReader(csdl); var csdlText = await reader.ReadToEndAsync(); var edmModel = CsdlReader.Parse(XElement.Parse(csdlText).CreateReader()); + + var config = GetConfiguration(settingsFile); + var settings = config.GetSection("OpenApiConvertSettings").Get(); - var config = GetConfiguration(); - OpenApiConvertSettings settings = config.GetSection("OpenApiConvertSettings").Get(); - if (settings == null) - { - settings = new OpenApiConvertSettings() + settings ??= new OpenApiConvertSettings() { - AddSingleQuotesForStringParameters = true, - AddEnumDescriptionExtension = true, - DeclarePathParametersOnPathItem = true, - EnableKeyAsSegment = true, - EnableOperationId = true, - ErrorResponsesAsDefault = false, - PrefixEntityTypeNameBeforeKey = true, - TagDepth = 2, - EnablePagination = true, - EnableDiscriminatorValue = true, - EnableDerivedTypesReferencesForRequestBody = false, - EnableDerivedTypesReferencesForResponses = false, - ShowRootPath = false, - ShowLinks = false, - ExpandDerivedTypesNavigationProperties = false, - EnableCount = true, - UseSuccessStatusCodeRange = true + AddSingleQuotesForStringParameters = true, + AddEnumDescriptionExtension = true, + DeclarePathParametersOnPathItem = true, + EnableKeyAsSegment = true, + EnableOperationId = true, + ErrorResponsesAsDefault = false, + PrefixEntityTypeNameBeforeKey = true, + TagDepth = 2, + EnablePagination = true, + EnableDiscriminatorValue = true, + EnableDerivedTypesReferencesForRequestBody = false, + EnableDerivedTypesReferencesForResponses = false, + ShowRootPath = false, + ShowLinks = false, + ExpandDerivedTypesNavigationProperties = false, + EnableCount = true, + UseSuccessStatusCodeRange = true }; - } + OpenApiDocument document = edmModel.ConvertToOpenApi(settings); document = FixReferences(document); diff --git a/src/Microsoft.OpenApi.Hidi/Program.cs b/src/Microsoft.OpenApi.Hidi/Program.cs index 67f4c2974..3af6818da 100644 --- a/src/Microsoft.OpenApi.Hidi/Program.cs +++ b/src/Microsoft.OpenApi.Hidi/Program.cs @@ -47,6 +47,9 @@ static async Task Main(string[] args) var terseOutputOption = new Option("--terse-output", "Produce terse json output"); terseOutputOption.AddAlias("--to"); + var settingsFileOption = new Option("--settingsFile", "The configuration file with CSDL conversion settings."); + settingsFileOption.AddAlias("--sf"); + var logLevelOption = new Option("--log-level", () => LogLevel.Information, "The log level to use when logging messages to the main output."); logLevelOption.AddAlias("--ll"); @@ -87,6 +90,7 @@ static async Task Main(string[] args) versionOption, formatOption, terseOutputOption, + settingsFileOption, logLevelOption, filterByOperationIdsOption, filterByTagsOption, @@ -105,6 +109,7 @@ static async Task Main(string[] args) VersionOption = versionOption, FormatOption = formatOption, TerseOutputOption = terseOutputOption, + SettingsFileOption = settingsFileOption, LogLevelOption = logLevelOption, FilterByOperationIdsOption = filterByOperationIdsOption, FilterByTagsOption = filterByTagsOption, From 67586ec6b99730d4de4883e5295112c3142f5faf Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 7 Nov 2022 11:31:03 +0300 Subject: [PATCH 12/36] Add test --- .../Microsoft.OpenApi.Hidi.Tests.csproj | 3 +++ .../Services/OpenApiServiceTests.cs | 16 ++++++++++++++++ .../Services/appsettingstest.json | 7 +++++++ 3 files changed, 26 insertions(+) create mode 100644 test/Microsoft.OpenApi.Hidi.Tests/Services/appsettingstest.json diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj b/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj index 2c53d82da..39fa1d87b 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj +++ b/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj @@ -34,6 +34,9 @@ + + Always + Always diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs index af5437aa1..aed9e4889 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs @@ -4,7 +4,9 @@ using System; using System.IO; using System.Threading.Tasks; +using Microsoft.Extensions.Configuration; using Microsoft.OpenApi.Hidi; +using Microsoft.OpenApi.OData; using Microsoft.OpenApi.Services; using Xunit; @@ -51,5 +53,19 @@ public async Task ReturnFilteredOpenApiDocBasedOnOperationIdsAndInputCsdlDocumen Assert.NotEmpty(subsetOpenApiDocument.Paths); Assert.Equal(expectedPathCount, subsetOpenApiDocument.Paths.Count); } + + [Fact] + public void ReturnOpenApiConvertSettings() + { + // Arrange + var filePath = "C:\\Users\\v-makim\\source\\repos\\OpenAPI.NET\\test\\Microsoft.OpenApi.Hidi.Tests\\Services\\appsettingstest.json"; + var config = OpenApiService.GetConfiguration(filePath); + + // Act + var settings = config.GetSection("OpenApiConvertSettings").Get(); + + // Assert + Assert.NotNull(settings); + } } } diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/appsettingstest.json b/test/Microsoft.OpenApi.Hidi.Tests/Services/appsettingstest.json new file mode 100644 index 000000000..2effcaced --- /dev/null +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/appsettingstest.json @@ -0,0 +1,7 @@ +{ + "OpenApiConvertSettings": { + "AddSingleQuotesForStringParameters": "true", + "AddEnumDescriptionExtension": "true", + "DeclarePathParametersOnPathItem": "true" + } +} \ No newline at end of file From 6f0bf136194bdc0d422a6abe4d34f9efd95ebe7f Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 7 Nov 2022 13:04:04 +0300 Subject: [PATCH 13/36] Use backslash in filePath --- .../Services/OpenApiServiceTests.cs | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs index aed9e4889..68fefe088 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs @@ -58,7 +58,7 @@ public async Task ReturnFilteredOpenApiDocBasedOnOperationIdsAndInputCsdlDocumen public void ReturnOpenApiConvertSettings() { // Arrange - var filePath = "C:\\Users\\v-makim\\source\\repos\\OpenAPI.NET\\test\\Microsoft.OpenApi.Hidi.Tests\\Services\\appsettingstest.json"; + var filePath = "C:/Users/v-makim/source/repos/OpenAPI.NET/test/Microsoft.OpenApi.Hidi.Tests/Services/appsettingstest.json"; var config = OpenApiService.GetConfiguration(filePath); // Act From 568cf91a855480a67e8583a9a399b3995c0c1257 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 7 Nov 2022 14:33:37 +0300 Subject: [PATCH 14/36] Clean up tests --- .../Microsoft.OpenApi.Hidi.Tests.csproj | 2 +- .../Services/OpenApiServiceTests.cs | 2 +- .../Services/appsettingstest.json | 7 ------- .../UtilityFiles/appsettingstest.json | 21 +++++++++++++++++++ 4 files changed, 23 insertions(+), 9 deletions(-) delete mode 100644 test/Microsoft.OpenApi.Hidi.Tests/Services/appsettingstest.json create mode 100644 test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/appsettingstest.json diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj b/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj index 39fa1d87b..9bc2e7849 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj +++ b/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj @@ -34,7 +34,7 @@ - + Always diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs index 68fefe088..44d0740be 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs @@ -58,7 +58,7 @@ public async Task ReturnFilteredOpenApiDocBasedOnOperationIdsAndInputCsdlDocumen public void ReturnOpenApiConvertSettings() { // Arrange - var filePath = "C:/Users/v-makim/source/repos/OpenAPI.NET/test/Microsoft.OpenApi.Hidi.Tests/Services/appsettingstest.json"; + var filePath = "C:/Users/v-makim/source/repos/OpenAPI.NET/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/appsettingstest.json"; var config = OpenApiService.GetConfiguration(filePath); // Act diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/appsettingstest.json b/test/Microsoft.OpenApi.Hidi.Tests/Services/appsettingstest.json deleted file mode 100644 index 2effcaced..000000000 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/appsettingstest.json +++ /dev/null @@ -1,7 +0,0 @@ -{ - "OpenApiConvertSettings": { - "AddSingleQuotesForStringParameters": "true", - "AddEnumDescriptionExtension": "true", - "DeclarePathParametersOnPathItem": "true" - } -} \ No newline at end of file diff --git a/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/appsettingstest.json b/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/appsettingstest.json new file mode 100644 index 000000000..a71d0a9fa --- /dev/null +++ b/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/appsettingstest.json @@ -0,0 +1,21 @@ +{ + "OpenApiConvertSettings": { + "AddSingleQuotesForStringParameters": "true", + "AddEnumDescriptionExtension": "true", + "DeclarePathParametersOnPathItem": "true", + "EnableKeyAsSegment": "true", + "EnableOperationId": "true", + "ErrorResponsesAsDefault": "false", + "PrefixEntityTypeNameBeforeKey": "true", + "TagDepth": 2, + "EnablePagination": "true", + "EnableDiscriminatorValue": "true", + "EnableDerivedTypesReferencesForRequestBody": "false", + "EnableDerivedTypesReferencesForResponses": "false", + "ShowRootPath": "false", + "ShowLinks": "false", + "ExpandDerivedTypesNavigationProperties": "false", + "EnableCount": "true", + "UseSuccessStatusCodeRange": "true" + } +} \ No newline at end of file From efd2ac871cae2f87a19b33118a7f1c708b5acc0f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Nov 2022 21:10:40 +0000 Subject: [PATCH 15/36] Bump Microsoft.Windows.Compatibility from 6.0.1 to 7.0.0 Bumps [Microsoft.Windows.Compatibility](https://github.com/dotnet/runtime) from 6.0.1 to 7.0.0. - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](https://github.com/dotnet/runtime/commits) --- updated-dependencies: - dependency-name: Microsoft.Windows.Compatibility dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- .../Microsoft.OpenApi.Workbench.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj index 6b83bdbca..cf3ff2225 100644 --- a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj +++ b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj @@ -10,7 +10,7 @@ all - + From 4f949113ef78c3e2252322bc181cf9abaf42e768 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Nov 2022 21:10:46 +0000 Subject: [PATCH 16/36] Bump Microsoft.NET.Test.Sdk from 17.3.2 to 17.4.0 Bumps [Microsoft.NET.Test.Sdk](https://github.com/microsoft/vstest) from 17.3.2 to 17.4.0. - [Release notes](https://github.com/microsoft/vstest/releases) - [Commits](https://github.com/microsoft/vstest/compare/v17.3.2...v17.4.0) --- updated-dependencies: - dependency-name: Microsoft.NET.Test.Sdk dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- .../Microsoft.OpenApi.Hidi.Tests.csproj | 2 +- .../Microsoft.OpenApi.Readers.Tests.csproj | 2 +- .../Microsoft.OpenApi.SmokeTests.csproj | 2 +- test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj b/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj index 2c53d82da..f4c368024 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj +++ b/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj @@ -9,7 +9,7 @@ - + diff --git a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj index 1c46de041..2e73118b2 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj +++ b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj @@ -250,7 +250,7 @@ - + diff --git a/test/Microsoft.OpenApi.SmokeTests/Microsoft.OpenApi.SmokeTests.csproj b/test/Microsoft.OpenApi.SmokeTests/Microsoft.OpenApi.SmokeTests.csproj index 7f41b101f..bb1cf129d 100644 --- a/test/Microsoft.OpenApi.SmokeTests/Microsoft.OpenApi.SmokeTests.csproj +++ b/test/Microsoft.OpenApi.SmokeTests/Microsoft.OpenApi.SmokeTests.csproj @@ -8,7 +8,7 @@ - + diff --git a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj index 33dd48253..3ee1f6322 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -16,7 +16,7 @@ - + From f5e3b2e1d443909bcecd0673384e7173bc876bc5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Nov 2022 21:10:53 +0000 Subject: [PATCH 17/36] Bump Verify.Xunit from 18.3.0 to 18.4.0 Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 18.3.0 to 18.4.0. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/compare/18.3.0...18.4.0) --- updated-dependencies: - dependency-name: Verify.Xunit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj index 33dd48253..49be5986c 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -20,7 +20,7 @@ - + all From 2bde9e8f799b9f57e5a71074bf325519198c1d7c Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Nov 2022 21:10:59 +0000 Subject: [PATCH 18/36] Bump Microsoft.Extensions.Logging.Abstractions from 6.0.2 to 7.0.0 Bumps [Microsoft.Extensions.Logging.Abstractions](https://github.com/dotnet/runtime) from 6.0.2 to 7.0.0. - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](https://github.com/dotnet/runtime/commits) --- updated-dependencies: - dependency-name: Microsoft.Extensions.Logging.Abstractions dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index e133b37cf..e11d1c315 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -38,7 +38,7 @@ - + From a4bbda0a8a9fef9ac087795f7bf371103a9e0b0f Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Nov 2022 21:51:07 +0000 Subject: [PATCH 19/36] Bump Microsoft.Extensions.Logging from 6.0.0 to 7.0.0 Bumps [Microsoft.Extensions.Logging](https://github.com/dotnet/runtime) from 6.0.0 to 7.0.0. - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](https://github.com/dotnet/runtime/commits) --- updated-dependencies: - dependency-name: Microsoft.Extensions.Logging dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index e11d1c315..c19926e38 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -37,7 +37,7 @@ - + From 4e81b9b1d9d2d825b5b338ab4c33a65a843b4dda Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Nov 2022 22:05:56 +0000 Subject: [PATCH 20/36] Bump Microsoft.Extensions.Logging.Console from 6.0.0 to 7.0.0 Bumps [Microsoft.Extensions.Logging.Console](https://github.com/dotnet/runtime) from 6.0.0 to 7.0.0. - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](https://github.com/dotnet/runtime/commits) --- updated-dependencies: - dependency-name: Microsoft.Extensions.Logging.Console dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index c19926e38..c884e91fe 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -39,7 +39,7 @@ - + From a54c8f9b38c6378cd8876d6d0faa426573688d18 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 7 Nov 2022 22:17:37 +0000 Subject: [PATCH 21/36] Bump Microsoft.Extensions.Logging.Debug from 6.0.0 to 7.0.0 Bumps [Microsoft.Extensions.Logging.Debug](https://github.com/dotnet/runtime) from 6.0.0 to 7.0.0. - [Release notes](https://github.com/dotnet/runtime/releases) - [Commits](https://github.com/dotnet/runtime/commits) --- updated-dependencies: - dependency-name: Microsoft.Extensions.Logging.Debug dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index c884e91fe..6c9b54e04 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -40,7 +40,7 @@ - + From ec05eca67e7096e30f5e1330c04b3e2b1bad592a Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Tue, 8 Nov 2022 12:45:30 +0300 Subject: [PATCH 22/36] Address PR feedback --- .../Microsoft.OpenApi.Hidi.csproj | 8 ++++ src/Microsoft.OpenApi.Hidi/OpenApiService.cs | 48 +++++++++---------- src/Microsoft.OpenApi.Hidi/Program.cs | 15 +----- .../Services/OpenApiServiceTests.cs | 24 ++++++---- 4 files changed, 48 insertions(+), 47 deletions(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index 0e7abdbdb..c2071f810 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -52,4 +52,12 @@ + + + + <_Parameter1>Microsoft.OpenApi.Hidi.Tests + + + + diff --git a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs index 488db08cf..0d9500682 100644 --- a/src/Microsoft.OpenApi.Hidi/OpenApiService.cs +++ b/src/Microsoft.OpenApi.Hidi/OpenApiService.cs @@ -28,6 +28,7 @@ using System.Xml; using System.Reflection; using Microsoft.Extensions.Configuration; +using System.Runtime.CompilerServices; namespace Microsoft.OpenApi.Hidi { @@ -307,7 +308,7 @@ public static async Task ValidateOpenApiDocument( } } - public static IConfiguration GetConfiguration(string settingsFile) + internal static IConfiguration GetConfiguration(string settingsFile) { settingsFile ??= "appsettings.json"; @@ -317,7 +318,7 @@ public static IConfiguration GetConfiguration(string settingsFile) return config; } - + /// /// Converts CSDL to OpenAPI /// @@ -330,28 +331,27 @@ public static async Task ConvertCsdlToOpenApi(Stream csdl, stri var edmModel = CsdlReader.Parse(XElement.Parse(csdlText).CreateReader()); var config = GetConfiguration(settingsFile); - var settings = config.GetSection("OpenApiConvertSettings").Get(); - - settings ??= new OpenApiConvertSettings() - { - AddSingleQuotesForStringParameters = true, - AddEnumDescriptionExtension = true, - DeclarePathParametersOnPathItem = true, - EnableKeyAsSegment = true, - EnableOperationId = true, - ErrorResponsesAsDefault = false, - PrefixEntityTypeNameBeforeKey = true, - TagDepth = 2, - EnablePagination = true, - EnableDiscriminatorValue = true, - EnableDerivedTypesReferencesForRequestBody = false, - EnableDerivedTypesReferencesForResponses = false, - ShowRootPath = false, - ShowLinks = false, - ExpandDerivedTypesNavigationProperties = false, - EnableCount = true, - UseSuccessStatusCodeRange = true - }; + var settings = new OpenApiConvertSettings() + { + AddSingleQuotesForStringParameters = true, + AddEnumDescriptionExtension = true, + DeclarePathParametersOnPathItem = true, + EnableKeyAsSegment = true, + EnableOperationId = true, + ErrorResponsesAsDefault = false, + PrefixEntityTypeNameBeforeKey = true, + TagDepth = 2, + EnablePagination = true, + EnableDiscriminatorValue = true, + EnableDerivedTypesReferencesForRequestBody = false, + EnableDerivedTypesReferencesForResponses = false, + ShowRootPath = false, + ShowLinks = false, + ExpandDerivedTypesNavigationProperties = false, + EnableCount = true, + UseSuccessStatusCodeRange = true + }; + config.GetSection("OpenApiConvertSettings").Bind(settings); OpenApiDocument document = edmModel.ConvertToOpenApi(settings); diff --git a/src/Microsoft.OpenApi.Hidi/Program.cs b/src/Microsoft.OpenApi.Hidi/Program.cs index 3af6818da..71e9e0d00 100644 --- a/src/Microsoft.OpenApi.Hidi/Program.cs +++ b/src/Microsoft.OpenApi.Hidi/Program.cs @@ -47,8 +47,8 @@ static async Task Main(string[] args) var terseOutputOption = new Option("--terse-output", "Produce terse json output"); terseOutputOption.AddAlias("--to"); - var settingsFileOption = new Option("--settingsFile", "The configuration file with CSDL conversion settings."); - settingsFileOption.AddAlias("--sf"); + var settingsFileOption = new Option("--settings-path", "The configuration file with CSDL conversion settings."); + settingsFileOption.AddAlias("--sp"); var logLevelOption = new Option("--log-level", () => LogLevel.Information, "The log level to use when logging messages to the main output."); logLevelOption.AddAlias("--ll"); @@ -121,20 +121,9 @@ static async Task Main(string[] args) rootCommand.Add(transformCommand); rootCommand.Add(validateCommand); - // Parse the incoming args and invoke the handler await rootCommand.InvokeAsync(args); - - //await new CommandLineBuilder(rootCommand) - // .UseHost(_ => Host.CreateDefaultBuilder(), - // host => { - // var config = host.Services.GetRequiredService(); - // }) - // .UseDefaults() - // .Build() - // .InvokeAsync(args); - //// Wait for logger to write messages to the console before exiting await Task.Delay(10); } diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs index 44d0740be..c2fb3798f 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs +++ b/test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs @@ -1,9 +1,6 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. -using System; -using System.IO; -using System.Threading.Tasks; using Microsoft.Extensions.Configuration; using Microsoft.OpenApi.Hidi; using Microsoft.OpenApi.OData; @@ -54,18 +51,25 @@ public async Task ReturnFilteredOpenApiDocBasedOnOperationIdsAndInputCsdlDocumen Assert.Equal(expectedPathCount, subsetOpenApiDocument.Paths.Count); } - [Fact] - public void ReturnOpenApiConvertSettings() + [Theory] + [InlineData("UtilityFiles/appsettingstest.json")] + [InlineData(null)] + public void ReturnOpenApiConvertSettingsWhenSettingsFileIsProvided(string filePath) { // Arrange - var filePath = "C:/Users/v-makim/source/repos/OpenAPI.NET/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/appsettingstest.json"; var config = OpenApiService.GetConfiguration(filePath); - - // Act + + // Act and Assert var settings = config.GetSection("OpenApiConvertSettings").Get(); - // Assert - Assert.NotNull(settings); + if (filePath == null) + { + Assert.Null(settings); + } + else + { + Assert.NotNull(settings); + } } } } From 973cd6da0fac60e9c338bfac7aabe5268f4ed798 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Tue, 8 Nov 2022 10:26:15 -0500 Subject: [PATCH 23/36] - upgrades to dotnet 7 Signed-off-by: Vincent Biret --- .azure-pipelines/ci-build.yml | 4 ++-- .github/workflows/ci-cd.yml | 2 +- .github/workflows/codeql-analysis.yml | 2 +- .vscode/launch.json | 2 +- Dockerfile | 6 +++--- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 6 +++--- .../Microsoft.OpenApi.Workbench.csproj | 2 +- .../Microsoft.OpenApi.Hidi.Tests.csproj | 2 +- .../Microsoft.OpenApi.Readers.Tests.csproj | 4 ++-- .../Microsoft.OpenApi.SmokeTests.csproj | 4 ++-- test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj | 2 +- .../PublicApi/PublicApi.approved.txt | 2 +- 12 files changed, 19 insertions(+), 19 deletions(-) diff --git a/.azure-pipelines/ci-build.yml b/.azure-pipelines/ci-build.yml index 2f1b6b9b5..363654179 100644 --- a/.azure-pipelines/ci-build.yml +++ b/.azure-pipelines/ci-build.yml @@ -31,9 +31,9 @@ stages: - job: build steps: - task: UseDotNet@2 - displayName: 'Use .NET 6' + displayName: 'Use .NET' inputs: - version: 6.x + version: 7.x - task: PoliCheck@1 displayName: 'Run PoliCheck "/src"' diff --git a/.github/workflows/ci-cd.yml b/.github/workflows/ci-cd.yml index b394e018b..097fc3b96 100644 --- a/.github/workflows/ci-cd.yml +++ b/.github/workflows/ci-cd.yml @@ -16,7 +16,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.x + dotnet-version: 7.0.x - name: Data gatherer id: data_gatherer diff --git a/.github/workflows/codeql-analysis.yml b/.github/workflows/codeql-analysis.yml index eb56ea14f..89d7e62c1 100644 --- a/.github/workflows/codeql-analysis.yml +++ b/.github/workflows/codeql-analysis.yml @@ -19,7 +19,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v3 with: - dotnet-version: 6.0.x + dotnet-version: 7.0.x - name: Initialize CodeQL id: init_codeql diff --git a/.vscode/launch.json b/.vscode/launch.json index b59349979..974002cfe 100644 --- a/.vscode/launch.json +++ b/.vscode/launch.json @@ -10,7 +10,7 @@ "request": "launch", "preLaunchTask": "build", // If you have changed target frameworks, make sure to update the program path. - "program": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi/bin/Debug/net6.0/Microsoft.OpenApi.Hidi.dll", + "program": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi/bin/Debug/net7.0/Microsoft.OpenApi.Hidi.dll", "args": [], "cwd": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi", // For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console diff --git a/Dockerfile b/Dockerfile index 8326ce3b9..6b3507124 100644 --- a/Dockerfile +++ b/Dockerfile @@ -1,14 +1,14 @@ -FROM mcr.microsoft.com/dotnet/sdk:6.0 AS build-env +FROM mcr.microsoft.com/dotnet/sdk:7.0 AS build-env WORKDIR /app COPY ./src ./hidi/src WORKDIR /app/hidi RUN dotnet publish ./src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj -c Release -FROM mcr.microsoft.com/dotnet/runtime:6.0 as runtime +FROM mcr.microsoft.com/dotnet/runtime:7.0 as runtime WORKDIR /app -COPY --from=build-env /app/hidi/src/Microsoft.OpenApi.Hidi/bin/Release/net6.0 ./ +COPY --from=build-env /app/hidi/src/Microsoft.OpenApi.Hidi/bin/Release/net7.0 ./ VOLUME /app/output VOLUME /app/openapi.yml diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index f88e7ed63..c7f84666a 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -2,7 +2,7 @@ Exe - net6.0 + net7.0 9.0 true http://go.microsoft.com/fwlink/?LinkID=288890 @@ -43,8 +43,8 @@ - - + + diff --git a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj index cf3ff2225..ed69b8145 100644 --- a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj +++ b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj @@ -1,6 +1,6 @@  - net6.0-windows + net7.0-windows WinExe false true diff --git a/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj b/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj index d73d8af81..f450e2ff7 100644 --- a/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj +++ b/test/Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj @@ -1,7 +1,7 @@ - net6.0 + net7.0 enable enable diff --git a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj index 2e73118b2..cecc1c777 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj +++ b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj @@ -1,6 +1,6 @@ - net6.0 + net7.0 false Microsoft @@ -253,7 +253,7 @@ - + diff --git a/test/Microsoft.OpenApi.SmokeTests/Microsoft.OpenApi.SmokeTests.csproj b/test/Microsoft.OpenApi.SmokeTests/Microsoft.OpenApi.SmokeTests.csproj index bb1cf129d..9c88e8394 100644 --- a/test/Microsoft.OpenApi.SmokeTests/Microsoft.OpenApi.SmokeTests.csproj +++ b/test/Microsoft.OpenApi.SmokeTests/Microsoft.OpenApi.SmokeTests.csproj @@ -1,7 +1,7 @@  - net6.0 + net7.0 @@ -9,7 +9,7 @@ - + all diff --git a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj index 666a2b39b..0a20ba420 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -1,6 +1,6 @@  - net6.0 + net7.0 false Microsoft diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 75e12f480..f0afc457f 100755 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -1,7 +1,7 @@ [assembly: System.Reflection.AssemblyMetadata("RepositoryUrl", "https://github.com/Microsoft/OpenAPI.NET")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"Microsoft.OpenApi.Readers.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100957cb48387b2a5f54f5ce39255f18f26d32a39990db27cf48737afc6bc62759ba996b8a2bfb675d4e39f3d06ecb55a178b1b4031dcb2a767e29977d88cce864a0d16bfc1b3bebb0edf9fe285f10fffc0a85f93d664fa05af07faa3aad2e545182dbf787e3fd32b56aca95df1a3c4e75dec164a3f1a4c653d971b01ffc39eb3c4")] [assembly: System.Runtime.CompilerServices.InternalsVisibleTo(@"Microsoft.OpenApi.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100957cb48387b2a5f54f5ce39255f18f26d32a39990db27cf48737afc6bc62759ba996b8a2bfb675d4e39f3d06ecb55a178b1b4031dcb2a767e29977d88cce864a0d16bfc1b3bebb0edf9fe285f10fffc0a85f93d664fa05af07faa3aad2e545182dbf787e3fd32b56aca95df1a3c4e75dec164a3f1a4c653d971b01ffc39eb3c4")] -[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName="")] +[assembly: System.Runtime.Versioning.TargetFramework(".NETStandard,Version=v2.0", FrameworkDisplayName=".NET Standard 2.0")] namespace Microsoft.OpenApi.Any { public enum AnyType From c9285d3900b2e54f48f845ef400e2e235adb48cf Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Nov 2022 21:01:46 +0000 Subject: [PATCH 24/36] Bump System.CommandLine.Hosting Bumps [System.CommandLine.Hosting](https://github.com/dotnet/command-line-api) from 0.4.0-alpha.22114.1 to 0.4.0-alpha.22272.1. - [Release notes](https://github.com/dotnet/command-line-api/releases) - [Changelog](https://github.com/dotnet/command-line-api/blob/main/docs/History.md) - [Commits](https://github.com/dotnet/command-line-api/commits) --- updated-dependencies: - dependency-name: System.CommandLine.Hosting dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index f88e7ed63..c3fe239bb 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -44,7 +44,7 @@ - + From 07c4567ada2c914d203e5a3016794c3ea4c97da5 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Tue, 8 Nov 2022 21:20:46 +0000 Subject: [PATCH 25/36] Bump Microsoft.OpenApi.OData from 1.2.0-preview6 to 1.2.0-preview7 Bumps [Microsoft.OpenApi.OData](https://github.com/Microsoft/OpenAPI.NET.OData) from 1.2.0-preview6 to 1.2.0-preview7. - [Release notes](https://github.com/Microsoft/OpenAPI.NET.OData/releases) - [Commits](https://github.com/Microsoft/OpenAPI.NET.OData/commits) --- updated-dependencies: - dependency-name: Microsoft.OpenApi.OData dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index c3fe239bb..d89cd5026 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -43,7 +43,7 @@ - + From b6a22d52381f6a775c7ae1ddfe53f1ce151d6c4b Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Nov 2022 21:01:40 +0000 Subject: [PATCH 26/36] Bump Verify.Xunit from 18.4.0 to 19.0.0 Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 18.4.0 to 19.0.0. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/commits) --- updated-dependencies: - dependency-name: Verify.Xunit dependency-type: direct:production update-type: version-update:semver-major ... Signed-off-by: dependabot[bot] --- test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj index 666a2b39b..2c3854a74 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -20,7 +20,7 @@ - + all From 8538d192ab23971c99b4c00a8bb85afc5273ece0 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Wed, 9 Nov 2022 21:01:49 +0000 Subject: [PATCH 27/36] Bump Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers Bumps [Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers](https://github.com/dotnet/upgrade-assistant) from 0.4.346202 to 0.4.355802. - [Release notes](https://github.com/dotnet/upgrade-assistant/releases) - [Changelog](https://github.com/dotnet/upgrade-assistant/blob/main/CHANGELOG.md) - [Commits](https://github.com/dotnet/upgrade-assistant/commits) --- updated-dependencies: - dependency-name: Microsoft.DotNet.UpgradeAssistant.Extensions.Default.Analyzers dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- .../Microsoft.OpenApi.Workbench.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj index cf3ff2225..6c6f8cac9 100644 --- a/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj +++ b/src/Microsoft.OpenApi.Workbench/Microsoft.OpenApi.Workbench.csproj @@ -7,7 +7,7 @@ true - + all From fb9633dcdaeec8c483778a497f0f356e05fbb4cd Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 10 Nov 2022 09:00:14 -0500 Subject: [PATCH 28/36] - adds dotnet 6 since ESRP requires it Signed-off-by: Vincent Biret --- .azure-pipelines/ci-build.yml | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) diff --git a/.azure-pipelines/ci-build.yml b/.azure-pipelines/ci-build.yml index 363654179..cc34d8e1f 100644 --- a/.azure-pipelines/ci-build.yml +++ b/.azure-pipelines/ci-build.yml @@ -31,7 +31,12 @@ stages: - job: build steps: - task: UseDotNet@2 - displayName: 'Use .NET' + displayName: 'Use .NET 6' # needed for ESRP signing + inputs: + version: 6.x + + - task: UseDotNet@2 + displayName: 'Use .NET 7' inputs: version: 7.x From 8529c423c9ecf1c3778fda0463b979352f11f772 Mon Sep 17 00:00:00 2001 From: Vincent Biret Date: Thu, 10 Nov 2022 09:42:01 -0500 Subject: [PATCH 29/36] - switches to dotnet 2 to fix ESRP Signed-off-by: Vincent Biret --- .azure-pipelines/ci-build.yml | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/.azure-pipelines/ci-build.yml b/.azure-pipelines/ci-build.yml index cc34d8e1f..4ce92b8e9 100644 --- a/.azure-pipelines/ci-build.yml +++ b/.azure-pipelines/ci-build.yml @@ -31,9 +31,9 @@ stages: - job: build steps: - task: UseDotNet@2 - displayName: 'Use .NET 6' # needed for ESRP signing + displayName: 'Use .NET 2' # needed for ESRP signing inputs: - version: 6.x + version: 2.x - task: UseDotNet@2 displayName: 'Use .NET 7' From b69da0d692d677936dd67327990e8fa7f37b43c4 Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Mon, 14 Nov 2022 21:02:32 +0000 Subject: [PATCH 30/36] Bump Verify.Xunit from 19.0.0 to 19.1.0 Bumps [Verify.Xunit](https://github.com/VerifyTests/Verify) from 19.0.0 to 19.1.0. - [Release notes](https://github.com/VerifyTests/Verify/releases) - [Commits](https://github.com/VerifyTests/Verify/compare/19.0.0...19.1.0) --- updated-dependencies: - dependency-name: Verify.Xunit dependency-type: direct:production update-type: version-update:semver-minor ... Signed-off-by: dependabot[bot] --- test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj index ecd30cfdd..e2a21cc74 100644 --- a/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj +++ b/test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj @@ -20,7 +20,7 @@ - + all From 3a679ddf3419d9d1d7437538b9946b093b09f76e Mon Sep 17 00:00:00 2001 From: "dependabot[bot]" <49699333+dependabot[bot]@users.noreply.github.com> Date: Thu, 17 Nov 2022 21:07:16 +0000 Subject: [PATCH 31/36] Bump Microsoft.OpenApi.OData from 1.2.0-preview7 to 1.2.0-preview8 Bumps [Microsoft.OpenApi.OData](https://github.com/Microsoft/OpenAPI.NET.OData) from 1.2.0-preview7 to 1.2.0-preview8. - [Release notes](https://github.com/Microsoft/OpenAPI.NET.OData/releases) - [Commits](https://github.com/Microsoft/OpenAPI.NET.OData/commits) --- updated-dependencies: - dependency-name: Microsoft.OpenApi.OData dependency-type: direct:production update-type: version-update:semver-patch ... Signed-off-by: dependabot[bot] --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index c7f84666a..03d8c70f0 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -43,7 +43,7 @@ - + From 2d48b610f589a1488f1ddf9ca087b28c6685a592 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Fri, 18 Nov 2022 12:35:54 +0300 Subject: [PATCH 32/36] Adds a flag for identifying whether an external reference is a fragment --- .../V3/OpenApiV3VersionService.cs | 16 ++++++++++------ src/Microsoft.OpenApi/Models/OpenApiReference.cs | 12 +++++++++++- 2 files changed, 21 insertions(+), 7 deletions(-) diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs index 1e729f30a..742b64388 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs @@ -71,6 +71,7 @@ public OpenApiReference ConvertToOpenApiReference( string reference, ReferenceType? type) { + var openApiReference = new OpenApiReference(); if (!string.IsNullOrWhiteSpace(reference)) { var segments = reference.Split('#'); @@ -127,13 +128,16 @@ public OpenApiReference ConvertToOpenApiReference( } id = localSegments[3]; } - - return new OpenApiReference + else { - ExternalResource = segments[0], - Type = type, - Id = id - }; + openApiReference.IsFragrament = true; + } + + openApiReference.ExternalResource = segments[0]; + openApiReference.Type = type; + openApiReference.Id = id; + + return openApiReference; } } diff --git a/src/Microsoft.OpenApi/Models/OpenApiReference.cs b/src/Microsoft.OpenApi/Models/OpenApiReference.cs index ecc643dc3..e8798cc64 100644 --- a/src/Microsoft.OpenApi/Models/OpenApiReference.cs +++ b/src/Microsoft.OpenApi/Models/OpenApiReference.cs @@ -45,6 +45,11 @@ public class OpenApiReference : IOpenApiSerializable /// public bool IsLocal => ExternalResource == null; + /// + /// Gets a flag indicating whether a file is a valid OpenAPI document or a fragment + /// + public bool IsFragrament = false; + /// /// The OpenApiDocument that is hosting the OpenApiReference instance. This is used to enable dereferencing the reference. /// @@ -196,7 +201,12 @@ private string GetExternalReferenceV3() { if (Id != null) { - return ExternalResource + "#/components/" + Type.GetDisplayName() + "/"+ Id; + if (IsFragrament) + { + return ExternalResource + "#" + Id; + } + + return ExternalResource + "#/components/" + Type.GetDisplayName() + "/"+ Id; } return ExternalResource; From 901346c404b711c6b5b85edff35f63c41ada976b Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Fri, 18 Nov 2022 12:36:26 +0300 Subject: [PATCH 33/36] Adds tests to verify external references that are fragments aren't rewritten --- .../Microsoft.OpenApi.Readers.Tests.csproj | 3 +++ .../V3Tests/OpenApiDocumentTests.cs | 20 +++++++++++++++++++ .../documentWithExternalRefs.yaml | 16 +++++++++++++++ 3 files changed, 39 insertions(+) create mode 100644 test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiDocument/documentWithExternalRefs.yaml diff --git a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj index 2e73118b2..b5d1167f3 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj +++ b/test/Microsoft.OpenApi.Readers.Tests/Microsoft.OpenApi.Readers.Tests.csproj @@ -149,6 +149,9 @@ Never + + Never + Never diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs index 6fbb7065a..362609291 100644 --- a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/OpenApiDocumentTests.cs @@ -6,6 +6,7 @@ using System.Globalization; using System.IO; using System.Linq; +using System.Text; using System.Threading; using FluentAssertions; using Microsoft.OpenApi.Any; @@ -1327,5 +1328,24 @@ public void HeaderParameterShouldAllowExample() }); } } + + [Fact] + public void DoesNotChangeExternalReferences() + { + // Arrange + using var stream = Resources.GetStream(Path.Combine(SampleFolderPath, "documentWithExternalRefs.yaml")); + + // Act + var doc = new OpenApiStreamReader( + new OpenApiReaderSettings { ReferenceResolution = ReferenceResolutionSetting.DoNotResolveReferences}) + .Read(stream, out var diagnostic); + + var externalRef = doc.Components.Schemas["Nested"].Properties["AnyOf"].AnyOf.First().Reference.ReferenceV3; + var externalRef2 = doc.Components.Schemas["Nested"].Properties["AnyOf"].AnyOf.Last().Reference.ReferenceV3; + + // Assert + Assert.Equal("file:///C:/MySchemas.json#/definitions/ArrayObject", externalRef); + Assert.Equal("../foo/schemas.yaml#/components/schemas/Number", externalRef2); + } } } diff --git a/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiDocument/documentWithExternalRefs.yaml b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiDocument/documentWithExternalRefs.yaml new file mode 100644 index 000000000..c0b7b3a25 --- /dev/null +++ b/test/Microsoft.OpenApi.Readers.Tests/V3Tests/Samples/OpenApiDocument/documentWithExternalRefs.yaml @@ -0,0 +1,16 @@ + openapi: 3.0.1 + info: + title: anyOf-oneOf + license: + name: MIT + version: 1.0.0 + paths: { } + components: + schemas: + Nested: + type: object + properties: + AnyOf: + anyOf: + - $ref: file:///C:/MySchemas.json#/definitions/ArrayObject + - $ref: ../foo/schemas.yaml#/components/schemas/Number \ No newline at end of file From f73e673ac00b5a1d1e3e9c51bd27c57631f6bbe9 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Fri, 18 Nov 2022 12:57:52 +0300 Subject: [PATCH 34/36] Update public API --- test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt | 1 + 1 file changed, 1 insertion(+) diff --git a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt index 75e12f480..4eb7a060d 100755 --- a/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt +++ b/test/Microsoft.OpenApi.Tests/PublicApi/PublicApi.approved.txt @@ -773,6 +773,7 @@ namespace Microsoft.OpenApi.Models } public class OpenApiReference : Microsoft.OpenApi.Interfaces.IOpenApiElement, Microsoft.OpenApi.Interfaces.IOpenApiSerializable { + public bool IsFragrament; public OpenApiReference() { } public OpenApiReference(Microsoft.OpenApi.Models.OpenApiReference reference) { } public string ExternalResource { get; set; } From 4428e67a9d61c69d9b77bd526e94b6c9ae42c0b7 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Fri, 18 Nov 2022 16:13:22 +0300 Subject: [PATCH 35/36] Move variable declaration closer to assignment --- src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs b/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs index 742b64388..ebe372d40 100644 --- a/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs +++ b/src/Microsoft.OpenApi.Readers/V3/OpenApiV3VersionService.cs @@ -71,7 +71,6 @@ public OpenApiReference ConvertToOpenApiReference( string reference, ReferenceType? type) { - var openApiReference = new OpenApiReference(); if (!string.IsNullOrWhiteSpace(reference)) { var segments = reference.Split('#'); @@ -110,6 +109,8 @@ public OpenApiReference ConvertToOpenApiReference( } // Where fragments point into a non-OpenAPI document, the id will be the complete fragment identifier string id = segments[1]; + var openApiReference = new OpenApiReference(); + // $ref: externalSource.yaml#/Pet if (id.StartsWith("/components/")) { From 5be9a79b48a097fb8e152c30b89e9e947253c4d1 Mon Sep 17 00:00:00 2001 From: Maggie Kimani Date: Mon, 21 Nov 2022 10:30:32 +0300 Subject: [PATCH 36/36] Bump up lib versions from preview to stable releases --- src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj | 2 +- src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj | 2 +- src/Microsoft.OpenApi/Microsoft.OpenApi.csproj | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj index f88e7ed63..da61c969f 100644 --- a/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj +++ b/src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj @@ -15,7 +15,7 @@ Microsoft.OpenApi.Hidi hidi ./../../artifacts - 1.1.0-preview3 + 1.1.0 OpenAPI.NET CLI tool for slicing OpenAPI documents © Microsoft Corporation. All rights reserved. OpenAPI .NET diff --git a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj index d21c300eb..defdfdd54 100644 --- a/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj +++ b/src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj @@ -10,7 +10,7 @@ Microsoft Microsoft.OpenApi.Readers Microsoft.OpenApi.Readers - 1.4.4-preview1 + 1.4.4 OpenAPI.NET Readers for JSON and YAML documents © Microsoft Corporation. All rights reserved. OpenAPI .NET diff --git a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj index 1affa74c6..50d026f91 100644 --- a/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj +++ b/src/Microsoft.OpenApi/Microsoft.OpenApi.csproj @@ -11,7 +11,7 @@ Microsoft Microsoft.OpenApi Microsoft.OpenApi - 1.4.4-preview1 + 1.4.4 .NET models with JSON and YAML writers for OpenAPI specification © Microsoft Corporation. All rights reserved. OpenAPI .NET