Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: only loads OpenAPI plugins extensions when generating plugins #4840

Merged
merged 2 commits into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
21 changes: 21 additions & 0 deletions src/Kiota.Builder/Extensions/OpenApiSettingsExtensions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
using System;
using Kiota.Builder.OpenApiExtensions;
using Microsoft.OpenApi.Readers;

namespace Kiota.Builder.Extensions;
public static class OpenApiSettingsExtensions
{
/// <summary>
/// Adds the OpenAPI extensions used for plugins generation.
/// </summary>
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));
}
}
8 changes: 2 additions & 6 deletions src/Kiota.Builder/OpenApiDocumentDownloadService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task ParsesInDocument()
await File.WriteAllTextAsync(documentPath, documentContent);
var mockLogger = new Mock<ILogger<OpenApiAiReasoningInstructionsExtension>>();
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public async Task ParsesInDocument()
await File.WriteAllTextAsync(documentPath, documentContent);
var mockLogger = new Mock<ILogger<OpenApiAiRespondingInstructionsExtension>>();
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);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public async Task ParsesInDocument()
await File.WriteAllTextAsync(documentPath, documentContent);
var mockLogger = new Mock<ILogger<OpenApiDescriptionForModelExtension>>();
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);
Expand Down
Loading