Skip to content

Commit 9552a32

Browse files
committed
Updated from vnext
2 parents 89cc609 + 5c849a2 commit 9552a32

26 files changed

+1443
-224
lines changed

.azure-pipelines/ci-build.yml

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@ steps:
3030
inputs:
3131
testAssemblyVer2: |
3232
**\*.Tests.dll
33-
33+
3434
vsTestVersion: 16.0
3535
codeCoverageEnabled: true
3636

@@ -94,6 +94,13 @@ steps:
9494
configuration: Release
9595
msbuildArguments: '/t:pack /p:PackageOutputPath=$(Build.ArtifactStagingDirectory) /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg'
9696

97+
- task: MSBuild@1
98+
displayName: 'Pack OpenApi Hidi'
99+
inputs:
100+
solution: src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
101+
configuration: Release
102+
msbuildArguments: '/t:pack /p:PackageOutputPath=$(Build.ArtifactStagingDirectory) /p:IncludeSymbols=true /p:SymbolPackageFormat=snupkg'
103+
97104
- task: SFP.build-tasks.custom-build-task-1.EsrpCodeSigning@1
98105
displayName: 'ESRP CodeSigning Nuget Packages'
99106
inputs:

.github/workflows/ci-cd.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -62,7 +62,7 @@ jobs:
6262
$projectsArray = @(
6363
'.\src\Microsoft.OpenApi\Microsoft.OpenApi.csproj',
6464
'.\src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj',
65-
'.\src\Microsoft.OpenApi.Tool\Microsoft.OpenApi.Tool.csproj'
65+
'.\src\Microsoft.OpenApi.Hidi\Microsoft.OpenApi.Hidi.csproj'
6666
)
6767
$gitNewVersion = if ("${{ steps.tag_generator.outputs.new_version }}") {"${{ steps.tag_generator.outputs.new_version }}"} else {$null}
6868
$projectCurrentVersion = ([xml](Get-Content .\src\Microsoft.OpenApi\Microsoft.OpenApi.csproj)).Project.PropertyGroup.Version

.github/workflows/codeql-analysis.yml

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@ name: CodeQL Analysis
22

33
on:
44
push:
5+
branches: [ vnext ]
56
pull_request:
67
schedule:
78
- cron: '0 8 * * *'
@@ -33,7 +34,7 @@ jobs:
3334
$projectsArray = @(
3435
'.\src\Microsoft.OpenApi\Microsoft.OpenApi.csproj',
3536
'.\src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj',
36-
'.\src\Microsoft.OpenApi.Tool\Microsoft.OpenApi.Tool.csproj'
37+
'.\src\Microsoft.OpenApi.Hidi\Microsoft.OpenApi.Hidi.csproj'
3738
)
3839
3940
$projectsArray | ForEach-Object {

.vscode/launch.json

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010
"request": "launch",
1111
"preLaunchTask": "build",
1212
// If you have changed target frameworks, make sure to update the program path.
13-
"program": "${workspaceFolder}/src/Microsoft.OpenApi.Tool/bin/Debug/netcoreapp3.1/Microsoft.OpenApi.Tool.dll",
13+
"program": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi/bin/Debug/netcoreapp3.1/Microsoft.OpenApi.Hidi.dll",
1414
"args": [],
15-
"cwd": "${workspaceFolder}/src/Microsoft.OpenApi.Tool",
15+
"cwd": "${workspaceFolder}/src/Microsoft.OpenApi.Hidi",
1616
// For more information about the 'console' field, see https://aka.ms/VSCode-CS-LaunchJson-Console
1717
"console": "internalConsole",
1818
"stopAtEntry": false

Microsoft.OpenApi.sln

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,7 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "test", "test", "{6357D7FD-2
2626
EndProject
2727
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.SmokeTests", "test\Microsoft.OpenApi.SmokeTests\Microsoft.OpenApi.SmokeTests.csproj", "{AD79B61D-88CF-497C-9ED5-41AE3867C5AC}"
2828
EndProject
29-
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.Tool", "src\Microsoft.OpenApi.Tool\Microsoft.OpenApi.Tool.csproj", "{254841B5-7DAC-4D1D-A9C5-44FE5CE467BE}"
29+
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.Hidi", "src\Microsoft.OpenApi.Hidi\Microsoft.OpenApi.Hidi.csproj", "{254841B5-7DAC-4D1D-A9C5-44FE5CE467BE}"
3030
EndProject
3131
Global
3232
GlobalSection(SolutionConfigurationPlatforms) = preSolution

build.cmd

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,21 @@
11
@echo off
2-
Echo Building Microsoft.OpenApi
2+
Echo Building Microsoft.OpenApi
33

4-
SET PROJ=%~dp0src\Microsoft.OpenApi\Microsoft.OpenApi.csproj
4+
SET PROJ=%~dp0src\Microsoft.OpenApi\Microsoft.OpenApi.csproj
55
dotnet msbuild %PROJ% /t:restore /p:Configuration=Release
66
dotnet msbuild %PROJ% /t:build /p:Configuration=Release
77
dotnet msbuild %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts
88

99
Echo Building Microsoft.OpenApi.Readers
1010

11-
SET PROJ=%~dp0src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj
11+
SET PROJ=%~dp0src\Microsoft.OpenApi.Readers\Microsoft.OpenApi.Readers.csproj
1212
dotnet msbuild %PROJ% /t:restore /p:Configuration=Release
1313
dotnet msbuild %PROJ% /t:build /p:Configuration=Release
1414
dotnet msbuild %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts
1515

16-
Echo Building Microsoft.OpenApi.Tool
16+
Echo Building Microsoft.OpenApi.Hidi
1717

18-
SET PROJ=%~dp0src\Microsoft.OpenApi.Tool\Microsoft.OpenApi.Tool.csproj
18+
SET PROJ=%~dp0src\Microsoft.OpenApi.Hidi\Microsoft.OpenApi.Hidi.csproj
1919
dotnet msbuild %PROJ% /t:restore /p:Configuration=Release
2020
dotnet msbuild %PROJ% /t:build /p:Configuration=Release
2121
dotnet msbuild %PROJ% /t:pack /p:Configuration=Release;PackageOutputPath=%~dp0artifacts

install-tool.ps1

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
$latest = Get-ChildItem .\artifacts\ Microsoft.OpenApi.Tool* | select-object -Last 1
1+
$latest = Get-ChildItem .\artifacts\Microsoft.OpenApi.Hidi* | select-object -Last 1
22
$version = $latest.Name.Split(".")[3..5] | join-string -Separator "."
33

4-
if (Test-Path -Path ./artifacts/openapi-parser.exe) {
5-
dotnet tool uninstall --tool-path artifacts Microsoft.OpenApi.Tool
4+
if (Test-Path -Path ./artifacts/hidi.exe) {
5+
dotnet tool uninstall --tool-path artifacts Microsoft.OpenApi.Hidi
66
}
7-
dotnet tool install --tool-path artifacts --add-source .\artifacts\ --version $version Microsoft.OpenApi.Tool
7+
dotnet tool install --tool-path artifacts --add-source .\artifacts\ --version $version Microsoft.OpenApi.Hidi

src/Microsoft.OpenApi.Tool/Microsoft.OpenApi.Tool.csproj renamed to src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,9 +4,9 @@
44
<OutputType>Exe</OutputType>
55
<TargetFramework>netcoreapp3.1</TargetFramework>
66
<PackAsTool>true</PackAsTool>
7-
<ToolCommandName>openapi-parser</ToolCommandName>
7+
<ToolCommandName>hidi</ToolCommandName>
88
<PackageOutputPath>./../../artifacts</PackageOutputPath>
9-
<Version>1.3.0-preview</Version>
9+
<Version>0.5.0-preview</Version>
1010
</PropertyGroup>
1111

1212
<ItemGroup>

src/Microsoft.OpenApi.Tool/OpenApiService.cs renamed to src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 52 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
1-
using System;
2-
using System.Collections.Generic;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System;
35
using System.IO;
46
using System.Linq;
57
using System.Net;
@@ -13,7 +15,7 @@
1315
using Microsoft.OpenApi.Validations;
1416
using Microsoft.OpenApi.Writers;
1517

16-
namespace Microsoft.OpenApi.Tool
18+
namespace Microsoft.OpenApi.Hidi
1719
{
1820
static class OpenApiService
1921
{
@@ -22,12 +24,22 @@ public static void ProcessOpenApiDocument(
2224
FileInfo output,
2325
OpenApiSpecVersion version,
2426
OpenApiFormat format,
27+
string filterByOperationIds,
28+
string filterByTags,
2529
bool inline,
2630
bool resolveExternal)
2731
{
28-
if (input == null)
32+
if (string.IsNullOrEmpty(input))
2933
{
30-
throw new ArgumentNullException("input");
34+
throw new ArgumentNullException(nameof(input));
35+
}
36+
if(output == null)
37+
{
38+
throw new ArgumentException(nameof(output));
39+
}
40+
if (output.Exists)
41+
{
42+
throw new IOException("The file you're writing to already exists. Please input a new output path.");
3143
}
3244

3345
var inputUrl = GetInputUrl(input);
@@ -43,10 +55,29 @@ public static void ProcessOpenApiDocument(
4355
}
4456
).ReadAsync(stream).GetAwaiter().GetResult();
4557

58+
OpenApiDocument document;
4659
document = result.OpenApiDocument;
60+
61+
// Check if filter options are provided, then execute
62+
if (!string.IsNullOrEmpty(filterByOperationIds) && !string.IsNullOrEmpty(filterByTags))
63+
{
64+
throw new InvalidOperationException("Cannot filter by operationIds and tags at the same time.");
65+
}
66+
67+
if (!string.IsNullOrEmpty(filterByOperationIds))
68+
{
69+
var predicate = OpenApiFilterService.CreatePredicate(operationIds: filterByOperationIds);
70+
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
71+
}
72+
if (!string.IsNullOrEmpty(filterByTags))
73+
{
74+
var predicate = OpenApiFilterService.CreatePredicate(tags: filterByTags);
75+
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
76+
}
77+
4778
var context = result.OpenApiDiagnostic;
4879

49-
if (context.Errors.Count != 0)
80+
if (context.Errors.Count > 0)
5081
{
5182
var errorReport = new StringBuilder();
5283

@@ -55,43 +86,26 @@ public static void ProcessOpenApiDocument(
5586
errorReport.AppendLine(error.ToString());
5687
}
5788

58-
throw new ArgumentException(String.Join(Environment.NewLine, context.Errors.Select(e => e.Message).ToArray()));
89+
throw new ArgumentException(string.Join(Environment.NewLine, context.Errors.Select(e => e.Message).ToArray()));
5990
}
6091

61-
using (var outputStream = output?.Create())
62-
{
63-
TextWriter textWriter;
92+
using var outputStream = output?.Create();
6493

65-
if (outputStream != null)
66-
{
67-
textWriter = new StreamWriter(outputStream);
68-
}
69-
else
70-
{
71-
textWriter = Console.Out;
72-
}
94+
var textWriter = outputStream != null ? new StreamWriter(outputStream) : Console.Out;
7395

74-
var settings = new OpenApiWriterSettings()
75-
{
76-
ReferenceInline = inline == true ? ReferenceInlineSetting.InlineLocalReferences : ReferenceInlineSetting.DoNotInlineReferences
77-
};
78-
IOpenApiWriter writer;
79-
switch (format)
80-
{
81-
case OpenApiFormat.Json:
82-
writer = new OpenApiJsonWriter(textWriter, settings);
83-
break;
84-
case OpenApiFormat.Yaml:
85-
writer = new OpenApiYamlWriter(textWriter, settings);
86-
break;
87-
default:
88-
throw new ArgumentException("Unknown format");
89-
}
90-
91-
document.Serialize(writer, version);
96+
var settings = new OpenApiWriterSettings()
97+
{
98+
ReferenceInline = inline ? ReferenceInlineSetting.InlineLocalReferences : ReferenceInlineSetting.DoNotInlineReferences
99+
};
100+
IOpenApiWriter writer = format switch
101+
{
102+
OpenApiFormat.Json => new OpenApiJsonWriter(textWriter, settings),
103+
OpenApiFormat.Yaml => new OpenApiYamlWriter(textWriter, settings),
104+
_ => throw new ArgumentException("Unknown format"),
105+
};
106+
document.Serialize(writer, version);
92107

93-
textWriter.Flush();
94-
}
108+
textWriter.Flush();
95109
}
96110

97111
private static Uri GetInputUrl(string input)

src/Microsoft.OpenApi.Tool/Program.cs renamed to src/Microsoft.OpenApi.Hidi/Program.cs

Lines changed: 9 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,15 @@
1-
using System;
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
24
using System.CommandLine;
35
using System.CommandLine.Invocation;
46
using System.IO;
57
using System.Threading.Tasks;
6-
using Microsoft.OpenApi;
78

8-
namespace Microsoft.OpenApi.Tool
9+
namespace Microsoft.OpenApi.Hidi
910
{
10-
class Program
11+
static class Program
1112
{
12-
static async Task<int> OldMain(string[] args)
13-
{
14-
15-
var command = new RootCommand
16-
{
17-
new Option("--input", "Input OpenAPI description file path or URL", typeof(string) ),
18-
new Option("--output","Output OpenAPI description file", typeof(FileInfo), arity: ArgumentArity.ZeroOrOne),
19-
new Option("--version", "OpenAPI specification version", typeof(OpenApiSpecVersion)),
20-
new Option("--format", "File format",typeof(OpenApiFormat) ),
21-
new Option("--inline", "Inline $ref instances", typeof(bool) ),
22-
new Option("--resolveExternal","Resolve external $refs", typeof(bool))
23-
};
24-
25-
command.Handler = CommandHandler.Create<string,FileInfo,OpenApiSpecVersion,OpenApiFormat,bool, bool>(
26-
OpenApiService.ProcessOpenApiDocument);
27-
28-
// Parse the incoming args and invoke the handler
29-
return await command.InvokeAsync(args);
30-
}
31-
3213
static async Task<int> Main(string[] args)
3314
{
3415
var rootCommand = new RootCommand() {
@@ -48,9 +29,11 @@ static async Task<int> Main(string[] args)
4829
new Option("--version", "OpenAPI specification version", typeof(OpenApiSpecVersion)),
4930
new Option("--format", "File format",typeof(OpenApiFormat) ),
5031
new Option("--inline", "Inline $ref instances", typeof(bool) ),
51-
new Option("--resolveExternal","Resolve external $refs", typeof(bool))
32+
new Option("--resolveExternal","Resolve external $refs", typeof(bool)),
33+
new Option("--filterByOperationIds", "Filters OpenApiDocument by OperationId(s) provided", typeof(string)),
34+
new Option("--filterByTags", "Filters OpenApiDocument by Tag(s) provided", typeof(string))
5235
};
53-
transformCommand.Handler = CommandHandler.Create<string, FileInfo, OpenApiSpecVersion, OpenApiFormat, bool, bool>(
36+
transformCommand.Handler = CommandHandler.Create<string, FileInfo, OpenApiSpecVersion, OpenApiFormat, string, string, bool, bool>(
5437
OpenApiService.ProcessOpenApiDocument);
5538

5639
rootCommand.Add(transformCommand);

0 commit comments

Comments
 (0)