Skip to content

Commit

Permalink
Add ExposeInternalParamsWithoutDefaultValue in ConnectorSettings to e…
Browse files Browse the repository at this point in the history
…xpose internal parameters without default value (#2713)
  • Loading branch information
LucGenetier authored Oct 23, 2024
1 parent 8f3a60b commit f907331
Show file tree
Hide file tree
Showing 3 changed files with 50 additions and 7 deletions.
20 changes: 13 additions & 7 deletions src/libraries/Microsoft.PowerFx.Connectors/ConnectorFunction.cs
Original file line number Diff line number Diff line change
Expand Up @@ -1390,14 +1390,17 @@ private ConnectorParameterInternals Initialize()
{
if (parameter.Required)
{
if (parameter.Schema.Default == null)
if (parameter.Schema.Default == null && (parameter.Name == "connectionId" || !ConnectorSettings.ExposeInternalParamsWithoutDefaultValue))
{
// Ex: connectionId
continue;
}

// Ex: Api-Version
hiddenRequired = true;

if (parameter.Schema.Default != null)
{
// Ex: Api-Version
hiddenRequired = true;
}
}
else if (ConnectorSettings.Compatibility.ExcludeInternals())
{
Expand Down Expand Up @@ -1462,12 +1465,15 @@ private ConnectorParameterInternals Initialize()
{
if (bodyPropertyRequired)
{
if (bodyPropertySchema.Default == null)
if (bodyPropertySchema.Default == null && !ConnectorSettings.ExposeInternalParamsWithoutDefaultValue)
{
continue;
}

if (bodyPropertySchema.Default != null)
{
bodyPropertyHiddenRequired = !ConnectorSettings.Compatibility.IsPowerAppsCompliant() || !requestBody.Required;
}

bodyPropertyHiddenRequired = !ConnectorSettings.Compatibility.IsPowerAppsCompliant() || !requestBody.Required;
}
else if (ConnectorSettings.Compatibility.ExcludeInternals())
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,19 @@ public ConnectorSettings(string @namespace)
/// Internally, internal functions will be kept (ConnectorFunction.FunctionList) as some of those are used for dynamic intellisense.
/// </summary>
public bool IncludeInternalFunctions { get; init; } = false;

/// <summary>
/// By default, internal parameters without default values are ignored, mandatory or not.
/// With this setting turned on, mandatory internal parameters will be exposed.
/// When Compatibility is set to PowerAppsCompabiliity, this parameter is always true.
/// </summary>
public bool ExposeInternalParamsWithoutDefaultValue
{
get => _exposeInternalParamsWithoutDefaultValue || Compatibility == ConnectorCompatibility.PowerAppsCompatibility;
init => _exposeInternalParamsWithoutDefaultValue = value;
}

private bool _exposeInternalParamsWithoutDefaultValue = false;

/// <summary>
/// In Power Apps, all record fields which are not declared in the swagger file will not be part of the Power Fx response.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1778,6 +1778,30 @@ public async Task SharePointOnlineTest()
Assert.Equal(expected, testConnector._log.ToString());
}

[Theory]
[InlineData(ConnectorCompatibility.SwaggerCompatibility, true, 4, "poster, location, notificationUrl, body")]
[InlineData(ConnectorCompatibility.PowerAppsCompatibility, false, 4, "poster, location, notificationUrl, body")]
[InlineData(ConnectorCompatibility.SwaggerCompatibility, false, 3, "poster, location, body")]
public void ExposeInternalParamsWithoutDefaultValueTest(ConnectorCompatibility compatibility, bool exposeInternalParamsWithoutDefaultValue, int expectedCount, string expectedParamaeters)
{
using LoggingTestServer testConnector = new LoggingTestServer(@"Swagger\Teams.json", _output);
OpenApiDocument apiDoc = testConnector._apiDocument;

ConnectorSettings connectorSettings = new ConnectorSettings("teams")
{
Compatibility = compatibility,
AllowUnsupportedFunctions = true,
IncludeInternalFunctions = true,
IncludeWebhookFunctions = true,
ExposeInternalParamsWithoutDefaultValue = exposeInternalParamsWithoutDefaultValue
};

ConnectorFunction function = OpenApiParser.GetFunctions(connectorSettings, apiDoc).First(f => f.Name == "PostCardAndWaitForResponse");

Assert.Equal(expectedCount, function.RequiredParameters.Length);
Assert.Equal(expectedParamaeters, string.Join(", ", function.RequiredParameters.Select(rp => rp.Name)));
}

[Fact]
public async Task EdenAITest()
{
Expand Down

0 comments on commit f907331

Please sign in to comment.