Merge pull request #260 from MiYanni/bodycomplex-testfix

BodyComplex testfix
This commit is contained in:
Michael Yanni 2019-11-22 15:31:38 -08:00 коммит произвёл GitHub
Родитель 3f994ab4fb 7825a71549
Коммит de0610d05f
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
15 изменённых файлов: 56 добавлений и 13 удалений

Просмотреть файл

@ -4,7 +4,7 @@
## Configuration
```yaml
use-extension:
"@autorest/modelerfour": "4.1.58"
"@autorest/modelerfour": "4.1.60"
pipeline:
# serialize-tester:

Просмотреть файл

@ -102,6 +102,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)
{
@ -163,20 +165,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)
@ -188,6 +192,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)
{

Просмотреть файл

@ -174,17 +174,20 @@ namespace AutoRest.CSharp.V3.Pipeline.Generated
{
/// <summary>namespace of the implementation of this item</summary>
[YamlMember(Alias = "namespace", Order = 2)]
public string Namespace { get; set; }
public string? Namespace { get; set; }
/// <summary>if this is a child of a polymorphic class, this will have the value of the discriminator.</summary>
[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<string, object> AdditionalProperties = new Dictionary<string, object>();

Просмотреть файл

@ -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<byte>();
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<byte>();
await using var writer = new Utf8JsonWriter(buffer);
complexBody.Serialize(writer, false);

Просмотреть файл

@ -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<byte>();
await using var writer = new Utf8JsonWriter(buffer);
complexBody.Serialize(writer, false);

Просмотреть файл

@ -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<byte>();
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<byte>();
await using var writer = new Utf8JsonWriter(buffer);
complexBody.Serialize(writer, false);

Просмотреть файл

@ -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<byte>();
await using var writer = new Utf8JsonWriter(buffer);
complexBody.Serialize(writer, false);

Просмотреть файл

@ -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<byte>();
await using var writer = new Utf8JsonWriter(buffer);
complexBody.Serialize(writer, false);

Просмотреть файл

@ -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<byte>();
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<byte>();
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<byte>();
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<byte>();
await using var writer = new Utf8JsonWriter(buffer);
complexBody.Serialize(writer, false);

Просмотреть файл

@ -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<byte>();
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<byte>();
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<byte>();
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<byte>();
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<byte>();
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<byte>();
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<byte>();
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<byte>();
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<byte>();
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<byte>();
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<byte>();
await using var writer = new Utf8JsonWriter(buffer);
complexBody.Serialize(writer, false);

Просмотреть файл

@ -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<byte>();
await using var writer = new Utf8JsonWriter(buffer);
complexBody.Serialize(writer, false);

Просмотреть файл

@ -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);

Просмотреть файл

@ -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<byte>();
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<byte>();
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<byte>();
await using var writer = new Utf8JsonWriter(buffer);
enumStringBody.Serialize(writer, false);

Просмотреть файл

@ -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<byte>();
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<byte>();
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<byte>();
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<byte>();
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<byte>();
await using var writer = new Utf8JsonWriter(buffer);
writer.WriteBase64String("stringBody", stringBody);

Просмотреть файл

@ -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());