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

Issue 2790 #2791

Closed
wants to merge 2 commits into from
Closed
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
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.Globalization;
using System.Linq;
using System.Text.Json;
using Microsoft.OpenApi.Any;
Expand Down Expand Up @@ -163,7 +164,7 @@ internal ConnectorType(ISwaggerSchema schema, ISwaggerParameter openApiParameter
if (IsEnum)
{
EnumValues = schema.Enum.Select(oaa =>
{
{
if (OpenApiExtensions.TryGetOpenApiValue(oaa, null, out FormulaValue fv, this))
{
return fv;
Expand All @@ -173,10 +174,37 @@ internal ConnectorType(ISwaggerSchema schema, ISwaggerParameter openApiParameter
return FormulaValue.NewBlank();
}).ToArray();

// x-ms-enum-display-name
EnumDisplayNames = schema.Extensions != null && schema.Extensions.TryGetValue(XMsEnumDisplayName, out IOpenApiExtension enumNames) && enumNames is IList<IOpenApiAny> oaa
? oaa.Cast<OpenApiString>().Select(oas => oas.Value).ToArray()
: Array.Empty<string>();
if (schema.Extensions != null && schema.Extensions.TryGetValue(XMsEnumDisplayName, out IOpenApiExtension enumNames) && enumNames is IList<IOpenApiAny> enumNamesEntries)
{
// x-ms-enum-display-name is present
EnumDisplayNames = enumNamesEntries.Cast<OpenApiString>().Select(oas => oas.Value).ToArray();
}
else if (openApiParameter.Extensions != null && openApiParameter.Extensions.TryGetValue(XMsEnumValues, out IOpenApiExtension enumValues) && enumValues is IList<IOpenApiAny> enumValuesEntries)
{
// x-ms-enum-values is present
EnumDisplayNames = enumValuesEntries.Cast<IDictionary<string, IOpenApiAny>>()
.Select(entry =>
{
var openApiDisplay = entry["displayName"];

if (openApiDisplay is OpenApiString displayStr)
{
return displayStr.Value;
}
else if (openApiDisplay is OpenApiInteger displayInt)
{
return displayInt.Value.ToString(CultureInfo.InvariantCulture);
}
else
{
return null;
}
}).ToArray();
}
else
{
EnumDisplayNames = Array.Empty<string>();
}
}
else
{
Expand Down
Loading