Skip to content

Commit 85b3c0f

Browse files
committed
Started adding the plugin creation command
1 parent ca241c0 commit 85b3c0f

File tree

3 files changed

+80
-0
lines changed

3 files changed

+80
-0
lines changed
Lines changed: 49 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,49 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT license.
3+
4+
using System;
5+
using System.CommandLine.Invocation;
6+
using System.Threading;
7+
using System.Threading.Tasks;
8+
using Microsoft.Extensions.Logging;
9+
using Microsoft.OpenApi.Hidi.Options;
10+
11+
namespace Microsoft.OpenApi.Hidi.Handlers
12+
{
13+
internal class PluginCommandHandler : ICommandHandler
14+
{
15+
public CommandOptions CommandOptions { get; }
16+
public PluginCommandHandler(CommandOptions commandOptions)
17+
{
18+
CommandOptions = commandOptions;
19+
}
20+
public int Invoke(InvocationContext context)
21+
{
22+
return InvokeAsync(context).GetAwaiter().GetResult();
23+
}
24+
public async Task<int> InvokeAsync(InvocationContext context)
25+
{
26+
HidiOptions hidiOptions = new HidiOptions(context.ParseResult, CommandOptions);
27+
CancellationToken cancellationToken = (CancellationToken)context.BindingContext.GetService(typeof(CancellationToken));
28+
29+
using var loggerFactory = Logger.ConfigureLogger(hidiOptions.LogLevel);
30+
var logger = loggerFactory.CreateLogger<OpenApiService>();
31+
try
32+
{
33+
await OpenApiService.PluginManifest(hidiOptions, logger, cancellationToken);
34+
35+
return 0;
36+
}
37+
catch (Exception ex)
38+
{
39+
#if DEBUG
40+
logger.LogCritical(ex, ex.Message);
41+
throw; // so debug tools go straight to the source of the exception when attached
42+
#else
43+
logger.LogCritical( ex.Message);
44+
return 1;
45+
#endif
46+
}
47+
}
48+
}
49+
}

src/Microsoft.OpenApi.Hidi/OpenApiService.cs

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -701,5 +701,28 @@ internal static void WriteTreeDocumentAsHtml(string sourceUrl, OpenApiDocument d
701701
// Write script tag to include JS library for rendering mermaid
702702
writer.WriteLine("</html");
703703
}
704+
705+
internal async static Task PluginManifest(HidiOptions options, ILogger<OpenApiService> logger, CancellationToken cancellationToken)
706+
{
707+
// If ApiManifest is provided, set the referenced OpenAPI document
708+
var apiDependency = await FindApiDependency(options.FilterOptions?.FilterByApiManifest, logger, cancellationToken);
709+
if (apiDependency != null) {
710+
options.OpenApi = apiDependency.ApiDescripionUrl;
711+
}
712+
713+
// Load OpenAPI document
714+
OpenApiDocument document = await GetOpenApi(options.OpenApi, options.Csdl, options.CsdlFilter, options.SettingsConfig, options.InlineExternal, logger, cancellationToken, options.MetadataVersion);
715+
716+
if (options.FilterOptions != null)
717+
{
718+
document = ApplyFilters(options, logger, apiDependency, null, document, cancellationToken);
719+
}
720+
721+
// Create OpenAIPluginManifest from ApiDependency and OpenAPI document
722+
723+
724+
// Save OpenAI Plugin manifest and filtered OpenAI to output folder
725+
726+
}
704727
}
705728
}

src/Microsoft.OpenApi.Hidi/readme.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,3 +105,11 @@ This command accepts an OpenAPI document as an input parameter and generates a M
105105
**Examples:**
106106

107107
1. hidi show -d files\People.yml -o People.md -ll trace
108+
109+
### Plugin
110+
111+
This command generates an OpenAI style Plugin manifest and minimal OpenAPI file based on the provided API Manifest
112+
113+
**Examples:**
114+
115+
1. hidi plugin -m exampleApiManifest.yml -o mypluginfolder

0 commit comments

Comments
 (0)