diff --git a/CHANGELOG.md b/CHANGELOG.md
index 454ff6c0b1..0157f639d1 100644
--- a/CHANGELOG.md
+++ b/CHANGELOG.md
@@ -11,11 +11,13 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Changed
+- Plugins OpenAPI extensions are only added when generating plugins to reduce the risk of parsing errors. [#4834](https://github.com/microsoft/kiota/issues/4834)
- TypeScript imports are now using ES6 imports with the .js extension.
- Remove LINQ usage in generated code.
- Ensures descriptions are not empty in sliced OpenApi file when generating a plugin.
- Plugins do not emit parameters anymore. [#4841](https://github.com/microsoft/kiota/issues/4841)
+
## [1.15.0] - 2024-06-06
### Added
diff --git a/src/Kiota.Builder/Extensions/OpenApiSettingsExtensions.cs b/src/Kiota.Builder/Extensions/OpenApiSettingsExtensions.cs
new file mode 100644
index 0000000000..eb097ce999
--- /dev/null
+++ b/src/Kiota.Builder/Extensions/OpenApiSettingsExtensions.cs
@@ -0,0 +1,21 @@
+using System;
+using Kiota.Builder.OpenApiExtensions;
+using Microsoft.OpenApi.Readers;
+
+namespace Kiota.Builder.Extensions;
+public static class OpenApiSettingsExtensions
+{
+ ///
+ /// Adds the OpenAPI extensions used for plugins generation.
+ ///
+ public static void AddPluginsExtensions(this OpenApiReaderSettings settings)
+ {
+ ArgumentNullException.ThrowIfNull(settings);
+ settings.ExtensionParsers.TryAdd(OpenApiLogoExtension.Name, static (i, _) => OpenApiLogoExtension.Parse(i));
+ settings.ExtensionParsers.TryAdd(OpenApiDescriptionForModelExtension.Name, static (i, _) => OpenApiDescriptionForModelExtension.Parse(i));
+ settings.ExtensionParsers.TryAdd(OpenApiPrivacyPolicyUrlExtension.Name, static (i, _) => OpenApiPrivacyPolicyUrlExtension.Parse(i));
+ settings.ExtensionParsers.TryAdd(OpenApiLegalInfoUrlExtension.Name, static (i, _) => OpenApiLegalInfoUrlExtension.Parse(i));
+ settings.ExtensionParsers.TryAdd(OpenApiAiReasoningInstructionsExtension.Name, static (i, _) => OpenApiAiReasoningInstructionsExtension.Parse(i));
+ settings.ExtensionParsers.TryAdd(OpenApiAiRespondingInstructionsExtension.Name, static (i, _) => OpenApiAiRespondingInstructionsExtension.Parse(i));
+ }
+}
diff --git a/src/Kiota.Builder/OpenApiDocumentDownloadService.cs b/src/Kiota.Builder/OpenApiDocumentDownloadService.cs
index b4dad81576..b62c438439 100644
--- a/src/Kiota.Builder/OpenApiDocumentDownloadService.cs
+++ b/src/Kiota.Builder/OpenApiDocumentDownloadService.cs
@@ -113,13 +113,9 @@ ex is SecurityException ||
RuleSet = ruleSet,
};
settings.AddMicrosoftExtensionParsers();
+ if (config.IsPluginConfiguration)
+ settings.AddPluginsExtensions();
settings.ExtensionParsers.TryAdd(OpenApiKiotaExtension.Name, static (i, _) => OpenApiKiotaExtension.Parse(i));
- settings.ExtensionParsers.TryAdd(OpenApiDescriptionForModelExtension.Name, static (i, _) => OpenApiDescriptionForModelExtension.Parse(i));
- settings.ExtensionParsers.TryAdd(OpenApiLogoExtension.Name, static (i, _) => OpenApiLogoExtension.Parse(i));
- settings.ExtensionParsers.TryAdd(OpenApiPrivacyPolicyUrlExtension.Name, static (i, _) => OpenApiPrivacyPolicyUrlExtension.Parse(i));
- settings.ExtensionParsers.TryAdd(OpenApiLegalInfoUrlExtension.Name, static (i, _) => OpenApiLegalInfoUrlExtension.Parse(i));
- settings.ExtensionParsers.TryAdd(OpenApiAiReasoningInstructionsExtension.Name, static (i, _) => OpenApiAiReasoningInstructionsExtension.Parse(i));
- settings.ExtensionParsers.TryAdd(OpenApiAiRespondingInstructionsExtension.Name, static (i, _) => OpenApiAiRespondingInstructionsExtension.Parse(i));
try
{
var rawUri = config.OpenAPIFilePath.TrimEnd(KiotaBuilder.ForwardSlash);
diff --git a/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiReasoningInstructionsExtensionTests.cs b/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiReasoningInstructionsExtensionTests.cs
index 1a4d716b51..8ee5bf5ad4 100644
--- a/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiReasoningInstructionsExtensionTests.cs
+++ b/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiReasoningInstructionsExtensionTests.cs
@@ -46,7 +46,7 @@ public async Task ParsesInDocument()
await File.WriteAllTextAsync(documentPath, documentContent);
var mockLogger = new Mock>();
var documentDownloadService = new OpenApiDocumentDownloadService(_httpClient, mockLogger.Object);
- var generationConfig = new GenerationConfiguration { OutputPath = TempDirectory };
+ var generationConfig = new GenerationConfiguration { OutputPath = TempDirectory, PluginTypes = [PluginType.APIPlugin] };
var (openApiDocumentStream, _) = await documentDownloadService.LoadStreamAsync(documentPath, generationConfig);
var document = await documentDownloadService.GetDocumentFromStreamAsync(openApiDocumentStream, generationConfig);
Assert.NotNull(document);
diff --git a/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiRespondingInstructionsExtensionTests.cs b/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiRespondingInstructionsExtensionTests.cs
index ba82ff57e7..591a9ab29d 100644
--- a/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiRespondingInstructionsExtensionTests.cs
+++ b/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiAiRespondingInstructionsExtensionTests.cs
@@ -46,7 +46,7 @@ public async Task ParsesInDocument()
await File.WriteAllTextAsync(documentPath, documentContent);
var mockLogger = new Mock>();
var documentDownloadService = new OpenApiDocumentDownloadService(_httpClient, mockLogger.Object);
- var generationConfig = new GenerationConfiguration { OutputPath = TempDirectory };
+ var generationConfig = new GenerationConfiguration { OutputPath = TempDirectory, PluginTypes = [PluginType.APIPlugin] };
var (openApiDocumentStream, _) = await documentDownloadService.LoadStreamAsync(documentPath, generationConfig);
var document = await documentDownloadService.GetDocumentFromStreamAsync(openApiDocumentStream, generationConfig);
Assert.NotNull(document);
diff --git a/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiDescriptionForModelExtensionTests.cs b/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiDescriptionForModelExtensionTests.cs
index f66cc5e28e..008052b648 100644
--- a/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiDescriptionForModelExtensionTests.cs
+++ b/tests/Kiota.Builder.Tests/OpenApiExtensions/OpenApiDescriptionForModelExtensionTests.cs
@@ -41,7 +41,7 @@ public async Task ParsesInDocument()
await File.WriteAllTextAsync(documentPath, documentContent);
var mockLogger = new Mock>();
var documentDownloadService = new OpenApiDocumentDownloadService(_httpClient, mockLogger.Object);
- var generationConfig = new GenerationConfiguration { OutputPath = TempDirectory };
+ var generationConfig = new GenerationConfiguration { OutputPath = TempDirectory, PluginTypes = [PluginType.APIPlugin] };
var (openApiDocumentStream, _) = await documentDownloadService.LoadStreamAsync(documentPath, generationConfig);
var document = await documentDownloadService.GetDocumentFromStreamAsync(openApiDocumentStream, generationConfig);
Assert.NotNull(document);