Skip to content

Commit ad0bc0d

Browse files
authored
Merge pull request #695 from microsoft/release/1.3.1-preview2
Release/1.3.1 preview2
2 parents 5e8e492 + cd45ea1 commit ad0bc0d

File tree

145 files changed

+27243
-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.

145 files changed

+27243
-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

.github/workflows/codeql-analysis.yml

Lines changed: 1 addition & 0 deletions
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 * * *'

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: 60 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,13 @@
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;
11+
using System.Text.Json;
1012
using Microsoft.OpenApi.Extensions;
1113
using Microsoft.OpenApi.Models;
1214
using Microsoft.OpenApi.Readers;
@@ -16,15 +18,16 @@
1618

1719
namespace Microsoft.OpenApi.Hidi
1820
{
19-
static class OpenApiService
21+
public static class OpenApiService
2022
{
2123
public static void ProcessOpenApiDocument(
2224
string input,
2325
FileInfo output,
24-
OpenApiSpecVersion version,
25-
OpenApiFormat format,
26+
OpenApiSpecVersion? version,
27+
OpenApiFormat? format,
2628
string filterByOperationIds,
2729
string filterByTags,
30+
string filterByCollection,
2831
bool inline,
2932
bool resolveExternal)
3033
{
@@ -49,23 +52,30 @@ public static void ProcessOpenApiDocument(
4952
}
5053
).ReadAsync(stream).GetAwaiter().GetResult();
5154

52-
OpenApiDocument document;
53-
document = result.OpenApiDocument;
55+
var document = result.OpenApiDocument;
56+
Func<string, OperationType?, OpenApiOperation, bool> predicate;
5457

5558
// Check if filter options are provided, then execute
5659
if (!string.IsNullOrEmpty(filterByOperationIds) && !string.IsNullOrEmpty(filterByTags))
5760
{
5861
throw new InvalidOperationException("Cannot filter by operationIds and tags at the same time.");
5962
}
60-
6163
if (!string.IsNullOrEmpty(filterByOperationIds))
6264
{
63-
var predicate = OpenApiFilterService.CreatePredicate(operationIds: filterByOperationIds);
65+
predicate = OpenApiFilterService.CreatePredicate(operationIds: filterByOperationIds);
6466
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
6567
}
6668
if (!string.IsNullOrEmpty(filterByTags))
6769
{
68-
var predicate = OpenApiFilterService.CreatePredicate(tags: filterByTags);
70+
predicate = OpenApiFilterService.CreatePredicate(tags: filterByTags);
71+
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
72+
}
73+
74+
if (!string.IsNullOrEmpty(filterByCollection))
75+
{
76+
var fileStream = GetStream(filterByCollection);
77+
var requestUrls = ParseJsonCollectionFile(fileStream);
78+
predicate = OpenApiFilterService.CreatePredicate(requestUrls: requestUrls, source:document);
6979
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
7080
}
7181

@@ -91,13 +101,16 @@ public static void ProcessOpenApiDocument(
91101
{
92102
ReferenceInline = inline ? ReferenceInlineSetting.InlineLocalReferences : ReferenceInlineSetting.DoNotInlineReferences
93103
};
94-
IOpenApiWriter writer = format switch
104+
105+
var openApiFormat = format ?? GetOpenApiFormat(input);
106+
var openApiVersion = version ?? result.OpenApiDiagnostic.SpecificationVersion;
107+
IOpenApiWriter writer = openApiFormat switch
95108
{
96109
OpenApiFormat.Json => new OpenApiJsonWriter(textWriter, settings),
97110
OpenApiFormat.Yaml => new OpenApiYamlWriter(textWriter, settings),
98111
_ => throw new ArgumentException("Unknown format"),
99112
};
100-
document.Serialize(writer, version);
113+
document.Serialize(writer, openApiVersion);
101114

102115
textWriter.Flush();
103116
}
@@ -125,6 +138,38 @@ private static Stream GetStream(string input)
125138
return stream;
126139
}
127140

141+
/// <summary>
142+
/// Takes in a file stream, parses the stream into a JsonDocument and gets a list of paths and Http methods
143+
/// </summary>
144+
/// <param name="stream"> A file stream.</param>
145+
/// <returns> A dictionary of request urls and http methods from a collection.</returns>
146+
public static Dictionary<string, List<string>> ParseJsonCollectionFile(Stream stream)
147+
{
148+
var requestUrls = new Dictionary<string, List<string>>();
149+
150+
// Convert file to JsonDocument
151+
using var document = JsonDocument.Parse(stream);
152+
var root = document.RootElement;
153+
var itemElement = root.GetProperty("item");
154+
foreach (var requestObject in itemElement.EnumerateArray().Select(item => item.GetProperty("request")))
155+
{
156+
// Fetch list of methods and urls from collection, store them in a dictionary
157+
var path = requestObject.GetProperty("url").GetProperty("raw").ToString();
158+
var method = requestObject.GetProperty("method").ToString();
159+
160+
if (!requestUrls.ContainsKey(path))
161+
{
162+
requestUrls.Add(path, new List<string> { method });
163+
}
164+
else
165+
{
166+
requestUrls[path].Add(method);
167+
}
168+
}
169+
170+
return requestUrls;
171+
}
172+
128173
internal static void ValidateOpenApiDocument(string input)
129174
{
130175
if (input == null)
@@ -156,5 +201,10 @@ internal static void ValidateOpenApiDocument(string input)
156201

157202
Console.WriteLine(statsVisitor.GetStatisticsReport());
158203
}
204+
205+
private static OpenApiFormat GetOpenApiFormat(string input)
206+
{
207+
return !input.StartsWith("http") && Path.GetExtension(input) == ".json" ? OpenApiFormat.Json : OpenApiFormat.Yaml;
208+
}
159209
}
160210
}

src/Microsoft.OpenApi.Hidi/Program.cs

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

3839
rootCommand.Add(transformCommand);

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

Lines changed: 3 additions & 3 deletions
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.3.1-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>
@@ -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.1-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)