Skip to content

Commit 03ff377

Browse files
Merge pull request #979 from microsoft/vnext
Release v1.4.0-preview2
2 parents 35b5282 + 232b45f commit 03ff377

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

46 files changed

+496
-274
lines changed

.github/workflows/docker.yml

+2-2
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,13 @@ jobs:
3030
id: getversion
3131
- name: Push to GitHub Packages - Nightly
3232
if: ${{ github.ref == 'refs/heads/vnext' }}
33-
uses: docker/[email protected].0
33+
uses: docker/[email protected].1
3434
with:
3535
push: true
3636
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:nightly
3737
- name: Push to GitHub Packages - Release
3838
if: ${{ github.ref == 'refs/heads/master' }}
39-
uses: docker/[email protected].0
39+
uses: docker/[email protected].1
4040
with:
4141
push: true
4242
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}:${{ steps.getversion.outputs.version }}

Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
</PropertyGroup>
1010

1111
<ItemGroup>
12-
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0-preview-20220612-01" />
13-
<PackageReference Include="Moq" Version="4.18.1" />
14-
<PackageReference Include="xunit" Version="2.4.2-pre.12" />
12+
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0" />
13+
<PackageReference Include="Moq" Version="4.18.2" />
14+
<PackageReference Include="xunit" Version="2.4.2" />
1515
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
1616
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
1717
<PrivateAssets>all</PrivateAssets>

README.md

+2-2
Original file line numberDiff line numberDiff line change
@@ -21,8 +21,8 @@ Project Objectives
2121

2222
# Installation
2323

24-
- Install core Nuget package `Microsoft.OpenApi`
25-
- Install readers Nuget package `Microsoft.OpenApi.Readers`
24+
- Install core Nuget package [**Microsoft.OpenApi**](https://www.nuget.org/packages/Microsoft.OpenApi)
25+
- Install readers Nuget package [**Microsoft.OpenApi.Readers**](https://www.nuget.org/packages/Microsoft.OpenApi.Readers)
2626

2727
# Processors
2828
The OpenAPI.NET project holds the base object model for representing OpenAPI documents as .NET objects. Some developers have found the need to write processors that convert other data formats into this OpenAPI.NET object model. We'd like to curate that list of processors in this section of the readme.
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,73 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System;
5+
using System.CommandLine;
6+
using System.CommandLine.Invocation;
7+
using System.IO;
8+
using System.Threading;
9+
using System.Threading.Tasks;
10+
using Microsoft.Extensions.Logging;
11+
12+
namespace Microsoft.OpenApi.Hidi.Handlers
13+
{
14+
internal class TransformCommandHandler : ICommandHandler
15+
{
16+
public Option<string> DescriptionOption { get; set; }
17+
public Option<string> CsdlOption { get; set; }
18+
public Option<string> CsdlFilterOption { get; set; }
19+
public Option<FileInfo> OutputOption { get; set; }
20+
public Option<bool> CleanOutputOption { get; set; }
21+
public Option<string?> VersionOption { get; set; }
22+
public Option<OpenApiFormat?> FormatOption { get; set; }
23+
public Option<bool> TerseOutputOption { get; set; }
24+
public Option<LogLevel> LogLevelOption { get; set; }
25+
public Option<string> FilterByOperationIdsOption { get; set; }
26+
public Option<string> FilterByTagsOption { get; set; }
27+
public Option<string> FilterByCollectionOption { get; set; }
28+
public Option<bool> InlineLocalOption { get; set; }
29+
public Option<bool> InlineExternalOption { get; set; }
30+
31+
public int Invoke(InvocationContext context)
32+
{
33+
return InvokeAsync(context).GetAwaiter().GetResult();
34+
}
35+
public async Task<int> InvokeAsync(InvocationContext context)
36+
{
37+
string openapi = context.ParseResult.GetValueForOption(DescriptionOption);
38+
string csdlFilter = context.ParseResult.GetValueForOption(CsdlFilterOption);
39+
string csdl = context.ParseResult.GetValueForOption(CsdlOption);
40+
FileInfo output = context.ParseResult.GetValueForOption(OutputOption);
41+
bool cleanOutput = context.ParseResult.GetValueForOption(CleanOutputOption);
42+
string? version = context.ParseResult.GetValueForOption(VersionOption);
43+
OpenApiFormat? format = context.ParseResult.GetValueForOption(FormatOption);
44+
bool terseOutput = context.ParseResult.GetValueForOption(TerseOutputOption);
45+
LogLevel logLevel = context.ParseResult.GetValueForOption(LogLevelOption);
46+
bool inlineLocal = context.ParseResult.GetValueForOption(InlineLocalOption);
47+
bool inlineExternal = context.ParseResult.GetValueForOption(InlineExternalOption);
48+
string filterbyoperationids = context.ParseResult.GetValueForOption(FilterByOperationIdsOption);
49+
string filterbytags = context.ParseResult.GetValueForOption(FilterByTagsOption);
50+
string filterbycollection = context.ParseResult.GetValueForOption(FilterByCollectionOption);
51+
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetService(typeof(CancellationToken));
52+
53+
using var loggerFactory = Logger.ConfigureLogger(logLevel);
54+
var logger = loggerFactory.CreateLogger<OpenApiService>();
55+
try
56+
{
57+
await OpenApiService.TransformOpenApiDocument(openapi, csdl, csdlFilter, output, cleanOutput, version, format, terseOutput, logLevel, inlineLocal, inlineExternal, filterbyoperationids, filterbytags, filterbycollection, cancellationToken);
58+
59+
return 0;
60+
}
61+
catch (Exception ex)
62+
{
63+
#if DEBUG
64+
logger.LogCritical(ex, ex.Message);
65+
throw; // so debug tools go straight to the source of the exception when attached
66+
#else
67+
logger.LogCritical( ex.Message);
68+
return 1;
69+
#endif
70+
}
71+
}
72+
}
73+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System;
5+
using System.CommandLine;
6+
using System.CommandLine.Invocation;
7+
using System.Threading;
8+
using System.Threading.Tasks;
9+
using Microsoft.Extensions.Logging;
10+
11+
namespace Microsoft.OpenApi.Hidi.Handlers
12+
{
13+
internal class ValidateCommandHandler : ICommandHandler
14+
{
15+
public Option<string> DescriptionOption { get; set; }
16+
public Option<LogLevel> LogLevelOption { get; set; }
17+
18+
public int Invoke(InvocationContext context)
19+
{
20+
return InvokeAsync(context).GetAwaiter().GetResult();
21+
}
22+
public async Task<int> InvokeAsync(InvocationContext context)
23+
{
24+
string openapi = context.ParseResult.GetValueForOption(DescriptionOption);
25+
LogLevel logLevel = context.ParseResult.GetValueForOption(LogLevelOption);
26+
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetService(typeof(CancellationToken));
27+
28+
29+
using var loggerFactory = Logger.ConfigureLogger(logLevel);
30+
var logger = loggerFactory.CreateLogger<OpenApiService>();
31+
try
32+
{
33+
await OpenApiService.ValidateOpenApiDocument(openapi, logLevel, cancellationToken);
34+
return 0;
35+
}
36+
catch (Exception ex)
37+
{
38+
#if DEBUG
39+
logger.LogCritical(ex, ex.Message);
40+
throw; // so debug tools go straight to the source of the exception when attached
41+
#else
42+
logger.LogCritical( ex.Message);
43+
return 1;
44+
#endif
45+
}
46+
}
47+
}
48+
}

src/Microsoft.OpenApi.Hidi/Logger.cs

+31
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,31 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using Microsoft.Extensions.Logging;
5+
6+
namespace Microsoft.OpenApi.Hidi
7+
{
8+
public class Logger
9+
{
10+
public static ILoggerFactory ConfigureLogger(LogLevel logLevel)
11+
{
12+
// Configure logger options
13+
#if DEBUG
14+
logLevel = logLevel > LogLevel.Debug ? LogLevel.Debug : logLevel;
15+
#endif
16+
17+
return LoggerFactory.Create((builder) =>
18+
{
19+
builder
20+
.AddSimpleConsole(c =>
21+
{
22+
c.IncludeScopes = true;
23+
})
24+
#if DEBUG
25+
.AddDebug()
26+
#endif
27+
.SetMinimumLevel(logLevel);
28+
});
29+
}
30+
}
31+
}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -41,8 +41,8 @@
4141
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="6.0.1" />
4242
<PackageReference Include="Microsoft.Extensions.Logging.Console" Version="6.0.0" />
4343
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
44-
<PackageReference Include="System.CommandLine" Version="2.0.0-beta3.22114.1" />
45-
<PackageReference Include="Microsoft.OData.Edm" Version="7.12.1" />
44+
<PackageReference Include="System.CommandLine" Version="2.0.0-beta4.22272.1" />
45+
<PackageReference Include="Microsoft.OData.Edm" Version="7.12.2" />
4646
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.0.11" />
4747
</ItemGroup>
4848

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

+11-29
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System;
@@ -26,7 +26,6 @@
2626
using System.Threading;
2727
using System.Xml.Xsl;
2828
using System.Xml;
29-
using System.Runtime.CompilerServices;
3029
using System.Reflection;
3130

3231
namespace Microsoft.OpenApi.Hidi
@@ -36,7 +35,7 @@ public class OpenApiService
3635
/// <summary>
3736
/// Implementation of the transform command
3837
/// </summary>
39-
public static async Task<int> TransformOpenApiDocument(
38+
public static async Task TransformOpenApiDocument(
4039
string openapi,
4140
string csdl,
4241
string csdlFilter,
@@ -45,7 +44,7 @@ public static async Task<int> TransformOpenApiDocument(
4544
string? version,
4645
OpenApiFormat? format,
4746
bool terseOutput,
48-
LogLevel loglevel,
47+
LogLevel logLevel,
4948
bool inlineLocal,
5049
bool inlineExternal,
5150
string filterbyoperationids,
@@ -54,9 +53,8 @@ public static async Task<int> TransformOpenApiDocument(
5453
CancellationToken cancellationToken
5554
)
5655
{
57-
using var loggerFactory = ConfigureLoggerInstance(loglevel);
56+
using var loggerFactory = Logger.ConfigureLogger(logLevel);
5857
var logger = loggerFactory.CreateLogger<OpenApiService>();
59-
6058
try
6159
{
6260
if (string.IsNullOrEmpty(openapi) && string.IsNullOrEmpty(csdl))
@@ -213,18 +211,11 @@ CancellationToken cancellationToken
213211
logger.LogTrace($"Finished serializing in {stopwatch.ElapsedMilliseconds}ms");
214212
textWriter.Flush();
215213
}
216-
return 0;
217214
}
218215
catch (Exception ex)
219216
{
220-
#if DEBUG
221-
logger.LogCritical(ex, ex.Message);
222-
#else
223-
logger.LogCritical(ex.Message);
224-
225-
#endif
226-
return 1;
227-
}
217+
throw new InvalidOperationException($"Could not transform the document, reason: {ex.Message}", ex);
218+
}
228219
}
229220

230221
private static XslCompiledTransform GetFilterTransform()
@@ -253,14 +244,13 @@ private static Stream ApplyFilter(string csdl, string entitySetOrSingleton, XslC
253244
/// <summary>
254245
/// Implementation of the validate command
255246
/// </summary>
256-
public static async Task<int> ValidateOpenApiDocument(
247+
public static async Task ValidateOpenApiDocument(
257248
string openapi,
258-
LogLevel loglevel,
249+
LogLevel logLevel,
259250
CancellationToken cancellationToken)
260251
{
261-
using var loggerFactory = ConfigureLoggerInstance(loglevel);
252+
using var loggerFactory = Logger.ConfigureLogger(logLevel);
262253
var logger = loggerFactory.CreateLogger<OpenApiService>();
263-
264254
try
265255
{
266256
if (string.IsNullOrEmpty(openapi))
@@ -307,19 +297,11 @@ public static async Task<int> ValidateOpenApiDocument(
307297
logger.LogTrace("Finished walking through the OpenApi document. Generating a statistics report..");
308298
logger.LogInformation(statsVisitor.GetStatisticsReport());
309299
}
310-
311-
return 0;
312300
}
313301
catch (Exception ex)
314302
{
315-
#if DEBUG
316-
logger.LogCritical(ex, ex.Message);
317-
#else
318-
logger.LogCritical(ex.Message);
319-
#endif
320-
return 1;
303+
throw new InvalidOperationException($"Could not validate the document, reason: {ex.Message}", ex);
321304
}
322-
323305
}
324306

325307
/// <summary>
@@ -596,7 +578,7 @@ private static ILoggerFactory ConfigureLoggerInstance(LogLevel loglevel)
596578
loglevel = loglevel > LogLevel.Debug ? LogLevel.Debug : loglevel;
597579
#endif
598580

599-
return LoggerFactory.Create((builder) => {
581+
return Microsoft.Extensions.Logging.LoggerFactory.Create((builder) => {
600582
builder
601583
.AddSimpleConsole(c => {
602584
c.IncludeScopes = true;

src/Microsoft.OpenApi.Hidi/Program.cs

+23-5
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,11 @@
11
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

4-
using System;
54
using System.CommandLine;
65
using System.IO;
7-
using System.Threading;
86
using System.Threading.Tasks;
97
using Microsoft.Extensions.Logging;
8+
using Microsoft.OpenApi.Hidi.Handlers;
109

1110
namespace Microsoft.OpenApi.Hidi
1211
{
@@ -66,7 +65,11 @@ static async Task Main(string[] args)
6665
logLevelOption
6766
};
6867

69-
validateCommand.SetHandler<string, LogLevel, CancellationToken>(OpenApiService.ValidateOpenApiDocument, descriptionOption, logLevelOption);
68+
validateCommand.Handler = new ValidateCommandHandler
69+
{
70+
DescriptionOption = descriptionOption,
71+
LogLevelOption = logLevelOption
72+
};
7073

7174
var transformCommand = new Command("transform")
7275
{
@@ -86,8 +89,23 @@ static async Task Main(string[] args)
8689
inlineExternalOption
8790
};
8891

89-
transformCommand.SetHandler<string, string, string, FileInfo, bool, string?, OpenApiFormat?, bool, LogLevel, bool, bool, string, string, string, CancellationToken> (
90-
OpenApiService.TransformOpenApiDocument, descriptionOption, csdlOption, csdlFilterOption, outputOption, cleanOutputOption, versionOption, formatOption, terseOutputOption, logLevelOption, inlineLocalOption, inlineExternalOption, filterByOperationIdsOption, filterByTagsOption, filterByCollectionOption);
92+
transformCommand.Handler = new TransformCommandHandler
93+
{
94+
DescriptionOption = descriptionOption,
95+
CsdlOption = csdlOption,
96+
CsdlFilterOption = csdlFilterOption,
97+
OutputOption = outputOption,
98+
CleanOutputOption = cleanOutputOption,
99+
VersionOption = versionOption,
100+
FormatOption = formatOption,
101+
TerseOutputOption = terseOutputOption,
102+
LogLevelOption = logLevelOption,
103+
FilterByOperationIdsOption = filterByOperationIdsOption,
104+
FilterByTagsOption = filterByTagsOption,
105+
FilterByCollectionOption = filterByCollectionOption,
106+
InlineLocalOption = inlineLocalOption,
107+
InlineExternalOption = inlineExternalOption
108+
};
91109

92110
rootCommand.Add(transformCommand);
93111
rootCommand.Add(validateCommand);

src/Microsoft.OpenApi.Readers/Microsoft.OpenApi.Readers.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<Company>Microsoft</Company>
1111
<Title>Microsoft.OpenApi.Readers</Title>
1212
<PackageId>Microsoft.OpenApi.Readers</PackageId>
13-
<Version>1.4.0-preview1</Version>
13+
<Version>1.4.0-preview2</Version>
1414
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
1515
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1616
<PackageTags>OpenAPI .NET</PackageTags>

src/Microsoft.OpenApi/Attributes/DisplayAttribute.cs

+1-1
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ namespace Microsoft.OpenApi.Attributes
99
/// Represents the Open Api Data type metadata attribute.
1010
/// </summary>
1111
[AttributeUsage(AttributeTargets.Property | AttributeTargets.Field)]
12-
internal class DisplayAttribute : Attribute
12+
public class DisplayAttribute : Attribute
1313
{
1414
/// <summary>
1515
/// Initializes a new instance of the <see cref="DisplayAttribute"/> class.

src/Microsoft.OpenApi/Microsoft.OpenApi.csproj

+1-1
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
<Company>Microsoft</Company>
1212
<Title>Microsoft.OpenApi</Title>
1313
<PackageId>Microsoft.OpenApi</PackageId>
14-
<Version>1.4.0-preview1</Version>
14+
<Version>1.4.0-preview2</Version>
1515
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
1616
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
1717
<PackageTags>OpenAPI .NET</PackageTags>

0 commit comments

Comments
 (0)