Skip to content

Commit 971d827

Browse files
committed
Updated branch from 1.3.1-preview2
2 parents 9552a32 + cd45ea1 commit 971d827

File tree

144 files changed

+27242
-2629
lines changed

Some content is hidden

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

144 files changed

+27242
-2629
lines changed

.github/workflows/ci-cd.yml

Lines changed: 1 addition & 1 deletion
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

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.Hidi/Microsoft.OpenApi.Hidi.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
<PackAsTool>true</PackAsTool>
77
<ToolCommandName>hidi</ToolCommandName>
88
<PackageOutputPath>./../../artifacts</PackageOutputPath>
9-
<Version>0.5.0-preview</Version>
9+
<Version>0.5.0-preview2</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.Hidi/OpenApiService.cs

Lines changed: 59 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,14 @@
22
// Licensed under the MIT license.
33

44
using System;
5+
using System.Collections.Generic;
56
using System.IO;
67
using System.Linq;
78
using System.Net;
89
using System.Net.Http;
910
using System.Text;
1011
using System.Threading.Tasks;
12+
using System.Text.Json;
1113
using Microsoft.OpenApi.Extensions;
1214
using Microsoft.OpenApi.Models;
1315
using Microsoft.OpenApi.Readers;
@@ -17,15 +19,16 @@
1719

1820
namespace Microsoft.OpenApi.Hidi
1921
{
20-
static class OpenApiService
22+
public static class OpenApiService
2123
{
2224
public static void ProcessOpenApiDocument(
2325
string input,
2426
FileInfo output,
25-
OpenApiSpecVersion version,
26-
OpenApiFormat format,
27+
OpenApiSpecVersion? version,
28+
OpenApiFormat? format,
2729
string filterByOperationIds,
2830
string filterByTags,
31+
string filterByCollection,
2932
bool inline,
3033
bool resolveExternal)
3134
{
@@ -55,23 +58,30 @@ public static void ProcessOpenApiDocument(
5558
}
5659
).ReadAsync(stream).GetAwaiter().GetResult();
5760

58-
OpenApiDocument document;
5961
document = result.OpenApiDocument;
62+
Func<string, OperationType?, OpenApiOperation, bool> predicate;
6063

6164
// Check if filter options are provided, then execute
6265
if (!string.IsNullOrEmpty(filterByOperationIds) && !string.IsNullOrEmpty(filterByTags))
6366
{
6467
throw new InvalidOperationException("Cannot filter by operationIds and tags at the same time.");
6568
}
66-
6769
if (!string.IsNullOrEmpty(filterByOperationIds))
6870
{
69-
var predicate = OpenApiFilterService.CreatePredicate(operationIds: filterByOperationIds);
71+
predicate = OpenApiFilterService.CreatePredicate(operationIds: filterByOperationIds);
7072
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
7173
}
7274
if (!string.IsNullOrEmpty(filterByTags))
7375
{
74-
var predicate = OpenApiFilterService.CreatePredicate(tags: filterByTags);
76+
predicate = OpenApiFilterService.CreatePredicate(tags: filterByTags);
77+
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
78+
}
79+
80+
if (!string.IsNullOrEmpty(filterByCollection))
81+
{
82+
var fileStream = GetStream(GetInputUrl(filterByCollection));
83+
var requestUrls = ParseJsonCollectionFile(fileStream);
84+
predicate = OpenApiFilterService.CreatePredicate(requestUrls: requestUrls, source:document);
7585
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
7686
}
7787

@@ -97,13 +107,16 @@ public static void ProcessOpenApiDocument(
97107
{
98108
ReferenceInline = inline ? ReferenceInlineSetting.InlineLocalReferences : ReferenceInlineSetting.DoNotInlineReferences
99109
};
100-
IOpenApiWriter writer = format switch
110+
111+
var openApiFormat = format ?? GetOpenApiFormat(input);
112+
var openApiVersion = version ?? result.OpenApiDiagnostic.SpecificationVersion;
113+
IOpenApiWriter writer = openApiFormat switch
101114
{
102115
OpenApiFormat.Json => new OpenApiJsonWriter(textWriter, settings),
103116
OpenApiFormat.Yaml => new OpenApiYamlWriter(textWriter, settings),
104117
_ => throw new ArgumentException("Unknown format"),
105118
};
106-
document.Serialize(writer, version);
119+
document.Serialize(writer, openApiVersion);
107120

108121
textWriter.Flush();
109122
}
@@ -147,6 +160,38 @@ private static Stream GetStream(Uri input)
147160
return stream;
148161
}
149162

163+
/// <summary>
164+
/// Takes in a file stream, parses the stream into a JsonDocument and gets a list of paths and Http methods
165+
/// </summary>
166+
/// <param name="stream"> A file stream.</param>
167+
/// <returns> A dictionary of request urls and http methods from a collection.</returns>
168+
public static Dictionary<string, List<string>> ParseJsonCollectionFile(Stream stream)
169+
{
170+
var requestUrls = new Dictionary<string, List<string>>();
171+
172+
// Convert file to JsonDocument
173+
using var document = JsonDocument.Parse(stream);
174+
var root = document.RootElement;
175+
var itemElement = root.GetProperty("item");
176+
foreach (var requestObject in itemElement.EnumerateArray().Select(item => item.GetProperty("request")))
177+
{
178+
// Fetch list of methods and urls from collection, store them in a dictionary
179+
var path = requestObject.GetProperty("url").GetProperty("raw").ToString();
180+
var method = requestObject.GetProperty("method").ToString();
181+
182+
if (!requestUrls.ContainsKey(path))
183+
{
184+
requestUrls.Add(path, new List<string> { method });
185+
}
186+
else
187+
{
188+
requestUrls[path].Add(method);
189+
}
190+
}
191+
192+
return requestUrls;
193+
}
194+
150195
internal static async Task ValidateOpenApiDocument(string input, bool resolveExternal)
151196
{
152197
if (input == null)
@@ -197,5 +242,10 @@ internal static async Task ValidateOpenApiDocument(string input, bool resolveExt
197242

198243

199244
}
245+
246+
private static OpenApiFormat GetOpenApiFormat(string input)
247+
{
248+
return !input.StartsWith("http") && Path.GetExtension(input) == ".json" ? OpenApiFormat.Json : OpenApiFormat.Yaml;
249+
}
200250
}
201251
}

src/Microsoft.OpenApi.Hidi/Program.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,9 +31,10 @@ static async Task<int> Main(string[] args)
3131
new Option("--inline", "Inline $ref instances", typeof(bool) ),
3232
new Option("--resolveExternal","Resolve external $refs", typeof(bool)),
3333
new Option("--filterByOperationIds", "Filters OpenApiDocument by OperationId(s) provided", typeof(string)),
34-
new Option("--filterByTags", "Filters OpenApiDocument by Tag(s) provided", typeof(string))
34+
new Option("--filterByTags", "Filters OpenApiDocument by Tag(s) provided", typeof(string)),
35+
new Option("--filterByCollection", "Filters OpenApiDocument by Postman collection provided", typeof(string))
3536
};
36-
transformCommand.Handler = CommandHandler.Create<string, FileInfo, OpenApiSpecVersion, OpenApiFormat, string, string, bool, bool>(
37+
transformCommand.Handler = CommandHandler.Create<string, FileInfo, OpenApiSpecVersion?, OpenApiFormat?, string, string, string, bool, bool>(
3738
OpenApiService.ProcessOpenApiDocument);
3839

3940
rootCommand.Add(transformCommand);

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

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -10,14 +10,14 @@
1010
<Company>Microsoft</Company>
1111
<Title>Microsoft.OpenApi.Readers</Title>
1212
<PackageId>Microsoft.OpenApi.Readers</PackageId>
13-
<Version>1.3.0-preview</Version>
13+
<Version>1.3.1-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>
1717
<RepositoryUrl>https://github.com/Microsoft/OpenAPI.NET</RepositoryUrl>
1818
<PackageReleaseNotes>
1919
- Publish symbols.
20-
</PackageReleaseNotes>
20+
</PackageReleaseNotes>
2121
<AssemblyName>Microsoft.OpenApi.Readers</AssemblyName>
2222
<RootNamespace>Microsoft.OpenApi.Readers</RootNamespace>
2323
<SignAssembly>true</SignAssembly>
@@ -36,11 +36,11 @@
3636
</PropertyGroup>
3737

3838
<ItemGroup>
39-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
39+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
4040
</ItemGroup>
4141

4242
<ItemGroup>
43-
<PackageReference Include="SharpYaml" Version="1.6.6" />
43+
<PackageReference Include="SharpYaml" Version="1.8.0" />
4444
</ItemGroup>
4545

4646
<ItemGroup>

src/Microsoft.OpenApi.Readers/V3/OpenApiEncodingDeserializer.cs

Lines changed: 1 addition & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -31,15 +31,7 @@ internal static partial class OpenApiV3Deserializer
3131
{
3232
"style", (o, n) =>
3333
{
34-
ParameterStyle style;
35-
if (Enum.TryParse(n.GetScalarValue(), out style))
36-
{
37-
o.Style = style;
38-
}
39-
else
40-
{
41-
o.Style = null;
42-
}
34+
o.Style = n.GetScalarValue().GetEnumFromDisplayName<ParameterStyle>();
4335
}
4436
},
4537
{

src/Microsoft.OpenApi.Readers/V3/OpenApiMediaTypeDeserializer.cs

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -81,11 +81,6 @@ public static OpenApiMediaType LoadMediaType(ParseNode node)
8181
{
8282
var mapNode = node.CheckMapNode(OpenApiConstants.Content);
8383

84-
if (!mapNode.Any())
85-
{
86-
return null;
87-
}
88-
8984
var mediaType = new OpenApiMediaType();
9085

9186
ParseMap(mapNode, mediaType, _mediaTypeFixedFields, _mediaTypePatternFields);

src/Microsoft.OpenApi/Microsoft.OpenApi.csproj

Lines changed: 3 additions & 2 deletions
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.3.0-preview</Version>
14+
<Version>1.3.1-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>
@@ -37,7 +37,8 @@
3737
</PropertyGroup>
3838

3939
<ItemGroup>
40-
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
40+
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
41+
<PackageReference Include="System.Text.Json" Version="6.0.1" />
4142
</ItemGroup>
4243

4344
<ItemGroup>

0 commit comments

Comments
 (0)