Skip to content

Commit

Permalink
Update logo extension
Browse files Browse the repository at this point in the history
  • Loading branch information
Andrew Omondi committed Apr 11, 2024
1 parent cab61c9 commit 35e1b49
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 8 deletions.
35 changes: 28 additions & 7 deletions src/Kiota.Builder/OpenApiExtensions/OpenApiLogoExtension.cs
Original file line number Diff line number Diff line change
@@ -1,20 +1,41 @@
using Microsoft.OpenApi.Any;
using System;
using Kiota.Builder.Extensions;
using Microsoft.OpenApi;
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
using Microsoft.OpenApi.Writers;

namespace Kiota.Builder.OpenApiExtensions;

public class OpenApiLogoExtension : OpenApiSimpleStringExtension
public class OpenApiLogoExtension : IOpenApiExtension
{
public static string Name => "x-logo";
public string? Logo
#pragma warning disable CA1056
public string? Url
#pragma warning restore CA1056
{
get; set;
}
protected override string? ValueSelector => Logo;
public static OpenApiLogoExtension Parse(IOpenApiAny source)
{
return new OpenApiLogoExtension
if (source is not OpenApiObject rawObject) throw new ArgumentOutOfRangeException(nameof(source));
var extension = new OpenApiLogoExtension();
if (rawObject.TryGetValue(nameof(Url).ToFirstCharacterLowerCase(), out var url) && url is OpenApiString urlValue)
{
Logo = ParseString(source)
};
extension.Url = urlValue.Value;
}
return extension;
}

public void Write(IOpenApiWriter writer, OpenApiSpecVersion specVersion)
{
ArgumentNullException.ThrowIfNull(writer);
if (!string.IsNullOrEmpty(Url))
{
writer.WriteStartObject();
writer.WritePropertyName(nameof(Url).ToFirstCharacterLowerCase());
writer.WriteValue(Url);
writer.WriteEndObject();
}
}
}
2 changes: 1 addition & 1 deletion src/Kiota.Builder/Plugins/PluginsGenerationService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ descriptionExtension is OpenApiDescriptionForModelExtension extension &&
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;
logoUrl = logo.Url;
if (OAIDocument.Info.Extensions.TryGetValue(OpenApiPrivacyPolicyUrlExtension.Name, out var privacyExtension) && privacyExtension is OpenApiPrivacyPolicyUrlExtension privacy)
privacyUrl = privacy.Privacy;
}
Expand Down

0 comments on commit 35e1b49

Please sign in to comment.