This commit is contained in:
Luc Genetier 2024-01-16 19:47:12 +01:00 коммит произвёл GitHub
Родитель cdcef30472
Коммит 8aa14b8140
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: B5690EEEBB952194
2 изменённых файлов: 41 добавлений и 2 удалений

Просмотреть файл

@ -7,6 +7,7 @@ using System.Collections.Generic;
using System.Dynamic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.Json;
using System.Text.RegularExpressions;
using Microsoft.OpenApi.Models;
@ -596,9 +597,13 @@ namespace Microsoft.PowerFx.Connectors.Tests
// Step 2: Get TexlFunctions to be exported
// Notice that TexlFunction is internal and requires InternalVisibleTo
List<TexlFunction> texlFunctions = OpenApiParser.ParseInternal(connectorSettings, connector.Value.document, logger).texlFunctions.Cast<TexlFunction>().ToList();
List<ConnectorFunction> connectorFunctions = OpenApiParser.ParseInternal(connectorSettings, connector.Value.document, logger).connectorFunctions.Cast<ConnectorFunction>().ToList();
// Step 3: Export TexlFunctions to Yaml
ExportTexlFunctionsToYaml(reference, outFolderPath, connector.Key, texlFunctions, false);
// Step 3: Export TexlFunctions to Yaml
ExportConnectorFunctionsToYaml(reference, outFolderPath, connector.Key, connectorFunctions);
}
}
@ -610,6 +615,32 @@ namespace Microsoft.PowerFx.Connectors.Tests
YamlExporter.ExportTexlFunction($"{Path.Combine(output, reference, connectorName.Replace("/", "_", StringComparison.OrdinalIgnoreCase))}", texlFunction, isLibrary);
}
}
private static void ExportConnectorFunctionsToYaml(string reference, string output, string connectorName, List<ConnectorFunction> connectorFunctions)
{
foreach (ConnectorFunction connectorFunction in connectorFunctions)
{
// Export TexlFunction definition as Yaml file
ExportConnectorFunction($"{Path.Combine(output, reference, connectorName.Replace("/", "_", StringComparison.OrdinalIgnoreCase))}", connectorFunction);
}
}
private static void ExportConnectorFunction(string folder, ConnectorFunction connectorFunction)
{
dynamic obj = connectorFunction.ToExpando(null);
var serializer = new SerializerBuilder().Build();
string yaml = serializer.Serialize(obj);
string functionFile = Path.Combine(folder, "ConnectorFunction_" + connectorFunction.Name.Replace("/", "_", StringComparison.OrdinalIgnoreCase) + ".yaml");
Directory.CreateDirectory(folder);
if (File.Exists(functionFile))
{
throw new IOException($"File {functionFile} already exists!");
}
File.WriteAllText(functionFile, yaml, Encoding.UTF8);
}
}
public static class Exts
@ -639,7 +670,11 @@ namespace Microsoft.PowerFx.Connectors.Tests
func.OperationId = connectorFunction.OriginalName;
func.Method = connectorFunction.HttpMethod.ToString().ToUpperInvariant();
func.Path = connectorFunction.OperationPath;
func.SwaggerFile = swaggerFile;
if (!string.IsNullOrEmpty(swaggerFile))
{
func.SwaggerFile = swaggerFile;
}
if (!string.IsNullOrEmpty(connectorFunction.Description))
{
@ -700,7 +735,9 @@ namespace Microsoft.PowerFx.Connectors.Tests
if (connectorParam.DefaultValue != null)
{
cParam.DefaultValue = connectorParam.DefaultValue.ToExpression();
StringBuilder sb = new StringBuilder();
connectorParam.DefaultValue.ToExpression(sb, new FormulaValueSerializerSettings() { UseCompactRepresentation = true });
cParam.DefaultValue = sb.ToString();
}
if (!string.IsNullOrEmpty(connectorParam.Title))

Просмотреть файл

@ -51,6 +51,8 @@ namespace Microsoft.PowerFx.TexlFunctionExporter
}
}
funcName = "Texl_" + funcName;
string functionFile = Path.Combine(folder, funcName.Replace("/", "_", StringComparison.OrdinalIgnoreCase) + ".yaml");
Directory.CreateDirectory(folder);