Skip to content

Commit ec05eca

Browse files
committed
Address PR feedback
1 parent 568cf91 commit ec05eca

File tree

4 files changed

+48
-47
lines changed

4 files changed

+48
-47
lines changed

src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,4 +52,12 @@
5252
<ProjectReference Include="..\Microsoft.OpenApi\Microsoft.OpenApi.csproj" />
5353
</ItemGroup>
5454

55+
<!-- Make internals available for Unit Testing -->
56+
<ItemGroup>
57+
<AssemblyAttribute Include="System.Runtime.CompilerServices.InternalsVisibleTo">
58+
<_Parameter1>Microsoft.OpenApi.Hidi.Tests</_Parameter1>
59+
</AssemblyAttribute>
60+
</ItemGroup>
61+
<!-- End Unit test Internals -->
62+
5563
</Project>

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
using System.Xml;
2929
using System.Reflection;
3030
using Microsoft.Extensions.Configuration;
31+
using System.Runtime.CompilerServices;
3132

3233
namespace Microsoft.OpenApi.Hidi
3334
{
@@ -307,7 +308,7 @@ public static async Task ValidateOpenApiDocument(
307308
}
308309
}
309310

310-
public static IConfiguration GetConfiguration(string settingsFile)
311+
internal static IConfiguration GetConfiguration(string settingsFile)
311312
{
312313
settingsFile ??= "appsettings.json";
313314

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

318319
return config;
319320
}
320-
321+
321322
/// <summary>
322323
/// Converts CSDL to OpenAPI
323324
/// </summary>
@@ -330,28 +331,27 @@ public static async Task<OpenApiDocument> ConvertCsdlToOpenApi(Stream csdl, stri
330331
var edmModel = CsdlReader.Parse(XElement.Parse(csdlText).CreateReader());
331332

332333
var config = GetConfiguration(settingsFile);
333-
var settings = config.GetSection("OpenApiConvertSettings").Get<OpenApiConvertSettings>();
334-
335-
settings ??= new OpenApiConvertSettings()
336-
{
337-
AddSingleQuotesForStringParameters = true,
338-
AddEnumDescriptionExtension = true,
339-
DeclarePathParametersOnPathItem = true,
340-
EnableKeyAsSegment = true,
341-
EnableOperationId = true,
342-
ErrorResponsesAsDefault = false,
343-
PrefixEntityTypeNameBeforeKey = true,
344-
TagDepth = 2,
345-
EnablePagination = true,
346-
EnableDiscriminatorValue = true,
347-
EnableDerivedTypesReferencesForRequestBody = false,
348-
EnableDerivedTypesReferencesForResponses = false,
349-
ShowRootPath = false,
350-
ShowLinks = false,
351-
ExpandDerivedTypesNavigationProperties = false,
352-
EnableCount = true,
353-
UseSuccessStatusCodeRange = true
354-
};
334+
var settings = new OpenApiConvertSettings()
335+
{
336+
AddSingleQuotesForStringParameters = true,
337+
AddEnumDescriptionExtension = true,
338+
DeclarePathParametersOnPathItem = true,
339+
EnableKeyAsSegment = true,
340+
EnableOperationId = true,
341+
ErrorResponsesAsDefault = false,
342+
PrefixEntityTypeNameBeforeKey = true,
343+
TagDepth = 2,
344+
EnablePagination = true,
345+
EnableDiscriminatorValue = true,
346+
EnableDerivedTypesReferencesForRequestBody = false,
347+
EnableDerivedTypesReferencesForResponses = false,
348+
ShowRootPath = false,
349+
ShowLinks = false,
350+
ExpandDerivedTypesNavigationProperties = false,
351+
EnableCount = true,
352+
UseSuccessStatusCodeRange = true
353+
};
354+
config.GetSection("OpenApiConvertSettings").Bind(settings);
355355

356356
OpenApiDocument document = edmModel.ConvertToOpenApi(settings);
357357

src/Microsoft.OpenApi.Hidi/Program.cs

Lines changed: 2 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -47,8 +47,8 @@ static async Task Main(string[] args)
4747
var terseOutputOption = new Option<bool>("--terse-output", "Produce terse json output");
4848
terseOutputOption.AddAlias("--to");
4949

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

5353
var logLevelOption = new Option<LogLevel>("--log-level", () => LogLevel.Information, "The log level to use when logging messages to the main output.");
5454
logLevelOption.AddAlias("--ll");
@@ -121,20 +121,9 @@ static async Task Main(string[] args)
121121
rootCommand.Add(transformCommand);
122122
rootCommand.Add(validateCommand);
123123

124-
125124
// Parse the incoming args and invoke the handler
126125
await rootCommand.InvokeAsync(args);
127126

128-
129-
//await new CommandLineBuilder(rootCommand)
130-
// .UseHost(_ => Host.CreateDefaultBuilder(),
131-
// host => {
132-
// var config = host.Services.GetRequiredService<IConfiguration>();
133-
// })
134-
// .UseDefaults()
135-
// .Build()
136-
// .InvokeAsync(args);
137-
138127
//// Wait for logger to write messages to the console before exiting
139128
await Task.Delay(10);
140129
}

test/Microsoft.OpenApi.Hidi.Tests/Services/OpenApiServiceTests.cs

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,6 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
using System;
5-
using System.IO;
6-
using System.Threading.Tasks;
74
using Microsoft.Extensions.Configuration;
85
using Microsoft.OpenApi.Hidi;
96
using Microsoft.OpenApi.OData;
@@ -54,18 +51,25 @@ public async Task ReturnFilteredOpenApiDocBasedOnOperationIdsAndInputCsdlDocumen
5451
Assert.Equal(expectedPathCount, subsetOpenApiDocument.Paths.Count);
5552
}
5653

57-
[Fact]
58-
public void ReturnOpenApiConvertSettings()
54+
[Theory]
55+
[InlineData("UtilityFiles/appsettingstest.json")]
56+
[InlineData(null)]
57+
public void ReturnOpenApiConvertSettingsWhenSettingsFileIsProvided(string filePath)
5958
{
6059
// Arrange
61-
var filePath = "C:/Users/v-makim/source/repos/OpenAPI.NET/test/Microsoft.OpenApi.Hidi.Tests/UtilityFiles/appsettingstest.json";
6260
var config = OpenApiService.GetConfiguration(filePath);
63-
64-
// Act
61+
62+
// Act and Assert
6563
var settings = config.GetSection("OpenApiConvertSettings").Get<OpenApiConvertSettings>();
6664

67-
// Assert
68-
Assert.NotNull(settings);
65+
if (filePath == null)
66+
{
67+
Assert.Null(settings);
68+
}
69+
else
70+
{
71+
Assert.NotNull(settings);
72+
}
6973
}
7074
}
7175
}

0 commit comments

Comments
 (0)