This commit is contained in:
Pavel Krymets 2020-05-12 13:37:48 -07:00 коммит произвёл GitHub
Родитель d4df595108
Коммит 672f5872f4
Не найден ключ, соответствующий данной подписи
Идентификатор ключа GPG: 4AEE18F83AFDEB23
58 изменённых файлов: 1166 добавлений и 513 удалений

18
package-lock.json сгенерированный
Просмотреть файл

@ -9,9 +9,9 @@
"dev": true
},
"@microsoft.azure/autorest.testserver": {
"version": "2.10.33",
"resolved": "https://registry.npmjs.org/@microsoft.azure/autorest.testserver/-/autorest.testserver-2.10.33.tgz",
"integrity": "sha512-jKdH0DM5fhbl0VqG5+cPKuAeUnPlSjyXgSLlFOcPo8vyxNrQCVA3hCzlYZ33pklkvzuAF4cbVJpY79cHC2Qyhw==",
"version": "2.10.36",
"resolved": "https://registry.npmjs.org/@microsoft.azure/autorest.testserver/-/autorest.testserver-2.10.36.tgz",
"integrity": "sha512-PznHUcpSnbnZ7lLzw6AhZ1wvOpqMNfipz3OTencgjCb9lWxuCLCFhIr/6TAkhAp8MPUMuVC5s4uWji927MjOgw==",
"dev": true,
"requires": {
"azure-storage": "^2.4.0",
@ -1739,9 +1739,9 @@
}
},
"safe-buffer": {
"version": "5.2.0",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.0.tgz",
"integrity": "sha512-fZEwUGbVl7kouZs1jCdMLdt95hdIv0ZeHg6L7qPeciMZhZ+/gdesW4wgTARkrFWEpspjEATAzUGPG8N2jJiwbg==",
"version": "5.2.1",
"resolved": "https://registry.npmjs.org/safe-buffer/-/safe-buffer-5.2.1.tgz",
"integrity": "sha512-rp3So07KcdmmKbGvgaNxQSJr7bGVSVk5S9Eq1F+ppbRo70+YeaDxkw5Dd8NPN+GD6bjnYm2VuPuCXmpuYvmCXQ==",
"dev": true
},
"safer-buffer": {
@ -2252,9 +2252,9 @@
"dev": true
},
"ws": {
"version": "7.2.5",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.2.5.tgz",
"integrity": "sha512-C34cIU4+DB2vMyAbmEKossWq2ZQDr6QEyuuCzWrM9zfw1sGc0mYiJ0UnG9zzNykt49C2Fi34hvr2vssFQRS6EA==",
"version": "7.3.0",
"resolved": "https://registry.npmjs.org/ws/-/ws-7.3.0.tgz",
"integrity": "sha512-iFtXzngZVXPGgpTlP1rBqsUK82p9tKqsWRPg5L56egiljujJT3vGAYnHANvFxBieXrTFavhzhxW52jnaWV+w2w==",
"dev": true
},
"xml2js": {

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

@ -4,7 +4,7 @@
"description": "package.json intended for in-repo use only, package.json used for publishing is located in src/AutoRest.CSharp.V3/package.json",
"devDependencies": {
"@autorest/autorest": "https://github.com/Azure/autorest/releases/download/autorest-3.0.6222/autorest-autorest-3.0.6222.tgz",
"@microsoft.azure/autorest.testserver": "^2.10.33"
"@microsoft.azure/autorest.testserver": "2.10.36"
},
"dependencies": {}
}

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

@ -56,7 +56,7 @@ namespace Azure.AI.FormRecognizer
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace Azure.AI.FormRecognizer
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace Azure.AI.FormRecognizer
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace Azure.AI.FormRecognizer
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace Azure.Management.Storage
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace Azure.Network.Management.Interface
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace Azure.Network.Management.Interface
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -34,7 +34,7 @@ namespace AutoRest.CSharp.V3.Generation.Writers
{
if (async)
{
writer.Line($"return await new {typeof(ValueTask<Response>)}({responseVariable});");
writer.Line($"return await new {typeof(ValueTask<Response>)}({responseVariable}).ConfigureAwait(false);");
}
else
{

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

@ -36,7 +36,7 @@ namespace AutoRest.CSharp.V3.Output.Models.Requests
if (finalResponseSchema != null)
{
ResultType = context.TypeFactory.CreateType(finalResponseSchema, false);
ResultType = TypeFactory.GetOutputType(context.TypeFactory.CreateType(finalResponseSchema, false));
ResultSerialization = new SerializationBuilder().Build(finalResponse.HttpResponse.KnownMediaType, finalResponseSchema, ResultType);
}
else

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

@ -108,7 +108,7 @@ namespace Azure.Core
}
public static DateTimeOffset ParseDateTimeOffset(string value) =>
DateTimeOffset.Parse(value, CultureInfo.InvariantCulture);
DateTimeOffset.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal);
public static TimeSpan ParseTimeSpan(string value, string format) => format switch
{

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

@ -124,6 +124,14 @@ namespace AutoRest.TestServer.Tests
return await new DatetimeClient(ClientDiagnostics, pipeline, host).PutUtcMinDateTimeAsync( value);
});
[Test]
[IgnoreOnTestServer(TestServerVersion.V2, "V1 and V2 tests are out of sync")]
public Task GetDateTimeMinLocalNoOffset() => Test(async (host, pipeline) =>
{
var response = await new DatetimeClient(ClientDiagnostics, pipeline, host).GetLocalNoOffsetMinDateTimeAsync();
Assert.AreEqual(DateTimeOffset.Parse("0001-01-01 00:00:00+00:00"), response.Value);
});
[Test]
public Task GetDateTimeMaxLocalNegativeOffsetLowercase() => Test((host, pipeline) =>
{

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

@ -2,6 +2,7 @@
// Licensed under the MIT License.
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
@ -716,6 +717,16 @@ namespace AutoRest.TestServer.Tests
Assert.AreEqual("Succeeded", result.Value.ProvisioningState);
});
[Test]
public Task LROPostAndGetList() => Test(async (host, pipeline) =>
{
var operation = await new LROsClient(ClientDiagnostics, pipeline, host).StartPost202ListAsync();
var result = await operation.WaitForCompletionAsync().ConfigureAwait(false);
Assert.AreEqual(1, result.Value.Count);
Assert.AreEqual("100", result.Value[0].Id);
Assert.AreEqual("foo", result.Value[0].Name);
});
[Test]
public Task LROPostAsyncNoRetrySucceeded_Sync() => Test((host, pipeline) =>
{
@ -1361,6 +1372,12 @@ namespace AutoRest.TestServer.Tests
Assert.AreEqual("Succeeded", result.Value.ProvisioningState);
});
[Test]
public void LROValueTypeIsReadOnlyList()
{
Assert.AreEqual(typeof(Operation<IReadOnlyList<Product>>), typeof(LROsPost202ListOperation).BaseType);
}
private static Response<TResult> WaitForCompletion<TResult>(Operation<TResult> operation, CancellationToken cancellationToken = default) where TResult : notnull
{
return WaitForCompletion(operation, OperationHelpers.DefaultPollingInterval, cancellationToken);

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

@ -36,5 +36,13 @@ namespace AutoRest.TestServer.Tests
var response = await new ServiceClient(ClientDiagnostics, pipeline, host).AnalyzeBodyAsync(ContentType.ApplicationPdf, value);
Assert.AreEqual("Nice job with PDF", response.Value);
});
[Test]
[Ignore("https://github.com/Azure/autorest.csharp/issues/751")]
public Task MediaTypeWithEncoding() => Test(async (host, pipeline) =>
{
var response = await new ServiceClient(ClientDiagnostics, pipeline, host).ContentTypeWithEncodingAsync("input");
Assert.AreEqual("Nice job sending content type with encoding", response.Value);
});
}
}

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

@ -56,7 +56,7 @@ namespace NameConflicts
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

51
test/TestServerProjects/body-datetime/CodeModel.yaml сгенерированный
Просмотреть файл

@ -1408,6 +1408,57 @@ operationGroups:
name: GetLocalNegativeOffsetMinDateTime
description: 'Get min datetime value 0001-01-01T00:00:00-14:00'
protocol: !<!Protocols> {}
- !<!Operation>
apiVersions:
- !<!ApiVersion>
version: 1.0.0
parameters:
- *ref_4
requests:
- !<!Request>
language: !<!Languages>
default:
name: ''
description: ''
protocol: !<!Protocols>
http: !<!HttpRequest>
path: /datetime/min/localnooffset
method: get
uri: '{$host}'
signatureParameters: []
responses:
- !<!SchemaResponse>
schema: *ref_1
language: !<!Languages>
default:
name: ''
description: ''
protocol: !<!Protocols>
http: !<!HttpResponse>
knownMediaType: json
mediaTypes:
- application/json
statusCodes:
- '200'
exceptions:
- !<!SchemaResponse>
schema: *ref_5
language: !<!Languages>
default:
name: ''
description: ''
protocol: !<!Protocols>
http: !<!HttpResponse>
knownMediaType: json
mediaTypes:
- application/json
statusCodes:
- default
language: !<!Languages>
default:
name: GetLocalNoOffsetMinDateTime
description: 'Get min datetime value 0001-01-01T00:00:00'
protocol: !<!Protocols> {}
language: !<!Languages>
default:
name: Datetime

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

@ -758,5 +758,39 @@ namespace body_datetime
throw;
}
}
/// <summary> Get min datetime value 0001-01-01T00:00:00. </summary>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<DateTimeOffset>> GetLocalNoOffsetMinDateTimeAsync(CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("DatetimeClient.GetLocalNoOffsetMinDateTime");
scope.Start();
try
{
return await RestClient.GetLocalNoOffsetMinDateTimeAsync(cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary> Get min datetime value 0001-01-01T00:00:00. </summary>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<DateTimeOffset> GetLocalNoOffsetMinDateTime(CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("DatetimeClient.GetLocalNoOffsetMinDateTime");
scope.Start();
try
{
return RestClient.GetLocalNoOffsetMinDateTime(cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
}
}

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

@ -1097,5 +1097,57 @@ namespace body_datetime
throw _clientDiagnostics.CreateRequestFailedException(message.Response);
}
}
internal HttpMessage CreateGetLocalNoOffsetMinDateTimeRequest()
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Get;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(host, false);
uri.AppendPath("/datetime/min/localnooffset", false);
request.Uri = uri;
return message;
}
/// <summary> Get min datetime value 0001-01-01T00:00:00. </summary>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public async ValueTask<Response<DateTimeOffset>> GetLocalNoOffsetMinDateTimeAsync(CancellationToken cancellationToken = default)
{
using var message = CreateGetLocalNoOffsetMinDateTimeRequest();
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
switch (message.Response.Status)
{
case 200:
{
DateTimeOffset value = default;
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
value = document.RootElement.GetDateTimeOffset("O");
return Response.FromValue(value, message.Response);
}
default:
throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
}
}
/// <summary> Get min datetime value 0001-01-01T00:00:00. </summary>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public Response<DateTimeOffset> GetLocalNoOffsetMinDateTime(CancellationToken cancellationToken = default)
{
using var message = CreateGetLocalNoOffsetMinDateTimeRequest();
_pipeline.Send(message, cancellationToken);
switch (message.Response.Status)
{
case 200:
{
DateTimeOffset value = default;
using var document = JsonDocument.Parse(message.Response.ContentStream);
value = document.RootElement.GetDateTimeOffset("O");
return Response.FromValue(value, message.Response);
}
default:
throw _clientDiagnostics.CreateRequestFailedException(message.Response);
}
}
}
}

1023
test/TestServerProjects/lro/CodeModel.yaml сгенерированный

Разница между файлами не показана из-за своего большого размера Загрузить разницу

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

36
test/TestServerProjects/lro/Generated/LROsClient.cs сгенерированный
Просмотреть файл

@ -69,6 +69,42 @@ namespace lro
}
}
/// <summary> Long running put request, service returns a 202 with empty body to first request, returns a 200 with body [{ &apos;id&apos;: &apos;100&apos;, &apos;name&apos;: &apos;foo&apos; }]. </summary>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async ValueTask<LROsPost202ListOperation> StartPost202ListAsync(CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("LROsClient.StartPost202List");
scope.Start();
try
{
var originalResponse = await RestClient.Post202ListAsync(cancellationToken).ConfigureAwait(false);
return new LROsPost202ListOperation(_clientDiagnostics, _pipeline, RestClient.CreatePost202ListRequest().Request, originalResponse);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary> Long running put request, service returns a 202 with empty body to first request, returns a 200 with body [{ &apos;id&apos;: &apos;100&apos;, &apos;name&apos;: &apos;foo&apos; }]. </summary>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual LROsPost202ListOperation StartPost202List(CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("LROsClient.StartPost202List");
scope.Start();
try
{
var originalResponse = RestClient.Post202List(cancellationToken);
return new LROsPost202ListOperation(_clientDiagnostics, _pipeline, RestClient.CreatePost202ListRequest().Request, originalResponse);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary> Long running put request, service returns a 200 to the initial request, with an entity that does not contain ProvisioningState=Succeeded. </summary>
/// <param name="product"> Product to put. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

105
test/TestServerProjects/lro/Generated/LROsPost202ListOperation.cs сгенерированный Normal file
Просмотреть файл

@ -0,0 +1,105 @@
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
// <auto-generated/>
#nullable disable
using System;
using System.Collections.Generic;
using System.Text.Json;
using System.Threading;
using System.Threading.Tasks;
using Azure;
using Azure.Core;
using Azure.Core.Pipeline;
using lro.Models;
namespace lro
{
/// <summary> Long running put request, service returns a 202 with empty body to first request, returns a 200 with body [{ &apos;id&apos;: &apos;100&apos;, &apos;name&apos;: &apos;foo&apos; }]. </summary>
public partial class LROsPost202ListOperation : Operation<IReadOnlyList<Product>>, IOperationSource<IReadOnlyList<Product>>
{
private readonly ArmOperationHelpers<IReadOnlyList<Product>> _operation;
internal LROsPost202ListOperation(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, Request request, Response response)
{
_operation = new ArmOperationHelpers<IReadOnlyList<Product>>(this, clientDiagnostics, pipeline, request, response, OperationFinalStateVia.Location, "LROsPost202ListOperation");
}
/// <inheritdoc />
public override string Id => _operation.Id;
/// <inheritdoc />
public override IReadOnlyList<Product> Value => _operation.Value;
/// <inheritdoc />
public override bool HasCompleted => _operation.HasCompleted;
/// <inheritdoc />
public override bool HasValue => _operation.HasValue;
/// <inheritdoc />
public override Response GetRawResponse() => _operation.GetRawResponse();
/// <inheritdoc />
public override Response UpdateStatus(CancellationToken cancellationToken = default) => _operation.UpdateStatus(cancellationToken);
/// <inheritdoc />
public override ValueTask<Response> UpdateStatusAsync(CancellationToken cancellationToken = default) => _operation.UpdateStatusAsync(cancellationToken);
/// <inheritdoc />
public override ValueTask<Response<IReadOnlyList<Product>>> WaitForCompletionAsync(CancellationToken cancellationToken = default) => _operation.WaitForCompletionAsync(cancellationToken);
/// <inheritdoc />
public override ValueTask<Response<IReadOnlyList<Product>>> WaitForCompletionAsync(TimeSpan pollingInterval, CancellationToken cancellationToken = default) => _operation.WaitForCompletionAsync(pollingInterval, cancellationToken);
IReadOnlyList<Product> IOperationSource<IReadOnlyList<Product>>.CreateResult(Response response, CancellationToken cancellationToken)
{
using var document = JsonDocument.Parse(response.ContentStream);
if (document.RootElement.ValueKind == JsonValueKind.Null)
{
return null;
}
else
{
List<Product> array = new List<Product>();
foreach (var item in document.RootElement.EnumerateArray())
{
if (item.ValueKind == JsonValueKind.Null)
{
array.Add(null);
}
else
{
array.Add(Product.DeserializeProduct(item));
}
}
return array;
}
}
async ValueTask<IReadOnlyList<Product>> IOperationSource<IReadOnlyList<Product>>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false);
if (document.RootElement.ValueKind == JsonValueKind.Null)
{
return null;
}
else
{
List<Product> array = new List<Product>();
foreach (var item in document.RootElement.EnumerateArray())
{
if (item.ValueKind == JsonValueKind.Null)
{
array.Add(null);
}
else
{
array.Add(Product.DeserializeProduct(item));
}
}
return array;
}
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -85,6 +85,50 @@ namespace lro
}
}
internal HttpMessage CreatePost202ListRequest()
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Post;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(host, false);
uri.AppendPath("/lro/list", false);
request.Uri = uri;
return message;
}
/// <summary> Long running put request, service returns a 202 with empty body to first request, returns a 200 with body [{ &apos;id&apos;: &apos;100&apos;, &apos;name&apos;: &apos;foo&apos; }]. </summary>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public async ValueTask<Response> Post202ListAsync(CancellationToken cancellationToken = default)
{
using var message = CreatePost202ListRequest();
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
switch (message.Response.Status)
{
case 202:
case 200:
return message.Response;
default:
throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
}
}
/// <summary> Long running put request, service returns a 202 with empty body to first request, returns a 200 with body [{ &apos;id&apos;: &apos;100&apos;, &apos;name&apos;: &apos;foo&apos; }]. </summary>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public Response Post202List(CancellationToken cancellationToken = default)
{
using var message = CreatePost202ListRequest();
_pipeline.Send(message, cancellationToken);
switch (message.Response.Status)
{
case 202:
case 200:
return message.Response;
default:
throw _clientDiagnostics.CreateRequestFailedException(message.Response);
}
}
internal HttpMessage CreatePut200SucceededNoStateRequest(Product product)
{
var message = _pipeline.CreateMessage();

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

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

@ -56,7 +56,7 @@ namespace lro
async ValueTask<Response> IOperationSource<Response>.CreateResultAsync(Response response, CancellationToken cancellationToken)
{
return await new ValueTask<Response>(response);
return await new ValueTask<Response>(response).ConfigureAwait(false);
}
}
}

79
test/TestServerProjects/media_types/CodeModel.yaml сгенерированный
Просмотреть файл

@ -77,6 +77,16 @@ schemas: !<!Schemas>
name: ApplicationJson
description: Content Type 'application/json'
protocol: !<!Protocols> {}
- !<!ConstantSchema> &ref_11
type: constant
value: !<!ConstantValue>
value: text/plain
valueType: *ref_0
language: !<!Languages>
default:
name: TextPlain
description: Content Type 'text/plain'
protocol: !<!Protocols> {}
binaries:
- !<!BinarySchema> &ref_4
type: binary
@ -248,6 +258,75 @@ operationGroups:
name: AnalyzeBody
description: 'Analyze body, that could be different media types.'
protocol: !<!Protocols> {}
- !<!Operation>
apiVersions:
- !<!ApiVersion>
version: 2.0-preview
parameters:
- *ref_2
requests:
- !<!Request>
parameters:
- !<!Parameter>
schema: *ref_11
implementation: Method
origin: 'modelerfour:synthesized/content-type'
required: true
language: !<!Languages>
default:
name: contentType
description: Upload file type
serializedName: Content-Type
protocol: !<!Protocols>
http: !<!HttpParameter>
in: header
- !<!Parameter> &ref_12
schema: *ref_0
implementation: Method
required: true
language: !<!Languages>
default:
name: input
description: Input parameter.
protocol: !<!Protocols>
http: !<!HttpParameter>
in: body
style: binary
signatureParameters:
- *ref_12
language: !<!Languages>
default:
name: ''
description: ''
protocol: !<!Protocols>
http: !<!HttpBinaryRequest>
path: /mediatypes/contentTypeWithEncoding
method: post
binary: true
knownMediaType: text
mediaTypes:
- text/plain
uri: '{$host}'
signatureParameters: []
responses:
- !<!SchemaResponse>
schema: *ref_10
language: !<!Languages>
default:
name: ''
description: ''
protocol: !<!Protocols>
http: !<!HttpResponse>
knownMediaType: json
mediaTypes:
- application/json
statusCodes:
- '200'
language: !<!Languages>
default:
name: ContentTypeWithEncoding
description: Pass in contentType 'text/plain; encoding=UTF-8' to pass test. Value for input does not matter
protocol: !<!Protocols> {}
language: !<!Languages>
default:
name: ''

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

@ -106,5 +106,41 @@ namespace media_types
throw;
}
}
/// <summary> Pass in contentType &apos;text/plain; encoding=UTF-8&apos; to pass test. Value for input does not matter. </summary>
/// <param name="input"> Input parameter. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual async Task<Response<string>> ContentTypeWithEncodingAsync(string input, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("ServiceClient.ContentTypeWithEncoding");
scope.Start();
try
{
return await RestClient.ContentTypeWithEncodingAsync(input, cancellationToken).ConfigureAwait(false);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
/// <summary> Pass in contentType &apos;text/plain; encoding=UTF-8&apos; to pass test. Value for input does not matter. </summary>
/// <param name="input"> Input parameter. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public virtual Response<string> ContentTypeWithEncoding(string input, CancellationToken cancellationToken = default)
{
using var scope = _clientDiagnostics.CreateScope("ServiceClient.ContentTypeWithEncoding");
scope.Start();
try
{
return RestClient.ContentTypeWithEncoding(input, cancellationToken);
}
catch (Exception e)
{
scope.Failed(e);
throw;
}
}
}
}

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

@ -192,5 +192,85 @@ namespace media_types
throw _clientDiagnostics.CreateRequestFailedException(message.Response);
}
}
internal HttpMessage CreateContentTypeWithEncodingRequest(string input)
{
var message = _pipeline.CreateMessage();
var request = message.Request;
request.Method = RequestMethod.Post;
var uri = new RawRequestUriBuilder();
uri.AppendRaw(host, false);
uri.AppendPath("/mediatypes/contentTypeWithEncoding", false);
request.Uri = uri;
request.Headers.Add("Content-Type", "text/plain");
request.Content = new StringRequestContent(input);
return message;
}
/// <summary> Pass in contentType &apos;text/plain; encoding=UTF-8&apos; to pass test. Value for input does not matter. </summary>
/// <param name="input"> Input parameter. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public async ValueTask<Response<string>> ContentTypeWithEncodingAsync(string input, CancellationToken cancellationToken = default)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
using var message = CreateContentTypeWithEncodingRequest(input);
await _pipeline.SendAsync(message, cancellationToken).ConfigureAwait(false);
switch (message.Response.Status)
{
case 200:
{
string value = default;
using var document = await JsonDocument.ParseAsync(message.Response.ContentStream, default, cancellationToken).ConfigureAwait(false);
if (document.RootElement.ValueKind == JsonValueKind.Null)
{
value = null;
}
else
{
value = document.RootElement.GetString();
}
return Response.FromValue(value, message.Response);
}
default:
throw await _clientDiagnostics.CreateRequestFailedExceptionAsync(message.Response).ConfigureAwait(false);
}
}
/// <summary> Pass in contentType &apos;text/plain; encoding=UTF-8&apos; to pass test. Value for input does not matter. </summary>
/// <param name="input"> Input parameter. </param>
/// <param name="cancellationToken"> The cancellation token to use. </param>
public Response<string> ContentTypeWithEncoding(string input, CancellationToken cancellationToken = default)
{
if (input == null)
{
throw new ArgumentNullException(nameof(input));
}
using var message = CreateContentTypeWithEncodingRequest(input);
_pipeline.Send(message, cancellationToken);
switch (message.Response.Status)
{
case 200:
{
string value = default;
using var document = JsonDocument.Parse(message.Response.ContentStream);
if (document.RootElement.ValueKind == JsonValueKind.Null)
{
value = null;
}
else
{
value = document.RootElement.GetString();
}
return Response.FromValue(value, message.Response);
}
default:
throw _clientDiagnostics.CreateRequestFailedException(message.Response);
}
}
}
}