Skip to content

Commit ca1b351

Browse files
committed
Infer input file path extension and add it to the default output path
1 parent 521920d commit ca1b351

File tree

2 files changed

+21
-7
lines changed

2 files changed

+21
-7
lines changed

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
// Copyright (c) Microsoft Corporation. All rights reserved.
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
22
// Licensed under the MIT license.
33

44
using System;
@@ -63,10 +63,11 @@ CancellationToken cancellationToken
6363
{
6464
throw new ArgumentException("Please input a file path");
6565
}
66-
if(output == null)
66+
if (output == null)
6767
{
68-
throw new ArgumentNullException(nameof(output));
69-
}
68+
var inputExtension = GetInputPathExtension(openapi, csdl);
69+
output = new FileInfo($"./output{inputExtension}");
70+
};
7071
if (cleanoutput && output.Exists)
7172
{
7273
output.Delete();
@@ -249,8 +250,6 @@ private static Stream ApplyFilter(string csdl, string entitySetOrSingleton, XslC
249250
return stream;
250251
}
251252

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

577+
private static string GetInputPathExtension(string openapi = null, string csdl = null)
578+
{
579+
var extension = String.Empty;
580+
if (!string.IsNullOrEmpty(openapi))
581+
{
582+
extension = Path.GetExtension(openapi);
583+
}
584+
if (!string.IsNullOrEmpty(csdl))
585+
{
586+
extension = ".yml";
587+
}
588+
589+
return extension;
590+
}
591+
578592
private static ILoggerFactory ConfigureLoggerInstance(LogLevel loglevel)
579593
{
580594
// Configure logger options

src/Microsoft.OpenApi.Hidi/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ static async Task Main(string[] args)
2727
var csdlFilterOption = new Option<string>("--csdl-filter", "Comma delimited list of EntitySets or Singletons to filter CSDL on. e.g. tasks,accounts");
2828
csdlFilterOption.AddAlias("--csf");
2929

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

3333
var cleanOutputOption = new Option<bool>("--clean-output", "Overwrite an existing file");

0 commit comments

Comments
 (0)