Skip to content

Commit

Permalink
Add UseDefaultBodyNameForSinglePropertyObject (#2815)
Browse files Browse the repository at this point in the history
In Power Apps, when a body parameter is used it's flattened and we
create one paramaeter for each
body object property. With that logic each parameter name will be the
object property name.

When UseDefaultBodyNameForSinglePropertyObject is set, we will use the
real body name specified
in the swagger instead of the property name of the object, provided
there is only one property.
  • Loading branch information
LucGenetier authored Jan 13, 2025
1 parent 1a43082 commit 0fa1968
Show file tree
Hide file tree
Showing 3 changed files with 34 additions and 2 deletions.
Original file line number Diff line number Diff line change
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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,15 @@ public bool ExposeInternalParamsWithoutDefaultValue
/// This flag will force all enums to be returns as FormulaType.String or FormulaType.Decimal regardless of x-ms-enum-*.
/// This flag is only in effect when SupportXMsEnumValues is true.
/// </summary>
public bool ReturnEnumsAsPrimitive { get; init; } = false;
public bool ReturnEnumsAsPrimitive { get; init; } = false;

/// <summary>
/// In Power Apps, when a body parameter is used it's flattened and we create one parameter for each
/// body object property. With that logic each parameter name will be the object property name.
/// When set, this setting will use the real body name specified in the swagger instead of the property name
/// of the object, provided there is only one property.
/// </summary>
public bool UseDefaultBodyNameForSinglePropertyObject { get; init; } = false;

public ConnectorCompatibility Compatibility { get; init; } = ConnectorCompatibility.Default;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2399,6 +2399,25 @@ public async Task SQL_ExecuteStoredProc_Scoped()
Assert.Equal(expected, actual);
}

[Theory]
[InlineData(true)]
[InlineData(false)]
public void ExchangeOnlineTest2(bool useDefaultBodyNameForSinglePropertyObject)
{
using var testConnector = new LoggingTestServer(@"Swagger\ExcelOnlineBusiness.swagger.json", _output);
List<ConnectorFunction> functions = OpenApiParser.GetFunctions(
new ConnectorSettings("Excel")
{
Compatibility = ConnectorCompatibility.Default,
UseDefaultBodyNameForSinglePropertyObject = useDefaultBodyNameForSinglePropertyObject
},
testConnector._apiDocument).ToList();

ConnectorFunction patchItem = functions.First(f => f.Name == "PatchItem");

Assert.Equal(!useDefaultBodyNameForSinglePropertyObject ? "dynamicProperties" : "item", patchItem.OptionalParameters[2].Name);
}

public class HttpLogger : HttpClient
{
private readonly ITestOutputHelper _console;
Expand Down

0 comments on commit 0fa1968

Please sign in to comment.