Skip to content

Commit 695eb05

Browse files
committed
Merge branch 'mk/align-hidi-params-with-kiota' into mk/feature/convert-csdl-to-openapi
2 parents b13c3ad + f81167e commit 695eb05

File tree

2 files changed

+62
-34
lines changed

2 files changed

+62
-34
lines changed

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 24 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -24,19 +24,19 @@ namespace Microsoft.OpenApi.Hidi
2424
public static class OpenApiService
2525
{
2626
public static void ProcessOpenApiDocument(
27-
string input,
27+
string openapi,
2828
FileInfo output,
2929
OpenApiSpecVersion? version,
3030
OpenApiFormat? format,
31-
string filterByOperationIds,
32-
string filterByTags,
33-
string filterByCollection,
31+
string filterbyoperationids,
32+
string filterbytags,
33+
string filterbycollection,
3434
bool inline,
35-
bool resolveExternal)
35+
bool resolveexternal)
3636
{
37-
if (string.IsNullOrEmpty(input))
37+
if (string.IsNullOrEmpty(openapi))
3838
{
39-
throw new ArgumentNullException(nameof(input));
39+
throw new ArgumentNullException(nameof(openapi));
4040
}
4141
if(output == null)
4242
{
@@ -86,24 +86,24 @@ public static void ProcessOpenApiDocument(
8686
Func<string, OperationType?, OpenApiOperation, bool> predicate;
8787

8888
// Check if filter options are provided, then execute
89-
if (!string.IsNullOrEmpty(filterByOperationIds) && !string.IsNullOrEmpty(filterByTags))
89+
if (!string.IsNullOrEmpty(filterbyoperationids) && !string.IsNullOrEmpty(filterbytags))
9090
{
9191
throw new InvalidOperationException("Cannot filter by operationIds and tags at the same time.");
9292
}
93-
if (!string.IsNullOrEmpty(filterByOperationIds))
93+
if (!string.IsNullOrEmpty(filterbyoperationids))
9494
{
95-
predicate = OpenApiFilterService.CreatePredicate(operationIds: filterByOperationIds);
95+
predicate = OpenApiFilterService.CreatePredicate(operationIds: filterbyoperationids);
9696
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
9797
}
98-
if (!string.IsNullOrEmpty(filterByTags))
98+
if (!string.IsNullOrEmpty(filterbytags))
9999
{
100-
predicate = OpenApiFilterService.CreatePredicate(tags: filterByTags);
100+
predicate = OpenApiFilterService.CreatePredicate(tags: filterbytags);
101101
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
102102
}
103103

104-
if (!string.IsNullOrEmpty(filterByCollection))
104+
if (!string.IsNullOrEmpty(filterbycollection))
105105
{
106-
var fileStream = GetStream(filterByCollection);
106+
var fileStream = GetStream(filterbycollection);
107107
var requestUrls = ParseJsonCollectionFile(fileStream);
108108
predicate = OpenApiFilterService.CreatePredicate(requestUrls: requestUrls, source:document);
109109
document = OpenApiFilterService.CreateFilteredDocument(document, predicate);
@@ -118,7 +118,7 @@ public static void ProcessOpenApiDocument(
118118
ReferenceInline = inline ? ReferenceInlineSetting.InlineLocalReferences : ReferenceInlineSetting.DoNotInlineReferences
119119
};
120120

121-
var openApiFormat = format ?? GetOpenApiFormat(input);
121+
var openApiFormat = format ?? GetOpenApiFormat(openapi);
122122
var openApiVersion = version ?? result.OpenApiDiagnostic.SpecificationVersion;
123123
IOpenApiWriter writer = openApiFormat switch
124124
{
@@ -182,7 +182,7 @@ public static OpenApiDocument FixReferences(OpenApiDocument document)
182182
private static Stream GetStream(string input)
183183
{
184184
Stream stream;
185-
if (input.StartsWith("http"))
185+
if (openapi.StartsWith("http"))
186186
{
187187
var httpClient = new HttpClient(new HttpClientHandler()
188188
{
@@ -191,11 +191,11 @@ private static Stream GetStream(string input)
191191
{
192192
DefaultRequestVersion = HttpVersion.Version20
193193
};
194-
stream = httpClient.GetStreamAsync(input).Result;
194+
stream = httpClient.GetStreamAsync(openapi).Result;
195195
}
196196
else
197197
{
198-
var fileInput = new FileInfo(input);
198+
var fileInput = new FileInfo(openapi);
199199
stream = fileInput.OpenRead();
200200
}
201201

@@ -234,14 +234,14 @@ public static Dictionary<string, List<string>> ParseJsonCollectionFile(Stream st
234234
return requestUrls;
235235
}
236236

237-
internal static void ValidateOpenApiDocument(string input)
237+
internal static void ValidateOpenApiDocument(string openapi)
238238
{
239-
if (input == null)
239+
if (openapi == null)
240240
{
241-
throw new ArgumentNullException("input");
241+
throw new ArgumentNullException("openapi");
242242
}
243243

244-
var stream = GetStream(input);
244+
var stream = GetStream(openapi);
245245

246246
OpenApiDocument document;
247247

@@ -266,9 +266,9 @@ internal static void ValidateOpenApiDocument(string input)
266266
Console.WriteLine(statsVisitor.GetStatisticsReport());
267267
}
268268

269-
private static OpenApiFormat GetOpenApiFormat(string input)
269+
private static OpenApiFormat GetOpenApiFormat(string openapi)
270270
{
271-
return !input.StartsWith("http") && Path.GetExtension(input) == ".json" ? OpenApiFormat.Json : OpenApiFormat.Yaml;
271+
return !openapi.StartsWith("http") && Path.GetExtension(openapi) == ".json" ? OpenApiFormat.Json : OpenApiFormat.Yaml;
272272
}
273273
}
274274
}

src/Microsoft.OpenApi.Hidi/Program.cs

Lines changed: 38 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -14,24 +14,52 @@ static async Task<int> Main(string[] args)
1414
{
1515
var rootCommand = new RootCommand() {
1616
};
17+
18+
// command option parameters and aliases
19+
var descriptionOption = new Option("--openapi", "Input OpenAPI description file path or URL", typeof(string));
20+
descriptionOption.AddAlias("-d");
21+
22+
var outputOption = new Option("--output", "The output directory path for the generated file.", typeof(FileInfo), () => "./output", arity: ArgumentArity.ZeroOrOne);
23+
outputOption.AddAlias("-o");
24+
25+
var versionOption = new Option("--version", "OpenAPI specification version", typeof(OpenApiSpecVersion));
26+
versionOption.AddAlias("-v");
27+
28+
var formatOption = new Option("--format", "File format", typeof(OpenApiFormat));
29+
formatOption.AddAlias("-f");
30+
;
31+
var inlineOption = new Option("--inline", "Inline $ref instances", typeof(bool));
32+
inlineOption.AddAlias("-i");
33+
;
34+
var resolveExternalOption = new Option("--resolve-external", "Resolve external $refs", typeof(bool));
35+
resolveExternalOption.AddAlias("-ex");
36+
;
37+
var filterByOperationIdsOption = new Option("--filter-by-operationids", "Filters OpenApiDocument by OperationId(s) provided", typeof(string));
38+
filterByOperationIdsOption.AddAlias("-op");
39+
;
40+
var filterByTagsOption = new Option("--filter-by-tags", "Filters OpenApiDocument by Tag(s) provided", typeof(string));
41+
filterByTagsOption.AddAlias("-t");
42+
;
43+
var filterByCollectionOption = new Option("--filter-by-collection", "Filters OpenApiDocument by Postman collection provided", typeof(string));
44+
filterByCollectionOption.AddAlias("-c");
1745

1846
var validateCommand = new Command("validate")
1947
{
20-
new Option("--input", "Input OpenAPI description file path or URL", typeof(string) )
48+
descriptionOption
2149
};
2250
validateCommand.Handler = CommandHandler.Create<string>(OpenApiService.ValidateOpenApiDocument);
2351

2452
var transformCommand = new Command("transform")
2553
{
26-
new Option("--input", "Input OpenAPI description, JSON or CSDL file path or URL", typeof(string) ),
27-
new Option("--output","Output OpenAPI description file", typeof(FileInfo), arity: ArgumentArity.ZeroOrOne),
28-
new Option("--version", "OpenAPI specification version", typeof(OpenApiSpecVersion)),
29-
new Option("--format", "File format",typeof(OpenApiFormat) ),
30-
new Option("--inline", "Inline $ref instances", typeof(bool) ),
31-
new Option("--resolveExternal","Resolve external $refs", typeof(bool)),
32-
new Option("--filterByOperationIds", "Filters OpenApiDocument by OperationId(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))
54+
descriptionOption,
55+
outputOption,
56+
versionOption,
57+
formatOption,
58+
inlineOption,
59+
resolveExternalOption,
60+
filterByOperationIdsOption,
61+
filterByTagsOption,
62+
filterByCollectionOption
3563
};
3664
transformCommand.Handler = CommandHandler.Create<string, FileInfo, OpenApiSpecVersion?, OpenApiFormat?, string, string, string, bool, bool>(
3765
OpenApiService.ProcessOpenApiDocument);

0 commit comments

Comments
 (0)