From e351eb565c9f86c52afcf6c3de36a501848cc818 Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 22 Nov 2019 15:11:36 -0800 Subject: [PATCH 1/2] Added media type writing for requests. Fixed last basic test with updated modelerfour and using serializedName. --- readme.md | 2 +- src/AutoRest.CSharp.V3/CodeGen/OperationWriter.cs | 15 +++++++++++++-- src/AutoRest.CSharp.V3/Pipeline/Modifications.cs | 11 +++++++---- .../Generated/Operations/ArrayOperations.cs | 2 ++ .../Generated/Operations/BasicOperations.cs | 4 ++-- .../Generated/Operations/DictionaryOperations.cs | 2 ++ .../Generated/Operations/InheritanceOperations.cs | 1 + .../Operations/PolymorphicrecursiveOperations.cs | 1 + .../Operations/PolymorphismOperations.cs | 4 ++++ .../Generated/Operations/PrimitiveOperations.cs | 11 +++++++++++ .../Operations/ReadonlypropertyOperations.cs | 1 + test/AutoRest.TestServer.Tests/BodyComplexTest.cs | 5 ++--- test/AutoRest.TestServer.Tests/BodyStringTest.cs | 2 +- 13 files changed, 48 insertions(+), 13 deletions(-) diff --git a/readme.md b/readme.md index 5a15db0d..cbb6ae53 100644 --- a/readme.md +++ b/readme.md @@ -4,7 +4,7 @@ ## Configuration ```yaml use-extension: - "@autorest/modelerfour": "4.1.58" + "@autorest/modelerfour": "4.1.60" include-csproj: true pipeline: diff --git a/src/AutoRest.CSharp.V3/CodeGen/OperationWriter.cs b/src/AutoRest.CSharp.V3/CodeGen/OperationWriter.cs index 1802131f..7ed09177 100644 --- a/src/AutoRest.CSharp.V3/CodeGen/OperationWriter.cs +++ b/src/AutoRest.CSharp.V3/CodeGen/OperationWriter.cs @@ -99,6 +99,8 @@ namespace AutoRest.CSharp.V3.CodeGen private static string GetWritableName(Parameter parameter, CSharpLanguage? parameterCs) => parameter.Schema is ConstantSchema constantSchema ? constantSchema.ToValueString() : parameterCs?.Name ?? "[NO NAME]"; + private static string GetSerializedName(Parameter parameter) => parameter.Language.Default.SerializedName ?? parameter.Language.Default.Name; + //TODO: Clean this up. It is written quickly and has a lot of parts that can be extracted from it. private void WriteOperation(Operation operation, CSharpNamespace? @namespace, bool includeBlankLine = true) { @@ -160,20 +162,22 @@ namespace AutoRest.CSharp.V3.CodeGen var method = httpRequest?.Method.ToCoreRequestMethod() ?? RequestMethod.Get; Line($"request.Method = {Type(typeof(RequestMethod))}.{method.ToRequestMethodName()};"); + //TODO: Redesign this since uri is now a separate value var uri = httpRequest?.Uri ?? String.Empty; var path = httpRequest?.Path ?? String.Empty; var pathParameters = parameters.Where(p => p.Location == ParameterLocation.Path || p.Location == ParameterLocation.Uri) - .Select(p => (Name: GetWritableName(p.Parameter, p.ParameterCs), SerializedName: p.Parameter.Language.Default.Name) as (string Name, string SerializedName)?).ToArray(); + .Select(p => (Name: GetWritableName(p.Parameter, p.ParameterCs), SerializedName: GetSerializedName(p.Parameter)) as (string Name, string SerializedName)?).ToArray(); var pathParts = GetPathParts(uri + path, pathParameters); //TODO: Add logic to escape the strings when specified, using Uri.EscapeDataString(value); //TODO: Need proper logic to convert the values to strings. Right now, everything is just using default ToString(). + //TODO: Need logic to trim duplicate slashes (/) so when combined, you don't end up with multiple // together var urlText = String.Join(String.Empty, pathParts.Select(p => p.IsLiteral ? p.Text : $"{{{p.Text}}}")); Line($"request.Uri.Reset(new Uri($\"{urlText}\"));"); var settableParameters = parameters .OrderBy(p => p.Location) - .Select(p => (Name: GetWritableName(p.Parameter, p.ParameterCs), SerializedName: p.Parameter.Language.Default.Name, MethodCall: ParameterSetMethodCall(p.Location), IsNullable: p.ParameterCs?.IsNullable ?? false)) + .Select(p => (Name: GetWritableName(p.Parameter, p.ParameterCs), SerializedName: GetSerializedName(p.Parameter), MethodCall: ParameterSetMethodCall(p.Location), IsNullable: p.ParameterCs?.IsNullable ?? false)) .Where(p => p.MethodCall != null) .ToArray(); foreach (var (name, serializedName, methodCall, isNullable) in settableParameters) @@ -185,6 +189,13 @@ namespace AutoRest.CSharp.V3.CodeGen } } + var mediaTypes = (httpRequest as HttpWithBodyRequest)?.MediaTypes; + if (mediaTypes?.Any() ?? false) + { + var methodCall = ParameterSetMethodCall(ParameterLocation.Header); + Line($"{methodCall}(\"Content-Type\", \"{mediaTypes.First()}\");"); + } + var bodyParameter = parameters.Select(p => p.Parameter).FirstOrDefault(p => (p.Protocol.Http as HttpParameter)?.In == ParameterLocation.Body); if (bodyParameter != null) { diff --git a/src/AutoRest.CSharp.V3/Pipeline/Modifications.cs b/src/AutoRest.CSharp.V3/Pipeline/Modifications.cs index 66ba2398..dc0de5f5 100644 --- a/src/AutoRest.CSharp.V3/Pipeline/Modifications.cs +++ b/src/AutoRest.CSharp.V3/Pipeline/Modifications.cs @@ -170,17 +170,20 @@ namespace AutoRest.CSharp.V3.Pipeline.Generated { /// namespace of the implementation of this item [YamlMember(Alias = "namespace", Order = 2)] - public string Namespace { get; set; } + public string? Namespace { get; set; } /// if this is a child of a polymorphic class, this will have the value of the discriminator. [YamlMember(Alias = "discriminatorValue", Order = 3)] - public string DiscriminatorValue { get; set; } + public string? DiscriminatorValue { get; set; } [YamlMember(Alias = "uid", Order = 4, ScalarStyle = ScalarStyle.SingleQuoted)] - public string Uid { get; set; } + public string? Uid { get; set; } [YamlMember(Alias = "internal", Order = 5)] - public bool Internal { get; set; } + public bool? Internal { get; set; } + + [YamlMember(Alias = "serializedName", Order = 6)] + public string? SerializedName { get; set; } [YamlIgnore] public IDictionary AdditionalProperties = new Dictionary(); diff --git a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/ArrayOperations.cs b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/ArrayOperations.cs index 8f6ab23e..f29259aa 100644 --- a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/ArrayOperations.cs +++ b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/ArrayOperations.cs @@ -50,6 +50,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/array/valid")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -102,6 +103,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/array/empty")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); diff --git a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/BasicOperations.cs b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/BasicOperations.cs index b7c4cc44..3c062c99 100644 --- a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/BasicOperations.cs +++ b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/BasicOperations.cs @@ -50,8 +50,8 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/basic/valid")); - request.Uri.AppendQuery("ApiVersion", "2016-02-29".ToString()!); - request.Headers.Add(HttpHeader.Common.JsonContentType); + request.Uri.AppendQuery("api-version", "2016-02-29".ToString()!); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); diff --git a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/DictionaryOperations.cs b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/DictionaryOperations.cs index 6dadf1a8..b69b51b5 100644 --- a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/DictionaryOperations.cs +++ b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/DictionaryOperations.cs @@ -50,6 +50,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/dictionary/typed/valid")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -102,6 +103,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/dictionary/typed/empty")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); diff --git a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/InheritanceOperations.cs b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/InheritanceOperations.cs index 807f72c1..4371cda9 100644 --- a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/InheritanceOperations.cs +++ b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/InheritanceOperations.cs @@ -50,6 +50,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/inheritance/valid")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); diff --git a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/PolymorphicrecursiveOperations.cs b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/PolymorphicrecursiveOperations.cs index cbe53cd6..88575601 100644 --- a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/PolymorphicrecursiveOperations.cs +++ b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/PolymorphicrecursiveOperations.cs @@ -50,6 +50,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/polymorphicrecursive/valid")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); diff --git a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/PolymorphismOperations.cs b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/PolymorphismOperations.cs index e4de82d1..a7c1dfd0 100644 --- a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/PolymorphismOperations.cs +++ b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/PolymorphismOperations.cs @@ -50,6 +50,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/polymorphism/valid")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -183,6 +184,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/polymorphism/complicated")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -208,6 +210,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/polymorphism/missingdiscriminator")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -240,6 +243,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/polymorphism/missingrequired/invalid")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); diff --git a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/PrimitiveOperations.cs b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/PrimitiveOperations.cs index cf903a78..ec933953 100644 --- a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/PrimitiveOperations.cs +++ b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/PrimitiveOperations.cs @@ -50,6 +50,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/primitive/integer")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -102,6 +103,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/primitive/long")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -154,6 +156,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/primitive/float")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -206,6 +209,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/primitive/double")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -258,6 +262,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/primitive/bool")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -310,6 +315,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/primitive/string")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -362,6 +368,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/primitive/date")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -414,6 +421,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/primitive/datetime")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -466,6 +474,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/primitive/datetimerfc1123")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -518,6 +527,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/primitive/duration")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); @@ -570,6 +580,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/primitive/byte")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); diff --git a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/ReadonlypropertyOperations.cs b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/ReadonlypropertyOperations.cs index 1535e7ad..df231ebf 100644 --- a/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/ReadonlypropertyOperations.cs +++ b/test/AutoRest.TestServer.Tests/BodyComplex/Generated/Generated/Operations/ReadonlypropertyOperations.cs @@ -50,6 +50,7 @@ namespace BodyComplex.Operations.V20160229 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/complex/readonlyproperty/valid")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); complexBody.Serialize(writer, false); diff --git a/test/AutoRest.TestServer.Tests/BodyComplexTest.cs b/test/AutoRest.TestServer.Tests/BodyComplexTest.cs index ed3d0b14..d80459e8 100644 --- a/test/AutoRest.TestServer.Tests/BodyComplexTest.cs +++ b/test/AutoRest.TestServer.Tests/BodyComplexTest.cs @@ -24,10 +24,9 @@ namespace AutoRest.TestServer.Tests } [Test] - [Ignore("Needs media type, and still failing after that")] public async Task PutValid() { - await using var server = TestServerSession.Start(true); + await using var server = TestServerSession.Start("complex_basic_valid"); var clientDiagnostics = new ClientDiagnostics(new DefaultAzureCredentialOptions()); var pipeline = HttpPipelineBuilder.Build(new DefaultAzureCredentialOptions()); @@ -35,7 +34,7 @@ namespace AutoRest.TestServer.Tests { Name = "abc", Id = 2, - Color = CMYKColors.YELLOW + Color = CMYKColors.Magenta }; var result = BasicOperations.PutValidAsync(clientDiagnostics, pipeline, basic, server.Client.BaseAddress.ToString().TrimEnd('/')).GetAwaiter().GetResult(); Assert.AreEqual(200, result.Status); diff --git a/test/AutoRest.TestServer.Tests/BodyStringTest.cs b/test/AutoRest.TestServer.Tests/BodyStringTest.cs index 54cdf321..3fa9ba80 100644 --- a/test/AutoRest.TestServer.Tests/BodyStringTest.cs +++ b/test/AutoRest.TestServer.Tests/BodyStringTest.cs @@ -22,7 +22,7 @@ namespace AutoRest.TestServer.Tests [Test] public async Task PutMbcs() { - await using var server = TestServerSession.Start(true); + await using var server = TestServerSession.Start("string_mbcs"); var clientDiagnostics = new ClientDiagnostics(new DefaultAzureCredentialOptions()); var pipeline = HttpPipelineBuilder.Build(new DefaultAzureCredentialOptions()); From 7825a7154945b7c351372cf714f69db7011b393d Mon Sep 17 00:00:00 2001 From: Michael Yanni Date: Fri, 22 Nov 2019 15:20:57 -0800 Subject: [PATCH 2/2] Regen changes. --- .../Generated/Generated/Operations/EnumOperations.cs | 3 +++ .../Generated/Generated/Operations/StringOperations.cs | 5 +++++ 2 files changed, 8 insertions(+) diff --git a/test/AutoRest.TestServer.Tests/BodyString/Generated/Generated/Operations/EnumOperations.cs b/test/AutoRest.TestServer.Tests/BodyString/Generated/Generated/Operations/EnumOperations.cs index 8f9e3c01..450f9b5b 100644 --- a/test/AutoRest.TestServer.Tests/BodyString/Generated/Generated/Operations/EnumOperations.cs +++ b/test/AutoRest.TestServer.Tests/BodyString/Generated/Generated/Operations/EnumOperations.cs @@ -50,6 +50,7 @@ namespace BodyString.Operations.V100 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/string/enum/notExpandable")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); writer.WriteString("stringBody", stringBody.ToString()); @@ -102,6 +103,7 @@ namespace BodyString.Operations.V100 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/string/enum/Referenced")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); writer.WriteString("enumStringBody", enumStringBody.ToString()); @@ -154,6 +156,7 @@ namespace BodyString.Operations.V100 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/string/enum/ReferencedConstant")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); enumStringBody.Serialize(writer, false); diff --git a/test/AutoRest.TestServer.Tests/BodyString/Generated/Generated/Operations/StringOperations.cs b/test/AutoRest.TestServer.Tests/BodyString/Generated/Generated/Operations/StringOperations.cs index 9ed7a643..bf1f82a5 100644 --- a/test/AutoRest.TestServer.Tests/BodyString/Generated/Generated/Operations/StringOperations.cs +++ b/test/AutoRest.TestServer.Tests/BodyString/Generated/Generated/Operations/StringOperations.cs @@ -49,6 +49,7 @@ namespace BodyString.Operations.V100 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/string/null")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); writer.WriteStringValue(""); @@ -101,6 +102,7 @@ namespace BodyString.Operations.V100 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/string/empty")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); writer.WriteStringValue(""); @@ -153,6 +155,7 @@ namespace BodyString.Operations.V100 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/string/mbcs")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); writer.WriteStringValue("啊齄丂狛狜隣郎隣兀﨩ˊ〞〡¦℡㈱‐ー﹡﹢﹫、〓ⅰⅹ⒈€㈠㈩ⅠⅫ! ̄ぁんァヶΑ︴АЯаяāɡㄅㄩ─╋︵﹄︻︱︳︴ⅰⅹɑɡ〇〾⿻⺁䜣€"); @@ -205,6 +208,7 @@ namespace BodyString.Operations.V100 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/string/whitespace")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); writer.WriteStringValue(" Now is the time for all good men to come to the aid of their country "); @@ -311,6 +315,7 @@ namespace BodyString.Operations.V100 var request = pipeline.CreateRequest(); request.Method = RequestMethod.Put; request.Uri.Reset(new Uri($"{host}/string/base64UrlEncoding")); + request.Headers.SetValue("Content-Type", "application/json"); var buffer = new ArrayBufferWriter(); await using var writer = new Utf8JsonWriter(buffer); writer.WriteBase64String("stringBody", stringBody);