Skip to content

Commit

Permalink
Merge pull request microsoft#4840 from microsoft/bugfix/logo-parsing
Browse files Browse the repository at this point in the history
fix: only loads OpenAPI plugins extensions when generating plugins
  • Loading branch information
andrueastman authored Jun 18, 2024
2 parents f9914f3 + b8c5a66 commit 9d8f071
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 9 deletions.
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

0 comments on commit 9d8f071

Please sign in to comment.