Skip to content

Commit

Permalink
Merge branch 'main' into jmstall/test-dependency-vistor
Browse files Browse the repository at this point in the history
  • Loading branch information
MikeStall authored Jan 14, 2025
2 parents dff122f + 0fa1968 commit 04e00b3
Show file tree
Hide file tree
Showing 30 changed files with 8,583 additions and 282 deletions.
37 changes: 21 additions & 16 deletions src/libraries/Microsoft.PowerFx.Connectors/ConnectorFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -156,7 +156,7 @@ public IReadOnlyCollection<ErrorResourceKey> Warnings
/// <summary>
/// Return type of the function.
/// </summary>
public FormulaType ReturnType => Operation.GetReturnType(ConnectorSettings.Compatibility);
public FormulaType ReturnType => Operation.GetReturnType(ConnectorSettings);

/// <summary>
/// Minimum number of arguments.
Expand Down Expand Up @@ -988,7 +988,7 @@ private async Task<ConnectorType> GetConnectorSuggestionsFromDynamicSchemaAsync(
return null;
}

ConnectorType connectorType = GetConnectorType(cds.ValuePath, sv, ConnectorSettings.Compatibility);
ConnectorType connectorType = GetConnectorType(cds.ValuePath, sv, ConnectorSettings);

if (connectorType.HasErrors)
{
Expand All @@ -1002,15 +1002,15 @@ private async Task<ConnectorType> GetConnectorSuggestionsFromDynamicSchemaAsync(
return connectorType;
}

internal static ConnectorType GetConnectorType(string valuePath, StringValue sv, ConnectorCompatibility compatibility)
internal static ConnectorType GetConnectorType(string valuePath, StringValue sv, ConnectorSettings settings)
{
JsonElement je = ExtractFromJson(sv, valuePath);
return GetConnectorTypeInternal(compatibility, je);
return GetConnectorTypeInternal(settings, je);
}

// Only called by ConnectorTable.GetSchema
// Returns a FormulaType with AssociatedDataSources set (done in AddTabularDataSource)
internal static ConnectorType GetCdpTableType(ICdpTableResolver tableResolver, string connectorName, string tableName, string valuePath, StringValue stringValue, ConnectorCompatibility compatibility, string datasetName,
internal static ConnectorType GetCdpTableType(ICdpTableResolver tableResolver, string connectorName, string tableName, string valuePath, StringValue stringValue, ConnectorSettings settings, string datasetName,
out string name, out string displayName, out TableDelegationInfo delegationInfo, out IEnumerable<OptionSet> optionSets)
{
// There are some errors when parsing this Json payload but that's not a problem here as we only need x-ms-capabilities parsing to work
Expand All @@ -1025,7 +1025,7 @@ internal static ConnectorType GetCdpTableType(ICdpTableResolver tableResolver, s
IList<ReferencedEntity> referencedEntities = GetReferenceEntities(connectorName, stringValue);

SymbolTable symbolTable = new SymbolTable();
ConnectorType connectorType = new ConnectorType(jsonElement, tableName, symbolTable, compatibility, referencedEntities, datasetName, name, connectorName, tableResolver, serviceCapabilities, isTableReadOnly);
ConnectorType connectorType = new ConnectorType(jsonElement, tableName, symbolTable, settings, referencedEntities, datasetName, name, connectorName, tableResolver, serviceCapabilities, isTableReadOnly);
delegationInfo = ((DataSourceInfo)connectorType.FormulaType._type.AssociatedDataSources.First()).DelegationInfo;
optionSets = symbolTable.OptionSets.Select(kvp => kvp.Value);

Expand Down Expand Up @@ -1081,12 +1081,12 @@ internal class SalesForceReferencedEntity
public bool RestrictedDelete { get; set; }
}

private static ConnectorType GetConnectorTypeInternal(ConnectorCompatibility compatibility, JsonElement je)
private static ConnectorType GetConnectorTypeInternal(ConnectorSettings settings, JsonElement je)
{
OpenApiReaderSettings oars = new OpenApiReaderSettings() { RuleSet = DefaultValidationRuleSet };
OpenApiSchema schema = new OpenApiStringReader(oars).ReadFragment<OpenApiSchema>(je.ToString(), OpenApi.OpenApiSpecVersion.OpenApi2_0, out OpenApiDiagnostic diag);

return new ConnectorType(SwaggerSchema.New(schema), compatibility);
return new ConnectorType(SwaggerSchema.New(schema), settings);
}

private async Task<ConnectorType> GetConnectorSuggestionsFromDynamicPropertyAsync(NamedValue[] knownParameters, BaseRuntimeConnectorContext runtimeContext, ConnectorDynamicProperty cdp, CancellationToken cancellationToken)
Expand All @@ -1107,7 +1107,7 @@ private async Task<ConnectorType> GetConnectorSuggestionsFromDynamicPropertyAsyn
return null;
}

ConnectorType connectorType = GetConnectorType(cdp.ItemValuePath, sv, ConnectorSettings.Compatibility);
ConnectorType connectorType = GetConnectorType(cdp.ItemValuePath, sv, ConnectorSettings);

if (connectorType.HasErrors)
{
Expand Down Expand Up @@ -1414,7 +1414,7 @@ private ConnectorParameterInternals Initialize()
return null;
}

ConnectorParameter connectorParameter = errorsAndWarnings.AggregateErrorsAndWarnings(new ConnectorParameter(parameter, ConnectorSettings.Compatibility));
ConnectorParameter connectorParameter = errorsAndWarnings.AggregateErrorsAndWarnings(new ConnectorParameter(parameter, ConnectorSettings));

if (connectorParameter.HiddenRecordType != null)
{
Expand Down Expand Up @@ -1460,7 +1460,12 @@ private ConnectorParameterInternals Initialize()
OpenApiSchema bodyPropertySchema = bodyProperty.Value;
string bodyPropertyName = bodyProperty.Key;
bool bodyPropertyRequired = bodySchema.Required.Contains(bodyPropertyName);
bool bodyPropertyHiddenRequired = false;
bool bodyPropertyHiddenRequired = false;

if (ConnectorSettings.UseDefaultBodyNameForSinglePropertyObject && bodySchema.Properties.Count == 1)
{
bodyPropertyName = bodyName;
}

if (bodyPropertySchema.IsInternal())
{
Expand All @@ -1483,12 +1488,12 @@ private ConnectorParameterInternals Initialize()
}

OpenApiParameter bodyParameter = new OpenApiParameter() { Name = bodyPropertyName, Schema = bodyPropertySchema, Description = requestBody.Description, Required = bodyPropertyRequired, Extensions = bodyPropertySchema.Extensions };
ConnectorParameter bodyConnectorParameter2 = errorsAndWarnings.AggregateErrorsAndWarnings(new ConnectorParameter(bodyParameter, requestBody, ConnectorSettings.Compatibility));
ConnectorParameter bodyConnectorParameter2 = errorsAndWarnings.AggregateErrorsAndWarnings(new ConnectorParameter(bodyParameter, requestBody, ConnectorSettings));
openApiBodyParameters.Add(bodyConnectorParameter2, OpenApiExtensions.TryGetOpenApiValue(bodyConnectorParameter2.Schema.Default, null, out FormulaValue defaultValue, errorsAndWarnings) ? defaultValue : null);

if (bodyConnectorParameter2.HiddenRecordType != null)
{
hiddenRequiredParameters.Add(errorsAndWarnings.AggregateErrorsAndWarnings(new ConnectorParameter(bodyParameter, true, ConnectorSettings.Compatibility)));
hiddenRequiredParameters.Add(errorsAndWarnings.AggregateErrorsAndWarnings(new ConnectorParameter(bodyParameter, true, ConnectorSettings)));
}

List<ConnectorParameter> parameterList = !bodyPropertyRequired ? optionalParameters : bodyPropertyHiddenRequired ? hiddenRequiredParameters : requiredParameters;
Expand All @@ -1507,7 +1512,7 @@ private ConnectorParameterInternals Initialize()
}

OpenApiParameter bodyParameter2 = new OpenApiParameter() { Name = bodyName, Schema = bodySchema, Description = requestBody.Description, Required = requestBody.Required, Extensions = bodySchema.Extensions };
ConnectorParameter bodyConnectorParameter3 = errorsAndWarnings.AggregateErrorsAndWarnings(new ConnectorParameter(bodyParameter2, requestBody, ConnectorSettings.Compatibility));
ConnectorParameter bodyConnectorParameter3 = errorsAndWarnings.AggregateErrorsAndWarnings(new ConnectorParameter(bodyParameter2, requestBody, ConnectorSettings));
openApiBodyParameters.Add(bodyConnectorParameter3, OpenApiExtensions.TryGetOpenApiValue(bodyConnectorParameter3.Schema.Default, null, out FormulaValue defaultValue, errorsAndWarnings) ? defaultValue : null);

if (bodyConnectorParameter3.HiddenRecordType != null)
Expand All @@ -1527,7 +1532,7 @@ private ConnectorParameterInternals Initialize()
OpenApiSchema bodyParameterSchema = new OpenApiSchema() { Type = "string" };

OpenApiParameter bodyParameter3 = new OpenApiParameter() { Name = bodyName, Schema = bodyParameterSchema, Description = "Body", Required = requestBody.Required };
ConnectorParameter bodyParameter = errorsAndWarnings.AggregateErrorsAndWarnings(new ConnectorParameter(bodyParameter3, requestBody, ConnectorSettings.Compatibility));
ConnectorParameter bodyParameter = errorsAndWarnings.AggregateErrorsAndWarnings(new ConnectorParameter(bodyParameter3, requestBody, ConnectorSettings));
openApiBodyParameters.Add(bodyParameter, OpenApiExtensions.TryGetOpenApiValue(bodyParameter.Schema.Default, null, out FormulaValue defaultValue, errorsAndWarnings) ? defaultValue : null);

List<ConnectorParameter> parameterList = requestBody.Required ? requiredParameters : optionalParameters;
Expand Down Expand Up @@ -1570,7 +1575,7 @@ private ConnectorParameterInternals Initialize()
_arityMax = _arityMin + (_optionalParameters.Length == 0 ? 0 : 1);
_warnings = new List<ErrorResourceKey>();

_returnType = errorsAndWarnings.AggregateErrorsAndWarnings(Operation.GetConnectorReturnType(ConnectorSettings.Compatibility));
_returnType = errorsAndWarnings.AggregateErrorsAndWarnings(Operation.GetConnectorReturnType(ConnectorSettings));

if (IsDeprecated)
{
Expand Down
Loading

0 comments on commit 04e00b3

Please sign in to comment.