Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
108 commits
Select commit Hold shift + click to select a range
a29d442
Made OpenApiVisitorBase Enter() and Exit() virtual, plus test
peteraritchie Jul 3, 2021
549111a
updated Public.approved.txt file to include two methods now being vir…
peteraritchie Jul 3, 2021
e95833a
Add a push trigger filter in our main branch for the codeql analysis …
MaggieKimani1 Nov 23, 2021
77bdafe
Merge branch 'vnext' into mk/add-push-trigger-filter
MaggieKimani1 Nov 23, 2021
6006334
Fix indentation
MaggieKimani1 Nov 23, 2021
d804150
Merge remote-tracking branch 'origin/mk/add-push-trigger-filter' into…
MaggieKimani1 Nov 23, 2021
5c849a2
Merge pull request #654 from microsoft/mk/add-push-trigger-filter
baywet Nov 23, 2021
03b0e37
Bump Microsoft.SourceLink.GitHub from 1.0.0 to 1.1.1
dependabot[bot] Nov 23, 2021
f640726
Bump FluentAssertions from 5.10.3 to 6.2.0
dependabot[bot] Nov 23, 2021
f749646
Merge pull request #648 from microsoft/dependabot/nuget/Microsoft.Sou…
darrelmiller Nov 25, 2021
d872551
Merge branch 'vnext' into dependabot/nuget/FluentAssertions-6.2.0
darrelmiller Nov 25, 2021
2e51617
Bump Microsoft.NET.Test.Sdk from 16.9.4 to 17.0.0
dependabot[bot] Nov 25, 2021
e5e84e4
Merge pull request #641 from microsoft/dependabot/nuget/Microsoft.NET…
darrelmiller Nov 25, 2021
5595542
Bump SharpYaml from 1.6.6 to 1.8.0
dependabot[bot] Nov 25, 2021
89439ee
Merge pull request #625 from microsoft/dependabot/nuget/SharpYaml-1.8.0
darrelmiller Nov 25, 2021
8fb7712
Merge branch 'vnext' into dependabot/nuget/FluentAssertions-6.2.0
darrelmiller Nov 25, 2021
ea99575
Add filter by collection parameter and logic
MaggieKimani1 Dec 7, 2021
e2d189c
Add library for json serialization
MaggieKimani1 Dec 7, 2021
4b3722f
Move declaration closer to assignment
MaggieKimani1 Dec 7, 2021
494e59c
Add necessary usings
MaggieKimani1 Dec 7, 2021
4789c87
Add condition that forbids filtering two params at the same time
MaggieKimani1 Dec 7, 2021
03a6b54
Add method for formatting url string to get the query path
MaggieKimani1 Dec 7, 2021
dd1fab6
MaggieKimani1 Dec 7, 2021
00a0545
Create predicate based on the urls from the postman collection
MaggieKimani1 Dec 7, 2021
0cf02d4
Use object initializer
MaggieKimani1 Dec 7, 2021
13b351d
Fix line formatting
MaggieKimani1 Dec 7, 2021
23a8991
Check expression for null
MaggieKimani1 Dec 7, 2021
21c1f20
Move declaration to the outer scope
MaggieKimani1 Dec 7, 2021
1915ae6
Clean up code
MaggieKimani1 Dec 7, 2021
4a940c9
Fix line formatting
MaggieKimani1 Dec 7, 2021
fd44771
Silence xUnit1013 warning
nulltoken Oct 27, 2021
bac54ed
Teach OpenApiJsonWriter to produce a terse output
nulltoken Oct 27, 2021
9868348
Reference Verify test helper
nulltoken Oct 31, 2021
76a7cc1
Ensure OpenApiCallbackTests cover terse output
nulltoken Oct 31, 2021
d0cc1b6
Ensure OpenApiDocumentTests cover terse output
nulltoken Oct 31, 2021
86b4cee
Ensure OpenApiExampleTests cover terse output
nulltoken Oct 31, 2021
632d655
Ensure OpenApiHeaderTests cover terse output
nulltoken Oct 31, 2021
83fc148
Ensure OpenApiLinkTests cover terse output
nulltoken Oct 31, 2021
8395a47
Ensure OpenApiWriterAnyExtensionsTests cover terse output
nulltoken Oct 31, 2021
b60ca92
Ensure OpenApiWriterSpecialCharacterTests cover terse output
nulltoken Oct 31, 2021
14478e3
Ensure OpenApiParameterTests cover terse output
nulltoken Oct 31, 2021
821e6b7
Ensure OpenApiRequestBodyTests cover terse output
nulltoken Oct 31, 2021
193098e
Ensure OpenApiResponseTests cover terse output
nulltoken Oct 31, 2021
b68a0a1
Ensure OpenApiSchemaTests cover terse output
nulltoken Oct 31, 2021
505b735
Ensure OpenApiSecuritySchemeTests cover terse output
nulltoken Oct 31, 2021
c932f6f
Ensure OpenApiTagTests cover terse output
nulltoken Oct 31, 2021
b800ae0
Ensure OpenApiJsonWriterTests cover terse output
nulltoken Oct 31, 2021
66a032e
Add extra params to predicate function
MaggieKimani1 Dec 14, 2021
ea8ef07
Add extra params to predicate
MaggieKimani1 Dec 14, 2021
bc05c20
Fetch operationTypes and clean urls and pass them to our predicate fu…
MaggieKimani1 Dec 14, 2021
718956f
Use server url to format the incoming request urls from collection
MaggieKimani1 Dec 14, 2021
9570383
Simplify and clean up code
MaggieKimani1 Dec 14, 2021
d1ce642
Move declaration close to assignment; wrap line of code
MaggieKimani1 Dec 14, 2021
fd6d8b0
Remove unnecessary parenthesis
MaggieKimani1 Dec 14, 2021
1dc9bcc
Clean up
MaggieKimani1 Dec 14, 2021
c752fcb
Concat operationType with url and use it for matching in our predicate
MaggieKimani1 Dec 14, 2021
e80e286
Clean up comments
MaggieKimani1 Dec 14, 2021
c96bc16
Add sample postman collections for testing
MaggieKimani1 Dec 14, 2021
f0bfe01
Add server object
MaggieKimani1 Dec 14, 2021
3caa0bf
Add unit tests for slicing based on postman collection
MaggieKimani1 Dec 14, 2021
62d0975
Update public Api text file
MaggieKimani1 Dec 14, 2021
1dd1cd5
Merge branch 'vnext' into mk/filter-by-collection
MaggieKimani1 Dec 14, 2021
a08028f
Merge pull request #640 from nulltoken/ntk/terse
darrelmiller Dec 15, 2021
6657430
Bump mathieudutour/github-tag-action from 5.4 to 6.0
dependabot[bot] Dec 15, 2021
093993b
Merge branch 'vnext' into dependabot/nuget/FluentAssertions-6.2.0
darrelmiller Dec 15, 2021
135f8b1
Merge pull request #638 from microsoft/dependabot/nuget/FluentAsserti…
darrelmiller Dec 15, 2021
591711d
Merge branch 'vnext' into dependabot/github_actions/mathieudutour/git…
darrelmiller Dec 15, 2021
c147547
Merge pull request #656 from microsoft/dependabot/github_actions/math…
darrelmiller Dec 15, 2021
387a256
Merge branch 'vnext' into vnext
darrelmiller Dec 15, 2021
ff584c7
Merge pull request #611 from peteraritchie/vnext
darrelmiller Dec 15, 2021
8fc8afe
Merge branch 'vnext' into mk/filter-by-collection
darrelmiller Dec 15, 2021
640e7dc
Remove redundant ()
MaggieKimani1 Dec 16, 2021
e555680
Remove trailing backslash
MaggieKimani1 Dec 16, 2021
619350e
Use var for consistency
MaggieKimani1 Dec 16, 2021
b3d040e
Rename predicate args
MaggieKimani1 Dec 16, 2021
0cf947b
Address PR feedback
MaggieKimani1 Dec 17, 2021
71399f6
Code cleanup
MaggieKimani1 Dec 17, 2021
df40781
Update package version
MaggieKimani1 Jan 11, 2022
29d207c
Capitalize postman and add necessary usings
MaggieKimani1 Jan 11, 2022
d0312ac
Move the json document parsing logic to OpenApiService
MaggieKimani1 Jan 11, 2022
bf2d0fe
Only add the available operations types if they are present in the po…
MaggieKimani1 Jan 11, 2022
422cdb2
Add public class access modifier
MaggieKimani1 Jan 14, 2022
7cc3e86
Add project reference and update framework to .net 50
MaggieKimani1 Jan 14, 2022
63b7373
Refactor tests
MaggieKimani1 Jan 14, 2022
77ce0bc
Merge pull request #663 from microsoft/mk/filter-by-collection
darrelmiller Jan 19, 2022
f266f19
Bump FluentAssertions from 6.2.0 to 6.3.0
dependabot[bot] Jan 19, 2022
9a33f47
Bump Verify from 13.3.1 to 14.14.1
dependabot[bot] Jan 19, 2022
4e0639f
Use input file OpenApi format as the default output format
danielmbaluka Dec 6, 2021
a06ab0c
replace verbose if statement with ternary operator
danielmbaluka Jan 22, 2022
ee1c4c6
Updated PublicApi file to no longer include ParseJsonCollectionFile
darrelmiller Jan 22, 2022
177b5ea
Merge pull request #658 from microsoft/feature/dm/use-input-file-form…
darrelmiller Jan 22, 2022
aa467e4
Merge branch 'vnext' into dependabot/nuget/FluentAssertions-6.3.0
darrelmiller Jan 22, 2022
b797dbb
Merge pull request #678 from microsoft/dependabot/nuget/FluentAsserti…
darrelmiller Jan 22, 2022
d682377
Merge branch 'vnext' into dependabot/nuget/Verify-14.14.1
darrelmiller Jan 22, 2022
daca2b2
Merge pull request #686 from microsoft/dependabot/nuget/Verify-14.14.1
darrelmiller Jan 22, 2022
0afb497
Bump Verify.Xunit from 13.3.1 to 14.14.1
dependabot[bot] Jan 22, 2022
41cf6ad
Bump System.Text.Json from 6.0.0 to 6.0.1
dependabot[bot] Jan 22, 2022
e5c3117
Merge pull request #691 from microsoft/dependabot/nuget/System.Text.J…
darrelmiller Jan 22, 2022
4230dfe
Merge branch 'vnext' into dependabot/nuget/Verify.Xunit-14.14.1
darrelmiller Jan 22, 2022
b0598a0
Merge pull request #687 from microsoft/dependabot/nuget/Verify.Xunit-…
darrelmiller Jan 22, 2022
a4aa421
Merge branch 'master' into dm/updatefrommaster2
darrelmiller Jan 22, 2022
703c6db
Merge pull request #692 from microsoft/dm/updatefrommaster2
darrelmiller Jan 22, 2022
482787f
Updated version to release new preview
darrelmiller Jan 23, 2022
e27c0e7
Fixed parsing of encoding style
darrelmiller Jan 23, 2022
666a94e
Allow empty objects to be considered valid media type objects
darrelmiller Jan 23, 2022
1deb0a2
Merge pull request #694 from microsoft/issue683
darrelmiller Jan 23, 2022
c3fca36
Merge branch 'vnext' into dm/updatepreviewversion
darrelmiller Jan 23, 2022
cd45ea1
Merge pull request #693 from microsoft/dm/updatepreviewversion
darrelmiller Jan 23, 2022
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/ci-cd.yml
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ jobs:
- if: steps.conditionals_handler.outputs.is_default_branch == 'true'
name: Bump GH tag
id: tag_generator
uses: mathieudutour/github-tag-action@v5.4
uses: mathieudutour/github-tag-action@v6.0
with:
github_token: ${{ secrets.GITHUB_TOKEN }}
default_bump: false
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/codeql-analysis.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ name: CodeQL Analysis

on:
push:
branches: [ vnext ]
pull_request:
schedule:
- cron: '0 8 * * *'
Expand Down
2 changes: 1 addition & 1 deletion src/Directory.Build.props
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,6 @@
<AllowedOutputExtensionsInPackageBuildOutputFolder>$(AllowedOutputExtensionsInPackageBuildOutputFolder);.pdb</AllowedOutputExtensionsInPackageBuildOutputFolder>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0-*" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1-*" PrivateAssets="All"/>
</ItemGroup>
</Project>
4 changes: 2 additions & 2 deletions src/Microsoft.OpenApi.Hidi/Microsoft.OpenApi.Hidi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
<PackAsTool>true</PackAsTool>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>0.5.0-preview</Version>
<Version>0.5.0-preview2</Version>
</PropertyGroup>

<ItemGroup>
Expand All @@ -19,7 +19,7 @@
</ItemGroup>

<ItemGroup>
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.0-beta-20204-02" />
<PackageReference Update="Microsoft.SourceLink.GitHub" Version="1.1.1" />
</ItemGroup>

</Project>
70 changes: 60 additions & 10 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,11 +2,13 @@
// Licensed under the MIT license.

using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Net;
using System.Net.Http;
using System.Text;
using System.Text.Json;
using Microsoft.OpenApi.Extensions;
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers;
Expand All @@ -16,15 +18,16 @@

namespace Microsoft.OpenApi.Hidi
{
static class OpenApiService
public static class OpenApiService
{
public static void ProcessOpenApiDocument(
string input,
FileInfo output,
OpenApiSpecVersion version,
OpenApiFormat format,
OpenApiSpecVersion? version,
OpenApiFormat? format,
string filterByOperationIds,
string filterByTags,
string filterByCollection,
bool inline,
bool resolveExternal)
{
Expand All @@ -49,23 +52,30 @@ public static void ProcessOpenApiDocument(
}
).ReadAsync(stream).GetAwaiter().GetResult();

OpenApiDocument document;
document = result.OpenApiDocument;
var document = result.OpenApiDocument;
Func<string, OperationType?, OpenApiOperation, bool> predicate;

// Check if filter options are provided, then execute
if (!string.IsNullOrEmpty(filterByOperationIds) && !string.IsNullOrEmpty(filterByTags))
{
throw new InvalidOperationException("Cannot filter by operationIds and tags at the same time.");
}

if (!string.IsNullOrEmpty(filterByOperationIds))
{
var predicate = OpenApiFilterService.CreatePredicate(operationIds: filterByOperationIds);
predicate = OpenApiFilterService.CreatePredicate(operationIds: filterByOperationIds);
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
}
if (!string.IsNullOrEmpty(filterByTags))
{
var predicate = OpenApiFilterService.CreatePredicate(tags: filterByTags);
predicate = OpenApiFilterService.CreatePredicate(tags: filterByTags);
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
}

if (!string.IsNullOrEmpty(filterByCollection))
{
var fileStream = GetStream(filterByCollection);
var requestUrls = ParseJsonCollectionFile(fileStream);
predicate = OpenApiFilterService.CreatePredicate(requestUrls: requestUrls, source:document);
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
}

Expand All @@ -91,13 +101,16 @@ public static void ProcessOpenApiDocument(
{
ReferenceInline = inline ? ReferenceInlineSetting.InlineLocalReferences : ReferenceInlineSetting.DoNotInlineReferences
};
IOpenApiWriter writer = format switch

var openApiFormat = format ?? GetOpenApiFormat(input);
var openApiVersion = version ?? result.OpenApiDiagnostic.SpecificationVersion;
IOpenApiWriter writer = openApiFormat switch
{
OpenApiFormat.Json => new OpenApiJsonWriter(textWriter, settings),
OpenApiFormat.Yaml => new OpenApiYamlWriter(textWriter, settings),
_ => throw new ArgumentException("Unknown format"),
};
document.Serialize(writer, version);
document.Serialize(writer, openApiVersion);

textWriter.Flush();
}
Expand Down Expand Up @@ -125,6 +138,38 @@ private static Stream GetStream(string input)
return stream;
}

/// <summary>
/// Takes in a file stream, parses the stream into a JsonDocument and gets a list of paths and Http methods
/// </summary>
/// <param name="stream"> A file stream.</param>
/// <returns> A dictionary of request urls and http methods from a collection.</returns>
public static Dictionary<string, List<string>> ParseJsonCollectionFile(Stream stream)
{
var requestUrls = new Dictionary<string, List<string>>();

// Convert file to JsonDocument
using var document = JsonDocument.Parse(stream);
var root = document.RootElement;
var itemElement = root.GetProperty("item");
foreach (var requestObject in itemElement.EnumerateArray().Select(item => item.GetProperty("request")))
{
// Fetch list of methods and urls from collection, store them in a dictionary
var path = requestObject.GetProperty("url").GetProperty("raw").ToString();
var method = requestObject.GetProperty("method").ToString();

if (!requestUrls.ContainsKey(path))
{
requestUrls.Add(path, new List<string> { method });
}
else
{
requestUrls[path].Add(method);
}
}

return requestUrls;
}

internal static void ValidateOpenApiDocument(string input)
{
if (input == null)
Expand Down Expand Up @@ -156,5 +201,10 @@ internal static void ValidateOpenApiDocument(string input)

Console.WriteLine(statsVisitor.GetStatisticsReport());
}

private static OpenApiFormat GetOpenApiFormat(string input)
{
return !input.StartsWith("http") && Path.GetExtension(input) == ".json" ? OpenApiFormat.Json : OpenApiFormat.Yaml;
}
}
}
5 changes: 3 additions & 2 deletions src/Microsoft.OpenApi.Hidi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,10 @@ static async Task<int> Main(string[] args)
new Option("--inline", "Inline $ref instances", typeof(bool) ),
new Option("--resolveExternal","Resolve external $refs", typeof(bool)),
new Option("--filterByOperationIds", "Filters OpenApiDocument by OperationId(s) provided", typeof(string)),
new Option("--filterByTags", "Filters OpenApiDocument by Tag(s) provided", typeof(string))
new Option("--filterByTags", "Filters OpenApiDocument by Tag(s) provided", typeof(string)),
new Option("--filterByCollection", "Filters OpenApiDocument by Postman collection provided", typeof(string))
};
transformCommand.Handler = CommandHandler.Create<string, FileInfo, OpenApiSpecVersion, OpenApiFormat, string, string, bool, bool>(
transformCommand.Handler = CommandHandler.Create<string, FileInfo, OpenApiSpecVersion?, OpenApiFormat?, string, string, string, bool, bool>(
OpenApiService.ProcessOpenApiDocument);

rootCommand.Add(transformCommand);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi.Readers</Title>
<PackageId>Microsoft.OpenApi.Readers</PackageId>
<Version>1.3.1-preview</Version>
<Version>1.3.1-preview2</Version>
<Description>OpenAPI.NET Readers for JSON and YAML documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand All @@ -36,11 +36,11 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All"/>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All"/>
</ItemGroup>

<ItemGroup>
<PackageReference Include="SharpYaml" Version="1.6.6" />
<PackageReference Include="SharpYaml" Version="1.8.0" />
</ItemGroup>

<ItemGroup>
Expand Down
10 changes: 1 addition & 9 deletions src/Microsoft.OpenApi.Readers/V3/OpenApiEncodingDeserializer.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,15 +31,7 @@ internal static partial class OpenApiV3Deserializer
{
"style", (o, n) =>
{
ParameterStyle style;
if (Enum.TryParse(n.GetScalarValue(), out style))
{
o.Style = style;
}
else
{
o.Style = null;
}
o.Style = n.GetScalarValue().GetEnumFromDisplayName<ParameterStyle>();
}
},
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -81,11 +81,6 @@ public static OpenApiMediaType LoadMediaType(ParseNode node)
{
var mapNode = node.CheckMapNode(OpenApiConstants.Content);

if (!mapNode.Any())
{
return null;
}

var mediaType = new OpenApiMediaType();

ParseMap(mapNode, mediaType, _mediaTypeFixedFields, _mediaTypePatternFields);
Expand Down
5 changes: 3 additions & 2 deletions src/Microsoft.OpenApi/Microsoft.OpenApi.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
<Company>Microsoft</Company>
<Title>Microsoft.OpenApi</Title>
<PackageId>Microsoft.OpenApi</PackageId>
<Version>1.3.1-preview</Version>
<Version>1.3.1-preview2</Version>
<Description>.NET models with JSON and YAML writers for OpenAPI specification</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand All @@ -37,7 +37,8 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.0.0" PrivateAssets="All" />
<PackageReference Include="Microsoft.SourceLink.GitHub" Version="1.1.1" PrivateAssets="All" />
<PackageReference Include="System.Text.Json" Version="6.0.1" />
</ItemGroup>

<ItemGroup>
Expand Down
Loading