diff --git a/images/kiota-options.png b/images/kiota-options.png
new file mode 100644
index 0000000000..ccf93755fa
Binary files /dev/null and b/images/kiota-options.png differ
diff --git a/src/CLI/ApiClientCodeGen.CLI/Commands/CSharp/KiotaCommand.cs b/src/CLI/ApiClientCodeGen.CLI/Commands/CSharp/KiotaCommand.cs
index 6d7eb2d4ec..0318ed5689 100644
--- a/src/CLI/ApiClientCodeGen.CLI/Commands/CSharp/KiotaCommand.cs
+++ b/src/CLI/ApiClientCodeGen.CLI/Commands/CSharp/KiotaCommand.cs
@@ -4,11 +4,12 @@
using Rapicgen.Core.Generators.Kiota;
using Rapicgen.Core.Installer;
using Rapicgen.Core.Logging;
+using Rapicgen.Core.Options.Kiota;
namespace Rapicgen.CLI.Commands.CSharp;
[Command("kiota", Description = "Microsoft Kiota (v1.14.0)")]
-public class KiotaCommand : CodeGeneratorCommand
+public class KiotaCommand : CodeGeneratorCommand, IKiotaOptions
{
private readonly IProcessLauncher processLauncher;
private readonly IDependencyInstaller dependencyInstaller;
@@ -29,5 +30,12 @@ public override ICodeGenerator CreateGenerator() =>
SwaggerFile,
DefaultNamespace,
processLauncher,
- dependencyInstaller);
+ dependencyInstaller,
+ this);
+
+ [Option(
+ ShortName = "m",
+ LongName = "generate-multiple-files",
+ Description = "Set this to TRUE to generate multiple files (default: FALSE)")]
+ public bool GenerateMultipleFiles { get; set; }
}
\ No newline at end of file
diff --git a/src/Core/ApiClientCodeGen.Core/Generators/Kiota/KiotaCodeGenerator.cs b/src/Core/ApiClientCodeGen.Core/Generators/Kiota/KiotaCodeGenerator.cs
index ab335688e4..dc837f97c2 100644
--- a/src/Core/ApiClientCodeGen.Core/Generators/Kiota/KiotaCodeGenerator.cs
+++ b/src/Core/ApiClientCodeGen.Core/Generators/Kiota/KiotaCodeGenerator.cs
@@ -2,36 +2,29 @@
using System.IO;
using Rapicgen.Core.Installer;
using Rapicgen.Core.Logging;
+using Rapicgen.Core.Options.Kiota;
namespace Rapicgen.Core.Generators.Kiota;
-public class KiotaCodeGenerator : ICodeGenerator
+public class KiotaCodeGenerator(
+ string swaggerFile,
+ string defaultNamespace,
+ IProcessLauncher processLauncher,
+ IDependencyInstaller dependencyInstaller,
+ IKiotaOptions options) : ICodeGenerator
{
- private readonly string swaggerFile;
- private readonly string defaultNamespace;
- private readonly IProcessLauncher processLauncher;
- private readonly IDependencyInstaller dependencyInstaller;
-
- public KiotaCodeGenerator(
- string swaggerFile,
- string defaultNamespace,
- IProcessLauncher processLauncher,
- IDependencyInstaller dependencyInstaller)
- {
- this.swaggerFile = swaggerFile;
- this.defaultNamespace = defaultNamespace;
- this.processLauncher = processLauncher;
- this.dependencyInstaller = dependencyInstaller;
- }
-
public string GenerateCode(IProgressReporter? pGenerateProgress)
{
pGenerateProgress?.Progress(10);
dependencyInstaller.InstallKiota();
pGenerateProgress?.Progress(30);
- var outputFolder = Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
- Directory.CreateDirectory(outputFolder);
+ string outputFolder = options.GenerateMultipleFiles
+ ? Path.GetDirectoryName(swaggerFile)
+ : Path.Combine(Path.GetTempPath(), Guid.NewGuid().ToString());
+
+ if (!Directory.Exists(outputFolder))
+ Directory.CreateDirectory(outputFolder);
pGenerateProgress?.Progress(40);
const string command = "kiota";
@@ -41,9 +34,17 @@ public string GenerateCode(IProgressReporter? pGenerateProgress)
context.Succeeded();
pGenerateProgress?.Progress(80);
- var output = CSharpFileMerger.MergeFiles(outputFolder);
+ string output = string.Empty;
+
+ if (!options.GenerateMultipleFiles)
+ {
+ output = CSharpFileMerger.MergeFiles(outputFolder);
+ }
pGenerateProgress?.Progress(100);
- return GeneratedCode.PrefixAutogeneratedCodeHeader(output, "Kiota", "v1.14.0");
+ return GeneratedCode.PrefixAutogeneratedCodeHeader(
+ output,
+ "Kiota",
+ "v1.14.0");
}
}
\ No newline at end of file
diff --git a/src/Core/ApiClientCodeGen.Core/Options/Kiota/DefaultKiotaOptions.cs b/src/Core/ApiClientCodeGen.Core/Options/Kiota/DefaultKiotaOptions.cs
new file mode 100644
index 0000000000..ef9f0d81ee
--- /dev/null
+++ b/src/Core/ApiClientCodeGen.Core/Options/Kiota/DefaultKiotaOptions.cs
@@ -0,0 +1,7 @@
+namespace Rapicgen.Core.Options.Kiota
+{
+ public class DefaultKiotaOptions : IKiotaOptions
+ {
+ public bool GenerateMultipleFiles => false;
+ }
+}
diff --git a/src/Core/ApiClientCodeGen.Core/Options/Kiota/IKiotaOptions.cs b/src/Core/ApiClientCodeGen.Core/Options/Kiota/IKiotaOptions.cs
new file mode 100644
index 0000000000..d2ac351fce
--- /dev/null
+++ b/src/Core/ApiClientCodeGen.Core/Options/Kiota/IKiotaOptions.cs
@@ -0,0 +1,7 @@
+namespace Rapicgen.Core.Options.Kiota
+{
+ public interface IKiotaOptions
+ {
+ bool GenerateMultipleFiles { get; }
+ }
+}
diff --git a/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/KiotaCodeGeneratorFixture.cs b/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/KiotaCodeGeneratorFixture.cs
index 6724df909a..69bc74c1e3 100644
--- a/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/KiotaCodeGeneratorFixture.cs
+++ b/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/KiotaCodeGeneratorFixture.cs
@@ -5,6 +5,7 @@
using Rapicgen.Core.Generators;
using Rapicgen.Core.Generators.Kiota;
using Rapicgen.Core.Installer;
+using Rapicgen.Core.Options.Kiota;
using Xunit;
namespace ApiClientCodeGen.Tests.Common.Fixtures
@@ -26,7 +27,8 @@ protected override async Task OnInitializeAsync()
new DependencyInstaller(
new NpmInstaller(new ProcessLauncher()),
new FileDownloader(new WebDownloader()),
- new ProcessLauncher()));
+ new ProcessLauncher()),
+ new DefaultKiotaOptions());
Code = codeGenerator.GenerateCode(ProgressReporterMock.Object);
}
diff --git a/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/OpenApi3/KiotaCodeGeneratorFixture.cs b/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/OpenApi3/KiotaCodeGeneratorFixture.cs
index 0574ef266a..0ab132a9e0 100644
--- a/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/OpenApi3/KiotaCodeGeneratorFixture.cs
+++ b/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/OpenApi3/KiotaCodeGeneratorFixture.cs
@@ -5,6 +5,7 @@
using Rapicgen.Core.Generators;
using Rapicgen.Core.Generators.Kiota;
using Rapicgen.Core.Installer;
+using Rapicgen.Core.Options.Kiota;
using Xunit;
namespace ApiClientCodeGen.Tests.Common.Fixtures.OpenApi3
@@ -16,7 +17,7 @@ public class KiotaCodeGeneratorFixture : TestWithResources
public string Code { get; private set; }
- protected override async Task OnInitializeAsync()
+ protected override Task OnInitializeAsync()
{
const string defaultNamespace = "GeneratedCode";
var codeGenerator = new KiotaCodeGenerator(
@@ -26,9 +27,11 @@ protected override async Task OnInitializeAsync()
new DependencyInstaller(
new NpmInstaller(new ProcessLauncher()),
new FileDownloader(new WebDownloader()),
- new ProcessLauncher()));
+ new ProcessLauncher()),
+ new DefaultKiotaOptions());
Code = codeGenerator.GenerateCode(ProgressReporterMock.Object);
+ return Task.CompletedTask;
}
}
}
\ No newline at end of file
diff --git a/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/OpenApi3/Yaml/KiotaCodeGeneratorFixture.cs b/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/OpenApi3/Yaml/KiotaCodeGeneratorFixture.cs
index 82b6a47237..4efa89edcd 100644
--- a/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/OpenApi3/Yaml/KiotaCodeGeneratorFixture.cs
+++ b/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/OpenApi3/Yaml/KiotaCodeGeneratorFixture.cs
@@ -5,6 +5,7 @@
using Rapicgen.Core.Generators;
using Rapicgen.Core.Generators.Kiota;
using Rapicgen.Core.Installer;
+using Rapicgen.Core.Options.Kiota;
using Xunit;
namespace ApiClientCodeGen.Tests.Common.Fixtures.OpenApi3.Yaml
@@ -26,7 +27,8 @@ protected override async Task OnInitializeAsync()
new DependencyInstaller(
new NpmInstaller(new ProcessLauncher()),
new FileDownloader(new WebDownloader()),
- new ProcessLauncher()));
+ new ProcessLauncher()),
+ new DefaultKiotaOptions());
Code = codeGenerator.GenerateCode(ProgressReporterMock.Object);
}
diff --git a/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/Yaml/KiotaCodeGeneratorFixture.cs b/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/Yaml/KiotaCodeGeneratorFixture.cs
index a3e52dc236..e92c8c540e 100644
--- a/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/Yaml/KiotaCodeGeneratorFixture.cs
+++ b/src/Core/ApiClientCodeGen.Tests.Common/Fixtures/Yaml/KiotaCodeGeneratorFixture.cs
@@ -5,6 +5,7 @@
using Rapicgen.Core.Generators;
using Rapicgen.Core.Generators.Kiota;
using Rapicgen.Core.Installer;
+using Rapicgen.Core.Options.Kiota;
using Xunit;
namespace ApiClientCodeGen.Tests.Common.Fixtures.Yaml
@@ -16,7 +17,7 @@ public class KiotaCodeGeneratorFixture : TestWithResources
public string Code { get; private set; }
- protected override async Task OnInitializeAsync()
+ protected override Task OnInitializeAsync()
{
const string defaultNamespace = "GeneratedCode";
var codeGenerator = new KiotaCodeGenerator(
@@ -26,9 +27,11 @@ protected override async Task OnInitializeAsync()
new DependencyInstaller(
new NpmInstaller(new ProcessLauncher()),
new FileDownloader(new WebDownloader()),
- new ProcessLauncher()));
+ new ProcessLauncher()),
+ new DefaultKiotaOptions());
Code = codeGenerator.GenerateCode(ProgressReporterMock.Object);
+ return Task.CompletedTask;
}
}
}
\ No newline at end of file
diff --git a/src/VSIX/ApiClientCodeGen.VSIX.Shared/ApiClientCodeGen.VSIX.Shared.projitems b/src/VSIX/ApiClientCodeGen.VSIX.Shared/ApiClientCodeGen.VSIX.Shared.projitems
index 7cda362944..2336583141 100644
--- a/src/VSIX/ApiClientCodeGen.VSIX.Shared/ApiClientCodeGen.VSIX.Shared.projitems
+++ b/src/VSIX/ApiClientCodeGen.VSIX.Shared/ApiClientCodeGen.VSIX.Shared.projitems
@@ -65,6 +65,10 @@
Component
+
+
+ Component
+
Component
diff --git a/src/VSIX/ApiClientCodeGen.VSIX.Shared/Generators/CodeGeneratorFactory.cs b/src/VSIX/ApiClientCodeGen.VSIX.Shared/Generators/CodeGeneratorFactory.cs
index 3ce83e6092..07a1fd688f 100644
--- a/src/VSIX/ApiClientCodeGen.VSIX.Shared/Generators/CodeGeneratorFactory.cs
+++ b/src/VSIX/ApiClientCodeGen.VSIX.Shared/Generators/CodeGeneratorFactory.cs
@@ -13,12 +13,14 @@
using Rapicgen.Core.Options;
using Rapicgen.Core.Options.AutoRest;
using Rapicgen.Core.Options.General;
+using Rapicgen.Core.Options.Kiota;
using Rapicgen.Core.Options.NSwag;
using Rapicgen.Core.Options.OpenApiGenerator;
using Rapicgen.Core.Options.Refitter;
using Rapicgen.Options;
using Rapicgen.Options.AutoRest;
using Rapicgen.Options.General;
+using Rapicgen.Options.Kiota;
using Rapicgen.Options.NSwag;
using Rapicgen.Options.OpenApiGenerator;
using Rapicgen.Options.Refitter;
@@ -102,7 +104,8 @@ public ICodeGenerator Create(
inputFilePath,
defaultNamespace,
processLauncher,
- dependencyInstaller);
+ dependencyInstaller,
+ optionsFactory.Create());
case SupportedCodeGenerator.Refitter:
return new RefitterCodeGenerator(
diff --git a/src/VSIX/ApiClientCodeGen.VSIX.Shared/Options/Kiota/KiotaOptions.cs b/src/VSIX/ApiClientCodeGen.VSIX.Shared/Options/Kiota/KiotaOptions.cs
new file mode 100644
index 0000000000..66b32ef43c
--- /dev/null
+++ b/src/VSIX/ApiClientCodeGen.VSIX.Shared/Options/Kiota/KiotaOptions.cs
@@ -0,0 +1,31 @@
+using System;
+using Rapicgen.Core.Logging;
+using Rapicgen.Core.Options.Kiota;
+
+namespace Rapicgen.Options.Kiota
+{
+ public class KiotaOptions
+ : OptionsBase, IKiotaOptions
+ {
+ public KiotaOptions(IKiotaOptions? options = null)
+ {
+ try
+ {
+ options ??= GetFromDialogPage();
+ GenerateMultipleFiles = options.GenerateMultipleFiles;
+ }
+ catch (Exception e)
+ {
+ Logger.Instance.TrackError(e);
+
+ Logger.Instance.WriteLine(Environment.NewLine);
+ Logger.Instance.WriteLine("Error reading user options. Reverting to default values");
+ Logger.Instance.WriteLine("GenerateMultipleFiles = false");
+
+ GenerateMultipleFiles = false;
+ }
+ }
+
+ public bool GenerateMultipleFiles { get; }
+ }
+}
\ No newline at end of file
diff --git a/src/VSIX/ApiClientCodeGen.VSIX.Shared/Options/Kiota/KiotaOptionsPage.cs b/src/VSIX/ApiClientCodeGen.VSIX.Shared/Options/Kiota/KiotaOptionsPage.cs
new file mode 100644
index 0000000000..489a97c8e5
--- /dev/null
+++ b/src/VSIX/ApiClientCodeGen.VSIX.Shared/Options/Kiota/KiotaOptionsPage.cs
@@ -0,0 +1,20 @@
+using System.ComponentModel;
+using System.Diagnostics.CodeAnalysis;
+using Rapicgen.Core.Options.Kiota;
+using Microsoft.VisualStudio.Shell;
+using System.Runtime.InteropServices;
+
+namespace Rapicgen.Options.Kiota
+{
+ [ExcludeFromCodeCoverage]
+ [ComVisible(true)]
+ public class KiotaOptionsPage : DialogPage, IKiotaOptions
+ {
+ public const string Name = "Kiota";
+
+ [Category(Name)]
+ [DisplayName("Generate Multiple Files")]
+ [Description("Generate multiple files for each operation. This only works for SDK style projects")]
+ public bool GenerateMultipleFiles { get; set; }
+ }
+}
diff --git a/src/VSIX/ApiClientCodeGen.VSIX.Shared/VsPackage.cs b/src/VSIX/ApiClientCodeGen.VSIX.Shared/VsPackage.cs
index 951db307ad..18ee8fbf28 100644
--- a/src/VSIX/ApiClientCodeGen.VSIX.Shared/VsPackage.cs
+++ b/src/VSIX/ApiClientCodeGen.VSIX.Shared/VsPackage.cs
@@ -18,6 +18,7 @@
using Task = System.Threading.Tasks.Task;
using Rapicgen.Options.Refitter;
using Rapicgen.Commands.Refitter;
+using Rapicgen.Options.Kiota;
namespace Rapicgen
{
@@ -94,6 +95,13 @@ namespace Rapicgen
0,
0,
true)]
+ [ProvideOptionPage(
+ typeof(KiotaOptionsPage),
+ VsixName,
+ KiotaOptionsPage.Name,
+ 0,
+ 0,
+ true)]
public sealed class VsPackage : AsyncPackage
{
public const string VsixName = "REST API Client Code Generator";
diff --git a/src/VSMac/ApiClientCodeGen.VSMac/CustomTools/Kiota/KiotaSingleFileCustomTool.cs b/src/VSMac/ApiClientCodeGen.VSMac/CustomTools/Kiota/KiotaSingleFileCustomTool.cs
index abb4b537ae..4aedea249e 100644
--- a/src/VSMac/ApiClientCodeGen.VSMac/CustomTools/Kiota/KiotaSingleFileCustomTool.cs
+++ b/src/VSMac/ApiClientCodeGen.VSMac/CustomTools/Kiota/KiotaSingleFileCustomTool.cs
@@ -1,6 +1,7 @@
using Rapicgen.Core.Generators;
using Rapicgen.Core.Generators.Kiota;
using Rapicgen.Core.Installer;
+using Rapicgen.Core.Options.Kiota;
namespace ApiClientCodeGen.VSMac.CustomTools.Kiota
{
@@ -18,6 +19,7 @@ protected override ICodeGenerator GetCodeGenerator(
new DependencyInstaller(
new NpmInstaller(new ProcessLauncher()),
new FileDownloader(new WebDownloader()),
- new ProcessLauncher()));
+ new ProcessLauncher()),
+ new DefaultKiotaOptions());
}
}
\ No newline at end of file