Skip to content

Commit 387a256

Browse files
authored
Merge branch 'vnext' into vnext
2 parents 549111a + c147547 commit 387a256

File tree

148 files changed

+4071
-2662
lines changed

Some content is hidden

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

148 files changed

+4071
-2662
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: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ jobs:
4949
- if: steps.conditionals_handler.outputs.is_default_branch == 'true'
5050
name: Bump GH tag
5151
id: tag_generator
52-
uses: mathieudutour/github-tag-action@v5.4
52+
uses: mathieudutour/github-tag-action@v6.0
5353
with:
5454
github_token: ${{ secrets.GITHUB_TOKEN }}
5555
default_bump: false
@@ -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/Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,6 @@
33
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
44
</PropertyGroup>
55
<ItemGroup>
6-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-*" PrivateAssets="All"/>
6+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1-*" PrivateAssets="All"/>
77
</ItemGroup>
88
</Project>

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

Lines changed: 3 additions & 3 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>
@@ -19,7 +19,7 @@
1919
</ItemGroup>
2020

2121
<ItemGroup>
22-
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.0-beta-20204-02" />
22+
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
2323
</ItemGroup>
2424

2525
</Project>

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

Lines changed: 53 additions & 43 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;
@@ -12,7 +14,7 @@
1214
using Microsoft.OpenApi.Validations;
1315
using Microsoft.OpenApi.Writers;
1416

15-
namespace Microsoft.OpenApi.Tool
17+
namespace Microsoft.OpenApi.Hidi
1618
{
1719
static class OpenApiService
1820
{
@@ -21,29 +23,55 @@ public static void ProcessOpenApiDocument(
2123
FileInfo output,
2224
OpenApiSpecVersion version,
2325
OpenApiFormat format,
26+
string filterByOperationIds,
27+
string filterByTags,
2428
bool inline,
2529
bool resolveExternal)
2630
{
27-
if (input == null)
31+
if (string.IsNullOrEmpty(input))
2832
{
29-
throw new ArgumentNullException("input");
33+
throw new ArgumentNullException(nameof(input));
34+
}
35+
if(output == null)
36+
{
37+
throw new ArgumentException(nameof(output));
38+
}
39+
if (output.Exists)
40+
{
41+
throw new IOException("The file you're writing to already exists. Please input a new output path.");
3042
}
3143

3244
var stream = GetStream(input);
33-
34-
OpenApiDocument document;
35-
3645
var result = new OpenApiStreamReader(new OpenApiReaderSettings
3746
{
38-
ReferenceResolution = resolveExternal == true ? ReferenceResolutionSetting.ResolveAllReferences : ReferenceResolutionSetting.ResolveLocalReferences,
47+
ReferenceResolution = resolveExternal ? ReferenceResolutionSetting.ResolveAllReferences : ReferenceResolutionSetting.ResolveLocalReferences,
3948
RuleSet = ValidationRuleSet.GetDefaultRuleSet()
4049
}
4150
).ReadAsync(stream).GetAwaiter().GetResult();
4251

52+
OpenApiDocument document;
4353
document = result.OpenApiDocument;
54+
55+
// Check if filter options are provided, then execute
56+
if (!string.IsNullOrEmpty(filterByOperationIds) && !string.IsNullOrEmpty(filterByTags))
57+
{
58+
throw new InvalidOperationException("Cannot filter by operationIds and tags at the same time.");
59+
}
60+
61+
if (!string.IsNullOrEmpty(filterByOperationIds))
62+
{
63+
var predicate = OpenApiFilterService.CreatePredicate(operationIds: filterByOperationIds);
64+
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
65+
}
66+
if (!string.IsNullOrEmpty(filterByTags))
67+
{
68+
var predicate = OpenApiFilterService.CreatePredicate(tags: filterByTags);
69+
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
70+
}
71+
4472
var context = result.OpenApiDiagnostic;
4573

46-
if (context.Errors.Count != 0)
74+
if (context.Errors.Count > 0)
4775
{
4876
var errorReport = new StringBuilder();
4977

@@ -52,43 +80,26 @@ public static void ProcessOpenApiDocument(
5280
errorReport.AppendLine(error.ToString());
5381
}
5482

55-
throw new ArgumentException(String.Join(Environment.NewLine, context.Errors.Select(e => e.Message).ToArray()));
83+
throw new ArgumentException(string.Join(Environment.NewLine, context.Errors.Select(e => e.Message).ToArray()));
5684
}
5785

58-
using (var outputStream = output?.Create())
59-
{
60-
TextWriter textWriter;
86+
using var outputStream = output?.Create();
6187

62-
if (outputStream != null)
63-
{
64-
textWriter = new StreamWriter(outputStream);
65-
}
66-
else
67-
{
68-
textWriter = Console.Out;
69-
}
88+
var textWriter = outputStream != null ? new StreamWriter(outputStream) : Console.Out;
7089

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

90-
textWriter.Flush();
91-
}
102+
textWriter.Flush();
92103
}
93104

94105
private static Stream GetStream(string input)
@@ -127,7 +138,6 @@ internal static void ValidateOpenApiDocument(string input)
127138

128139
document = new OpenApiStreamReader(new OpenApiReaderSettings
129140
{
130-
//ReferenceResolution = resolveExternal == true ? ReferenceResolutionSetting.ResolveAllReferences : ReferenceResolutionSetting.ResolveLocalReferences,
131141
RuleSet = ValidationRuleSet.GetDefaultRuleSet()
132142
}
133143
).Read(stream, out var context);

0 commit comments

Comments
 (0)