-
Notifications
You must be signed in to change notification settings - Fork 253
/
Copy pathOpenApiExtensibleExtensions.cs
25 lines (24 loc) · 1.09 KB
/
OpenApiExtensibleExtensions.cs
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
using Microsoft.OpenApi.Any;
using Microsoft.OpenApi.Interfaces;
using System.Collections.Generic;
using System.Text.Json.Nodes;
namespace Microsoft.OpenApi.Hidi.Extensions
{
internal static class OpenApiExtensibleExtensions
{
/// <summary>
/// Gets an extension value from the extensions dictionary.
/// </summary>
/// <param name="extensions">A dictionary of <see cref="IOpenApiExtension"/>.</param>
/// <param name="extensionKey">The key corresponding to the <see cref="IOpenApiExtension"/>.</param>
/// <returns>A <see cref="string"/> value matching the provided extensionKey. Return null when extensionKey is not found. </returns>
internal static string GetExtension(this Dictionary<string, IOpenApiExtension> extensions, string extensionKey)
{
if (extensions.TryGetValue(extensionKey, out var value) && value is OpenApiAny { Node: JsonValue castValue } && castValue.TryGetValue<string>(out var stringValue))
{
return stringValue;
}
return string.Empty;
}
}
}