Skip to content

Commit

Permalink
Fix issue when body is an array (#2845)
Browse files Browse the repository at this point in the history
Issue: when the body was an array, the parameter was fully ignored
  • Loading branch information
LucGenetier authored Feb 12, 2025
1 parent edcd860 commit c5e5c9b
Show file tree
Hide file tree
Showing 5 changed files with 103 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -957,7 +957,7 @@ public static (string ContentType, OpenApiMediaType MediaType) GetContentTypeAnd
}

// application/json
if (mediaType.Schema.Properties.Any() || mediaType.Schema.Type == "object")
if (mediaType.Schema.Properties.Any() || mediaType.Schema.Type == "object" || mediaType.Schema.Type == "array")
{
return (ct, mediaType);
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,8 +57,8 @@ private static void AssertLog(LoggingTestServer testConnector, string expectedLo
[InlineData(16, @"Test.PostWeather8({z: {x: [1, 2], y:3 }, dt: DateTime(2022,6,16,13,26,24,900), db:0, str:""str"" })", "POST http://localhost:5000/weatherPost8\r\n [content-header] Content-Type: application/json; charset=utf-8\r\n [body] {\"z\":{\"x\":[1,2],\"y\":3},\"dt\":\"2022-06-16T20:26:24.900Z\",\"db\":0,\"str\":\"str\"}")]
[InlineData(17, @"Test.PostWeatherWithUrlEncodedBody({x: [1, 2], y:3})", "POST http://localhost:5000/weatherPost5\r\n [content-header] Content-Type: application/x-www-form-urlencoded; charset=utf-8\r\n [body] x=1&x=2&y=3")]
[InlineData(18, @"Test.GetT7(1, ""abc"", 5, { id_B: 4, name_B: ""foo"", countB: 44 })", "POST http://localhost:5000/weather/t7\r\n [content-header] Content-Type: application/json; charset=utf-8\r\n [body] {\"id_A\":1,\"name_A\":\"abc\",\"count\":5,\"object_B\":{\"id_B\":4,\"name_B\":\"foo\",\"countB\":44}}")]
[InlineData(19, @"Test.GetT8({body: Table({Value: 1}, {Value: 3})})", "POST http://localhost:5000/weather/t8\r\n [content-header] Content-Type: text/json; charset=utf-8\r\n [body] [1,3]")]
[InlineData(20, @"Test.GetT8a(Table({Value: 1}, {Value: 444}))", "POST http://localhost:5000/weather/t8a\r\n [content-header] Content-Type: text/json; charset=utf-8\r\n [body] [1,444]")]
[InlineData(19, @"Test.GetT8({body: Table({Value: 1}, {Value: 3})})", "POST http://localhost:5000/weather/t8\r\n [content-header] Content-Type: application/json; charset=utf-8\r\n [body] [1,3]")]
[InlineData(20, @"Test.GetT8a(Table({Value: 1}, {Value: 444}))", "POST http://localhost:5000/weather/t8a\r\n [content-header] Content-Type: application/json; charset=utf-8\r\n [body] [1,444]")]
[InlineData(21, @"Test.PostWeatherWithComplexInput({children: [{parent: { someNumbers: [123] }, otherString: ""xyz""}], someNumbers: [1,2,3]})", "POST http://localhost:5000/weatherPost4\r\n [content-header] Content-Type: application/json; charset=utf-8\r\n [body] {\"complexInput\":{\"children\":[{\"parent\":{\"someNumbers\":[123]},\"otherString\":\"xyz\"}],\"someNumbers\":[1,2,3]}}")]
public async Task ValidateHttpCalls(int i /* used for debugging */, string fxQuery, string httpQuery)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Swagger\TestConnector12.json" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Swagger\TestConnectorDateTimeFormat.json" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Swagger\TestOpenAPI.json" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Swagger\TestSwagger1.json" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Swagger\ZenDesk.json" />
<EmbeddedResource Include="$(MSBuildThisFileDirectory)Swagger\shared_sendmail.json" />
</ItemGroup>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -59,8 +59,8 @@ public void ACSL_GetFunctionNames22()

Assert.Equal("Documents", detectSentimentV3.OptionalParameters[0].Summary);
Assert.Equal("The documents to analyze.", detectSentimentV3.OptionalParameters[0].Description);
}

}

[Fact]
public void DocuSign_ListEnvelopes_DefaultValue()
{
Expand All @@ -75,6 +75,18 @@ public void DocuSign_ListEnvelopes_DefaultValue()
Assert.Equal(new DateTime(2000, 1, 2, 12, 45, 0, DateTimeKind.Utc), dtv.GetConvertedValue(TimeZoneInfo.Utc));
}

[Fact]
public void SwaggerWithArrayBody()
{
OpenApiDocument doc = Helpers.ReadSwagger(@"Swagger\TestSwagger1.json", _output);
List<ConnectorFunction> functions = OpenApiParser.GetFunctions(new ConnectorSettings("swagger") { AllowUnsupportedFunctions = true, IncludeInternalFunctions = true }, doc, new ConsoleLogger(_output)).OrderBy(cf => cf.Name).ToList();
ConnectorFunction createFileWithTable = functions.First(cf => cf.Name == "CreateFileWithTable");

Assert.Single(createFileWithTable.RequiredParameters);
Assert.Equal("rows", createFileWithTable.RequiredParameters[0].Name);
Assert.Equal("*[Value:*[]]", createFileWithTable.RequiredParameters[0].FormulaType.ToStringWithDisplayNames());
}

[Fact]
public void ACSL_Load()
{
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,85 @@
{
"swagger": "2.0",
"info": {
"title": "Power Apps Connector",
"description": "API definition for Power Apps Connector",
"version": "1.0.0"
},
"paths": {
"/{connectionId}/codeless/createFileWithTable": {
"post": {
"summary": "Create File with Table",
"description": "Create an excel file with a table",
"operationId": "CreateFileWithTable",
"consumes": [],
"produces": [
"application/json",
"text/json",
"application/xml",
"text/xml"
],
"parameters": [
{
"name": "connectionId",
"in": "path",
"required": true,
"type": "string",
"x-ms-visibility": "internal"
},
{
"name": "rows",
"in": "body",
"description": "Input an array with comma separated values",
"required": true,
"schema": {
"type": "array",
"items": {
"type": "array",
"items": {
"allOf": [
{
"type": "number"
},
{
"type": "string"
}
]
}
}
},
"x-ms-summary": "Rows to be added to the table"
}
],
"responses": {
"200": {
"description": "OK",
"schema": {
"$ref": "#/definitions/CreateFileMetadata"
}
},
"default": {
"description": "Operation Failed."
}
},
"deprecated": false,
"x-ms-visibility": "important",
"externalDocs": {
"url": "https://docs.microsoft.com/connectors/excelonlinebusiness/#create-file-with-table"
}
}
}
},
"definitions": {
"CreateFileMetadata": {
"type": "object",
"properties": {
"fileId": {
"type": "string"
},
"fileName": {
"type": "string"
}
}
}
}
}

0 comments on commit c5e5c9b

Please sign in to comment.