Skip to content

Commit 6699bcc

Browse files
authored
only convert to type object for body parameter (#3195)
1 parent 1b980a9 commit 6699bcc

File tree

6 files changed

+286
-7
lines changed

6 files changed

+286
-7
lines changed

src/AutoRest.CSharp/LowLevel/Output/OperationMethodChainBuilder.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -224,7 +224,7 @@ private ConvenienceMethod BuildConvenienceMethod(ReturnTypeChain returnTypeChain
224224
else
225225
{
226226
// we do not support arrays as a body type, therefore we change the type to object on purpose to emphasize this: https://github.com/Azure/autorest.csharp/pull/3044
227-
if (TypeFactory.IsList(convenienceParameter.Type))
227+
if (TypeFactory.IsList(convenienceParameter.Type) && convenienceParameter.RequestLocation == RequestLocation.Body)
228228
{
229229
parameterList.Add(convenienceParameter with { Type = new CSharpType(typeof(object)) });
230230
}

test/TestProjects/CollectionFormat-Cadl/CollectionFormat-Cadl.cadl

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,20 +31,25 @@ model Thing {
3131

3232
@get
3333
@route("/csvQuery")
34+
@convenientAPI(true)
3435
op csvQuery(@query({format: "csv"}) options?: string[]): Thing;
3536

3637
@get
3738
@route("/multiQuery")
39+
@convenientAPI(true)
3840
op multiQuery(@query({format: "multi"}) options?: string[]): Thing;
3941

4042
@get
4143
@route("/noFormatQuery")
44+
@convenientAPI(true)
4245
op noFormatQuery(@query options?: string[]): Thing;
4346

4447
@get
4548
@route("/csvHeader")
49+
@convenientAPI(true)
4650
op csvHeader(@header({format: "csv"}) options?: string[]): Thing;
4751

4852
@get
4953
@route("/noFormatHeader")
54+
@convenientAPI(true)
5055
op noFormatHeader(@header options?: string[]): Thing;

test/TestProjects/CollectionFormat-Cadl/Generated/ArrayAsQueryOrHeaderClient.cs

Lines changed: 203 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// <auto-generated/>
5+
6+
#nullable disable
7+
8+
using System.Text.Json;
9+
using Azure;
10+
using Azure.Core;
11+
12+
namespace ArrayAsQueryOrHeader.Models
13+
{
14+
public partial class Thing
15+
{
16+
internal static Thing DeserializeThing(JsonElement element)
17+
{
18+
if (element.ValueKind == JsonValueKind.Null)
19+
{
20+
return null;
21+
}
22+
string name = default;
23+
foreach (var property in element.EnumerateObject())
24+
{
25+
if (property.NameEquals("name"u8))
26+
{
27+
name = property.Value.GetString();
28+
continue;
29+
}
30+
}
31+
return new Thing(name);
32+
}
33+
34+
/// <summary> Deserializes the model from a raw response. </summary>
35+
/// <param name="response"> The response to deserialize the model from. </param>
36+
internal static Thing FromResponse(Response response)
37+
{
38+
using var document = JsonDocument.Parse(response.Content);
39+
return DeserializeThing(document.RootElement);
40+
}
41+
}
42+
}
Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
// Copyright (c) Microsoft Corporation. All rights reserved.
2+
// Licensed under the MIT License.
3+
4+
// <auto-generated/>
5+
6+
#nullable disable
7+
8+
using System;
9+
using Azure.Core;
10+
11+
namespace ArrayAsQueryOrHeader.Models
12+
{
13+
/// <summary> The Thing. </summary>
14+
public partial class Thing
15+
{
16+
/// <summary> Initializes a new instance of Thing. </summary>
17+
/// <param name="name"> the object name. </param>
18+
/// <exception cref="ArgumentNullException"> <paramref name="name"/> is null. </exception>
19+
internal Thing(string name)
20+
{
21+
Argument.AssertNotNull(name, nameof(name));
22+
23+
Name = name;
24+
}
25+
26+
/// <summary> the object name. </summary>
27+
public string Name { get; }
28+
}
29+
}

0 commit comments

Comments
 (0)