Skip to content

Commit

Permalink
Merge branch 'main' into carlosff/scopeinfo/addcolumnssearch
Browse files Browse the repository at this point in the history
  • Loading branch information
CarlosFigueiraMSFT authored Mar 8, 2024
2 parents 39d5144 + 7287db1 commit fde2ad0
Show file tree
Hide file tree
Showing 239 changed files with 18,538 additions and 3,161 deletions.
16 changes: 9 additions & 7 deletions .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -41,10 +41,10 @@ dotnet_sort_system_directives_first = true
dotnet_separate_import_directive_groups = false

# this. preferences
dotnet_style_qualification_for_field = false:error
dotnet_style_qualification_for_property = false:error
dotnet_style_qualification_for_method = false:error
dotnet_style_qualification_for_event = false:error
dotnet_style_qualification_for_field = false:none
dotnet_style_qualification_for_property = false:none
dotnet_style_qualification_for_method = false:none
dotnet_style_qualification_for_event = false:none

# Language keywords vs BCL types preferences
dotnet_style_predefined_type_for_locals_parameters_members = true:error
Expand All @@ -68,7 +68,7 @@ dotnet_style_coalesce_expression = true:error
dotnet_style_prefer_is_null_check_over_reference_equality_method = true:none
dotnet_prefer_inferred_tuple_names = true:error
dotnet_prefer_inferred_anonymous_type_member_names = true:error
dotnet_style_prefer_auto_properties = true:error
dotnet_style_prefer_auto_properties = true:none
dotnet_style_prefer_conditional_expression_over_assignment = true:silent
dotnet_style_prefer_conditional_expression_over_return = true:silent

Expand Down Expand Up @@ -104,8 +104,8 @@ dotnet_code_quality_unused_parameters = all:suggestion
###############################
[*.cs]
# var preferences
csharp_style_var_for_built_in_types = true:error
csharp_style_var_when_type_is_apparent = true:error
csharp_style_var_for_built_in_types = false:none
csharp_style_var_when_type_is_apparent = false:none
csharp_style_var_elsewhere = false:none

# Expression-bodied members
Expand Down Expand Up @@ -195,6 +195,8 @@ csharp_style_prefer_not_pattern = true:suggestion
csharp_style_prefer_extended_property_pattern = true:suggestion

# IDE0003: Name can be simplified
# Beware - updates to IDE0000 rules may also require an update to the options above.
# See https://learn.microsoft.com/en-us/dotnet/fundamentals/code-analysis/style-rules/
dotnet_diagnostic.IDE0003.severity = none
# IDE0004: Cast is redundant
dotnet_diagnostic.IDE0004.severity = warning
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT license.

using System.Resources;
using System.Runtime.CompilerServices;

[assembly: InternalsVisibleTo("Microsoft.PowerFx.Connectors.Tests, PublicKey=0024000004800000940000000602000000240000525341310004000001000100b5fc90e7027f67871e773a8fde8938c81dd402ba65b9201d60593e96c492651e889cc13f1415ebb53fac1131ae0bd333c5ee6021672d9718ea31a8aebd0da0072f25d87dba6fc90ffd598ed4da35e44c398c454307e8e33b8426143daec9f596836f97c8f74750e5975c64e2189f45def46b2a2b1247adc3652bf5c308055da9")]
[assembly: NeutralResourcesLanguage("en-US", UltimateResourceFallbackLocation.Satellite)]
86 changes: 67 additions & 19 deletions src/libraries/Microsoft.PowerFx.Connectors/ConnectorFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,9 @@
using Microsoft.OpenApi.Models;
using Microsoft.OpenApi.Readers;
using Microsoft.OpenApi.Validations;
using Microsoft.PowerFx.Connectors.Localization;
using Microsoft.PowerFx.Core.Errors;
using Microsoft.PowerFx.Core.Localization;
using Microsoft.PowerFx.Core.Types;
using Microsoft.PowerFx.Core.Utils;
using Microsoft.PowerFx.Functions;
Expand Down Expand Up @@ -67,6 +70,18 @@ public string NotSupportedReason
}
}

/// <summary>
/// Warnings to be reported to end user.
/// </summary>
public IReadOnlyCollection<ErrorResourceKey> Warnings
{
get
{
EnsureInitialized();
return _warnings;
}
}

/// <summary>
/// Defines if the function is deprecated.
/// </summary>
Expand Down Expand Up @@ -253,6 +268,7 @@ public ConnectorType ReturnParameterType
private ConnectorType _returnType;
private bool _isSupported;
private string _notSupportedReason;
private List<ErrorResourceKey> _warnings;

// Those properties are only used by HttpFunctionInvoker
internal ConnectorParameterInternals _internals = null;
Expand Down Expand Up @@ -599,6 +615,12 @@ internal async Task<FormulaValue> InvokeInternalAsync(FormulaValue[] arguments,
throw new InvalidOperationException($"In namespace {Namespace}, function {Name} is not supported.");
}

FormulaValue ev = arguments.Where(arg => arg is ErrorValue).FirstOrDefault();
if (ev != null)
{
return ev;
}

BaseRuntimeConnectorContext context = ReturnParameterType.Binary ? runtimeContext.WithRawResults() : runtimeContext;
ScopedHttpFunctionInvoker invoker = new ScopedHttpFunctionInvoker(DPath.Root.Append(DName.MakeValid(Namespace, out _)), Name, Namespace, new HttpFunctionInvoker(this, context), context.ThrowOnError);
FormulaValue result = await invoker.InvokeAsync(arguments, context, cancellationToken).ConfigureAwait(false);
Expand Down Expand Up @@ -968,15 +990,15 @@ private ConnectorParameterInternals Initialize()
bool schemaLessBody = false;
bool fatalError = false;
string contentType = OpenApiExtensions.ContentType_ApplicationJson;
ConnectorErrors errors = new ConnectorErrors();
ConnectorErrors errorsAndWarnings = new ConnectorErrors();

foreach (OpenApiParameter parameter in Operation.Parameters)
{
bool hiddenRequired = false;

if (parameter == null)
{
errors.AddError($"OpenApiParameter is null, this swagger file is probably containing errors");
errorsAndWarnings.AddError($"OpenApiParameter is null, this swagger file is probably containing errors");
fatalError = true;
break;
}
Expand Down Expand Up @@ -1005,15 +1027,15 @@ private ConnectorParameterInternals Initialize()
return null;
}

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

if (connectorParameter.HiddenRecordType != null)
{
errors.AddError("[Internal error] Unexpected HiddenRecordType non-null value");
errorsAndWarnings.AddError("[Internal error] Unexpected HiddenRecordType non-null value");
fatalError = true;
}

if (parameter.Schema.TryGetDefaultValue(connectorParameter.FormulaType, out FormulaValue defaultValue, errors))
if (parameter.Schema.TryGetDefaultValue(connectorParameter.FormulaType, out FormulaValue defaultValue, errorsAndWarnings))
{
parameterDefaultValues[parameter.Name] = (connectorParameter.ConnectorType.IsRequired, defaultValue, connectorParameter.FormulaType._type);
}
Expand Down Expand Up @@ -1042,7 +1064,7 @@ private ConnectorParameterInternals Initialize()
// Additional properties are ignored for now
if (bodySchema.AnyOf.Any() || bodySchema.Not != null || (bodySchema.Items != null && bodySchema.Type != "array"))
{
errors.AddError("[Body] OpenApiSchema is not supported - AnyOf, Not, AdditionalProperties or Items not array");
errorsAndWarnings.AddError("[Body] OpenApiSchema is not supported - AnyOf, Not, AdditionalProperties or Items not array");
}
else if (bodySchema.AllOf.Any() || bodySchema.Properties.Any())
{
Expand Down Expand Up @@ -1071,12 +1093,12 @@ private ConnectorParameterInternals Initialize()
}

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

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

List<ConnectorParameter> parameterList = !bodyPropertyRequired ? optionalParameters : bodyPropertyHiddenRequired ? hiddenRequiredParameters : requiredParameters;
Expand All @@ -1087,13 +1109,20 @@ private ConnectorParameterInternals Initialize()
{
schemaLessBody = true;

if (bodySchema.Type == "string" && bodySchema.Format == "binary")
{
// Blob - In Power Apps, when the body parameter is of type "binary", the name of the parameter becomes "file"
// ServiceConfigParser.cs, see DefaultBinaryRequestBodyParameterName reference
bodyName = "file";
}

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

if (bodyConnectorParameter3.HiddenRecordType != null)
{
errors.AddError("[Internal error] Unexpected HiddenRecordType not-null value for schema-less body");
errorsAndWarnings.AddError("[Internal error] Unexpected HiddenRecordType not-null value for schema-less body");
}

List<ConnectorParameter> parameterList = requestBody.Required ? requiredParameters : optionalParameters;
Expand All @@ -1108,8 +1137,8 @@ private ConnectorParameterInternals Initialize()
OpenApiSchema bodyParameterSchema = new OpenApiSchema() { Type = "string" };

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

List<ConnectorParameter> parameterList = requestBody.Required ? requiredParameters : optionalParameters;
parameterList.Add(bodyParameter);
Expand Down Expand Up @@ -1149,18 +1178,37 @@ private ConnectorParameterInternals Initialize()
_hiddenRequiredParameters = hiddenRequiredParameters.ToArray();
_arityMin = _requiredParameters.Length;
_arityMax = _arityMin + (_optionalParameters.Length == 0 ? 0 : 1);
_warnings = new List<ErrorResourceKey>();

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

if (errors.HasErrors)
if (IsDeprecated)
{
_warnings.Add(ConnectorStringResources.WarnDeprecatedFunction);
string msg = ErrorUtils.FormatMessage(StringResources.Get(ConnectorStringResources.WarnDeprecatedFunction), null, Name, Namespace);
_configurationLogger?.LogWarning($"{msg}");
}

if (errorsAndWarnings.HasErrors)
{
foreach (string error in errors.Errors)
foreach (string error in errorsAndWarnings.Errors)
{
_configurationLogger?.LogError($"Function {Name}: {error}");
}

SetUnsupported(string.Join(", ", errors.Errors));
}
SetUnsupported(string.Join(", ", errorsAndWarnings.Errors));
}

if (errorsAndWarnings.HasWarnings)
{
foreach (ErrorResourceKey warning in errorsAndWarnings.Warnings)
{
string msg = ErrorUtils.FormatMessage(StringResources.Get(warning), null, Name, Namespace);
_configurationLogger?.LogWarning($"Function {Name}: {msg}");
}

_warnings.AddRange(errorsAndWarnings.Warnings.ToArray());
}

return new ConnectorParameterInternals()
{
Expand Down
Loading

0 comments on commit fde2ad0

Please sign in to comment.