Skip to content

Commit

Permalink
Address PR feedback
Browse files Browse the repository at this point in the history
  • Loading branch information
MaggieKimani1 committed Nov 8, 2022
1 parent 568cf91 commit ec05eca
Show file tree
Hide file tree
Showing 4 changed files with 48 additions and 47 deletions.
8 changes: 8 additions & 0 deletions src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -52,4 +52,12 @@
<ProjectReference Include="..\Microsoft.OpenApi\Microsoft.OpenApi.csproj" />
</ItemGroup>

<!-- Make internals available for Unit Testing -->
<ItemGroup>
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
<_Parameter1>Microsoft.OpenApi.Hidi.Tests</_Parameter1>
</AssemblyAttribute>
</ItemGroup>
<!-- End Unit test Internals -->

</Project>
48 changes: 24 additions & 24 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@
using System.Xml;
using System.Reflection;
using Microsoft.Extensions.Configuration;
using System.Runtime.CompilerServices;

namespace Microsoft.OpenApi.Hidi
{
Expand Down Expand Up @@ -307,7 +308,7 @@ public static async Task ValidateOpenApiDocument(
}
}

public static IConfiguration GetConfiguration(string settingsFile)
internal static IConfiguration GetConfiguration(string settingsFile)
{
settingsFile ??= "appsettings.json";

Expand All @@ -317,7 +318,7 @@ public static IConfiguration GetConfiguration(string settingsFile)

return config;
}

/// <summary>
/// Converts CSDL to OpenAPI
/// </summary>
Expand All @@ -330,28 +331,27 @@ public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl, stri
var edmModel = CsdlReader.Parse(XElement.Parse(csdlText).CreateReader());

var config = GetConfiguration(settingsFile);
var settings = config.GetSection("OpenApiConvertSettings").Get<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
};
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);

Expand Down
15 changes: 2 additions & 13 deletions src/Microsoft.OpenApi.Hidi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -47,8 +47,8 @@ static async Task Main(string[] args)
var terseOutputOption = new Option<bool>("--terse-output", "Produce terse json output");
terseOutputOption.AddAlias("--to");

var settingsFileOption = new Option<string>("--settingsFile", "The configuration file with CSDL conversion settings.");
settingsFileOption.AddAlias("--sf");
var settingsFileOption = new Option<string>("--settings-path", "The configuration file with CSDL conversion settings.");
settingsFileOption.AddAlias("--sp");

var logLevelOption = new Option<LogLevel>("--log-level", () => LogLevel.Information, "The log level to use when logging messages to the main output.");
logLevelOption.AddAlias("--ll");
Expand Down Expand Up @@ -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<IConfiguration>();
// })
// .UseDefaults()
// .Build()
// .InvokeAsync(args);

//// Wait for logger to write messages to the console before exiting
await Task.Delay(10);
}
Expand Down
24 changes: 14 additions & 10 deletions test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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<OpenApiConvertSettings>();

// Assert
Assert.NotNull(settings);
if (filePath == null)
{
Assert.Null(settings);
}
else
{
Assert.NotNull(settings);
}
}
}
}

0 comments on commit ec05eca

Please sign in to comment.