diff --git a/src/Kiota.Builder/OpenApiDocumentDownloadService.cs b/src/Kiota.Builder/OpenApiDocumentDownloadService.cs index 20ce471058..b4dad81576 100644 --- a/src/Kiota.Builder/OpenApiDocumentDownloadService.cs +++ b/src/Kiota.Builder/OpenApiDocumentDownloadService.cs @@ -115,6 +115,9 @@ ex is SecurityException || settings.AddMicrosoftExtensionParsers(); 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 diff --git a/src/Kiota.Builder/OpenApiExtensions/OpenApiDescriptionForModelExtension.cs b/src/Kiota.Builder/OpenApiExtensions/OpenApiDescriptionForModelExtension.cs index 3e3acfa5bf..ba198df7c9 100644 --- a/src/Kiota.Builder/OpenApiExtensions/OpenApiDescriptionForModelExtension.cs +++ b/src/Kiota.Builder/OpenApiExtensions/OpenApiDescriptionForModelExtension.cs @@ -1,32 +1,20 @@ -using System; -using Microsoft.OpenApi; -using Microsoft.OpenApi.Any; -using Microsoft.OpenApi.Interfaces; -using Microsoft.OpenApi.Writers; +using Microsoft.OpenApi.Any; namespace Kiota.Builder.OpenApiExtensions; -public class OpenApiDescriptionForModelExtension : IOpenApiExtension +public class OpenApiDescriptionForModelExtension : OpenApiSimpleStringExtension { public static string Name => "x-ai-description"; public string? Description { get; set; } - public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) - { - ArgumentNullException.ThrowIfNull(writer); - if (!string.IsNullOrWhiteSpace(Description)) - { - writer.WriteValue(Description); - } - } + protected override string? ValueSelector => Description; public static OpenApiDescriptionForModelExtension Parse(IOpenApiAny source) { - if (source is not OpenApiString rawString) throw new ArgumentOutOfRangeException(nameof(source)); return new OpenApiDescriptionForModelExtension { - Description = rawString.Value + Description = ParseString(source) }; } } diff --git a/src/Kiota.Builder/OpenApiExtensions/OpenApiLegalInfoUrlExtension.cs b/src/Kiota.Builder/OpenApiExtensions/OpenApiLegalInfoUrlExtension.cs new file mode 100644 index 0000000000..3f042fc70c --- /dev/null +++ b/src/Kiota.Builder/OpenApiExtensions/OpenApiLegalInfoUrlExtension.cs @@ -0,0 +1,20 @@ +using Microsoft.OpenApi.Any; + +namespace Kiota.Builder.OpenApiExtensions; + +public class OpenApiLegalInfoUrlExtension : OpenApiSimpleStringExtension +{ + public static string Name => "x-legal-info-url"; + public string? Legal + { + get; set; + } + protected override string? ValueSelector => Legal; + public static OpenApiLegalInfoUrlExtension Parse(IOpenApiAny source) + { + return new OpenApiLegalInfoUrlExtension + { + Legal = ParseString(source) + }; + } +} diff --git a/src/Kiota.Builder/OpenApiExtensions/OpenApiLogoExtension.cs b/src/Kiota.Builder/OpenApiExtensions/OpenApiLogoExtension.cs new file mode 100644 index 0000000000..c987228fab --- /dev/null +++ b/src/Kiota.Builder/OpenApiExtensions/OpenApiLogoExtension.cs @@ -0,0 +1,20 @@ +using Microsoft.OpenApi.Any; + +namespace Kiota.Builder.OpenApiExtensions; + +public class OpenApiLogoExtension : OpenApiSimpleStringExtension +{ + public static string Name => "x-logo"; + public string? Logo + { + get; set; + } + protected override string? ValueSelector => Logo; + public static OpenApiLogoExtension Parse(IOpenApiAny source) + { + return new OpenApiLogoExtension + { + Logo = ParseString(source) + }; + } +} diff --git a/src/Kiota.Builder/OpenApiExtensions/OpenApiPrivacyPolicyUrlExtension.cs b/src/Kiota.Builder/OpenApiExtensions/OpenApiPrivacyPolicyUrlExtension.cs new file mode 100644 index 0000000000..4cbc47c72a --- /dev/null +++ b/src/Kiota.Builder/OpenApiExtensions/OpenApiPrivacyPolicyUrlExtension.cs @@ -0,0 +1,20 @@ +using Microsoft.OpenApi.Any; + +namespace Kiota.Builder.OpenApiExtensions; + +public class OpenApiPrivacyPolicyUrlExtension : OpenApiSimpleStringExtension +{ + public static string Name => "x-privacy-policy-url"; + public string? Privacy + { + get; set; + } + protected override string? ValueSelector => Privacy; + public static OpenApiPrivacyPolicyUrlExtension Parse(IOpenApiAny source) + { + return new OpenApiPrivacyPolicyUrlExtension + { + Privacy = ParseString(source) + }; + } +} diff --git a/src/Kiota.Builder/OpenApiExtensions/OpenApiSimpleStringExtension.cs b/src/Kiota.Builder/OpenApiExtensions/OpenApiSimpleStringExtension.cs new file mode 100644 index 0000000000..9978939205 --- /dev/null +++ b/src/Kiota.Builder/OpenApiExtensions/OpenApiSimpleStringExtension.cs @@ -0,0 +1,28 @@ +using System; +using Microsoft.OpenApi; +using Microsoft.OpenApi.Any; +using Microsoft.OpenApi.Interfaces; +using Microsoft.OpenApi.Writers; + +namespace Kiota.Builder.OpenApiExtensions; + +public abstract class OpenApiSimpleStringExtension : IOpenApiExtension +{ + protected abstract string? ValueSelector + { + get; + } + public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion) + { + ArgumentNullException.ThrowIfNull(writer); + if (!string.IsNullOrWhiteSpace(ValueSelector)) + { + writer.WriteValue(ValueSelector); + } + } + public static string ParseString(IOpenApiAny source) + { + if (source is not OpenApiString rawString) throw new ArgumentOutOfRangeException(nameof(source)); + return rawString.Value; + } +} diff --git a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs index e5ff9436d7..318ab007c7 100644 --- a/src/Kiota.Builder/Plugins/PluginsGenerationService.cs +++ b/src/Kiota.Builder/Plugins/PluginsGenerationService.cs @@ -59,11 +59,23 @@ private ManifestDocument GetManifestDocument(string openApiDocumentPath) var (runtimes, functions) = GetRuntimesAndFunctionsFromTree(TreeNode, openApiDocumentPath); var descriptionForHuman = OAIDocument.Info?.Description.CleanupXMLString() is string d && !string.IsNullOrEmpty(d) ? d : $"Description for {OAIDocument.Info?.Title.CleanupXMLString()}"; var descriptionForModel = descriptionForHuman; - if (OAIDocument.Info is not null && - OAIDocument.Info.Extensions.TryGetValue(OpenApiDescriptionForModelExtension.Name, out var descriptionExtension) && + string? legalUrl = null; + string? logoUrl = null; + string? privacyUrl = null; + if (OAIDocument.Info is not null) + { + + if (OAIDocument.Info.Extensions.TryGetValue(OpenApiDescriptionForModelExtension.Name, out var descriptionExtension) && descriptionExtension is OpenApiDescriptionForModelExtension extension && !string.IsNullOrEmpty(extension.Description)) - descriptionForModel = extension.Description.CleanupXMLString(); + descriptionForModel = extension.Description.CleanupXMLString(); + if (OAIDocument.Info.Extensions.TryGetValue(OpenApiLegalInfoUrlExtension.Name, out var legalExtension) && legalExtension is OpenApiLegalInfoUrlExtension legal) + legalUrl = legal.Legal; + if (OAIDocument.Info.Extensions.TryGetValue(OpenApiLogoExtension.Name, out var logoExtension) && logoExtension is OpenApiLogoExtension logo) + logoUrl = logo.Logo; + if (OAIDocument.Info.Extensions.TryGetValue(OpenApiPrivacyPolicyUrlExtension.Name, out var privacyExtension) && privacyExtension is OpenApiPrivacyPolicyUrlExtension privacy) + privacyUrl = privacy.Privacy; + } return new ManifestDocument { SchemaVersion = "v2", @@ -73,7 +85,9 @@ descriptionExtension is OpenApiDescriptionForModelExtension extension && DescriptionForModel = descriptionForModel, ContactEmail = OAIDocument.Info?.Contact?.Email, Namespace = Configuration.ClientClassName, - //TODO logo + LogoUrl = logoUrl, + LegalInfoUrl = legalUrl, + PrivacyPolicyUrl = privacyUrl, Runtimes = [.. runtimes .GroupBy(static x => x, _openAPIRuntimeComparer) .Select(static x =>