Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
54 changes: 54 additions & 0 deletions Microsoft.OpenApi.Hidi.Tests/Microsoft.OpenApi.Hidi.Tests.csproj
Original file line number Diff line number Diff line change
@@ -0,0 +1,54 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net6.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>

<IsPackable>false</IsPackable>
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0-preview-20220612-01" />
<PackageReference Include="Moq" Version="4.18.1" />
<PackageReference Include="xunit" Version="2.4.2-pre.12" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
<PackageReference Include="coverlet.collector" Version="3.1.2">
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
<PrivateAssets>all</PrivateAssets>
</PackageReference>
</ItemGroup>

<ItemGroup>
<ProjectReference Include="..\src\Microsoft.OpenApi.Hidi\Microsoft.OpenApi.Hidi.csproj" />
<ProjectReference Include="..\src\Microsoft.OpenApi\Microsoft.OpenApi.csproj" />
</ItemGroup>

<ItemGroup>
<Compile Update="UtilityFiles\OpenApiDocumentMock.cs">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</Compile>
</ItemGroup>

<ItemGroup>
<None Update="UtilityFiles\postmanCollection_ver1.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="UtilityFiles\postmanCollection_ver2.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="UtilityFiles\postmanCollection_ver3.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="UtilityFiles\postmanCollection_ver4.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="UtilityFiles\Todo.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>

</Project>
7 changes: 7 additions & 0 deletions Microsoft.OpenApi.sln
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.SmokeTest
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "Microsoft.OpenApi.Hidi", "src\Microsoft.OpenApi.Hidi\Microsoft.OpenApi.Hidi.csproj", "{254841B5-7DAC-4D1D-A9C5-44FE5CE467BE}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Microsoft.OpenApi.Hidi.Tests", "Microsoft.OpenApi.Hidi.Tests\Microsoft.OpenApi.Hidi.Tests.csproj", "{D8F799DD-04AC-4A13-B344-45A5B944450A}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -62,6 +64,10 @@ Global
{254841B5-7DAC-4D1D-A9C5-44FE5CE467BE}.Debug|Any CPU.Build.0 = Debug|Any CPU
{254841B5-7DAC-4D1D-A9C5-44FE5CE467BE}.Release|Any CPU.ActiveCfg = Release|Any CPU
{254841B5-7DAC-4D1D-A9C5-44FE5CE467BE}.Release|Any CPU.Build.0 = Release|Any CPU
{D8F799DD-04AC-4A13-B344-45A5B944450A}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D8F799DD-04AC-4A13-B344-45A5B944450A}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D8F799DD-04AC-4A13-B344-45A5B944450A}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D8F799DD-04AC-4A13-B344-45A5B944450A}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand All @@ -74,6 +80,7 @@ Global
{1ED3C2C1-E1E7-4925-B4E6-2D969C3F5237} = {6357D7FD-2DE4-4900-ADB9-ABC37052040A}
{AD79B61D-88CF-497C-9ED5-41AE3867C5AC} = {6357D7FD-2DE4-4900-ADB9-ABC37052040A}
{254841B5-7DAC-4D1D-A9C5-44FE5CE467BE} = {E546B92F-20A8-49C3-8323-4B25BB78F3E1}
{D8F799DD-04AC-4A13-B344-45A5B944450A} = {6357D7FD-2DE4-4900-ADB9-ABC37052040A}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {9F171EFC-0DB5-4B10-ABFA-AF48D52CC565}
Expand Down
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 @@ -15,7 +15,7 @@
<PackageId>Microsoft.OpenApi.Hidi</PackageId>
<ToolCommandName>hidi</ToolCommandName>
<PackageOutputPath>./../../artifacts</PackageOutputPath>
<Version>1.0.0-preview7</Version>
<Version>1.0.0-preview8</Version>
<Description>OpenAPI.NET CLI tool for slicing OpenAPI documents</Description>
<Copyright>© Microsoft Corporation. All rights reserved.</Copyright>
<PackageTags>OpenAPI .NET</PackageTags>
Expand Down Expand Up @@ -43,7 +43,7 @@
<PackageReference Include="Microsoft.Extensions.Logging.Debug" Version="6.0.0" />
<PackageReference Include="System.CommandLine" Version="2.0.0-beta3.22114.1" />
<PackageReference Include="Microsoft.OData.Edm" Version="7.12.0" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.0.11-preview4" />
<PackageReference Include="Microsoft.OpenApi.OData" Version="1.0.11-preview5" />
</ItemGroup>

<ItemGroup>
Expand Down
26 changes: 20 additions & 6 deletions src/Microsoft.OpenApi.Hidi/OpenApiService.cs
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT license.

using System;
Expand Down Expand Up @@ -63,10 +63,11 @@ CancellationToken cancellationToken
{
throw new ArgumentException("Please input a file path");
}
if(output == null)
if (output == null)
{
throw new ArgumentNullException(nameof(output));
}
var inputExtension = GetInputPathExtension(openapi, csdl);
output = new FileInfo($"./output{inputExtension}");
};
if (cleanoutput && output.Exists)
{
output.Delete();
Expand Down Expand Up @@ -249,8 +250,6 @@ private static Stream ApplyFilter(string csdl, string entitySetOrSingleton, XslC
return stream;
}



/// <summary>
/// Implementation of the validate command
/// </summary>
Expand Down Expand Up @@ -575,6 +574,21 @@ private static OpenApiFormat GetOpenApiFormat(string input, ILogger logger)
return !input.StartsWith("http") && Path.GetExtension(input) == ".json" ? OpenApiFormat.Json : OpenApiFormat.Yaml;
}

private static string GetInputPathExtension(string openapi = null, string csdl = null)
{
var extension = String.Empty;
if (!string.IsNullOrEmpty(openapi))
{
extension = Path.GetExtension(openapi);
}
else if (!string.IsNullOrEmpty(csdl))
{
extension = ".yml";
}

return extension;
}

private static ILoggerFactory ConfigureLoggerInstance(LogLevel loglevel)
{
// Configure logger options
Expand Down
2 changes: 1 addition & 1 deletion src/Microsoft.OpenApi.Hidi/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,7 @@ static async Task Main(string[] args)
var csdlFilterOption = new Option<string>("--csdl-filter", "Comma delimited list of EntitySets or Singletons to filter CSDL on. e.g. tasks,accounts");
csdlFilterOption.AddAlias("--csf");

var outputOption = new Option<FileInfo>("--output", () => new FileInfo("./output"), "The output directory path for the generated file.") { Arity = ArgumentArity.ZeroOrOne };
var outputOption = new Option<FileInfo>("--output", "The output directory path for the generated file.") { Arity = ArgumentArity.ZeroOrOne };
outputOption.AddAlias("-o");

var cleanOutputOption = new Option<bool>("--clean-output", "Overwrite an existing file");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -250,14 +250,14 @@
</ItemGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0-preview-20220612-01" />
<PackageReference Include="FluentAssertions" Version="6.7.0">
</PackageReference>
<PackageReference Include="Newtonsoft.Json" Version="13.0.1">
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta1">
</PackageReference>
<PackageReference Include="SharpYaml" Version="1.9.2">
<PackageReference Include="SharpYaml" Version="2.0.0">
</PackageReference>
<PackageReference Include="xunit" Version="2.4.1">
<PackageReference Include="xunit" Version="2.4.2-pre.12">
</PackageReference>
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
</PropertyGroup>

<ItemGroup>
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.3.0-preview-20220612-01" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.2-beta1" />
<PackageReference Include="xunit" Version="2.4.2-pre.12" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
<PrivateAssets>all</PrivateAssets>
<IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
Expand Down
17 changes: 1 addition & 16 deletions test/Microsoft.OpenApi.Tests/Microsoft.OpenApi.Tests.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@
<PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.2.0" />
<PackageReference Include="Moq" Version="4.18.1" />
<PackageReference Include="Newtonsoft.Json" Version="13.0.1" />
<PackageReference Include="SharpYaml" Version="1.9.2" />
<PackageReference Include="SharpYaml" Version="2.0.0" />
<PackageReference Include="Verify.Xunit" Version="17.2.1" />
<PackageReference Include="xunit" Version="2.4.1" />
<PackageReference Include="xunit.runner.visualstudio" Version="2.4.5">
Expand All @@ -37,20 +37,5 @@

<ItemGroup>
<None Update="PublicApi\PublicApi.approved.txt" CopyToOutputDirectory="Always" />
<None Update="UtilityFiles\postmanCollection_ver1.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="UtilityFiles\postmanCollection_ver2.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="UtilityFiles\postmanCollection_ver3.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="UtilityFiles\postmanCollection_ver4.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
<None Update="UtilityFiles\Todo.xml">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
</None>
</ItemGroup>
</Project>