diff --git a/Packages.Data.props b/Packages.Data.props index ab991260724..87bd3a20d3a 100644 --- a/Packages.Data.props +++ b/Packages.Data.props @@ -33,7 +33,7 @@ - + diff --git a/eng/testProjects.json b/eng/testProjects.json index 5f27649944e..9102de1e080 100644 --- a/eng/testProjects.json +++ b/eng/testProjects.json @@ -52,6 +52,8 @@ "client/structure/two-operation-group" ], "CadlRanchProjectsNonAzure":[ + "type/array", + "type/dictionary", "authentication/http/custom" ], "TestServerProjects": [ diff --git a/src/AutoRest.CSharp/Common/AutoRest/Plugins/NewProjectScaffolding.cs b/src/AutoRest.CSharp/Common/AutoRest/Plugins/NewProjectScaffolding.cs index 41a113b5289..1289b5f8764 100644 --- a/src/AutoRest.CSharp/Common/AutoRest/Plugins/NewProjectScaffolding.cs +++ b/src/AutoRest.CSharp/Common/AutoRest/Plugins/NewProjectScaffolding.cs @@ -343,7 +343,7 @@ private string GetUnbrandedSrcCSProj() }; private static readonly IReadOnlyList _unbrandedDependencyPackages = new CSProjWriter.CSProjDependencyPackage[] { - new("System.ClientModel", "1.1.0-beta.2"), + new("System.ClientModel", "1.1.0-beta.3"), new("System.Text.Json", "4.7.2") }; diff --git a/src/AutoRest.CSharp/Common/Output/Expressions/KnownValueExpressions/JsonDocumentExpression.cs b/src/AutoRest.CSharp/Common/Output/Expressions/KnownValueExpressions/JsonDocumentExpression.cs index f8b91b1cb22..77eb1290b33 100644 --- a/src/AutoRest.CSharp/Common/Output/Expressions/KnownValueExpressions/JsonDocumentExpression.cs +++ b/src/AutoRest.CSharp/Common/Output/Expressions/KnownValueExpressions/JsonDocumentExpression.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using AutoRest.CSharp.Common.Input; using AutoRest.CSharp.Common.Output.Expressions.ValueExpressions; using AutoRest.CSharp.Common.Output.Models; using AutoRest.CSharp.Output.Models.Shared; @@ -21,7 +22,8 @@ public static JsonDocumentExpression Parse(StreamExpression stream, bool async) { // Sync and async methods have different set of parameters return async - ? new JsonDocumentExpression(InvokeStatic(nameof(JsonDocument.ParseAsync), new[] { stream, Snippets.Default, KnownParameters.CancellationTokenParameter }, true)) + // non-azure libraries do not have cancellationToken parameter + ? new JsonDocumentExpression(InvokeStatic(nameof(JsonDocument.ParseAsync), new[] { stream, Snippets.Default, Configuration.IsBranded ? KnownParameters.CancellationTokenParameter : Snippets.Default }, true)) : new JsonDocumentExpression(InvokeStatic(nameof(JsonDocument.Parse), stream)); } } diff --git a/src/AutoRest.CSharp/Common/Output/Models/Types/ExpressionTypeProvider.cs b/src/AutoRest.CSharp/Common/Output/Models/Types/ExpressionTypeProvider.cs index 5061f632264..d108d5fc6a0 100644 --- a/src/AutoRest.CSharp/Common/Output/Models/Types/ExpressionTypeProvider.cs +++ b/src/AutoRest.CSharp/Common/Output/Models/Types/ExpressionTypeProvider.cs @@ -30,11 +30,8 @@ internal static IEnumerable GetHelperProviders() yield return ClientPipelineExtensionsProvider.Instance; yield return ClientUriBuilderProvider.Instance; } - if (Configuration.IsBranded) - { - yield return RequestContentHelperProvider.Instance; - yield return Utf8JsonRequestContentProvider.Instance; - } + yield return RequestContentHelperProvider.Instance; + yield return Utf8JsonRequestContentProvider.Instance; if (Configuration.EnableBicepSerialization) { yield return BicepSerializationTypeProvider.Instance; diff --git a/src/AutoRest.CSharp/Common/Output/Models/Types/HelperTypeProviders/RequestContentHelperProvider.cs b/src/AutoRest.CSharp/Common/Output/Models/Types/HelperTypeProviders/RequestContentHelperProvider.cs index ebdf44b1220..7aded5304f7 100644 --- a/src/AutoRest.CSharp/Common/Output/Models/Types/HelperTypeProviders/RequestContentHelperProvider.cs +++ b/src/AutoRest.CSharp/Common/Output/Models/Types/HelperTypeProviders/RequestContentHelperProvider.cs @@ -26,15 +26,13 @@ internal class RequestContentHelperProvider : ExpressionTypeProvider private readonly MethodSignatureModifiers _methodModifiers = MethodSignatureModifiers.Public | MethodSignatureModifiers.Static; private RequestContentHelperProvider() : base(Configuration.HelperNamespace, null) { - // non-azure libraries do not need this type - Debug.Assert(Configuration.IsBranded); - + DefaultName = $"{Configuration.ApiTypes.RequestContentType.Name}Helper"; DeclarationModifiers = TypeSignatureModifiers.Internal | TypeSignatureModifiers.Static; _requestBodyType = Configuration.ApiTypes.RequestContentType; _utf8JsonRequestBodyType = Utf8JsonRequestContentProvider.Instance.Type; } - protected override string DefaultName => "RequestContentHelper"; + protected override string DefaultName { get; } protected override IEnumerable BuildMethods() { diff --git a/src/AutoRest.CSharp/Common/Output/Models/Types/HelperTypeProviders/Utf8JsonRequestContentProvider.cs b/src/AutoRest.CSharp/Common/Output/Models/Types/HelperTypeProviders/Utf8JsonRequestContentProvider.cs index 59471dc7c25..3267086d6c9 100644 --- a/src/AutoRest.CSharp/Common/Output/Models/Types/HelperTypeProviders/Utf8JsonRequestContentProvider.cs +++ b/src/AutoRest.CSharp/Common/Output/Models/Types/HelperTypeProviders/Utf8JsonRequestContentProvider.cs @@ -28,11 +28,8 @@ internal class Utf8JsonRequestContentProvider : ExpressionTypeProvider private Utf8JsonRequestContentProvider() : base(Configuration.HelperNamespace, null) { - // non-azure libraries do not need this type - Debug.Assert(Configuration.IsBranded); - DeclarationModifiers = TypeSignatureModifiers.Internal; - DefaultName = Configuration.IsBranded ? "Utf8JsonRequestContent" : "Utf8JsonRequestBody"; + DefaultName = $"Utf8Json{Configuration.ApiTypes.RequestContentType.Name}"; Inherits = Configuration.ApiTypes.RequestContentType; _streamField = new FieldDeclaration( diff --git a/src/AutoRest.CSharp/LowLevel/Output/ConvenienceMethod.cs b/src/AutoRest.CSharp/LowLevel/Output/ConvenienceMethod.cs index f5cf85ed4cd..7c3d5993390 100644 --- a/src/AutoRest.CSharp/LowLevel/Output/ConvenienceMethod.cs +++ b/src/AutoRest.CSharp/LowLevel/Output/ConvenienceMethod.cs @@ -146,7 +146,7 @@ public IEnumerable GetConvertStatements(LowLevelClientMetho yield return new[] { - new DeclareVariableStatement(value.Type, value.Declaration, Default), + Declare(value, Default), JsonSerializationMethodsBuilder.BuildDeserializationForMethods(serialization, async, value, Extensible.RestOperations.GetContentStream(response), false, null), Return(Extensible.RestOperations.GetTypedResponseFromValue(value, response)) }; diff --git a/src/AutoRest.CSharp/Properties/launchSettings.json b/src/AutoRest.CSharp/Properties/launchSettings.json index a5164b38551..fed4b3ccd14 100644 --- a/src/AutoRest.CSharp/Properties/launchSettings.json +++ b/src/AutoRest.CSharp/Properties/launchSettings.json @@ -688,6 +688,14 @@ "commandName": "Project", "commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjectsNonAzure\\authentication\\http\\custom\\src\\Generated -n" }, + "typespec-nonAzure-type/array": { + "commandName": "Project", + "commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjectsNonAzure\\type\\array\\src\\Generated -n" + }, + "typespec-nonAzure-type/dictionary": { + "commandName": "Project", + "commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjectsNonAzure\\type\\dictionary\\src\\Generated -n" + }, "typespec-parameters/body-optionality": { "commandName": "Project", "commandLineArgs": "--standalone $(SolutionDir)\\test\\CadlRanchProjects\\parameters\\body-optionality\\src\\Generated -n" diff --git a/test/AutoRest.Shared.Tests/RequestContentHelperTests.cs b/test/AutoRest.Shared.Tests/RequestContentHelperTests.cs index cb47cb942ae..f1cf588b50f 100644 --- a/test/AutoRest.Shared.Tests/RequestContentHelperTests.cs +++ b/test/AutoRest.Shared.Tests/RequestContentHelperTests.cs @@ -23,8 +23,8 @@ public static IEnumerable GetDateTimeData() [TestCase(1, 2)] [TestCase("a", "b")] [TestCase(true, false)] - [TestCaseSource("GetTimeSpanData")] - [TestCaseSource("GetDateTimeData")] + [TestCaseSource(nameof(GetTimeSpanData))] + [TestCaseSource(nameof(GetDateTimeData))] public void TestGenericFromEnumerable(T expectedValue1, T expectedValue2) { var expectedList = new List { expectedValue1, expectedValue2 }; @@ -81,8 +81,8 @@ public void TestBinaryDataFromEnumerable() [TestCase(1, 2)] [TestCase("a", "b")] [TestCase(true, false)] - [TestCaseSource("GetTimeSpanData")] - [TestCaseSource("GetDateTimeData")] + [TestCaseSource(nameof(GetTimeSpanData))] + [TestCaseSource(nameof(GetDateTimeData))] public void TestGenericFromDictionary(T expectedValue1, T expectedValue2) { var expectedDictionary = new Dictionary() diff --git a/test/CadlRanchProjects.Tests/type-array.cs b/test/CadlRanchProjects.Tests/type-array.cs index b3ecfbc1255..8d428d945fc 100644 --- a/test/CadlRanchProjects.Tests/type-array.cs +++ b/test/CadlRanchProjects.Tests/type-array.cs @@ -20,14 +20,13 @@ public class TypeArrayTests : CadlRanchTestBase public Task Type_Array_Int32Value_get() => Test(async (host) => { var response = await new ArrayClient(host, null).GetInt32ValueClient().GetInt32ValueAsync(); - Assert.AreEqual(1, response.Value.First()); - Assert.AreEqual(2, response.Value.Last()); + CollectionAssert.AreEqual(new[] { 1, 2 }, response.Value); }); [Test] public Task Type_Array_Int32Value_put() => Test(async (host) => { - var response = await new ArrayClient(host, null).GetInt32ValueClient().PutAsync(new List { 1, 2}); + var response = await new ArrayClient(host, null).GetInt32ValueClient().PutAsync(new List { 1, 2 }); Assert.AreEqual(204, response.Status); }); @@ -35,8 +34,7 @@ public Task Type_Array_Int32Value_put() => Test(async (host) => public Task Type_Array_Int64Value_get() => Test(async (host) => { var response = await new ArrayClient(host, null).GetInt64ValueClient().GetInt64ValueAsync(); - Assert.AreEqual(9007199254740991, response.Value.First()); - Assert.AreEqual(-9007199254740991, response.Value.Last()); + CollectionAssert.AreEqual(new[] { 9007199254740991, -9007199254740991 }, response.Value); }); [Test] @@ -50,8 +48,7 @@ public Task Type_Array_Int64Value_put() => Test(async (host) => public Task Type_Array_BooleanValue_get() => Test(async (host) => { var response = await new ArrayClient(host, null).GetBooleanValueClient().GetBooleanValueAsync(); - Assert.AreEqual(true, response.Value.First()); - Assert.AreEqual(false, response.Value.Last()); + CollectionAssert.AreEqual(new[] { true, false }, response.Value); }); [Test] @@ -65,8 +62,7 @@ public Task Type_Array_BooleanValue_put() => Test(async (host) => public Task Type_Array_StringValue_get() => Test(async (host) => { var response = await new ArrayClient(host, null).GetStringValueClient().GetStringValueAsync(); - Assert.AreEqual("hello", response.Value.First()); - Assert.AreEqual("", response.Value.Last()); + CollectionAssert.AreEqual(new[] { "hello", "" }, response.Value); }); [Test] @@ -80,7 +76,7 @@ public Task Type_Array_StringValue_put() => Test(async (host) => public Task Type_Array_Float32Value_get() => Test(async (host) => { var response = await new ArrayClient(host, null).GetFloat32ValueClient().GetFloat32ValueAsync(); - Assert.AreEqual(43.125f, response.Value.First()); + CollectionAssert.AreEqual(new[] { 43.125f }, response.Value); }); [Test] @@ -94,7 +90,8 @@ public Task Type_Array_Float32Value_put() => Test(async (host) => public Task Type_Array_DatetimeValue_get() => Test(async (host) => { var response = await new ArrayClient(host, null).GetDatetimeValueClient().GetDatetimeValueAsync(); - Assert.AreEqual(DateTimeOffset.Parse("2022-08-26T18:38:00Z"), response.Value.First()); + Assert.AreEqual(1, response.Value.Count); + Assert.AreEqual(DateTimeOffset.Parse("2022-08-26T18:38:00Z"), response.Value[0]); }); [Test] @@ -108,13 +105,14 @@ public Task Type_Array_DatetimeValue_put() => Test(async (host) => public Task Type_Array_DurationValue_get() => Test(async (host) => { var response = await new ArrayClient(host, null).GetDurationValueClient().GetDurationValueAsync(); - Assert.AreEqual(XmlConvert.ToTimeSpan("P123DT22H14M12.011S"), response.Value.First()); + Assert.AreEqual(1, response.Value.Count); + Assert.AreEqual(XmlConvert.ToTimeSpan("P123DT22H14M12.011S"), response.Value[0]); }); [Test] public Task Type_Array_DurationValue_put() => Test(async (host) => { - var response = await new ArrayClient(host, null).GetDurationValueClient().PutAsync(new List { XmlConvert.ToTimeSpan("P123DT22H14M12.011S")}); + var response = await new ArrayClient(host, null).GetDurationValueClient().PutAsync(new List { XmlConvert.ToTimeSpan("P123DT22H14M12.011S") }); Assert.AreEqual(204, response.Status); }); @@ -138,8 +136,9 @@ public Task Type_Array_UnknownValue_put() => Test(async (host) => public Task Type_Array_ModelValue_get() => Test(async (host) => { var response = await new ArrayClient(host, null).GetModelValueClient().GetModelValueAsync(); - Assert.AreEqual("hello", response.Value.First().Property); - Assert.AreEqual("world", response.Value.Last().Property); + Assert.AreEqual(2, response.Value.Count); + Assert.AreEqual("hello", response.Value[0].Property); + Assert.AreEqual("world", response.Value[1].Property); }); [Test] @@ -153,10 +152,7 @@ public Task Type_Array_ModelValue_put() => Test(async (host) => public Task Type_Array_NullableFloatValue_get() => Test(async (host) => { var response = await new ArrayClient(host, null).GetNullableFloatValueClient().GetNullableFloatValueAsync(); - var result = response.Value.ToList(); - Assert.AreEqual(1.25f, result[0]); - Assert.AreEqual(null, result[1]); - Assert.AreEqual(3.0f, result[2]); + CollectionAssert.AreEqual(new float?[] { 1.25f, null, 3.0f }, response.Value); }); [Test] diff --git a/test/CadlRanchProjects.Tests/type-dictionary.cs b/test/CadlRanchProjects.Tests/type-dictionary.cs index 6b269c7dbc5..d4e5b60e84e 100644 --- a/test/CadlRanchProjects.Tests/type-dictionary.cs +++ b/test/CadlRanchProjects.Tests/type-dictionary.cs @@ -16,6 +16,7 @@ public class TypeDictionaryTests : CadlRanchTestBase public Task Dictionary_Int32Value_get() => Test(async (host) => { var response = await new DictionaryClient(host, null).GetInt32ValueClient().GetInt32ValueAsync(); + Assert.AreEqual(2, response.Value.Count); Assert.AreEqual(1, response.Value["k1"]); Assert.AreEqual(2, response.Value["k2"]); }); @@ -35,6 +36,7 @@ public Task Dictionary_Int32Value_put() => Test(async (host) => public Task Dictionary_Int64Value_get() => Test(async (host) => { var response = await new DictionaryClient(host, null).GetInt64ValueClient().GetInt64ValueAsync(); + Assert.AreEqual(2, response.Value.Count); Assert.AreEqual(9007199254740991, response.Value["k1"]); Assert.AreEqual(-9007199254740991, response.Value["k2"]); }); @@ -54,6 +56,7 @@ public Task Dictionary_Int64Value_put() => Test(async (host) => public Task Dictionary_BooleanValue_get() => Test(async (host) => { var response = await new DictionaryClient(host, null).GetBooleanValueClient().GetBooleanValueAsync(); + Assert.AreEqual(2, response.Value.Count); Assert.AreEqual(true, response.Value["k1"]); Assert.AreEqual(false, response.Value["k2"]); }); @@ -73,6 +76,7 @@ public Task Dictionary_BooleanValue_put() => Test(async (host) => public Task Dictionary_StringValue_get() => Test(async (host) => { var response = await new DictionaryClient(host, null).GetStringValueClient().GetStringValueAsync(); + Assert.AreEqual(2, response.Value.Count); Assert.AreEqual("hello", response.Value["k1"]); Assert.AreEqual("", response.Value["k2"]); }); @@ -92,6 +96,7 @@ public Task Dictionary_StringValue_put() => Test(async (host) => public Task Dictionary_Float32Value_get() => Test(async (host) => { var response = await new DictionaryClient(host, null).GetFloat32ValueClient().GetFloat32ValueAsync(); + Assert.AreEqual(1, response.Value.Count); Assert.AreEqual(43.125f, response.Value["k1"]); }); @@ -109,6 +114,7 @@ public Task Dictionary_Float32Value_put() => Test(async (host) => public Task Dictionary_DatetimeValue_get() => Test(async (host) => { var response = await new DictionaryClient(host, null).GetDatetimeValueClient().GetDatetimeValueAsync(); + Assert.AreEqual(1, response.Value.Count); Assert.AreEqual(DateTimeOffset.Parse("2022-08-26T18:38:00Z"), response.Value["k1"]); }); @@ -126,6 +132,7 @@ public Task Dictionary_DatetimeValue_put() => Test(async (host) => public Task Dictionary_DurationValue_get() => Test(async (host) => { var response = await new DictionaryClient(host, null).GetDurationValueClient().GetDurationValueAsync(); + Assert.AreEqual(1, response.Value.Count); Assert.AreEqual(XmlConvert.ToTimeSpan("P123DT22H14M12.011S"), response.Value["k1"]); }); @@ -143,6 +150,7 @@ public Task Dictionary_DurationValue_put() => Test(async (host) => public Task Dictionary_UnknownValue_get() => Test(async (host) => { var response = await new DictionaryClient(host, null).GetUnknownValueClient().GetUnknownValueAsync(); + Assert.AreEqual(3, response.Value.Count); Assert.AreEqual(1, response.Value["k1"].ToObjectFromJson()); Assert.AreEqual("hello", response.Value["k2"].ToObjectFromJson()); Assert.AreEqual(null, response.Value["k3"]); @@ -164,6 +172,7 @@ public Task Dictionary_UnknownValue_put() => Test(async (host) => public Task Dictionary_ModelValue_get() => Test(async (host) => { var response = await new DictionaryClient(host, null).GetModelValueClient().GetModelValueAsync(); + Assert.AreEqual(2, response.Value.Count); Assert.AreEqual("hello", response.Value["k1"].Property); Assert.AreEqual("world", response.Value["k2"].Property); }); @@ -183,6 +192,7 @@ public Task Dictionary_ModelValue_put() => Test(async (host) => public Task Dictionary_RecursiveModelValue_get() => Test(async (host) => { var response = await new DictionaryClient(host, null).GetRecursiveModelValueClient().GetRecursiveModelValueAsync(); + Assert.AreEqual(2, response.Value.Count); Assert.AreEqual("hello", response.Value["k1"].Property); Assert.AreEqual(0, response.Value["k1"].Children.Count); Assert.AreEqual("world", response.Value["k2"].Property); @@ -212,6 +222,7 @@ public Task Dictionary_RecursiveModelValue_put() => Test(async (host) => public Task Type_Dictionary_NullableFloatValue_get() => Test(async (host) => { var response = await new DictionaryClient(host, null).GetNullableFloatValueClient().GetNullableFloatValueAsync(); + Assert.AreEqual(3, response.Value.Count); Assert.AreEqual(1.25f, response.Value["k1"]); Assert.AreEqual(0.5f, response.Value["k2"]); Assert.AreEqual(null, response.Value["k3"]); diff --git a/test/CadlRanchProjectsNonAzure.Tests/authentication-http-custom.cs b/test/CadlRanchProjectsNonAzure.Tests/authentication-http-custom.cs index 922f2d849cb..90785e1b2ed 100644 --- a/test/CadlRanchProjectsNonAzure.Tests/authentication-http-custom.cs +++ b/test/CadlRanchProjectsNonAzure.Tests/authentication-http-custom.cs @@ -6,7 +6,7 @@ namespace CadlRanchProjectsNonAzure.Tests { - public class AuthenticationHttpCustomTests: CadlRanchNonAzureTestBase + public class AuthenticationHttpCustomTests : CadlRanchNonAzureTestBase { [Test] public Task Authentication_Http_Custom_valid() => Test(async (host) => diff --git a/test/CadlRanchProjectsNonAzure.Tests/type-array.cs b/test/CadlRanchProjectsNonAzure.Tests/type-array.cs new file mode 100644 index 00000000000..e2484c432bd --- /dev/null +++ b/test/CadlRanchProjectsNonAzure.Tests/type-array.cs @@ -0,0 +1,165 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Threading.Tasks; +using System.Xml; +using AutoRest.TestServer.Tests.Infrastructure; +using Azure; +using NUnit.Framework; +using Scm._Type._Array; +using Scm._Type._Array.Models; + +namespace CadlRanchProjectsNonAzure.Tests +{ + public class TypeArrayTests : CadlRanchNonAzureTestBase + { + [Test] + public Task Type_Array_Int32Value_get() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetInt32ValueClient().GetInt32ValueAsync(); + CollectionAssert.AreEqual(new[] { 1, 2 }, response.Value); + }); + + [Test] + public Task Type_Array_Int32Value_put() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetInt32ValueClient().PutAsync(new List { 1, 2 }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Type_Array_Int64Value_get() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetInt64ValueClient().GetInt64ValueAsync(); + CollectionAssert.AreEqual(new[] { 9007199254740991, -9007199254740991 }, response.Value); + }); + + [Test] + public Task Type_Array_Int64Value_put() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetInt64ValueClient().PutAsync(new List { 9007199254740991, -9007199254740991 }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Type_Array_BooleanValue_get() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetBooleanValueClient().GetBooleanValueAsync(); + CollectionAssert.AreEqual(new[] { true, false }, response.Value); + }); + + [Test] + public Task Type_Array_BooleanValue_put() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetBooleanValueClient().PutAsync(new List { true, false }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Type_Array_StringValue_get() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetStringValueClient().GetStringValueAsync(); + CollectionAssert.AreEqual(new[] { "hello", "" }, response.Value); + }); + + [Test] + public Task Type_Array_StringValue_put() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetStringValueClient().PutAsync(new List { "hello", "" }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Type_Array_Float32Value_get() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetFloat32ValueClient().GetFloat32ValueAsync(); + CollectionAssert.AreEqual(new[] { 43.125f }, response.Value); + }); + + [Test] + public Task Type_Array_Float32Value_put() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetFloat32ValueClient().PutAsync(new List { 43.125f }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Type_Array_DatetimeValue_get() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetDatetimeValueClient().GetDatetimeValueAsync(); + Assert.AreEqual(1, response.Value.Count); + Assert.AreEqual(DateTimeOffset.Parse("2022-08-26T18:38:00Z"), response.Value[0]); + }); + + [Test] + public Task Type_Array_DatetimeValue_put() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetDatetimeValueClient().PutAsync(new List { DateTimeOffset.Parse("2022-08-26T18:38:00Z") }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Type_Array_DurationValue_get() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetDurationValueClient().GetDurationValueAsync(); + Assert.AreEqual(1, response.Value.Count); + Assert.AreEqual(XmlConvert.ToTimeSpan("P123DT22H14M12.011S"), response.Value[0]); + }); + + [Test] + public Task Type_Array_DurationValue_put() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetDurationValueClient().PutAsync(new List { XmlConvert.ToTimeSpan("P123DT22H14M12.011S") }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Type_Array_UnknownValue_get() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetUnknownValueClient().GetUnknownValueAsync(); + var expected = new List { 1, "hello", null }; + var actual = response.Value.Select(item => item?.ToObjectFromJson()).ToArray(); + CollectionAssert.AreEqual(expected, actual); + }); + + [Test] + public Task Type_Array_UnknownValue_put() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetUnknownValueClient().PutAsync(new List { new BinaryData(1), new BinaryData("\"hello\""), null }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Type_Array_ModelValue_get() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetModelValueClient().GetModelValueAsync(); + Assert.AreEqual(2, response.Value.Count); + Assert.AreEqual("hello", response.Value[0].Property); + Assert.AreEqual("world", response.Value[1].Property); + }); + + [Test] + public Task Type_Array_ModelValue_put() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetModelValueClient().PutAsync(new List { new InnerModel("hello"), new InnerModel("world") }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Type_Array_NullableFloatValue_get() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetNullableFloatValueClient().GetNullableFloatValueAsync(); + CollectionAssert.AreEqual(new float?[] { 1.25f, null, 3.0f }, response.Value); + }); + + [Test] + public Task Type_Array_NullableFloatValue_put() => Test(async (host) => + { + var response = await new ArrayClient(host, null).GetNullableFloatValueClient().PutAsync(new List { 1.25f, null, 3.0f }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + } +} diff --git a/test/CadlRanchProjectsNonAzure.Tests/type-dictionary.cs b/test/CadlRanchProjectsNonAzure.Tests/type-dictionary.cs new file mode 100644 index 00000000000..8b15552b937 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure.Tests/type-dictionary.cs @@ -0,0 +1,241 @@ +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using System.Xml; +using Scm._Type._Dictionary; +using Scm._Type._Dictionary.Models; +using AutoRest.TestServer.Tests.Infrastructure; +using NUnit.Framework; + +namespace CadlRanchProjectsNonAzure.Tests +{ + public class TypeDictionaryTests : CadlRanchTestBase + { + [Test] + public Task Dictionary_Int32Value_get() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetInt32ValueClient().GetInt32ValueAsync(); + Assert.AreEqual(2, response.Value.Count); + Assert.AreEqual(1, response.Value["k1"]); + Assert.AreEqual(2, response.Value["k2"]); + }); + + [Test] + public Task Dictionary_Int32Value_put() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetInt32ValueClient().PutAsync(new Dictionary() + { + {"k1", 1 }, + {"k2", 2 } + }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Dictionary_Int64Value_get() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetInt64ValueClient().GetInt64ValueAsync(); + Assert.AreEqual(2, response.Value.Count); + Assert.AreEqual(9007199254740991, response.Value["k1"]); + Assert.AreEqual(-9007199254740991, response.Value["k2"]); + }); + + [Test] + public Task Dictionary_Int64Value_put() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetInt64ValueClient().PutAsync(new Dictionary() + { + {"k1", 9007199254740991 }, + {"k2", -9007199254740991 } + }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Dictionary_BooleanValue_get() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetBooleanValueClient().GetBooleanValueAsync(); + Assert.AreEqual(true, response.Value["k1"]); + Assert.AreEqual(false, response.Value["k2"]); + }); + + [Test] + public Task Dictionary_BooleanValue_put() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetBooleanValueClient().PutAsync(new Dictionary() + { + {"k1", true }, + {"k2", false } + }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Dictionary_StringValue_get() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetStringValueClient().GetStringValueAsync(); + Assert.AreEqual(2, response.Value.Count); + Assert.AreEqual("hello", response.Value["k1"]); + Assert.AreEqual("", response.Value["k2"]); + }); + + [Test] + public Task Dictionary_StringValue_put() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetStringValueClient().PutAsync(new Dictionary() + { + {"k1", "hello" }, + {"k2", "" } + }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Dictionary_Float32Value_get() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetFloat32ValueClient().GetFloat32ValueAsync(); + Assert.AreEqual(1, response.Value.Count); + Assert.AreEqual(43.125f, response.Value["k1"]); + }); + + [Test] + public Task Dictionary_Float32Value_put() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetFloat32ValueClient().PutAsync(new Dictionary() + { + {"k1", 43.125f } + }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Dictionary_DatetimeValue_get() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetDatetimeValueClient().GetDatetimeValueAsync(); + Assert.AreEqual(1, response.Value.Count); + Assert.AreEqual(DateTimeOffset.Parse("2022-08-26T18:38:00Z"), response.Value["k1"]); + }); + + [Test] + public Task Dictionary_DatetimeValue_put() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetDatetimeValueClient().PutAsync(new Dictionary() + { + {"k1", DateTimeOffset.Parse("2022-08-26T18:38:00Z") } + }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Dictionary_DurationValue_get() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetDurationValueClient().GetDurationValueAsync(); + Assert.AreEqual(1, response.Value.Count); + Assert.AreEqual(XmlConvert.ToTimeSpan("P123DT22H14M12.011S"), response.Value["k1"]); + }); + + [Test] + public Task Dictionary_DurationValue_put() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetDurationValueClient().PutAsync(new Dictionary() + { + {"k1", XmlConvert.ToTimeSpan("P123DT22H14M12.011S") } + }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Dictionary_UnknownValue_get() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetUnknownValueClient().GetUnknownValueAsync(); + Assert.AreEqual(3, response.Value.Count); + Assert.AreEqual(1, response.Value["k1"].ToObjectFromJson()); + Assert.AreEqual("hello", response.Value["k2"].ToObjectFromJson()); + Assert.AreEqual(null, response.Value["k3"]); + }); + + [Test] + public Task Dictionary_UnknownValue_put() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetUnknownValueClient().PutAsync(new Dictionary() + { + {"k1", new BinaryData(1) }, + {"k2", new BinaryData("\"hello\"") }, + {"k3", null } + }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Dictionary_ModelValue_get() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetModelValueClient().GetModelValueAsync(); + Assert.AreEqual(2, response.Value.Count); + Assert.AreEqual("hello", response.Value["k1"].Property); + Assert.AreEqual("world", response.Value["k2"].Property); + }); + + [Test] + public Task Dictionary_ModelValue_put() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetModelValueClient().PutAsync(new Dictionary() + { + {"k1", new InnerModel("hello") }, + {"k2", new InnerModel("world") } + }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Dictionary_RecursiveModelValue_get() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetRecursiveModelValueClient().GetRecursiveModelValueAsync(); + Assert.AreEqual(2, response.Value.Count); + Assert.AreEqual("hello", response.Value["k1"].Property); + Assert.AreEqual(0, response.Value["k1"].Children.Count); + Assert.AreEqual("world", response.Value["k2"].Property); + Assert.AreEqual("inner world", response.Value["k2"].Children["k2.1"].Property); + }); + + [Test] + public Task Dictionary_RecursiveModelValue_put() => Test(async (host) => + { + var firstModel = new InnerModel("hello"); + firstModel.Children.Clear(); + var response = await new DictionaryClient(host, null).GetRecursiveModelValueClient().PutAsync(new Dictionary() + { + ["k1"] = firstModel, + ["k2"] = new InnerModel("world") + { + Children = + { + ["k2.1"] = new InnerModel("inner world") + } + } + }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + + [Test] + public Task Type_Dictionary_NullableFloatValue_get() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetNullableFloatValueClient().GetNullableFloatValueAsync(); + Assert.AreEqual(3, response.Value.Count); + Assert.AreEqual(1.25f, response.Value["k1"]); + Assert.AreEqual(0.5f, response.Value["k2"]); + Assert.AreEqual(null, response.Value["k3"]); + }); + + [Test] + public Task Type_Dictionary_NullableFloatValue_put() => Test(async (host) => + { + var response = await new DictionaryClient(host, null).GetNullableFloatValueClient().PutAsync(new Dictionary() + { + {"k1", 1.25f }, + {"k2", 0.5f }, + {"k3", null } + }); + Assert.AreEqual(204, response.GetRawResponse().Status); + }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/authentication/http/custom/src/Scm.Authentication.Http.Custom.csproj b/test/CadlRanchProjectsNonAzure/authentication/http/custom/src/Scm.Authentication.Http.Custom.csproj index 1b22b0edeed..fca07fc3eac 100644 --- a/test/CadlRanchProjectsNonAzure/authentication/http/custom/src/Scm.Authentication.Http.Custom.csproj +++ b/test/CadlRanchProjectsNonAzure/authentication/http/custom/src/Scm.Authentication.Http.Custom.csproj @@ -10,7 +10,7 @@ - + diff --git a/test/CadlRanchProjectsNonAzure/type/array/Scm._Type._Array.sln b/test/CadlRanchProjectsNonAzure/type/array/Scm._Type._Array.sln new file mode 100644 index 00000000000..294a4806cbe --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/Scm._Type._Array.sln @@ -0,0 +1,50 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29709.97 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scm._Type._Array", "src\Scm._Type._Array.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scm._Type._Array.Tests", "tests\Scm._Type._Array.Tests.csproj", "{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE} + EndGlobalSection +EndGlobal diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/ArrayClient.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/ArrayClient.cs new file mode 100644 index 00000000000..6bd2a4a8d49 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/ArrayClient.cs @@ -0,0 +1,110 @@ +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Threading; + +namespace Scm._Type._Array +{ + // Data plane generated client. + /// The Array service client. + public partial class ArrayClient + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of ArrayClient. + public ArrayClient() : this(new Uri("http://localhost:3000"), new ArrayClientOptions()) + { + } + + /// Initializes a new instance of ArrayClient. + /// TestServer endpoint. + /// The options for configuring the client. + /// is null. + public ArrayClient(Uri endpoint, ArrayClientOptions options) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + options ??= new ArrayClientOptions(); + + _pipeline = ClientPipeline.Create(options, Array.Empty(), Array.Empty(), Array.Empty()); + _endpoint = endpoint; + } + + private Int32Value _cachedInt32Value; + private Int64Value _cachedInt64Value; + private BooleanValue _cachedBooleanValue; + private StringValue _cachedStringValue; + private Float32Value _cachedFloat32Value; + private DatetimeValue _cachedDatetimeValue; + private DurationValue _cachedDurationValue; + private UnknownValue _cachedUnknownValue; + private ModelValue _cachedModelValue; + private NullableFloatValue _cachedNullableFloatValue; + + /// Initializes a new instance of Int32Value. + public virtual Int32Value GetInt32ValueClient() + { + return Volatile.Read(ref _cachedInt32Value) ?? Interlocked.CompareExchange(ref _cachedInt32Value, new Int32Value(_pipeline, _endpoint), null) ?? _cachedInt32Value; + } + + /// Initializes a new instance of Int64Value. + public virtual Int64Value GetInt64ValueClient() + { + return Volatile.Read(ref _cachedInt64Value) ?? Interlocked.CompareExchange(ref _cachedInt64Value, new Int64Value(_pipeline, _endpoint), null) ?? _cachedInt64Value; + } + + /// Initializes a new instance of BooleanValue. + public virtual BooleanValue GetBooleanValueClient() + { + return Volatile.Read(ref _cachedBooleanValue) ?? Interlocked.CompareExchange(ref _cachedBooleanValue, new BooleanValue(_pipeline, _endpoint), null) ?? _cachedBooleanValue; + } + + /// Initializes a new instance of StringValue. + public virtual StringValue GetStringValueClient() + { + return Volatile.Read(ref _cachedStringValue) ?? Interlocked.CompareExchange(ref _cachedStringValue, new StringValue(_pipeline, _endpoint), null) ?? _cachedStringValue; + } + + /// Initializes a new instance of Float32Value. + public virtual Float32Value GetFloat32ValueClient() + { + return Volatile.Read(ref _cachedFloat32Value) ?? Interlocked.CompareExchange(ref _cachedFloat32Value, new Float32Value(_pipeline, _endpoint), null) ?? _cachedFloat32Value; + } + + /// Initializes a new instance of DatetimeValue. + public virtual DatetimeValue GetDatetimeValueClient() + { + return Volatile.Read(ref _cachedDatetimeValue) ?? Interlocked.CompareExchange(ref _cachedDatetimeValue, new DatetimeValue(_pipeline, _endpoint), null) ?? _cachedDatetimeValue; + } + + /// Initializes a new instance of DurationValue. + public virtual DurationValue GetDurationValueClient() + { + return Volatile.Read(ref _cachedDurationValue) ?? Interlocked.CompareExchange(ref _cachedDurationValue, new DurationValue(_pipeline, _endpoint), null) ?? _cachedDurationValue; + } + + /// Initializes a new instance of UnknownValue. + public virtual UnknownValue GetUnknownValueClient() + { + return Volatile.Read(ref _cachedUnknownValue) ?? Interlocked.CompareExchange(ref _cachedUnknownValue, new UnknownValue(_pipeline, _endpoint), null) ?? _cachedUnknownValue; + } + + /// Initializes a new instance of ModelValue. + public virtual ModelValue GetModelValueClient() + { + return Volatile.Read(ref _cachedModelValue) ?? Interlocked.CompareExchange(ref _cachedModelValue, new ModelValue(_pipeline, _endpoint), null) ?? _cachedModelValue; + } + + /// Initializes a new instance of NullableFloatValue. + public virtual NullableFloatValue GetNullableFloatValueClient() + { + return Volatile.Read(ref _cachedNullableFloatValue) ?? Interlocked.CompareExchange(ref _cachedNullableFloatValue, new NullableFloatValue(_pipeline, _endpoint), null) ?? _cachedNullableFloatValue; + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/ArrayClientOptions.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/ArrayClientOptions.cs new file mode 100644 index 00000000000..ea76049aacd --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/ArrayClientOptions.cs @@ -0,0 +1,13 @@ +// + +#nullable disable + +using System.ClientModel.Primitives; + +namespace Scm._Type._Array +{ + /// Client options for ArrayClient. + public partial class ArrayClientOptions : ClientPipelineOptions + { + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/BooleanValue.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/BooleanValue.cs new file mode 100644 index 00000000000..89771821a8b --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/BooleanValue.cs @@ -0,0 +1,239 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Array +{ + // Data plane generated sub-client. + /// Array of boolean values. + public partial class BooleanValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of BooleanValue for mocking. + protected BooleanValue() + { + } + + /// Initializes a new instance of BooleanValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal BooleanValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetBooleanValueAsync() + { + ClientResult result = await GetBooleanValueAsync(null).ConfigureAwait(false); + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetBoolean()); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetBooleanValue() + { + ClientResult result = GetBooleanValue(null); + IReadOnlyList value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetBoolean()); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetBooleanValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetBooleanValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetBooleanValue(RequestOptions options) + { + using PipelineMessage message = CreateGetBooleanValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual async Task PutAsync(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual ClientResult Put(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetBooleanValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/boolean", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/boolean", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Configuration.json b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Configuration.json new file mode 100644 index 00000000000..4fae699aa1d --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Configuration.json @@ -0,0 +1,10 @@ +{ + "output-folder": ".", + "namespace": "Scm._Type._Array", + "library-name": "Scm._Type._Array", + "shared-source-folders": [ + "../../../../../../artifacts/bin/AutoRest.CSharp/Debug/net7.0/Generator.Shared", + "../../../../../../artifacts/bin/AutoRest.CSharp/Debug/net7.0/Azure.Core.Shared" + ], + "use-model-reader-writer": true +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/DatetimeValue.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/DatetimeValue.cs new file mode 100644 index 00000000000..3acdfe3dd45 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/DatetimeValue.cs @@ -0,0 +1,239 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Array +{ + // Data plane generated sub-client. + /// Array of datetime values. + public partial class DatetimeValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of DatetimeValue for mocking. + protected DatetimeValue() + { + } + + /// Initializes a new instance of DatetimeValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal DatetimeValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetDatetimeValueAsync() + { + ClientResult result = await GetDatetimeValueAsync(null).ConfigureAwait(false); + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetDateTimeOffset("O")); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetDatetimeValue() + { + ClientResult result = GetDatetimeValue(null); + IReadOnlyList value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetDateTimeOffset("O")); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetDatetimeValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetDatetimeValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetDatetimeValue(RequestOptions options) + { + using PipelineMessage message = CreateGetDatetimeValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual async Task PutAsync(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual ClientResult Put(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetDatetimeValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/datetime", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/datetime", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/DurationValue.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/DurationValue.cs new file mode 100644 index 00000000000..7e03dae0ea4 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/DurationValue.cs @@ -0,0 +1,239 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Array +{ + // Data plane generated sub-client. + /// Array of duration values. + public partial class DurationValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of DurationValue for mocking. + protected DurationValue() + { + } + + /// Initializes a new instance of DurationValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal DurationValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetDurationValueAsync() + { + ClientResult result = await GetDurationValueAsync(null).ConfigureAwait(false); + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetTimeSpan("P")); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetDurationValue() + { + ClientResult result = GetDurationValue(null); + IReadOnlyList value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetTimeSpan("P")); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetDurationValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetDurationValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetDurationValue(RequestOptions options) + { + using PipelineMessage message = CreateGetDurationValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual async Task PutAsync(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual ClientResult Put(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetDurationValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/duration", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/duration", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Float32Value.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Float32Value.cs new file mode 100644 index 00000000000..26700ce0991 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Float32Value.cs @@ -0,0 +1,239 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Array +{ + // Data plane generated sub-client. + /// Array of float values. + public partial class Float32Value + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of Float32Value for mocking. + protected Float32Value() + { + } + + /// Initializes a new instance of Float32Value. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal Float32Value(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetFloat32ValueAsync() + { + ClientResult result = await GetFloat32ValueAsync(null).ConfigureAwait(false); + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetSingle()); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetFloat32Value() + { + ClientResult result = GetFloat32Value(null); + IReadOnlyList value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetSingle()); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetFloat32ValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetFloat32ValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetFloat32Value(RequestOptions options) + { + using PipelineMessage message = CreateGetFloat32ValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual async Task PutAsync(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual ClientResult Put(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetFloat32ValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/float32", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/float32", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Int32Value.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Int32Value.cs new file mode 100644 index 00000000000..d053e778748 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Int32Value.cs @@ -0,0 +1,239 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Array +{ + // Data plane generated sub-client. + /// Array of int32 values. + public partial class Int32Value + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of Int32Value for mocking. + protected Int32Value() + { + } + + /// Initializes a new instance of Int32Value. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal Int32Value(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetInt32ValueAsync() + { + ClientResult result = await GetInt32ValueAsync(null).ConfigureAwait(false); + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetInt32()); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetInt32Value() + { + ClientResult result = GetInt32Value(null); + IReadOnlyList value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetInt32()); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetInt32ValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetInt32ValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetInt32Value(RequestOptions options) + { + using PipelineMessage message = CreateGetInt32ValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual async Task PutAsync(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual ClientResult Put(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetInt32ValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/int32", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/int32", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Int64Value.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Int64Value.cs new file mode 100644 index 00000000000..edb033f45bd --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Int64Value.cs @@ -0,0 +1,239 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Array +{ + // Data plane generated sub-client. + /// Array of int64 values. + public partial class Int64Value + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of Int64Value for mocking. + protected Int64Value() + { + } + + /// Initializes a new instance of Int64Value. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal Int64Value(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetInt64ValueAsync() + { + ClientResult result = await GetInt64ValueAsync(null).ConfigureAwait(false); + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetInt64()); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetInt64Value() + { + ClientResult result = GetInt64Value(null); + IReadOnlyList value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetInt64()); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetInt64ValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetInt64ValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetInt64Value(RequestOptions options) + { + using PipelineMessage message = CreateGetInt64ValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual async Task PutAsync(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual ClientResult Put(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetInt64ValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/int64", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/int64", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/Argument.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/Argument.cs new file mode 100644 index 00000000000..e026b1aa424 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/Argument.cs @@ -0,0 +1,126 @@ +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Scm._Type._Array +{ + internal static class Argument + { + public static void AssertNotNull(T value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + } + + public static void AssertNotNull(T? value, string name) + where T : struct + { + if (!value.HasValue) + { + throw new ArgumentNullException(name); + } + } + + public static void AssertNotNullOrEmpty(IEnumerable value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (value is ICollection collectionOfT && collectionOfT.Count == 0) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + if (value is ICollection collection && collection.Count == 0) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + using IEnumerator e = value.GetEnumerator(); + if (!e.MoveNext()) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + } + + public static void AssertNotNullOrEmpty(string value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (value.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", name); + } + } + + public static void AssertNotNullOrWhiteSpace(string value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Value cannot be empty or contain only white-space characters.", name); + } + } + + public static void AssertNotDefault(ref T value, string name) + where T : struct, IEquatable + { + if (value.Equals(default)) + { + throw new ArgumentException("Value cannot be empty.", name); + } + } + + public static void AssertInRange(T value, T minimum, T maximum, string name) + where T : notnull, IComparable + { + if (minimum.CompareTo(value) > 0) + { + throw new ArgumentOutOfRangeException(name, "Value is less than the minimum allowed."); + } + if (maximum.CompareTo(value) < 0) + { + throw new ArgumentOutOfRangeException(name, "Value is greater than the maximum allowed."); + } + } + + public static void AssertEnumDefined(Type enumType, object value, string name) + { + if (!Enum.IsDefined(enumType, value)) + { + throw new ArgumentException($"Value not defined for {enumType.FullName}.", name); + } + } + + public static T CheckNotNull(T value, string name) + where T : class + { + AssertNotNull(value, name); + return value; + } + + public static string CheckNotNullOrEmpty(string value, string name) + { + AssertNotNullOrEmpty(value, name); + return value; + } + + public static void AssertNull(T value, string name, string message = null) + { + if (value != null) + { + throw new ArgumentException(message ?? "Value must be null.", name); + } + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/BinaryContentHelper.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/BinaryContentHelper.cs new file mode 100644 index 00000000000..cf484039200 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/BinaryContentHelper.cs @@ -0,0 +1,119 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.Collections.Generic; +using System.Text.Json; + +namespace Scm._Type._Array +{ + internal static class BinaryContentHelper + { + public static BinaryContent FromEnumerable(IEnumerable enumerable) + where T : notnull + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteStartArray(); + foreach (var item in enumerable) + { + content.JsonWriter.WriteObjectValue(item, ModelSerializationExtensions.WireOptions); + } + content.JsonWriter.WriteEndArray(); + + return content; + } + + public static BinaryContent FromEnumerable(IEnumerable enumerable) + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteStartArray(); + foreach (var item in enumerable) + { + if (item == null) + { + content.JsonWriter.WriteNullValue(); + } + else + { +#if NET6_0_OR_GREATER + content.JsonWriter.WriteRawValue(item); +#else + using (JsonDocument document = JsonDocument.Parse(item)) + { + JsonSerializer.Serialize(content.JsonWriter, document.RootElement); + } +#endif + } + } + content.JsonWriter.WriteEndArray(); + + return content; + } + + public static BinaryContent FromDictionary(IDictionary dictionary) + where TValue : notnull + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteStartObject(); + foreach (var item in dictionary) + { + content.JsonWriter.WritePropertyName(item.Key); + content.JsonWriter.WriteObjectValue(item.Value, ModelSerializationExtensions.WireOptions); + } + content.JsonWriter.WriteEndObject(); + + return content; + } + + public static BinaryContent FromDictionary(IDictionary dictionary) + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteStartObject(); + foreach (var item in dictionary) + { + content.JsonWriter.WritePropertyName(item.Key); + if (item.Value == null) + { + content.JsonWriter.WriteNullValue(); + } + else + { +#if NET6_0_OR_GREATER + content.JsonWriter.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(content.JsonWriter, document.RootElement); + } +#endif + } + } + content.JsonWriter.WriteEndObject(); + + return content; + } + + public static BinaryContent FromObject(object value) + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(value, ModelSerializationExtensions.WireOptions); + return content; + } + + public static BinaryContent FromObject(BinaryData value) + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); +#if NET6_0_OR_GREATER + content.JsonWriter.WriteRawValue(value); +#else + using (JsonDocument document = JsonDocument.Parse(value)) + { + JsonSerializer.Serialize(content.JsonWriter, document.RootElement); + } +#endif + return content; + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ChangeTrackingDictionary.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ChangeTrackingDictionary.cs new file mode 100644 index 00000000000..28ce6525939 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ChangeTrackingDictionary.cs @@ -0,0 +1,164 @@ +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Scm._Type._Array +{ + internal class ChangeTrackingDictionary : IDictionary, IReadOnlyDictionary where TKey : notnull + { + private IDictionary _innerDictionary; + + public ChangeTrackingDictionary() + { + } + + public ChangeTrackingDictionary(IDictionary dictionary) + { + if (dictionary == null) + { + return; + } + _innerDictionary = new Dictionary(dictionary); + } + + public ChangeTrackingDictionary(IReadOnlyDictionary dictionary) + { + if (dictionary == null) + { + return; + } + _innerDictionary = new Dictionary(); + foreach (var pair in dictionary) + { + _innerDictionary.Add(pair); + } + } + + public bool IsUndefined => _innerDictionary == null; + + public int Count => IsUndefined ? 0 : EnsureDictionary().Count; + + public bool IsReadOnly => IsUndefined ? false : EnsureDictionary().IsReadOnly; + + public ICollection Keys => IsUndefined ? Array.Empty() : EnsureDictionary().Keys; + + public ICollection Values => IsUndefined ? Array.Empty() : EnsureDictionary().Values; + + public TValue this[TKey key] + { + get + { + if (IsUndefined) + { + throw new KeyNotFoundException(nameof(key)); + } + return EnsureDictionary()[key]; + } + set + { + EnsureDictionary()[key] = value; + } + } + + IEnumerable IReadOnlyDictionary.Keys => Keys; + + IEnumerable IReadOnlyDictionary.Values => Values; + + public IEnumerator> GetEnumerator() + { + if (IsUndefined) + { + IEnumerator> enumerateEmpty() + { + yield break; + } + return enumerateEmpty(); + } + return EnsureDictionary().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(KeyValuePair item) + { + EnsureDictionary().Add(item); + } + + public void Clear() + { + EnsureDictionary().Clear(); + } + + public bool Contains(KeyValuePair item) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Contains(item); + } + + public void CopyTo(KeyValuePair[] array, int index) + { + if (IsUndefined) + { + return; + } + EnsureDictionary().CopyTo(array, index); + } + + public bool Remove(KeyValuePair item) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Remove(item); + } + + public void Add(TKey key, TValue value) + { + EnsureDictionary().Add(key, value); + } + + public bool ContainsKey(TKey key) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().ContainsKey(key); + } + + public bool Remove(TKey key) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Remove(key); + } + + public bool TryGetValue(TKey key, out TValue value) + { + if (IsUndefined) + { + value = default; + return false; + } + return EnsureDictionary().TryGetValue(key, out value); + } + + public IDictionary EnsureDictionary() + { + return _innerDictionary ??= new Dictionary(); + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ChangeTrackingList.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ChangeTrackingList.cs new file mode 100644 index 00000000000..5bc4841eb89 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ChangeTrackingList.cs @@ -0,0 +1,150 @@ +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Scm._Type._Array +{ + internal class ChangeTrackingList : IList, IReadOnlyList + { + private IList _innerList; + + public ChangeTrackingList() + { + } + + public ChangeTrackingList(IList innerList) + { + if (innerList != null) + { + _innerList = innerList; + } + } + + public ChangeTrackingList(IReadOnlyList innerList) + { + if (innerList != null) + { + _innerList = innerList.ToList(); + } + } + + public bool IsUndefined => _innerList == null; + + public int Count => IsUndefined ? 0 : EnsureList().Count; + + public bool IsReadOnly => IsUndefined ? false : EnsureList().IsReadOnly; + + public T this[int index] + { + get + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + return EnsureList()[index]; + } + set + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureList()[index] = value; + } + } + + public void Reset() + { + _innerList = null; + } + + public IEnumerator GetEnumerator() + { + if (IsUndefined) + { + IEnumerator enumerateEmpty() + { + yield break; + } + return enumerateEmpty(); + } + return EnsureList().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(T item) + { + EnsureList().Add(item); + } + + public void Clear() + { + EnsureList().Clear(); + } + + public bool Contains(T item) + { + if (IsUndefined) + { + return false; + } + return EnsureList().Contains(item); + } + + public void CopyTo(T[] array, int arrayIndex) + { + if (IsUndefined) + { + return; + } + EnsureList().CopyTo(array, arrayIndex); + } + + public bool Remove(T item) + { + if (IsUndefined) + { + return false; + } + return EnsureList().Remove(item); + } + + public int IndexOf(T item) + { + if (IsUndefined) + { + return -1; + } + return EnsureList().IndexOf(item); + } + + public void Insert(int index, T item) + { + EnsureList().Insert(index, item); + } + + public void RemoveAt(int index) + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureList().RemoveAt(index); + } + + public IList EnsureList() + { + return _innerList ??= new List(); + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ClientPipelineExtensions.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ClientPipelineExtensions.cs new file mode 100644 index 00000000000..f0b5ed2d0d7 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ClientPipelineExtensions.cs @@ -0,0 +1,65 @@ +// + +#nullable disable + +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Threading.Tasks; + +namespace Scm._Type._Array +{ + internal static class ClientPipelineExtensions + { + public static async ValueTask ProcessMessageAsync(this ClientPipeline pipeline, PipelineMessage message, RequestOptions options) + { + await pipeline.SendAsync(message).ConfigureAwait(false); + + if (message.Response.IsError && (options?.ErrorOptions & ClientErrorBehaviors.NoThrow) != ClientErrorBehaviors.NoThrow) + { + throw await ClientResultException.CreateAsync(message.Response).ConfigureAwait(false); + } + + return message.Response; + } + + public static PipelineResponse ProcessMessage(this ClientPipeline pipeline, PipelineMessage message, RequestOptions options) + { + pipeline.Send(message); + + if (message.Response.IsError && (options?.ErrorOptions & ClientErrorBehaviors.NoThrow) != ClientErrorBehaviors.NoThrow) + { + throw new ClientResultException(message.Response); + } + + return message.Response; + } + + public static async ValueTask> ProcessHeadAsBoolMessageAsync(this ClientPipeline pipeline, PipelineMessage message, RequestOptions options) + { + PipelineResponse response = await pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); + switch (response.Status) + { + case >= 200 and < 300: + return ClientResult.FromValue(true, response); + case >= 400 and < 500: + return ClientResult.FromValue(false, response); + default: + return new ErrorResult(response, new ClientResultException(response)); + } + } + + public static ClientResult ProcessHeadAsBoolMessage(this ClientPipeline pipeline, PipelineMessage message, RequestOptions options) + { + PipelineResponse response = pipeline.ProcessMessage(message, options); + switch (response.Status) + { + case >= 200 and < 300: + return ClientResult.FromValue(true, response); + case >= 400 and < 500: + return ClientResult.FromValue(false, response); + default: + return new ErrorResult(response, new ClientResultException(response)); + } + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ClientUriBuilder.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ClientUriBuilder.cs new file mode 100644 index 00000000000..2c56242eb67 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ClientUriBuilder.cs @@ -0,0 +1,209 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Scm._Type._Array +{ + internal class ClientUriBuilder + { + private UriBuilder _uriBuilder; + private StringBuilder _pathBuilder; + private StringBuilder _queryBuilder; + + public ClientUriBuilder() + { + } + + private UriBuilder UriBuilder => _uriBuilder ??= new UriBuilder(); + + private StringBuilder PathBuilder => _pathBuilder ??= new StringBuilder(UriBuilder.Path); + + private StringBuilder QueryBuilder => _queryBuilder ??= new StringBuilder(UriBuilder.Query); + + public void Reset(Uri uri) + { + _uriBuilder = new UriBuilder(uri); + _pathBuilder = new StringBuilder(UriBuilder.Path); + _queryBuilder = new StringBuilder(UriBuilder.Query); + } + + public void AppendPath(string value, bool escape) + { + Argument.AssertNotNullOrWhiteSpace(value, nameof(value)); + + if (escape) + { + value = Uri.EscapeDataString(value); + } + + if (PathBuilder.Length > 0 && PathBuilder[PathBuilder.Length - 1] == '/' && value[0] == '/') + { + PathBuilder.Remove(PathBuilder.Length - 1, 1); + } + + PathBuilder.Append(value); + UriBuilder.Path = PathBuilder.ToString(); + } + + public void AppendPath(bool value, bool escape = false) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendPath(float value, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendPath(double value, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendPath(int value, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendPath(byte[] value, string format, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value, format), escape); + } + + public void AppendPath(IEnumerable value, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendPath(DateTimeOffset value, string format, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value, format), escape); + } + + public void AppendPath(TimeSpan value, string format, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value, format), escape); + } + + public void AppendPath(Guid value, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendPath(long value, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, string value, bool escape) + { + Argument.AssertNotNullOrWhiteSpace(name, nameof(name)); + Argument.AssertNotNullOrWhiteSpace(value, nameof(value)); + + if (QueryBuilder.Length == 0) + { + QueryBuilder.Append('?'); + } + else + { + QueryBuilder.Append('&'); + } + + if (escape) + { + value = Uri.EscapeDataString(value); + } + + QueryBuilder.Append(name); + QueryBuilder.Append('='); + QueryBuilder.Append(value); + } + + public void AppendQuery(string name, bool value, bool escape = false) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, float value, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, DateTimeOffset value, string format, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value, format), escape); + } + + public void AppendQuery(string name, TimeSpan value, string format, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value, format), escape); + } + + public void AppendQuery(string name, double value, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, decimal value, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, int value, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, long value, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, TimeSpan value, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, byte[] value, string format, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value, format), escape); + } + + public void AppendQuery(string name, Guid value, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQueryDelimited(string name, IEnumerable value, string delimiter, bool escape = true) + { + var stringValues = value.Select(v => ModelSerializationExtensions.TypeFormatters.ConvertToString(v)); + AppendQuery(name, string.Join(delimiter, stringValues), escape); + } + + public void AppendQueryDelimited(string name, IEnumerable value, string delimiter, string format, bool escape = true) + { + var stringValues = value.Select(v => ModelSerializationExtensions.TypeFormatters.ConvertToString(v, format)); + AppendQuery(name, string.Join(delimiter, stringValues), escape); + } + + public Uri ToUri() + { + if (_pathBuilder != null) + { + UriBuilder.Path = _pathBuilder.ToString(); + } + + if (_queryBuilder != null) + { + UriBuilder.Query = _queryBuilder.ToString(); + } + + return UriBuilder.Uri; + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ErrorResult.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ErrorResult.cs new file mode 100644 index 00000000000..4db962b68e6 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ErrorResult.cs @@ -0,0 +1,23 @@ +// + +#nullable disable + +using System.ClientModel; +using System.ClientModel.Primitives; + +namespace Scm._Type._Array +{ + internal class ErrorResult : ClientResult + { + private readonly PipelineResponse _response; + private readonly ClientResultException _exception; + + public ErrorResult(PipelineResponse response, ClientResultException exception) : base(default, response) + { + _response = response; + _exception = exception; + } + + public override T Value => throw _exception; + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ModelSerializationExtensions.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ModelSerializationExtensions.cs new file mode 100644 index 00000000000..4c52756a57c --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/ModelSerializationExtensions.cs @@ -0,0 +1,391 @@ +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Text.Json; +using System.Xml; + +namespace Scm._Type._Array +{ + internal static class ModelSerializationExtensions + { + internal static readonly ModelReaderWriterOptions WireOptions = new ModelReaderWriterOptions("W"); + + public static object GetObject(this JsonElement element) + { + switch (element.ValueKind) + { + case JsonValueKind.String: + return element.GetString(); + case JsonValueKind.Number: + if (element.TryGetInt32(out int intValue)) + { + return intValue; + } + if (element.TryGetInt64(out long longValue)) + { + return longValue; + } + return element.GetDouble(); + case JsonValueKind.True: + return true; + case JsonValueKind.False: + return false; + case JsonValueKind.Undefined: + case JsonValueKind.Null: + return null; + case JsonValueKind.Object: + var dictionary = new Dictionary(); + foreach (var jsonProperty in element.EnumerateObject()) + { + dictionary.Add(jsonProperty.Name, jsonProperty.Value.GetObject()); + } + return dictionary; + case JsonValueKind.Array: + var list = new List(); + foreach (var item in element.EnumerateArray()) + { + list.Add(item.GetObject()); + } + return list.ToArray(); + default: + throw new NotSupportedException($"Not supported value kind {element.ValueKind}"); + } + } + + public static byte[] GetBytesFromBase64(this JsonElement element, string format) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + + return format switch + { + "U" => TypeFormatters.FromBase64UrlString(element.GetRequiredString()), + "D" => element.GetBytesFromBase64(), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + } + + public static DateTimeOffset GetDateTimeOffset(this JsonElement element, string format) => format switch + { + "U" when element.ValueKind == JsonValueKind.Number => DateTimeOffset.FromUnixTimeSeconds(element.GetInt64()), + _ => TypeFormatters.ParseDateTimeOffset(element.GetString(), format) + }; + + public static TimeSpan GetTimeSpan(this JsonElement element, string format) => TypeFormatters.ParseTimeSpan(element.GetString(), format); + + public static char GetChar(this JsonElement element) + { + if (element.ValueKind == JsonValueKind.String) + { + var text = element.GetString(); + if (text == null || text.Length != 1) + { + throw new NotSupportedException($"Cannot convert \"{text}\" to a char"); + } + return text[0]; + } + else + { + throw new NotSupportedException($"Cannot convert {element.ValueKind} to a char"); + } + } + + [Conditional("DEBUG")] + public static void ThrowNonNullablePropertyIsNull(this JsonProperty property) + { + throw new JsonException($"A property '{property.Name}' defined as non-nullable but received as null from the service. This exception only happens in DEBUG builds of the library and would be ignored in the release build"); + } + + public static string GetRequiredString(this JsonElement element) + { + var value = element.GetString(); + if (value == null) + { + throw new InvalidOperationException($"The requested operation requires an element of type 'String', but the target element has type '{element.ValueKind}'."); + } + return value; + } + + public static void WriteStringValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, DateTime value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, TimeSpan value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, char value) + { + writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); + } + + public static void WriteBase64StringValue(this Utf8JsonWriter writer, byte[] value, string format) + { + if (value == null) + { + writer.WriteNullValue(); + return; + } + switch (format) + { + case "U": + writer.WriteStringValue(TypeFormatters.ToBase64UrlString(value)); + break; + case "D": + writer.WriteBase64StringValue(value); + break; + default: + throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)); + } + } + + public static void WriteNumberValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) + { + if (format != "U") + { + throw new ArgumentOutOfRangeException(nameof(format), "Only 'U' format is supported when writing a DateTimeOffset as a Number."); + } + writer.WriteNumberValue(value.ToUnixTimeSeconds()); + } + + public static void WriteObjectValue(this Utf8JsonWriter writer, T value, ModelReaderWriterOptions options = null) + { + switch (value) + { + case null: + writer.WriteNullValue(); + break; + case IJsonModel jsonModel: + jsonModel.Write(writer, options ?? WireOptions); + break; + case byte[] bytes: + writer.WriteBase64StringValue(bytes); + break; + case BinaryData bytes0: + writer.WriteBase64StringValue(bytes0); + break; + case JsonElement json: + json.WriteTo(writer); + break; + case int i: + writer.WriteNumberValue(i); + break; + case decimal d: + writer.WriteNumberValue(d); + break; + case double d0: + if (double.IsNaN(d0)) + { + writer.WriteStringValue("NaN"); + } + else + { + writer.WriteNumberValue(d0); + } + break; + case float f: + writer.WriteNumberValue(f); + break; + case long l: + writer.WriteNumberValue(l); + break; + case string s: + writer.WriteStringValue(s); + break; + case bool b: + writer.WriteBooleanValue(b); + break; + case Guid g: + writer.WriteStringValue(g); + break; + case DateTimeOffset dateTimeOffset: + writer.WriteStringValue(dateTimeOffset, "O"); + break; + case DateTime dateTime: + writer.WriteStringValue(dateTime, "O"); + break; + case IEnumerable> enumerable: + writer.WriteStartObject(); + foreach (var pair in enumerable) + { + writer.WritePropertyName(pair.Key); + writer.WriteObjectValue(pair.Value, options); + } + writer.WriteEndObject(); + break; + case IEnumerable objectEnumerable: + writer.WriteStartArray(); + foreach (var item in objectEnumerable) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + break; + case TimeSpan timeSpan: + writer.WriteStringValue(timeSpan, "P"); + break; + default: + throw new NotSupportedException($"Not supported type {value.GetType()}"); + } + } + + public static void WriteObjectValue(this Utf8JsonWriter writer, object value, ModelReaderWriterOptions options = null) + { + writer.WriteObjectValue(value, options); + } + + internal static class TypeFormatters + { + private const string RoundtripZFormat = "yyyy-MM-ddTHH:mm:ss.fffffffZ"; + public const string DefaultNumberFormat = "G"; + + public static string ToString(bool value) => value ? "true" : "false"; + + public static string ToString(DateTime value, string format) => value.Kind switch + { + DateTimeKind.Utc => ToString((DateTimeOffset)value, format), + _ => throw new NotSupportedException($"DateTime {value} has a Kind of {value.Kind}. Generated clients require it to be UTC. You can call DateTime.SpecifyKind to change Kind property value to DateTimeKind.Utc.") + }; + + public static string ToString(DateTimeOffset value, string format) => format switch + { + "D" => value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), + "U" => value.ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture), + "O" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "o" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "R" => value.ToString("r", CultureInfo.InvariantCulture), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(TimeSpan value, string format) => format switch + { + "P" => XmlConvert.ToString(value), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(byte[] value, string format) => format switch + { + "U" => ToBase64UrlString(value), + "D" => Convert.ToBase64String(value), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + + public static string ToBase64UrlString(byte[] value) + { + int numWholeOrPartialInputBlocks = checked(value.Length + 2) / 3; + int size = checked(numWholeOrPartialInputBlocks * 4); + char[] output = new char[size]; + + int numBase64Chars = Convert.ToBase64CharArray(value, 0, value.Length, output, 0); + + int i = 0; + for (; i < numBase64Chars; i++) + { + char ch = output[i]; + if (ch == '+') + { + output[i] = '-'; + } + else + { + if (ch == '/') + { + output[i] = '_'; + } + else + { + if (ch == '=') + { + break; + } + } + } + } + + return new string(output, 0, i); + } + + public static byte[] FromBase64UrlString(string value) + { + int paddingCharsToAdd = (value.Length % 4) switch + { + 0 => 0, + 2 => 2, + 3 => 1, + _ => throw new InvalidOperationException("Malformed input") + }; + char[] output = new char[(value.Length + paddingCharsToAdd)]; + int i = 0; + for (; i < value.Length; i++) + { + char ch = value[i]; + if (ch == '-') + { + output[i] = '+'; + } + else + { + if (ch == '_') + { + output[i] = '/'; + } + else + { + output[i] = ch; + } + } + } + + for (; i < output.Length; i++) + { + output[i] = '='; + } + + return Convert.FromBase64CharArray(output, 0, output.Length); + } + + public static DateTimeOffset ParseDateTimeOffset(string value, string format) => format switch + { + "U" => DateTimeOffset.FromUnixTimeSeconds(long.Parse(value, CultureInfo.InvariantCulture)), + _ => DateTimeOffset.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) + }; + + public static TimeSpan ParseTimeSpan(string value, string format) => format switch + { + "P" => XmlConvert.ToTimeSpan(value), + _ => TimeSpan.ParseExact(value, format, CultureInfo.InvariantCulture) + }; + + public static string ConvertToString(object value, string format = null) => value switch + { + null => "null", + string s => s, + bool b => ToString(b), + int or float or double or long or decimal => ((IFormattable)value).ToString(DefaultNumberFormat, CultureInfo.InvariantCulture), + byte[] b0 when format != null => ToString(b0, format), + IEnumerable s0 => string.Join(",", s0), + DateTimeOffset dateTime when format != null => ToString(dateTime, format), + TimeSpan timeSpan when format != null => ToString(timeSpan, format), + TimeSpan timeSpan0 => XmlConvert.ToString(timeSpan0), + Guid guid => guid.ToString(), + BinaryData binaryData => ConvertToString(binaryData.ToArray(), format), + _ => value.ToString() + }; + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/Optional.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/Optional.cs new file mode 100644 index 00000000000..460af01a14d --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/Optional.cs @@ -0,0 +1,48 @@ +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; + +namespace Scm._Type._Array +{ + internal static class Optional + { + public static bool IsCollectionDefined(IEnumerable collection) + { + return !(collection is ChangeTrackingList changeTrackingList && changeTrackingList.IsUndefined); + } + + public static bool IsCollectionDefined(IDictionary collection) + { + return !(collection is ChangeTrackingDictionary changeTrackingDictionary && changeTrackingDictionary.IsUndefined); + } + + public static bool IsCollectionDefined(IReadOnlyDictionary collection) + { + return !(collection is ChangeTrackingDictionary changeTrackingDictionary && changeTrackingDictionary.IsUndefined); + } + + public static bool IsDefined(T? value) + where T : struct + { + return value.HasValue; + } + + public static bool IsDefined(object value) + { + return value != null; + } + + public static bool IsDefined(JsonElement value) + { + return value.ValueKind != JsonValueKind.Undefined; + } + + public static bool IsDefined(string value) + { + return value != null; + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/Utf8JsonBinaryContent.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/Utf8JsonBinaryContent.cs new file mode 100644 index 00000000000..71970f0014c --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Internal/Utf8JsonBinaryContent.cs @@ -0,0 +1,52 @@ +// + +#nullable disable + +using System.ClientModel; +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; + +namespace Scm._Type._Array +{ + internal class Utf8JsonBinaryContent : BinaryContent + { + private readonly MemoryStream _stream; + private readonly BinaryContent _content; + + public Utf8JsonBinaryContent() + { + _stream = new MemoryStream(); + _content = Create(_stream); + JsonWriter = new Utf8JsonWriter(_stream); + } + + public Utf8JsonWriter JsonWriter { get; } + + public override async Task WriteToAsync(Stream stream, CancellationToken cancellationToken = default) + { + await JsonWriter.FlushAsync().ConfigureAwait(false); + await _content.WriteToAsync(stream, cancellationToken).ConfigureAwait(false); + } + + public override void WriteTo(Stream stream, CancellationToken cancellationToken = default) + { + JsonWriter.Flush(); + _content.WriteTo(stream, cancellationToken); + } + + public override bool TryComputeLength(out long length) + { + length = JsonWriter.BytesCommitted + JsonWriter.BytesPending; + return true; + } + + public override void Dispose() + { + JsonWriter.Dispose(); + _content.Dispose(); + _stream.Dispose(); + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/ModelValue.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/ModelValue.cs new file mode 100644 index 00000000000..1caa8d8bf14 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/ModelValue.cs @@ -0,0 +1,240 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; +using Scm._Type._Array.Models; + +namespace Scm._Type._Array +{ + // Data plane generated sub-client. + /// Array of model values. + public partial class ModelValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of ModelValue for mocking. + protected ModelValue() + { + } + + /// Initializes a new instance of ModelValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal ModelValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetModelValueAsync() + { + ClientResult result = await GetModelValueAsync(null).ConfigureAwait(false); + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(InnerModel.DeserializeInnerModel(item)); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetModelValue() + { + ClientResult result = GetModelValue(null); + IReadOnlyList value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(InnerModel.DeserializeInnerModel(item)); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetModelValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetModelValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetModelValue(RequestOptions options) + { + using PipelineMessage message = CreateGetModelValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual async Task PutAsync(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual ClientResult Put(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetModelValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/model", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/model", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Models/InnerModel.Serialization.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Models/InnerModel.Serialization.cs new file mode 100644 index 00000000000..cf33223aa97 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Models/InnerModel.Serialization.cs @@ -0,0 +1,153 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace Scm._Type._Array.Models +{ + public partial class InnerModel : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InnerModel)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("property"u8); + writer.WriteStringValue(Property); + if (Optional.IsCollectionDefined(Children)) + { + writer.WritePropertyName("children"u8); + writer.WriteStartArray(); + foreach (var item in Children) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InnerModel IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InnerModel)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInnerModel(document.RootElement, options); + } + + internal static InnerModel DeserializeInnerModel(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string property = default; + IList children = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property0 in element.EnumerateObject()) + { + if (property0.NameEquals("property"u8)) + { + property = property0.Value.GetString(); + continue; + } + if (property0.NameEquals("children"u8)) + { + if (property0.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property0.Value.EnumerateArray()) + { + array.Add(DeserializeInnerModel(item, options)); + } + children = array; + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property0.Name, BinaryData.FromString(property0.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InnerModel(property, children ?? new ChangeTrackingList(), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InnerModel)} does not support writing '{options.Format}' format."); + } + } + + InnerModel IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInnerModel(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InnerModel)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The result to deserialize the model from. + internal static InnerModel FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInnerModel(document.RootElement); + } + + /// Convert into a . + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Models/InnerModel.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Models/InnerModel.cs new file mode 100644 index 00000000000..74225894d14 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/Models/InnerModel.cs @@ -0,0 +1,77 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Scm._Type._Array.Models +{ + /// Array inner model. + public partial class InnerModel + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Required string property. + /// is null. + public InnerModel(string property) + { + Argument.AssertNotNull(property, nameof(property)); + + Property = property; + Children = new ChangeTrackingList(); + } + + /// Initializes a new instance of . + /// Required string property. + /// + /// Keeps track of any properties unknown to the library. + internal InnerModel(string property, IList children, IDictionary serializedAdditionalRawData) + { + Property = property; + Children = children; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InnerModel() + { + } + + /// Required string property. + public string Property { get; set; } + /// Gets the children. + public IList Children { get; } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/NullableFloatValue.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/NullableFloatValue.cs new file mode 100644 index 00000000000..ddcca71dd99 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/NullableFloatValue.cs @@ -0,0 +1,253 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Array +{ + // Data plane generated sub-client. + /// Array of nullable float values. + public partial class NullableFloatValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of NullableFloatValue for mocking. + protected NullableFloatValue() + { + } + + /// Initializes a new instance of NullableFloatValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal NullableFloatValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetNullableFloatValueAsync() + { + ClientResult result = await GetNullableFloatValueAsync(null).ConfigureAwait(false); + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(item.GetSingle()); + } + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetNullableFloatValue() + { + ClientResult result = GetNullableFloatValue(null); + IReadOnlyList value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(item.GetSingle()); + } + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetNullableFloatValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetNullableFloatValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetNullableFloatValue(RequestOptions options) + { + using PipelineMessage message = CreateGetNullableFloatValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where T is of type ? to use. + /// is null. + public virtual async Task PutAsync(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where T is of type ? to use. + /// is null. + public virtual ClientResult Put(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetNullableFloatValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/nullable-float", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/nullable-float", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/StringValue.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/StringValue.cs new file mode 100644 index 00000000000..c3bbced4a7f --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/StringValue.cs @@ -0,0 +1,239 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Array +{ + // Data plane generated sub-client. + /// Array of string values. + public partial class StringValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of StringValue for mocking. + protected StringValue() + { + } + + /// Initializes a new instance of StringValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal StringValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetStringValueAsync() + { + ClientResult result = await GetStringValueAsync(null).ConfigureAwait(false); + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetString()); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetStringValue() + { + ClientResult result = GetStringValue(null); + IReadOnlyList value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetString()); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetStringValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetStringValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetStringValue(RequestOptions options) + { + using PipelineMessage message = CreateGetStringValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual async Task PutAsync(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual ClientResult Put(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetStringValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/string", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/string", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/UnknownValue.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/UnknownValue.cs new file mode 100644 index 00000000000..487592c81c8 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/UnknownValue.cs @@ -0,0 +1,253 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Array +{ + // Data plane generated sub-client. + /// Array of unknown values. + public partial class UnknownValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of UnknownValue for mocking. + protected UnknownValue() + { + } + + /// Initializes a new instance of UnknownValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal UnknownValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetUnknownValueAsync() + { + ClientResult result = await GetUnknownValueAsync(null).ConfigureAwait(false); + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(BinaryData.FromString(item.GetRawText())); + } + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetUnknownValue() + { + ClientResult result = GetUnknownValue(null); + IReadOnlyList value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(BinaryData.FromString(item.GetRawText())); + } + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetUnknownValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetUnknownValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetUnknownValue(RequestOptions options) + { + using PipelineMessage message = CreateGetUnknownValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual async Task PutAsync(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where T is of type to use. + /// is null. + public virtual ClientResult Put(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetUnknownValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/unknown", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/array/unknown", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Generated/tspCodeModel.json b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/tspCodeModel.json new file mode 100644 index 00000000000..eb4357e2427 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Generated/tspCodeModel.json @@ -0,0 +1,2015 @@ +{ + "$id": "1", + "Name": "Type.Array", + "Description": "Illustrates various types of arrays.", + "ApiVersions": [], + "Enums": [], + "Models": [ + { + "$id": "2", + "Kind": "Model", + "Name": "InnerModel", + "Namespace": "Type.Array", + "Description": "Array inner model", + "IsNullable": false, + "Usage": "RoundTrip", + "Properties": [ + { + "$id": "3", + "Name": "property", + "SerializedName": "property", + "Description": "Required string property", + "Type": { + "$id": "4", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "IsRequired": true, + "IsReadOnly": false + }, + { + "$id": "5", + "Name": "children", + "SerializedName": "children", + "Description": "", + "Type": { + "$id": "6", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$ref": "2" + }, + "IsNullable": false + }, + "IsRequired": false, + "IsReadOnly": false + } + ] + } + ], + "Clients": [ + { + "$id": "7", + "Name": "ArrayClient", + "Description": "", + "Operations": [], + "Protocol": { + "$id": "8" + }, + "Creatable": true + }, + { + "$id": "9", + "Name": "Int32Value", + "Description": "Array of int32 values", + "Operations": [ + { + "$id": "10", + "Name": "get", + "ResourceName": "Int32Value", + "Parameters": [ + { + "$id": "11", + "Name": "host", + "NameInRequest": "host", + "Description": "TestServer endpoint", + "Type": { + "$id": "12", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Uri", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": true, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Client", + "DefaultValue": { + "$id": "13", + "Type": { + "$id": "14", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Value": "http://localhost:3000" + } + }, + { + "$id": "15", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "16", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "17", + "Type": { + "$ref": "16" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "18", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "19", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "20", + "Kind": "Primitive", + "Name": "Int32", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/array/int32", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "21", + "Name": "put", + "ResourceName": "Int32Value", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "22", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "23", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "24", + "Kind": "Primitive", + "Name": "Int32", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "25", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "26", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "27", + "Type": { + "$ref": "26" + }, + "Value": "application/json" + } + }, + { + "$id": "28", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "29", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "30", + "Type": { + "$ref": "29" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "31", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/array/int32", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "32" + }, + "Creatable": false, + "Parent": "ArrayClient" + }, + { + "$id": "33", + "Name": "Int64Value", + "Description": "Array of int64 values", + "Operations": [ + { + "$id": "34", + "Name": "get", + "ResourceName": "Int64Value", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "35", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "36", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "37", + "Type": { + "$ref": "36" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "38", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "39", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "40", + "Kind": "Primitive", + "Name": "Int64", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/array/int64", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "41", + "Name": "put", + "ResourceName": "Int64Value", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "42", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "43", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "44", + "Kind": "Primitive", + "Name": "Int64", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "45", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "46", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "47", + "Type": { + "$ref": "46" + }, + "Value": "application/json" + } + }, + { + "$id": "48", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "49", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "50", + "Type": { + "$ref": "49" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "51", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/array/int64", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "52" + }, + "Creatable": false, + "Parent": "ArrayClient" + }, + { + "$id": "53", + "Name": "BooleanValue", + "Description": "Array of boolean values", + "Operations": [ + { + "$id": "54", + "Name": "get", + "ResourceName": "BooleanValue", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "55", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "56", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "57", + "Type": { + "$ref": "56" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "58", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "59", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "60", + "Kind": "Primitive", + "Name": "Boolean", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/array/boolean", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "61", + "Name": "put", + "ResourceName": "BooleanValue", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "62", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "63", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "64", + "Kind": "Primitive", + "Name": "Boolean", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "65", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "66", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "67", + "Type": { + "$ref": "66" + }, + "Value": "application/json" + } + }, + { + "$id": "68", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "69", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "70", + "Type": { + "$ref": "69" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "71", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/array/boolean", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "72" + }, + "Creatable": false, + "Parent": "ArrayClient" + }, + { + "$id": "73", + "Name": "StringValue", + "Description": "Array of string values", + "Operations": [ + { + "$id": "74", + "Name": "get", + "ResourceName": "StringValue", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "75", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "76", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "77", + "Type": { + "$ref": "76" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "78", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "79", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "80", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/array/string", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "81", + "Name": "put", + "ResourceName": "StringValue", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "82", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "83", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "84", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "85", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "86", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "87", + "Type": { + "$ref": "86" + }, + "Value": "application/json" + } + }, + { + "$id": "88", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "89", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "90", + "Type": { + "$ref": "89" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "91", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/array/string", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "92" + }, + "Creatable": false, + "Parent": "ArrayClient" + }, + { + "$id": "93", + "Name": "Float32Value", + "Description": "Array of float values", + "Operations": [ + { + "$id": "94", + "Name": "get", + "ResourceName": "Float32Value", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "95", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "96", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "97", + "Type": { + "$ref": "96" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "98", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "99", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "100", + "Kind": "Primitive", + "Name": "Float32", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/array/float32", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "101", + "Name": "put", + "ResourceName": "Float32Value", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "102", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "103", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "104", + "Kind": "Primitive", + "Name": "Float32", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "105", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "106", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "107", + "Type": { + "$ref": "106" + }, + "Value": "application/json" + } + }, + { + "$id": "108", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "109", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "110", + "Type": { + "$ref": "109" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "111", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/array/float32", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "112" + }, + "Creatable": false, + "Parent": "ArrayClient" + }, + { + "$id": "113", + "Name": "DatetimeValue", + "Description": "Array of datetime values", + "Operations": [ + { + "$id": "114", + "Name": "get", + "ResourceName": "DatetimeValue", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "115", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "116", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "117", + "Type": { + "$ref": "116" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "118", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "119", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "120", + "Kind": "Primitive", + "Name": "DateTime", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/array/datetime", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "121", + "Name": "put", + "ResourceName": "DatetimeValue", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "122", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "123", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "124", + "Kind": "Primitive", + "Name": "DateTime", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "125", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "126", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "127", + "Type": { + "$ref": "126" + }, + "Value": "application/json" + } + }, + { + "$id": "128", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "129", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "130", + "Type": { + "$ref": "129" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "131", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/array/datetime", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "132" + }, + "Creatable": false, + "Parent": "ArrayClient" + }, + { + "$id": "133", + "Name": "DurationValue", + "Description": "Array of duration values", + "Operations": [ + { + "$id": "134", + "Name": "get", + "ResourceName": "DurationValue", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "135", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "136", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "137", + "Type": { + "$ref": "136" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "138", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "139", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "140", + "Kind": "Primitive", + "Name": "DurationISO8601", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/array/duration", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "141", + "Name": "put", + "ResourceName": "DurationValue", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "142", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "143", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "144", + "Kind": "Primitive", + "Name": "DurationISO8601", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "145", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "146", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "147", + "Type": { + "$ref": "146" + }, + "Value": "application/json" + } + }, + { + "$id": "148", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "149", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "150", + "Type": { + "$ref": "149" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "151", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/array/duration", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "152" + }, + "Creatable": false, + "Parent": "ArrayClient" + }, + { + "$id": "153", + "Name": "UnknownValue", + "Description": "Array of unknown values", + "Operations": [ + { + "$id": "154", + "Name": "get", + "ResourceName": "UnknownValue", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "155", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "156", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "157", + "Type": { + "$ref": "156" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "158", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "159", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "160", + "Kind": "Intrinsic", + "Name": "unknown", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/array/unknown", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "161", + "Name": "put", + "ResourceName": "UnknownValue", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "162", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "163", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "164", + "Kind": "Intrinsic", + "Name": "unknown", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "165", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "166", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "167", + "Type": { + "$ref": "166" + }, + "Value": "application/json" + } + }, + { + "$id": "168", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "169", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "170", + "Type": { + "$ref": "169" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "171", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/array/unknown", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "172" + }, + "Creatable": false, + "Parent": "ArrayClient" + }, + { + "$id": "173", + "Name": "ModelValue", + "Description": "Array of model values", + "Operations": [ + { + "$id": "174", + "Name": "get", + "ResourceName": "ModelValue", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "175", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "176", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "177", + "Type": { + "$ref": "176" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "178", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "179", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$ref": "2" + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/array/model", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "180", + "Name": "put", + "ResourceName": "ModelValue", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "181", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "182", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$ref": "2" + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "183", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "184", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "185", + "Type": { + "$ref": "184" + }, + "Value": "application/json" + } + }, + { + "$id": "186", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "187", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "188", + "Type": { + "$ref": "187" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "189", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/array/model", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "190" + }, + "Creatable": false, + "Parent": "ArrayClient" + }, + { + "$id": "191", + "Name": "NullableFloatValue", + "Description": "Array of nullable float values", + "Operations": [ + { + "$id": "192", + "Name": "get", + "ResourceName": "NullableFloatValue", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "193", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "194", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "195", + "Type": { + "$ref": "194" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "196", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "197", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "198", + "Kind": "Primitive", + "Name": "Float32", + "IsNullable": true + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/array/nullable-float", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "199", + "Name": "put", + "ResourceName": "NullableFloatValue", + "Parameters": [ + { + "$ref": "11" + }, + { + "$id": "200", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "201", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "202", + "Kind": "Primitive", + "Name": "Float32", + "IsNullable": true + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "203", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "204", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "205", + "Type": { + "$ref": "204" + }, + "Value": "application/json" + } + }, + { + "$id": "206", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "207", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "208", + "Type": { + "$ref": "207" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "209", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/array/nullable-float", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "210" + }, + "Creatable": false, + "Parent": "ArrayClient" + } + ] +} diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Properties/AssemblyInfo.cs b/test/CadlRanchProjectsNonAzure/type/array/src/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..ce923003a20 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Scm._Type._Array.Tests")] diff --git a/test/CadlRanchProjectsNonAzure/type/array/src/Scm._Type._Array.csproj b/test/CadlRanchProjectsNonAzure/type/array/src/Scm._Type._Array.csproj new file mode 100644 index 00000000000..f6434b6be4d --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/src/Scm._Type._Array.csproj @@ -0,0 +1,16 @@ + + + This is the Scm._Type._Array client library for developing .NET applications with rich experience. + SDK Code Generation Scm._Type._Array + 1.0.0-beta.1 + Scm._Type._Array + netstandard2.0 + latest + true + + + + + + + diff --git a/test/CadlRanchProjectsNonAzure/type/array/tests/Scm._Type._Array.Tests.csproj b/test/CadlRanchProjectsNonAzure/type/array/tests/Scm._Type._Array.Tests.csproj new file mode 100644 index 00000000000..54960a3b155 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/tests/Scm._Type._Array.Tests.csproj @@ -0,0 +1,18 @@ + + + net7.0 + + $(NoWarn);CS1591 + + + + + + + + + + + + + diff --git a/test/CadlRanchProjectsNonAzure/type/array/tspconfig.yaml b/test/CadlRanchProjectsNonAzure/type/array/tspconfig.yaml new file mode 100644 index 00000000000..11a3e390ca0 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/array/tspconfig.yaml @@ -0,0 +1,3 @@ +options: + "@azure-tools/typespec-csharp": + namespace: Scm._Type._Array diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/Scm._Type._Dictionary.sln b/test/CadlRanchProjectsNonAzure/type/dictionary/Scm._Type._Dictionary.sln new file mode 100644 index 00000000000..b3cfecfe7f7 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/Scm._Type._Dictionary.sln @@ -0,0 +1,50 @@ +Microsoft Visual Studio Solution File, Format Version 12.00 +# Visual Studio Version 16 +VisualStudioVersion = 16.0.29709.97 +MinimumVisualStudioVersion = 10.0.40219.1 +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scm._Type._Dictionary", "src\Scm._Type._Dictionary.csproj", "{28FF4005-4467-4E36-92E7-DEA27DEB1519}" +EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "Scm._Type._Dictionary.Tests", "tests\Scm._Type._Dictionary.Tests.csproj", "{1F1CD1D4-9932-4B73-99D8-C252A67D4B46}" +EndProject +Global + GlobalSection(SolutionConfigurationPlatforms) = preSolution + Debug|Any CPU = Debug|Any CPU + Release|Any CPU = Release|Any CPU + EndGlobalSection + GlobalSection(ProjectConfigurationPlatforms) = postSolution + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Debug|Any CPU.Build.0 = Debug|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.ActiveCfg = Release|Any CPU + {B0C276D1-2930-4887-B29A-D1A33E7009A2}.Release|Any CPU.Build.0 = Release|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Debug|Any CPU.Build.0 = Debug|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.ActiveCfg = Release|Any CPU + {8E9A77AC-792A-4432-8320-ACFD46730401}.Release|Any CPU.Build.0 = Release|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Debug|Any CPU.Build.0 = Debug|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.ActiveCfg = Release|Any CPU + {A4241C1F-A53D-474C-9E4E-075054407E74}.Release|Any CPU.Build.0 = Release|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Debug|Any CPU.Build.0 = Debug|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.ActiveCfg = Release|Any CPU + {FA8BD3F1-8616-47B6-974C-7576CDF4717E}.Release|Any CPU.Build.0 = Release|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Debug|Any CPU.Build.0 = Debug|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.ActiveCfg = Release|Any CPU + {85677AD3-C214-42FA-AE6E-49B956CAC8DC}.Release|Any CPU.Build.0 = Release|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Debug|Any CPU.Build.0 = Debug|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.ActiveCfg = Release|Any CPU + {28FF4005-4467-4E36-92E7-DEA27DEB1519}.Release|Any CPU.Build.0 = Release|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Debug|Any CPU.Build.0 = Debug|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.ActiveCfg = Release|Any CPU + {1F1CD1D4-9932-4B73-99D8-C252A67D4B46}.Release|Any CPU.Build.0 = Release|Any CPU + EndGlobalSection + GlobalSection(SolutionProperties) = preSolution + HideSolutionNode = FALSE + EndGlobalSection + GlobalSection(ExtensibilityGlobals) = postSolution + SolutionGuid = {A97F4B90-2591-4689-B1F8-5F21FE6D6CAE} + EndGlobalSection +EndGlobal diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/BooleanValue.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/BooleanValue.cs new file mode 100644 index 00000000000..19131642eb8 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/BooleanValue.cs @@ -0,0 +1,239 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Dictionary +{ + // Data plane generated sub-client. + /// Dictionary of boolean values. + public partial class BooleanValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of BooleanValue for mocking. + protected BooleanValue() + { + } + + /// Initializes a new instance of BooleanValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal BooleanValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetBooleanValueAsync() + { + ClientResult result = await GetBooleanValueAsync(null).ConfigureAwait(false); + IReadOnlyDictionary value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, property.Value.GetBoolean()); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetBooleanValue() + { + ClientResult result = GetBooleanValue(null); + IReadOnlyDictionary value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, property.Value.GetBoolean()); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetBooleanValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetBooleanValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetBooleanValue(RequestOptions options) + { + using PipelineMessage message = CreateGetBooleanValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual async Task PutAsync(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual ClientResult Put(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetBooleanValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/boolean", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/boolean", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Configuration.json b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Configuration.json new file mode 100644 index 00000000000..86e86ebb522 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Configuration.json @@ -0,0 +1,10 @@ +{ + "output-folder": ".", + "namespace": "Scm._Type._Dictionary", + "library-name": "Scm._Type._Dictionary", + "shared-source-folders": [ + "../../../../../../artifacts/bin/AutoRest.CSharp/Debug/net7.0/Generator.Shared", + "../../../../../../artifacts/bin/AutoRest.CSharp/Debug/net7.0/Azure.Core.Shared" + ], + "use-model-reader-writer": true +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/DatetimeValue.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/DatetimeValue.cs new file mode 100644 index 00000000000..bd9fb49f554 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/DatetimeValue.cs @@ -0,0 +1,239 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Dictionary +{ + // Data plane generated sub-client. + /// Dictionary of datetime values. + public partial class DatetimeValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of DatetimeValue for mocking. + protected DatetimeValue() + { + } + + /// Initializes a new instance of DatetimeValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal DatetimeValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetDatetimeValueAsync() + { + ClientResult result = await GetDatetimeValueAsync(null).ConfigureAwait(false); + IReadOnlyDictionary value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, property.Value.GetDateTimeOffset("O")); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetDatetimeValue() + { + ClientResult result = GetDatetimeValue(null); + IReadOnlyDictionary value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, property.Value.GetDateTimeOffset("O")); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetDatetimeValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetDatetimeValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetDatetimeValue(RequestOptions options) + { + using PipelineMessage message = CreateGetDatetimeValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual async Task PutAsync(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual ClientResult Put(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetDatetimeValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/datetime", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/datetime", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/DictionaryClient.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/DictionaryClient.cs new file mode 100644 index 00000000000..bbf7bf62ded --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/DictionaryClient.cs @@ -0,0 +1,117 @@ +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Threading; + +namespace Scm._Type._Dictionary +{ + // Data plane generated client. + /// The Dictionary service client. + public partial class DictionaryClient + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of DictionaryClient. + public DictionaryClient() : this(new Uri("http://localhost:3000"), new DictionaryClientOptions()) + { + } + + /// Initializes a new instance of DictionaryClient. + /// TestServer endpoint. + /// The options for configuring the client. + /// is null. + public DictionaryClient(Uri endpoint, DictionaryClientOptions options) + { + Argument.AssertNotNull(endpoint, nameof(endpoint)); + options ??= new DictionaryClientOptions(); + + _pipeline = ClientPipeline.Create(options, Array.Empty(), Array.Empty(), Array.Empty()); + _endpoint = endpoint; + } + + private Int32Value _cachedInt32Value; + private Int64Value _cachedInt64Value; + private BooleanValue _cachedBooleanValue; + private StringValue _cachedStringValue; + private Float32Value _cachedFloat32Value; + private DatetimeValue _cachedDatetimeValue; + private DurationValue _cachedDurationValue; + private UnknownValue _cachedUnknownValue; + private ModelValue _cachedModelValue; + private RecursiveModelValue _cachedRecursiveModelValue; + private NullableFloatValue _cachedNullableFloatValue; + + /// Initializes a new instance of Int32Value. + public virtual Int32Value GetInt32ValueClient() + { + return Volatile.Read(ref _cachedInt32Value) ?? Interlocked.CompareExchange(ref _cachedInt32Value, new Int32Value(_pipeline, _endpoint), null) ?? _cachedInt32Value; + } + + /// Initializes a new instance of Int64Value. + public virtual Int64Value GetInt64ValueClient() + { + return Volatile.Read(ref _cachedInt64Value) ?? Interlocked.CompareExchange(ref _cachedInt64Value, new Int64Value(_pipeline, _endpoint), null) ?? _cachedInt64Value; + } + + /// Initializes a new instance of BooleanValue. + public virtual BooleanValue GetBooleanValueClient() + { + return Volatile.Read(ref _cachedBooleanValue) ?? Interlocked.CompareExchange(ref _cachedBooleanValue, new BooleanValue(_pipeline, _endpoint), null) ?? _cachedBooleanValue; + } + + /// Initializes a new instance of StringValue. + public virtual StringValue GetStringValueClient() + { + return Volatile.Read(ref _cachedStringValue) ?? Interlocked.CompareExchange(ref _cachedStringValue, new StringValue(_pipeline, _endpoint), null) ?? _cachedStringValue; + } + + /// Initializes a new instance of Float32Value. + public virtual Float32Value GetFloat32ValueClient() + { + return Volatile.Read(ref _cachedFloat32Value) ?? Interlocked.CompareExchange(ref _cachedFloat32Value, new Float32Value(_pipeline, _endpoint), null) ?? _cachedFloat32Value; + } + + /// Initializes a new instance of DatetimeValue. + public virtual DatetimeValue GetDatetimeValueClient() + { + return Volatile.Read(ref _cachedDatetimeValue) ?? Interlocked.CompareExchange(ref _cachedDatetimeValue, new DatetimeValue(_pipeline, _endpoint), null) ?? _cachedDatetimeValue; + } + + /// Initializes a new instance of DurationValue. + public virtual DurationValue GetDurationValueClient() + { + return Volatile.Read(ref _cachedDurationValue) ?? Interlocked.CompareExchange(ref _cachedDurationValue, new DurationValue(_pipeline, _endpoint), null) ?? _cachedDurationValue; + } + + /// Initializes a new instance of UnknownValue. + public virtual UnknownValue GetUnknownValueClient() + { + return Volatile.Read(ref _cachedUnknownValue) ?? Interlocked.CompareExchange(ref _cachedUnknownValue, new UnknownValue(_pipeline, _endpoint), null) ?? _cachedUnknownValue; + } + + /// Initializes a new instance of ModelValue. + public virtual ModelValue GetModelValueClient() + { + return Volatile.Read(ref _cachedModelValue) ?? Interlocked.CompareExchange(ref _cachedModelValue, new ModelValue(_pipeline, _endpoint), null) ?? _cachedModelValue; + } + + /// Initializes a new instance of RecursiveModelValue. + public virtual RecursiveModelValue GetRecursiveModelValueClient() + { + return Volatile.Read(ref _cachedRecursiveModelValue) ?? Interlocked.CompareExchange(ref _cachedRecursiveModelValue, new RecursiveModelValue(_pipeline, _endpoint), null) ?? _cachedRecursiveModelValue; + } + + /// Initializes a new instance of NullableFloatValue. + public virtual NullableFloatValue GetNullableFloatValueClient() + { + return Volatile.Read(ref _cachedNullableFloatValue) ?? Interlocked.CompareExchange(ref _cachedNullableFloatValue, new NullableFloatValue(_pipeline, _endpoint), null) ?? _cachedNullableFloatValue; + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/DictionaryClientOptions.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/DictionaryClientOptions.cs new file mode 100644 index 00000000000..fdb77929aae --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/DictionaryClientOptions.cs @@ -0,0 +1,13 @@ +// + +#nullable disable + +using System.ClientModel.Primitives; + +namespace Scm._Type._Dictionary +{ + /// Client options for DictionaryClient. + public partial class DictionaryClientOptions : ClientPipelineOptions + { + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/DurationValue.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/DurationValue.cs new file mode 100644 index 00000000000..8b82340c3a4 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/DurationValue.cs @@ -0,0 +1,239 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Dictionary +{ + // Data plane generated sub-client. + /// Dictionary of duration values. + public partial class DurationValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of DurationValue for mocking. + protected DurationValue() + { + } + + /// Initializes a new instance of DurationValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal DurationValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetDurationValueAsync() + { + ClientResult result = await GetDurationValueAsync(null).ConfigureAwait(false); + IReadOnlyDictionary value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, property.Value.GetTimeSpan("P")); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetDurationValue() + { + ClientResult result = GetDurationValue(null); + IReadOnlyDictionary value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, property.Value.GetTimeSpan("P")); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetDurationValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetDurationValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetDurationValue(RequestOptions options) + { + using PipelineMessage message = CreateGetDurationValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual async Task PutAsync(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual ClientResult Put(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetDurationValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/duration", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/duration", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Float32Value.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Float32Value.cs new file mode 100644 index 00000000000..5cadbc76103 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Float32Value.cs @@ -0,0 +1,239 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Dictionary +{ + // Data plane generated sub-client. + /// Dictionary of float values. + public partial class Float32Value + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of Float32Value for mocking. + protected Float32Value() + { + } + + /// Initializes a new instance of Float32Value. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal Float32Value(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetFloat32ValueAsync() + { + ClientResult result = await GetFloat32ValueAsync(null).ConfigureAwait(false); + IReadOnlyDictionary value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, property.Value.GetSingle()); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetFloat32Value() + { + ClientResult result = GetFloat32Value(null); + IReadOnlyDictionary value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, property.Value.GetSingle()); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetFloat32ValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetFloat32ValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetFloat32Value(RequestOptions options) + { + using PipelineMessage message = CreateGetFloat32ValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual async Task PutAsync(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual ClientResult Put(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetFloat32ValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/float32", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/float32", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Int32Value.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Int32Value.cs new file mode 100644 index 00000000000..a7d73d6cbff --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Int32Value.cs @@ -0,0 +1,239 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Dictionary +{ + // Data plane generated sub-client. + /// Dictionary of int32 values. + public partial class Int32Value + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of Int32Value for mocking. + protected Int32Value() + { + } + + /// Initializes a new instance of Int32Value. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal Int32Value(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetInt32ValueAsync() + { + ClientResult result = await GetInt32ValueAsync(null).ConfigureAwait(false); + IReadOnlyDictionary value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, property.Value.GetInt32()); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetInt32Value() + { + ClientResult result = GetInt32Value(null); + IReadOnlyDictionary value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, property.Value.GetInt32()); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetInt32ValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetInt32ValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetInt32Value(RequestOptions options) + { + using PipelineMessage message = CreateGetInt32ValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual async Task PutAsync(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual ClientResult Put(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetInt32ValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/int32", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/int32", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Int64Value.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Int64Value.cs new file mode 100644 index 00000000000..6033146dbf6 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Int64Value.cs @@ -0,0 +1,239 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Dictionary +{ + // Data plane generated sub-client. + /// Dictionary of int64 values. + public partial class Int64Value + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of Int64Value for mocking. + protected Int64Value() + { + } + + /// Initializes a new instance of Int64Value. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal Int64Value(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetInt64ValueAsync() + { + ClientResult result = await GetInt64ValueAsync(null).ConfigureAwait(false); + IReadOnlyDictionary value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, property.Value.GetInt64()); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetInt64Value() + { + ClientResult result = GetInt64Value(null); + IReadOnlyDictionary value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, property.Value.GetInt64()); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetInt64ValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetInt64ValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetInt64Value(RequestOptions options) + { + using PipelineMessage message = CreateGetInt64ValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual async Task PutAsync(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual ClientResult Put(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetInt64ValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/int64", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/int64", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/Argument.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/Argument.cs new file mode 100644 index 00000000000..043b93d17c3 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/Argument.cs @@ -0,0 +1,126 @@ +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Scm._Type._Dictionary +{ + internal static class Argument + { + public static void AssertNotNull(T value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + } + + public static void AssertNotNull(T? value, string name) + where T : struct + { + if (!value.HasValue) + { + throw new ArgumentNullException(name); + } + } + + public static void AssertNotNullOrEmpty(IEnumerable value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (value is ICollection collectionOfT && collectionOfT.Count == 0) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + if (value is ICollection collection && collection.Count == 0) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + using IEnumerator e = value.GetEnumerator(); + if (!e.MoveNext()) + { + throw new ArgumentException("Value cannot be an empty collection.", name); + } + } + + public static void AssertNotNullOrEmpty(string value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (value.Length == 0) + { + throw new ArgumentException("Value cannot be an empty string.", name); + } + } + + public static void AssertNotNullOrWhiteSpace(string value, string name) + { + if (value is null) + { + throw new ArgumentNullException(name); + } + if (string.IsNullOrWhiteSpace(value)) + { + throw new ArgumentException("Value cannot be empty or contain only white-space characters.", name); + } + } + + public static void AssertNotDefault(ref T value, string name) + where T : struct, IEquatable + { + if (value.Equals(default)) + { + throw new ArgumentException("Value cannot be empty.", name); + } + } + + public static void AssertInRange(T value, T minimum, T maximum, string name) + where T : notnull, IComparable + { + if (minimum.CompareTo(value) > 0) + { + throw new ArgumentOutOfRangeException(name, "Value is less than the minimum allowed."); + } + if (maximum.CompareTo(value) < 0) + { + throw new ArgumentOutOfRangeException(name, "Value is greater than the maximum allowed."); + } + } + + public static void AssertEnumDefined(Type enumType, object value, string name) + { + if (!Enum.IsDefined(enumType, value)) + { + throw new ArgumentException($"Value not defined for {enumType.FullName}.", name); + } + } + + public static T CheckNotNull(T value, string name) + where T : class + { + AssertNotNull(value, name); + return value; + } + + public static string CheckNotNullOrEmpty(string value, string name) + { + AssertNotNullOrEmpty(value, name); + return value; + } + + public static void AssertNull(T value, string name, string message = null) + { + if (value != null) + { + throw new ArgumentException(message ?? "Value must be null.", name); + } + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/BinaryContentHelper.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/BinaryContentHelper.cs new file mode 100644 index 00000000000..210de26c43f --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/BinaryContentHelper.cs @@ -0,0 +1,119 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.Collections.Generic; +using System.Text.Json; + +namespace Scm._Type._Dictionary +{ + internal static class BinaryContentHelper + { + public static BinaryContent FromEnumerable(IEnumerable enumerable) + where T : notnull + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteStartArray(); + foreach (var item in enumerable) + { + content.JsonWriter.WriteObjectValue(item, ModelSerializationExtensions.WireOptions); + } + content.JsonWriter.WriteEndArray(); + + return content; + } + + public static BinaryContent FromEnumerable(IEnumerable enumerable) + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteStartArray(); + foreach (var item in enumerable) + { + if (item == null) + { + content.JsonWriter.WriteNullValue(); + } + else + { +#if NET6_0_OR_GREATER + content.JsonWriter.WriteRawValue(item); +#else + using (JsonDocument document = JsonDocument.Parse(item)) + { + JsonSerializer.Serialize(content.JsonWriter, document.RootElement); + } +#endif + } + } + content.JsonWriter.WriteEndArray(); + + return content; + } + + public static BinaryContent FromDictionary(IDictionary dictionary) + where TValue : notnull + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteStartObject(); + foreach (var item in dictionary) + { + content.JsonWriter.WritePropertyName(item.Key); + content.JsonWriter.WriteObjectValue(item.Value, ModelSerializationExtensions.WireOptions); + } + content.JsonWriter.WriteEndObject(); + + return content; + } + + public static BinaryContent FromDictionary(IDictionary dictionary) + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteStartObject(); + foreach (var item in dictionary) + { + content.JsonWriter.WritePropertyName(item.Key); + if (item.Value == null) + { + content.JsonWriter.WriteNullValue(); + } + else + { +#if NET6_0_OR_GREATER + content.JsonWriter.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(content.JsonWriter, document.RootElement); + } +#endif + } + } + content.JsonWriter.WriteEndObject(); + + return content; + } + + public static BinaryContent FromObject(object value) + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(value, ModelSerializationExtensions.WireOptions); + return content; + } + + public static BinaryContent FromObject(BinaryData value) + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); +#if NET6_0_OR_GREATER + content.JsonWriter.WriteRawValue(value); +#else + using (JsonDocument document = JsonDocument.Parse(value)) + { + JsonSerializer.Serialize(content.JsonWriter, document.RootElement); + } +#endif + return content; + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ChangeTrackingDictionary.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ChangeTrackingDictionary.cs new file mode 100644 index 00000000000..5ea4c9e7b42 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ChangeTrackingDictionary.cs @@ -0,0 +1,164 @@ +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; + +namespace Scm._Type._Dictionary +{ + internal class ChangeTrackingDictionary : IDictionary, IReadOnlyDictionary where TKey : notnull + { + private IDictionary _innerDictionary; + + public ChangeTrackingDictionary() + { + } + + public ChangeTrackingDictionary(IDictionary dictionary) + { + if (dictionary == null) + { + return; + } + _innerDictionary = new Dictionary(dictionary); + } + + public ChangeTrackingDictionary(IReadOnlyDictionary dictionary) + { + if (dictionary == null) + { + return; + } + _innerDictionary = new Dictionary(); + foreach (var pair in dictionary) + { + _innerDictionary.Add(pair); + } + } + + public bool IsUndefined => _innerDictionary == null; + + public int Count => IsUndefined ? 0 : EnsureDictionary().Count; + + public bool IsReadOnly => IsUndefined ? false : EnsureDictionary().IsReadOnly; + + public ICollection Keys => IsUndefined ? Array.Empty() : EnsureDictionary().Keys; + + public ICollection Values => IsUndefined ? Array.Empty() : EnsureDictionary().Values; + + public TValue this[TKey key] + { + get + { + if (IsUndefined) + { + throw new KeyNotFoundException(nameof(key)); + } + return EnsureDictionary()[key]; + } + set + { + EnsureDictionary()[key] = value; + } + } + + IEnumerable IReadOnlyDictionary.Keys => Keys; + + IEnumerable IReadOnlyDictionary.Values => Values; + + public IEnumerator> GetEnumerator() + { + if (IsUndefined) + { + IEnumerator> enumerateEmpty() + { + yield break; + } + return enumerateEmpty(); + } + return EnsureDictionary().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(KeyValuePair item) + { + EnsureDictionary().Add(item); + } + + public void Clear() + { + EnsureDictionary().Clear(); + } + + public bool Contains(KeyValuePair item) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Contains(item); + } + + public void CopyTo(KeyValuePair[] array, int index) + { + if (IsUndefined) + { + return; + } + EnsureDictionary().CopyTo(array, index); + } + + public bool Remove(KeyValuePair item) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Remove(item); + } + + public void Add(TKey key, TValue value) + { + EnsureDictionary().Add(key, value); + } + + public bool ContainsKey(TKey key) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().ContainsKey(key); + } + + public bool Remove(TKey key) + { + if (IsUndefined) + { + return false; + } + return EnsureDictionary().Remove(key); + } + + public bool TryGetValue(TKey key, out TValue value) + { + if (IsUndefined) + { + value = default; + return false; + } + return EnsureDictionary().TryGetValue(key, out value); + } + + public IDictionary EnsureDictionary() + { + return _innerDictionary ??= new Dictionary(); + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ChangeTrackingList.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ChangeTrackingList.cs new file mode 100644 index 00000000000..0e72c71e2a4 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ChangeTrackingList.cs @@ -0,0 +1,150 @@ +// + +#nullable disable + +using System; +using System.Collections; +using System.Collections.Generic; +using System.Linq; + +namespace Scm._Type._Dictionary +{ + internal class ChangeTrackingList : IList, IReadOnlyList + { + private IList _innerList; + + public ChangeTrackingList() + { + } + + public ChangeTrackingList(IList innerList) + { + if (innerList != null) + { + _innerList = innerList; + } + } + + public ChangeTrackingList(IReadOnlyList innerList) + { + if (innerList != null) + { + _innerList = innerList.ToList(); + } + } + + public bool IsUndefined => _innerList == null; + + public int Count => IsUndefined ? 0 : EnsureList().Count; + + public bool IsReadOnly => IsUndefined ? false : EnsureList().IsReadOnly; + + public T this[int index] + { + get + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + return EnsureList()[index]; + } + set + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureList()[index] = value; + } + } + + public void Reset() + { + _innerList = null; + } + + public IEnumerator GetEnumerator() + { + if (IsUndefined) + { + IEnumerator enumerateEmpty() + { + yield break; + } + return enumerateEmpty(); + } + return EnsureList().GetEnumerator(); + } + + IEnumerator IEnumerable.GetEnumerator() + { + return GetEnumerator(); + } + + public void Add(T item) + { + EnsureList().Add(item); + } + + public void Clear() + { + EnsureList().Clear(); + } + + public bool Contains(T item) + { + if (IsUndefined) + { + return false; + } + return EnsureList().Contains(item); + } + + public void CopyTo(T[] array, int arrayIndex) + { + if (IsUndefined) + { + return; + } + EnsureList().CopyTo(array, arrayIndex); + } + + public bool Remove(T item) + { + if (IsUndefined) + { + return false; + } + return EnsureList().Remove(item); + } + + public int IndexOf(T item) + { + if (IsUndefined) + { + return -1; + } + return EnsureList().IndexOf(item); + } + + public void Insert(int index, T item) + { + EnsureList().Insert(index, item); + } + + public void RemoveAt(int index) + { + if (IsUndefined) + { + throw new ArgumentOutOfRangeException(nameof(index)); + } + EnsureList().RemoveAt(index); + } + + public IList EnsureList() + { + return _innerList ??= new List(); + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ClientPipelineExtensions.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ClientPipelineExtensions.cs new file mode 100644 index 00000000000..b5fcaef2d8b --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ClientPipelineExtensions.cs @@ -0,0 +1,65 @@ +// + +#nullable disable + +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Threading.Tasks; + +namespace Scm._Type._Dictionary +{ + internal static class ClientPipelineExtensions + { + public static async ValueTask ProcessMessageAsync(this ClientPipeline pipeline, PipelineMessage message, RequestOptions options) + { + await pipeline.SendAsync(message).ConfigureAwait(false); + + if (message.Response.IsError && (options?.ErrorOptions & ClientErrorBehaviors.NoThrow) != ClientErrorBehaviors.NoThrow) + { + throw await ClientResultException.CreateAsync(message.Response).ConfigureAwait(false); + } + + return message.Response; + } + + public static PipelineResponse ProcessMessage(this ClientPipeline pipeline, PipelineMessage message, RequestOptions options) + { + pipeline.Send(message); + + if (message.Response.IsError && (options?.ErrorOptions & ClientErrorBehaviors.NoThrow) != ClientErrorBehaviors.NoThrow) + { + throw new ClientResultException(message.Response); + } + + return message.Response; + } + + public static async ValueTask> ProcessHeadAsBoolMessageAsync(this ClientPipeline pipeline, PipelineMessage message, RequestOptions options) + { + PipelineResponse response = await pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false); + switch (response.Status) + { + case >= 200 and < 300: + return ClientResult.FromValue(true, response); + case >= 400 and < 500: + return ClientResult.FromValue(false, response); + default: + return new ErrorResult(response, new ClientResultException(response)); + } + } + + public static ClientResult ProcessHeadAsBoolMessage(this ClientPipeline pipeline, PipelineMessage message, RequestOptions options) + { + PipelineResponse response = pipeline.ProcessMessage(message, options); + switch (response.Status) + { + case >= 200 and < 300: + return ClientResult.FromValue(true, response); + case >= 400 and < 500: + return ClientResult.FromValue(false, response); + default: + return new ErrorResult(response, new ClientResultException(response)); + } + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ClientUriBuilder.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ClientUriBuilder.cs new file mode 100644 index 00000000000..142c244b720 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ClientUriBuilder.cs @@ -0,0 +1,209 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Text; + +namespace Scm._Type._Dictionary +{ + internal class ClientUriBuilder + { + private UriBuilder _uriBuilder; + private StringBuilder _pathBuilder; + private StringBuilder _queryBuilder; + + public ClientUriBuilder() + { + } + + private UriBuilder UriBuilder => _uriBuilder ??= new UriBuilder(); + + private StringBuilder PathBuilder => _pathBuilder ??= new StringBuilder(UriBuilder.Path); + + private StringBuilder QueryBuilder => _queryBuilder ??= new StringBuilder(UriBuilder.Query); + + public void Reset(Uri uri) + { + _uriBuilder = new UriBuilder(uri); + _pathBuilder = new StringBuilder(UriBuilder.Path); + _queryBuilder = new StringBuilder(UriBuilder.Query); + } + + public void AppendPath(string value, bool escape) + { + Argument.AssertNotNullOrWhiteSpace(value, nameof(value)); + + if (escape) + { + value = Uri.EscapeDataString(value); + } + + if (PathBuilder.Length > 0 && PathBuilder[PathBuilder.Length - 1] == '/' && value[0] == '/') + { + PathBuilder.Remove(PathBuilder.Length - 1, 1); + } + + PathBuilder.Append(value); + UriBuilder.Path = PathBuilder.ToString(); + } + + public void AppendPath(bool value, bool escape = false) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendPath(float value, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendPath(double value, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendPath(int value, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendPath(byte[] value, string format, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value, format), escape); + } + + public void AppendPath(IEnumerable value, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendPath(DateTimeOffset value, string format, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value, format), escape); + } + + public void AppendPath(TimeSpan value, string format, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value, format), escape); + } + + public void AppendPath(Guid value, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendPath(long value, bool escape = true) + { + AppendPath(ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, string value, bool escape) + { + Argument.AssertNotNullOrWhiteSpace(name, nameof(name)); + Argument.AssertNotNullOrWhiteSpace(value, nameof(value)); + + if (QueryBuilder.Length == 0) + { + QueryBuilder.Append('?'); + } + else + { + QueryBuilder.Append('&'); + } + + if (escape) + { + value = Uri.EscapeDataString(value); + } + + QueryBuilder.Append(name); + QueryBuilder.Append('='); + QueryBuilder.Append(value); + } + + public void AppendQuery(string name, bool value, bool escape = false) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, float value, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, DateTimeOffset value, string format, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value, format), escape); + } + + public void AppendQuery(string name, TimeSpan value, string format, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value, format), escape); + } + + public void AppendQuery(string name, double value, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, decimal value, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, int value, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, long value, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, TimeSpan value, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQuery(string name, byte[] value, string format, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value, format), escape); + } + + public void AppendQuery(string name, Guid value, bool escape = true) + { + AppendQuery(name, ModelSerializationExtensions.TypeFormatters.ConvertToString(value), escape); + } + + public void AppendQueryDelimited(string name, IEnumerable value, string delimiter, bool escape = true) + { + var stringValues = value.Select(v => ModelSerializationExtensions.TypeFormatters.ConvertToString(v)); + AppendQuery(name, string.Join(delimiter, stringValues), escape); + } + + public void AppendQueryDelimited(string name, IEnumerable value, string delimiter, string format, bool escape = true) + { + var stringValues = value.Select(v => ModelSerializationExtensions.TypeFormatters.ConvertToString(v, format)); + AppendQuery(name, string.Join(delimiter, stringValues), escape); + } + + public Uri ToUri() + { + if (_pathBuilder != null) + { + UriBuilder.Path = _pathBuilder.ToString(); + } + + if (_queryBuilder != null) + { + UriBuilder.Query = _queryBuilder.ToString(); + } + + return UriBuilder.Uri; + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ErrorResult.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ErrorResult.cs new file mode 100644 index 00000000000..97d864cfe24 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ErrorResult.cs @@ -0,0 +1,23 @@ +// + +#nullable disable + +using System.ClientModel; +using System.ClientModel.Primitives; + +namespace Scm._Type._Dictionary +{ + internal class ErrorResult : ClientResult + { + private readonly PipelineResponse _response; + private readonly ClientResultException _exception; + + public ErrorResult(PipelineResponse response, ClientResultException exception) : base(default, response) + { + _response = response; + _exception = exception; + } + + public override T Value => throw _exception; + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ModelSerializationExtensions.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ModelSerializationExtensions.cs new file mode 100644 index 00000000000..1d2a93ec41c --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/ModelSerializationExtensions.cs @@ -0,0 +1,391 @@ +// + +#nullable disable + +using System; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Diagnostics; +using System.Globalization; +using System.Text.Json; +using System.Xml; + +namespace Scm._Type._Dictionary +{ + internal static class ModelSerializationExtensions + { + internal static readonly ModelReaderWriterOptions WireOptions = new ModelReaderWriterOptions("W"); + + public static object GetObject(this JsonElement element) + { + switch (element.ValueKind) + { + case JsonValueKind.String: + return element.GetString(); + case JsonValueKind.Number: + if (element.TryGetInt32(out int intValue)) + { + return intValue; + } + if (element.TryGetInt64(out long longValue)) + { + return longValue; + } + return element.GetDouble(); + case JsonValueKind.True: + return true; + case JsonValueKind.False: + return false; + case JsonValueKind.Undefined: + case JsonValueKind.Null: + return null; + case JsonValueKind.Object: + var dictionary = new Dictionary(); + foreach (var jsonProperty in element.EnumerateObject()) + { + dictionary.Add(jsonProperty.Name, jsonProperty.Value.GetObject()); + } + return dictionary; + case JsonValueKind.Array: + var list = new List(); + foreach (var item in element.EnumerateArray()) + { + list.Add(item.GetObject()); + } + return list.ToArray(); + default: + throw new NotSupportedException($"Not supported value kind {element.ValueKind}"); + } + } + + public static byte[] GetBytesFromBase64(this JsonElement element, string format) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + + return format switch + { + "U" => TypeFormatters.FromBase64UrlString(element.GetRequiredString()), + "D" => element.GetBytesFromBase64(), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + } + + public static DateTimeOffset GetDateTimeOffset(this JsonElement element, string format) => format switch + { + "U" when element.ValueKind == JsonValueKind.Number => DateTimeOffset.FromUnixTimeSeconds(element.GetInt64()), + _ => TypeFormatters.ParseDateTimeOffset(element.GetString(), format) + }; + + public static TimeSpan GetTimeSpan(this JsonElement element, string format) => TypeFormatters.ParseTimeSpan(element.GetString(), format); + + public static char GetChar(this JsonElement element) + { + if (element.ValueKind == JsonValueKind.String) + { + var text = element.GetString(); + if (text == null || text.Length != 1) + { + throw new NotSupportedException($"Cannot convert \"{text}\" to a char"); + } + return text[0]; + } + else + { + throw new NotSupportedException($"Cannot convert {element.ValueKind} to a char"); + } + } + + [Conditional("DEBUG")] + public static void ThrowNonNullablePropertyIsNull(this JsonProperty property) + { + throw new JsonException($"A property '{property.Name}' defined as non-nullable but received as null from the service. This exception only happens in DEBUG builds of the library and would be ignored in the release build"); + } + + public static string GetRequiredString(this JsonElement element) + { + var value = element.GetString(); + if (value == null) + { + throw new InvalidOperationException($"The requested operation requires an element of type 'String', but the target element has type '{element.ValueKind}'."); + } + return value; + } + + public static void WriteStringValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, DateTime value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, TimeSpan value, string format) + { + writer.WriteStringValue(TypeFormatters.ToString(value, format)); + } + + public static void WriteStringValue(this Utf8JsonWriter writer, char value) + { + writer.WriteStringValue(value.ToString(CultureInfo.InvariantCulture)); + } + + public static void WriteBase64StringValue(this Utf8JsonWriter writer, byte[] value, string format) + { + if (value == null) + { + writer.WriteNullValue(); + return; + } + switch (format) + { + case "U": + writer.WriteStringValue(TypeFormatters.ToBase64UrlString(value)); + break; + case "D": + writer.WriteBase64StringValue(value); + break; + default: + throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)); + } + } + + public static void WriteNumberValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) + { + if (format != "U") + { + throw new ArgumentOutOfRangeException(nameof(format), "Only 'U' format is supported when writing a DateTimeOffset as a Number."); + } + writer.WriteNumberValue(value.ToUnixTimeSeconds()); + } + + public static void WriteObjectValue(this Utf8JsonWriter writer, T value, ModelReaderWriterOptions options = null) + { + switch (value) + { + case null: + writer.WriteNullValue(); + break; + case IJsonModel jsonModel: + jsonModel.Write(writer, options ?? WireOptions); + break; + case byte[] bytes: + writer.WriteBase64StringValue(bytes); + break; + case BinaryData bytes0: + writer.WriteBase64StringValue(bytes0); + break; + case JsonElement json: + json.WriteTo(writer); + break; + case int i: + writer.WriteNumberValue(i); + break; + case decimal d: + writer.WriteNumberValue(d); + break; + case double d0: + if (double.IsNaN(d0)) + { + writer.WriteStringValue("NaN"); + } + else + { + writer.WriteNumberValue(d0); + } + break; + case float f: + writer.WriteNumberValue(f); + break; + case long l: + writer.WriteNumberValue(l); + break; + case string s: + writer.WriteStringValue(s); + break; + case bool b: + writer.WriteBooleanValue(b); + break; + case Guid g: + writer.WriteStringValue(g); + break; + case DateTimeOffset dateTimeOffset: + writer.WriteStringValue(dateTimeOffset, "O"); + break; + case DateTime dateTime: + writer.WriteStringValue(dateTime, "O"); + break; + case IEnumerable> enumerable: + writer.WriteStartObject(); + foreach (var pair in enumerable) + { + writer.WritePropertyName(pair.Key); + writer.WriteObjectValue(pair.Value, options); + } + writer.WriteEndObject(); + break; + case IEnumerable objectEnumerable: + writer.WriteStartArray(); + foreach (var item in objectEnumerable) + { + writer.WriteObjectValue(item, options); + } + writer.WriteEndArray(); + break; + case TimeSpan timeSpan: + writer.WriteStringValue(timeSpan, "P"); + break; + default: + throw new NotSupportedException($"Not supported type {value.GetType()}"); + } + } + + public static void WriteObjectValue(this Utf8JsonWriter writer, object value, ModelReaderWriterOptions options = null) + { + writer.WriteObjectValue(value, options); + } + + internal static class TypeFormatters + { + private const string RoundtripZFormat = "yyyy-MM-ddTHH:mm:ss.fffffffZ"; + public const string DefaultNumberFormat = "G"; + + public static string ToString(bool value) => value ? "true" : "false"; + + public static string ToString(DateTime value, string format) => value.Kind switch + { + DateTimeKind.Utc => ToString((DateTimeOffset)value, format), + _ => throw new NotSupportedException($"DateTime {value} has a Kind of {value.Kind}. Generated clients require it to be UTC. You can call DateTime.SpecifyKind to change Kind property value to DateTimeKind.Utc.") + }; + + public static string ToString(DateTimeOffset value, string format) => format switch + { + "D" => value.ToString("yyyy-MM-dd", CultureInfo.InvariantCulture), + "U" => value.ToUnixTimeSeconds().ToString(CultureInfo.InvariantCulture), + "O" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "o" => value.ToUniversalTime().ToString(RoundtripZFormat, CultureInfo.InvariantCulture), + "R" => value.ToString("r", CultureInfo.InvariantCulture), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(TimeSpan value, string format) => format switch + { + "P" => XmlConvert.ToString(value), + _ => value.ToString(format, CultureInfo.InvariantCulture) + }; + + public static string ToString(byte[] value, string format) => format switch + { + "U" => ToBase64UrlString(value), + "D" => Convert.ToBase64String(value), + _ => throw new ArgumentException($"Format is not supported: '{format}'", nameof(format)) + }; + + public static string ToBase64UrlString(byte[] value) + { + int numWholeOrPartialInputBlocks = checked(value.Length + 2) / 3; + int size = checked(numWholeOrPartialInputBlocks * 4); + char[] output = new char[size]; + + int numBase64Chars = Convert.ToBase64CharArray(value, 0, value.Length, output, 0); + + int i = 0; + for (; i < numBase64Chars; i++) + { + char ch = output[i]; + if (ch == '+') + { + output[i] = '-'; + } + else + { + if (ch == '/') + { + output[i] = '_'; + } + else + { + if (ch == '=') + { + break; + } + } + } + } + + return new string(output, 0, i); + } + + public static byte[] FromBase64UrlString(string value) + { + int paddingCharsToAdd = (value.Length % 4) switch + { + 0 => 0, + 2 => 2, + 3 => 1, + _ => throw new InvalidOperationException("Malformed input") + }; + char[] output = new char[(value.Length + paddingCharsToAdd)]; + int i = 0; + for (; i < value.Length; i++) + { + char ch = value[i]; + if (ch == '-') + { + output[i] = '+'; + } + else + { + if (ch == '_') + { + output[i] = '/'; + } + else + { + output[i] = ch; + } + } + } + + for (; i < output.Length; i++) + { + output[i] = '='; + } + + return Convert.FromBase64CharArray(output, 0, output.Length); + } + + public static DateTimeOffset ParseDateTimeOffset(string value, string format) => format switch + { + "U" => DateTimeOffset.FromUnixTimeSeconds(long.Parse(value, CultureInfo.InvariantCulture)), + _ => DateTimeOffset.Parse(value, CultureInfo.InvariantCulture, DateTimeStyles.AssumeUniversal) + }; + + public static TimeSpan ParseTimeSpan(string value, string format) => format switch + { + "P" => XmlConvert.ToTimeSpan(value), + _ => TimeSpan.ParseExact(value, format, CultureInfo.InvariantCulture) + }; + + public static string ConvertToString(object value, string format = null) => value switch + { + null => "null", + string s => s, + bool b => ToString(b), + int or float or double or long or decimal => ((IFormattable)value).ToString(DefaultNumberFormat, CultureInfo.InvariantCulture), + byte[] b0 when format != null => ToString(b0, format), + IEnumerable s0 => string.Join(",", s0), + DateTimeOffset dateTime when format != null => ToString(dateTime, format), + TimeSpan timeSpan when format != null => ToString(timeSpan, format), + TimeSpan timeSpan0 => XmlConvert.ToString(timeSpan0), + Guid guid => guid.ToString(), + BinaryData binaryData => ConvertToString(binaryData.ToArray(), format), + _ => value.ToString() + }; + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/Optional.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/Optional.cs new file mode 100644 index 00000000000..b0feb02ce67 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/Optional.cs @@ -0,0 +1,48 @@ +// + +#nullable disable + +using System.Collections.Generic; +using System.Text.Json; + +namespace Scm._Type._Dictionary +{ + internal static class Optional + { + public static bool IsCollectionDefined(IEnumerable collection) + { + return !(collection is ChangeTrackingList changeTrackingList && changeTrackingList.IsUndefined); + } + + public static bool IsCollectionDefined(IDictionary collection) + { + return !(collection is ChangeTrackingDictionary changeTrackingDictionary && changeTrackingDictionary.IsUndefined); + } + + public static bool IsCollectionDefined(IReadOnlyDictionary collection) + { + return !(collection is ChangeTrackingDictionary changeTrackingDictionary && changeTrackingDictionary.IsUndefined); + } + + public static bool IsDefined(T? value) + where T : struct + { + return value.HasValue; + } + + public static bool IsDefined(object value) + { + return value != null; + } + + public static bool IsDefined(JsonElement value) + { + return value.ValueKind != JsonValueKind.Undefined; + } + + public static bool IsDefined(string value) + { + return value != null; + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/Utf8JsonBinaryContent.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/Utf8JsonBinaryContent.cs new file mode 100644 index 00000000000..728fb2364fb --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Internal/Utf8JsonBinaryContent.cs @@ -0,0 +1,52 @@ +// + +#nullable disable + +using System.ClientModel; +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; + +namespace Scm._Type._Dictionary +{ + internal class Utf8JsonBinaryContent : BinaryContent + { + private readonly MemoryStream _stream; + private readonly BinaryContent _content; + + public Utf8JsonBinaryContent() + { + _stream = new MemoryStream(); + _content = Create(_stream); + JsonWriter = new Utf8JsonWriter(_stream); + } + + public Utf8JsonWriter JsonWriter { get; } + + public override async Task WriteToAsync(Stream stream, CancellationToken cancellationToken = default) + { + await JsonWriter.FlushAsync().ConfigureAwait(false); + await _content.WriteToAsync(stream, cancellationToken).ConfigureAwait(false); + } + + public override void WriteTo(Stream stream, CancellationToken cancellationToken = default) + { + JsonWriter.Flush(); + _content.WriteTo(stream, cancellationToken); + } + + public override bool TryComputeLength(out long length) + { + length = JsonWriter.BytesCommitted + JsonWriter.BytesPending; + return true; + } + + public override void Dispose() + { + JsonWriter.Dispose(); + _content.Dispose(); + _stream.Dispose(); + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/ModelValue.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/ModelValue.cs new file mode 100644 index 00000000000..e0f7b4d5914 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/ModelValue.cs @@ -0,0 +1,240 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; +using Scm._Type._Dictionary.Models; + +namespace Scm._Type._Dictionary +{ + // Data plane generated sub-client. + /// Dictionary of model values. + public partial class ModelValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of ModelValue for mocking. + protected ModelValue() + { + } + + /// Initializes a new instance of ModelValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal ModelValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetModelValueAsync() + { + ClientResult result = await GetModelValueAsync(null).ConfigureAwait(false); + IReadOnlyDictionary value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, InnerModel.DeserializeInnerModel(property.Value)); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetModelValue() + { + ClientResult result = GetModelValue(null); + IReadOnlyDictionary value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, InnerModel.DeserializeInnerModel(property.Value)); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetModelValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetModelValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetModelValue(RequestOptions options) + { + using PipelineMessage message = CreateGetModelValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual async Task PutAsync(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual ClientResult Put(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetModelValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/model", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/model", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Models/InnerModel.Serialization.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Models/InnerModel.Serialization.cs new file mode 100644 index 00000000000..2e5b788d002 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Models/InnerModel.Serialization.cs @@ -0,0 +1,154 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; + +namespace Scm._Type._Dictionary.Models +{ + public partial class InnerModel : IJsonModel + { + void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InnerModel)} does not support writing '{format}' format."); + } + + writer.WriteStartObject(); + writer.WritePropertyName("property"u8); + writer.WriteStringValue(Property); + if (Optional.IsCollectionDefined(Children)) + { + writer.WritePropertyName("children"u8); + writer.WriteStartObject(); + foreach (var item in Children) + { + writer.WritePropertyName(item.Key); + writer.WriteObjectValue(item.Value, options); + } + writer.WriteEndObject(); + } + if (options.Format != "W" && _serializedAdditionalRawData != null) + { + foreach (var item in _serializedAdditionalRawData) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } + } + writer.WriteEndObject(); + } + + InnerModel IJsonModel.Create(ref Utf8JsonReader reader, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + if (format != "J") + { + throw new FormatException($"The model {nameof(InnerModel)} does not support reading '{format}' format."); + } + + using JsonDocument document = JsonDocument.ParseValue(ref reader); + return DeserializeInnerModel(document.RootElement, options); + } + + internal static InnerModel DeserializeInnerModel(JsonElement element, ModelReaderWriterOptions options = null) + { + options ??= ModelSerializationExtensions.WireOptions; + + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + string property = default; + IDictionary children = default; + IDictionary serializedAdditionalRawData = default; + Dictionary rawDataDictionary = new Dictionary(); + foreach (var property0 in element.EnumerateObject()) + { + if (property0.NameEquals("property"u8)) + { + property = property0.Value.GetString(); + continue; + } + if (property0.NameEquals("children"u8)) + { + if (property0.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property1 in property0.Value.EnumerateObject()) + { + dictionary.Add(property1.Name, DeserializeInnerModel(property1.Value, options)); + } + children = dictionary; + continue; + } + if (options.Format != "W") + { + rawDataDictionary.Add(property0.Name, BinaryData.FromString(property0.Value.GetRawText())); + } + } + serializedAdditionalRawData = rawDataDictionary; + return new InnerModel(property, children ?? new ChangeTrackingDictionary(), serializedAdditionalRawData); + } + + BinaryData IPersistableModel.Write(ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + return ModelReaderWriter.Write(this, options); + default: + throw new FormatException($"The model {nameof(InnerModel)} does not support writing '{options.Format}' format."); + } + } + + InnerModel IPersistableModel.Create(BinaryData data, ModelReaderWriterOptions options) + { + var format = options.Format == "W" ? ((IPersistableModel)this).GetFormatFromOptions(options) : options.Format; + + switch (format) + { + case "J": + { + using JsonDocument document = JsonDocument.Parse(data); + return DeserializeInnerModel(document.RootElement, options); + } + default: + throw new FormatException($"The model {nameof(InnerModel)} does not support reading '{options.Format}' format."); + } + } + + string IPersistableModel.GetFormatFromOptions(ModelReaderWriterOptions options) => "J"; + + /// Deserializes the model from a raw response. + /// The result to deserialize the model from. + internal static InnerModel FromResponse(PipelineResponse response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeInnerModel(document.RootElement); + } + + /// Convert into a . + internal virtual BinaryContent ToBinaryContent() + { + return BinaryContent.Create(this, ModelSerializationExtensions.WireOptions); + } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Models/InnerModel.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Models/InnerModel.cs new file mode 100644 index 00000000000..71edfe9dce1 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/Models/InnerModel.cs @@ -0,0 +1,77 @@ +// + +#nullable disable + +using System; +using System.Collections.Generic; + +namespace Scm._Type._Dictionary.Models +{ + /// Dictionary inner model. + public partial class InnerModel + { + /// + /// Keeps track of any properties unknown to the library. + /// + /// To assign an object to the value of this property use . + /// + /// + /// To assign an already formatted json string to this property use . + /// + /// + /// Examples: + /// + /// + /// BinaryData.FromObjectAsJson("foo") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromString("\"foo\"") + /// Creates a payload of "foo". + /// + /// + /// BinaryData.FromObjectAsJson(new { key = "value" }) + /// Creates a payload of { "key": "value" }. + /// + /// + /// BinaryData.FromString("{\"key\": \"value\"}") + /// Creates a payload of { "key": "value" }. + /// + /// + /// + /// + private IDictionary _serializedAdditionalRawData; + + /// Initializes a new instance of . + /// Required string property. + /// is null. + public InnerModel(string property) + { + Argument.AssertNotNull(property, nameof(property)); + + Property = property; + Children = new ChangeTrackingDictionary(); + } + + /// Initializes a new instance of . + /// Required string property. + /// + /// Keeps track of any properties unknown to the library. + internal InnerModel(string property, IDictionary children, IDictionary serializedAdditionalRawData) + { + Property = property; + Children = children; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + + /// Initializes a new instance of for deserialization. + internal InnerModel() + { + } + + /// Required string property. + public string Property { get; set; } + /// Gets the children. + public IDictionary Children { get; } + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/NullableFloatValue.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/NullableFloatValue.cs new file mode 100644 index 00000000000..e79f4b962e3 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/NullableFloatValue.cs @@ -0,0 +1,253 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Dictionary +{ + // Data plane generated sub-client. + /// Dictionary of nullable float values. + public partial class NullableFloatValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of NullableFloatValue for mocking. + protected NullableFloatValue() + { + } + + /// Initializes a new instance of NullableFloatValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal NullableFloatValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetNullableFloatValueAsync() + { + ClientResult result = await GetNullableFloatValueAsync(null).ConfigureAwait(false); + IReadOnlyDictionary value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(property.Name, null); + } + else + { + dictionary.Add(property.Name, property.Value.GetSingle()); + } + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetNullableFloatValue() + { + ClientResult result = GetNullableFloatValue(null); + IReadOnlyDictionary value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(property.Name, null); + } + else + { + dictionary.Add(property.Name, property.Value.GetSingle()); + } + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetNullableFloatValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetNullableFloatValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetNullableFloatValue(RequestOptions options) + { + using PipelineMessage message = CreateGetNullableFloatValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where TKey is of type , where TValue is of type ? to use. + /// is null. + public virtual async Task PutAsync(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where TKey is of type , where TValue is of type ? to use. + /// is null. + public virtual ClientResult Put(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetNullableFloatValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/nullable-float", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/nullable-float", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/RecursiveModelValue.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/RecursiveModelValue.cs new file mode 100644 index 00000000000..3b201eeeefd --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/RecursiveModelValue.cs @@ -0,0 +1,240 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; +using Scm._Type._Dictionary.Models; + +namespace Scm._Type._Dictionary +{ + // Data plane generated sub-client. + /// Dictionary of model values. + public partial class RecursiveModelValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of RecursiveModelValue for mocking. + protected RecursiveModelValue() + { + } + + /// Initializes a new instance of RecursiveModelValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal RecursiveModelValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetRecursiveModelValueAsync() + { + ClientResult result = await GetRecursiveModelValueAsync(null).ConfigureAwait(false); + IReadOnlyDictionary value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, InnerModel.DeserializeInnerModel(property.Value)); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetRecursiveModelValue() + { + ClientResult result = GetRecursiveModelValue(null); + IReadOnlyDictionary value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, InnerModel.DeserializeInnerModel(property.Value)); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetRecursiveModelValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetRecursiveModelValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetRecursiveModelValue(RequestOptions options) + { + using PipelineMessage message = CreateGetRecursiveModelValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual async Task PutAsync(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual ClientResult Put(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetRecursiveModelValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/model/recursive", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/model/recursive", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/StringValue.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/StringValue.cs new file mode 100644 index 00000000000..debc67b43f6 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/StringValue.cs @@ -0,0 +1,239 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Dictionary +{ + // Data plane generated sub-client. + /// Dictionary of string values. + public partial class StringValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of StringValue for mocking. + protected StringValue() + { + } + + /// Initializes a new instance of StringValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal StringValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetStringValueAsync() + { + ClientResult result = await GetStringValueAsync(null).ConfigureAwait(false); + IReadOnlyDictionary value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, property.Value.GetString()); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetStringValue() + { + ClientResult result = GetStringValue(null); + IReadOnlyDictionary value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + dictionary.Add(property.Name, property.Value.GetString()); + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetStringValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetStringValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetStringValue(RequestOptions options) + { + using PipelineMessage message = CreateGetStringValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual async Task PutAsync(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual ClientResult Put(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetStringValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/string", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/string", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/UnknownValue.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/UnknownValue.cs new file mode 100644 index 00000000000..0d46bb4e123 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/UnknownValue.cs @@ -0,0 +1,253 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; +using System.Threading.Tasks; + +namespace Scm._Type._Dictionary +{ + // Data plane generated sub-client. + /// Dictionary of unknown values. + public partial class UnknownValue + { + private readonly ClientPipeline _pipeline; + private readonly Uri _endpoint; + + /// The HTTP pipeline for sending and receiving REST requests and responses. + public virtual ClientPipeline Pipeline => _pipeline; + + /// Initializes a new instance of UnknownValue for mocking. + protected UnknownValue() + { + } + + /// Initializes a new instance of UnknownValue. + /// The HTTP pipeline for sending and receiving REST requests and responses. + /// TestServer endpoint. + internal UnknownValue(ClientPipeline pipeline, Uri endpoint) + { + _pipeline = pipeline; + _endpoint = endpoint; + } + + /// Get. + public virtual async Task>> GetUnknownValueAsync() + { + ClientResult result = await GetUnknownValueAsync(null).ConfigureAwait(false); + IReadOnlyDictionary value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(property.Name, null); + } + else + { + dictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// Get. + public virtual ClientResult> GetUnknownValue() + { + ClientResult result = GetUnknownValue(null); + IReadOnlyDictionary value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + Dictionary dictionary = new Dictionary(); + foreach (var property in document.RootElement.EnumerateObject()) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(property.Name, null); + } + else + { + dictionary.Add(property.Name, BinaryData.FromString(property.Value.GetRawText())); + } + } + value = dictionary; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task GetUnknownValueAsync(RequestOptions options) + { + using PipelineMessage message = CreateGetUnknownValueRequest(options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Get. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult GetUnknownValue(RequestOptions options) + { + using PipelineMessage message = CreateGetUnknownValueRequest(options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual async Task PutAsync(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = await PutAsync(content, null).ConfigureAwait(false); + return result; + } + + /// Put. + /// The where TKey is of type , where TValue is of type to use. + /// is null. + public virtual ClientResult Put(IDictionary body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromDictionary(body); + ClientResult result = Put(content, null); + return result; + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task PutAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] Put. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult Put(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreatePutRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + + internal PipelineMessage CreateGetUnknownValueRequest(RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "GET"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/unknown", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + if (options != null) + { + message.Apply(options); + } + return message; + } + + internal PipelineMessage CreatePutRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier204; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/type/dictionary/unknown", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + + private static PipelineMessageClassifier _pipelineMessageClassifier200; + private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); + private static PipelineMessageClassifier _pipelineMessageClassifier204; + private static PipelineMessageClassifier PipelineMessageClassifier204 => _pipelineMessageClassifier204 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 204 }); + } +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/tspCodeModel.json b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/tspCodeModel.json new file mode 100644 index 00000000000..a058167a4b2 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Generated/tspCodeModel.json @@ -0,0 +1,2340 @@ +{ + "$id": "1", + "Name": "Type.Dictionary", + "Description": "Illustrates various of dictionaries.", + "ApiVersions": [], + "Enums": [], + "Models": [ + { + "$id": "2", + "Kind": "Model", + "Name": "InnerModel", + "Namespace": "Type.Dictionary", + "Description": "Dictionary inner model", + "IsNullable": false, + "Usage": "RoundTrip", + "Properties": [ + { + "$id": "3", + "Name": "property", + "SerializedName": "property", + "Description": "Required string property", + "Type": { + "$id": "4", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "IsRequired": true, + "IsReadOnly": false + }, + { + "$id": "5", + "Name": "children", + "SerializedName": "children", + "Description": "", + "Type": { + "$id": "6", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "7", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$ref": "2" + }, + "IsNullable": false + }, + "IsRequired": false, + "IsReadOnly": false + } + ] + } + ], + "Clients": [ + { + "$id": "8", + "Name": "DictionaryClient", + "Description": "", + "Operations": [], + "Protocol": { + "$id": "9" + }, + "Creatable": true + }, + { + "$id": "10", + "Name": "Int32Value", + "Description": "Dictionary of int32 values", + "Operations": [ + { + "$id": "11", + "Name": "get", + "ResourceName": "Int32Value", + "Parameters": [ + { + "$id": "12", + "Name": "host", + "NameInRequest": "host", + "Description": "TestServer endpoint", + "Type": { + "$id": "13", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Uri", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": true, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Client", + "DefaultValue": { + "$id": "14", + "Type": { + "$id": "15", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Value": "http://localhost:3000" + } + }, + { + "$id": "16", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "17", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "18", + "Type": { + "$ref": "17" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "19", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "20", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "21", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "22", + "Kind": "Primitive", + "Name": "Int32", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/dictionary/int32", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "23", + "Name": "put", + "ResourceName": "Int32Value", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "24", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "25", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "26", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "27", + "Kind": "Primitive", + "Name": "Int32", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "28", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "29", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "30", + "Type": { + "$ref": "29" + }, + "Value": "application/json" + } + }, + { + "$id": "31", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "32", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "33", + "Type": { + "$ref": "32" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "34", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/dictionary/int32", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "35" + }, + "Creatable": false, + "Parent": "DictionaryClient" + }, + { + "$id": "36", + "Name": "Int64Value", + "Description": "Dictionary of int64 values", + "Operations": [ + { + "$id": "37", + "Name": "get", + "ResourceName": "Int64Value", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "38", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "39", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "40", + "Type": { + "$ref": "39" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "41", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "42", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "43", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "44", + "Kind": "Primitive", + "Name": "Int64", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/dictionary/int64", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "45", + "Name": "put", + "ResourceName": "Int64Value", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "46", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "47", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "48", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "49", + "Kind": "Primitive", + "Name": "Int64", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "50", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "51", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "52", + "Type": { + "$ref": "51" + }, + "Value": "application/json" + } + }, + { + "$id": "53", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "54", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "55", + "Type": { + "$ref": "54" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "56", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/dictionary/int64", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "57" + }, + "Creatable": false, + "Parent": "DictionaryClient" + }, + { + "$id": "58", + "Name": "BooleanValue", + "Description": "Dictionary of boolean values", + "Operations": [ + { + "$id": "59", + "Name": "get", + "ResourceName": "BooleanValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "60", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "61", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "62", + "Type": { + "$ref": "61" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "63", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "64", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "65", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "66", + "Kind": "Primitive", + "Name": "Boolean", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/dictionary/boolean", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "67", + "Name": "put", + "ResourceName": "BooleanValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "68", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "69", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "70", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "71", + "Kind": "Primitive", + "Name": "Boolean", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "72", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "73", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "74", + "Type": { + "$ref": "73" + }, + "Value": "application/json" + } + }, + { + "$id": "75", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "76", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "77", + "Type": { + "$ref": "76" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "78", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/dictionary/boolean", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "79" + }, + "Creatable": false, + "Parent": "DictionaryClient" + }, + { + "$id": "80", + "Name": "StringValue", + "Description": "Dictionary of string values", + "Operations": [ + { + "$id": "81", + "Name": "get", + "ResourceName": "StringValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "82", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "83", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "84", + "Type": { + "$ref": "83" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "85", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "86", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "87", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "88", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/dictionary/string", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "89", + "Name": "put", + "ResourceName": "StringValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "90", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "91", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "92", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "93", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "94", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "95", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "96", + "Type": { + "$ref": "95" + }, + "Value": "application/json" + } + }, + { + "$id": "97", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "98", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "99", + "Type": { + "$ref": "98" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "100", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/dictionary/string", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "101" + }, + "Creatable": false, + "Parent": "DictionaryClient" + }, + { + "$id": "102", + "Name": "Float32Value", + "Description": "Dictionary of float values", + "Operations": [ + { + "$id": "103", + "Name": "get", + "ResourceName": "Float32Value", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "104", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "105", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "106", + "Type": { + "$ref": "105" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "107", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "108", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "109", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "110", + "Kind": "Primitive", + "Name": "Float32", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/dictionary/float32", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "111", + "Name": "put", + "ResourceName": "Float32Value", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "112", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "113", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "114", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "115", + "Kind": "Primitive", + "Name": "Float32", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "116", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "117", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "118", + "Type": { + "$ref": "117" + }, + "Value": "application/json" + } + }, + { + "$id": "119", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "120", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "121", + "Type": { + "$ref": "120" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "122", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/dictionary/float32", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "123" + }, + "Creatable": false, + "Parent": "DictionaryClient" + }, + { + "$id": "124", + "Name": "DatetimeValue", + "Description": "Dictionary of datetime values", + "Operations": [ + { + "$id": "125", + "Name": "get", + "ResourceName": "DatetimeValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "126", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "127", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "128", + "Type": { + "$ref": "127" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "129", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "130", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "131", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "132", + "Kind": "Primitive", + "Name": "DateTime", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/dictionary/datetime", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "133", + "Name": "put", + "ResourceName": "DatetimeValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "134", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "135", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "136", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "137", + "Kind": "Primitive", + "Name": "DateTime", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "138", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "139", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "140", + "Type": { + "$ref": "139" + }, + "Value": "application/json" + } + }, + { + "$id": "141", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "142", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "143", + "Type": { + "$ref": "142" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "144", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/dictionary/datetime", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "145" + }, + "Creatable": false, + "Parent": "DictionaryClient" + }, + { + "$id": "146", + "Name": "DurationValue", + "Description": "Dictionary of duration values", + "Operations": [ + { + "$id": "147", + "Name": "get", + "ResourceName": "DurationValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "148", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "149", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "150", + "Type": { + "$ref": "149" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "151", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "152", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "153", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "154", + "Kind": "Primitive", + "Name": "DurationISO8601", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/dictionary/duration", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "155", + "Name": "put", + "ResourceName": "DurationValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "156", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "157", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "158", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "159", + "Kind": "Primitive", + "Name": "DurationISO8601", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "160", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "161", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "162", + "Type": { + "$ref": "161" + }, + "Value": "application/json" + } + }, + { + "$id": "163", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "164", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "165", + "Type": { + "$ref": "164" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "166", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/dictionary/duration", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "167" + }, + "Creatable": false, + "Parent": "DictionaryClient" + }, + { + "$id": "168", + "Name": "UnknownValue", + "Description": "Dictionary of unknown values", + "Operations": [ + { + "$id": "169", + "Name": "get", + "ResourceName": "UnknownValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "170", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "171", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "172", + "Type": { + "$ref": "171" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "173", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "174", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "175", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "176", + "Kind": "Intrinsic", + "Name": "unknown", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/dictionary/unknown", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "177", + "Name": "put", + "ResourceName": "UnknownValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "178", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "179", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "180", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "181", + "Kind": "Intrinsic", + "Name": "unknown", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "182", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "183", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "184", + "Type": { + "$ref": "183" + }, + "Value": "application/json" + } + }, + { + "$id": "185", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "186", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "187", + "Type": { + "$ref": "186" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "188", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/dictionary/unknown", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "189" + }, + "Creatable": false, + "Parent": "DictionaryClient" + }, + { + "$id": "190", + "Name": "ModelValue", + "Description": "Dictionary of model values", + "Operations": [ + { + "$id": "191", + "Name": "get", + "ResourceName": "ModelValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "192", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "193", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "194", + "Type": { + "$ref": "193" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "195", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "196", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "197", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$ref": "2" + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/dictionary/model", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "198", + "Name": "put", + "ResourceName": "ModelValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "199", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "200", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "201", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$ref": "2" + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "202", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "203", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "204", + "Type": { + "$ref": "203" + }, + "Value": "application/json" + } + }, + { + "$id": "205", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "206", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "207", + "Type": { + "$ref": "206" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "208", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/dictionary/model", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "209" + }, + "Creatable": false, + "Parent": "DictionaryClient" + }, + { + "$id": "210", + "Name": "RecursiveModelValue", + "Description": "Dictionary of model values", + "Operations": [ + { + "$id": "211", + "Name": "get", + "ResourceName": "RecursiveModelValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "212", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "213", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "214", + "Type": { + "$ref": "213" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "215", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "216", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "217", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$ref": "2" + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/dictionary/model/recursive", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "218", + "Name": "put", + "ResourceName": "RecursiveModelValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "219", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "220", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "221", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$ref": "2" + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "222", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "223", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "224", + "Type": { + "$ref": "223" + }, + "Value": "application/json" + } + }, + { + "$id": "225", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "226", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "227", + "Type": { + "$ref": "226" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "228", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/dictionary/model/recursive", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "229" + }, + "Creatable": false, + "Parent": "DictionaryClient" + }, + { + "$id": "230", + "Name": "NullableFloatValue", + "Description": "Dictionary of nullable float values", + "Operations": [ + { + "$id": "231", + "Name": "get", + "ResourceName": "NullableFloatValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "232", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "233", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "234", + "Type": { + "$ref": "233" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "235", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "236", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "237", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "238", + "Kind": "Primitive", + "Name": "Float32", + "IsNullable": true + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "GET", + "RequestBodyMediaType": "None", + "Uri": "{host}", + "Path": "/type/dictionary/nullable-float", + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + }, + { + "$id": "239", + "Name": "put", + "ResourceName": "NullableFloatValue", + "Parameters": [ + { + "$ref": "12" + }, + { + "$id": "240", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "241", + "Kind": "Dictionary", + "Name": "Dictionary", + "KeyType": { + "$id": "242", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "ValueType": { + "$id": "243", + "Kind": "Primitive", + "Name": "Float32", + "IsNullable": true + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "244", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "245", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "246", + "Type": { + "$ref": "245" + }, + "Value": "application/json" + } + }, + { + "$id": "247", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "248", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "249", + "Type": { + "$ref": "248" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "250", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{host}", + "Path": "/type/dictionary/nullable-float", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true + } + ], + "Protocol": { + "$id": "251" + }, + "Creatable": false, + "Parent": "DictionaryClient" + } + ] +} diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Properties/AssemblyInfo.cs b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Properties/AssemblyInfo.cs new file mode 100644 index 00000000000..3b2c503e7bb --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Properties/AssemblyInfo.cs @@ -0,0 +1,6 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Runtime.CompilerServices; + +[assembly: InternalsVisibleTo("Scm._Type._Dictionary.Tests")] diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/src/Scm._Type._Dictionary.csproj b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Scm._Type._Dictionary.csproj new file mode 100644 index 00000000000..e36fbaf84f1 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/src/Scm._Type._Dictionary.csproj @@ -0,0 +1,16 @@ + + + This is the Scm._Type._Dictionary client library for developing .NET applications with rich experience. + SDK Code Generation Scm._Type._Dictionary + 1.0.0-beta.1 + Scm._Type._Dictionary + netstandard2.0 + latest + true + + + + + + + diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/tests/Scm._Type._Dictionary.Tests.csproj b/test/CadlRanchProjectsNonAzure/type/dictionary/tests/Scm._Type._Dictionary.Tests.csproj new file mode 100644 index 00000000000..2525966469b --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/tests/Scm._Type._Dictionary.Tests.csproj @@ -0,0 +1,18 @@ + + + net7.0 + + $(NoWarn);CS1591 + + + + + + + + + + + + + diff --git a/test/CadlRanchProjectsNonAzure/type/dictionary/tspconfig.yaml b/test/CadlRanchProjectsNonAzure/type/dictionary/tspconfig.yaml new file mode 100644 index 00000000000..cff89ea7728 --- /dev/null +++ b/test/CadlRanchProjectsNonAzure/type/dictionary/tspconfig.yaml @@ -0,0 +1,3 @@ +options: + "@azure-tools/typespec-csharp": + namespace: Scm._Type._Dictionary diff --git a/test/UnbrandedProjects.Tests/BinaryContentHelperTests.cs b/test/UnbrandedProjects.Tests/BinaryContentHelperTests.cs new file mode 100644 index 00000000000..b59ff19667f --- /dev/null +++ b/test/UnbrandedProjects.Tests/BinaryContentHelperTests.cs @@ -0,0 +1,213 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.IO; +using System.Text.Json; +using System.Xml; +using AutoRest.TestServer.Tests.Infrastructure; +using NUnit.Framework; +using UnbrandedTypeSpec; + +namespace UnbrandedProjects.Tests +{ + public class BinaryContentHelperTests + { + public static IEnumerable GetTimeSpanData() + { + yield return new TestCaseData(XmlConvert.ToTimeSpan("P123DT22H14M12.011S"), XmlConvert.ToTimeSpan("P163DT22H14M12.011S")); + } + + public static IEnumerable GetDateTimeData() + { + yield return new TestCaseData(DateTimeOffset.Parse("2022-08-26T18:38:00Z"), DateTimeOffset.Parse("2022-09-26T18:38:00Z")); + } + + public static IEnumerable GetOneDateTimeData() + { + yield return new TestCaseData(DateTimeOffset.Parse("2022-08-26T18:38:00Z")); + } + + public static object[] BinaryDataCases = + { + new object[] { BinaryData.FromString("\"test\"") }, + new object[] { new BinaryData(1)}, + new object[] { new BinaryData(1.1)}, + new object[] { new BinaryData(true)}, + new object[] { BinaryData.FromObjectAsJson(new {name="a", age=1})}, + new object[] { new BinaryData(DateTimeOffset.Parse("2022-08-26T18:38:00Z"))} + }; + + [TestCase(1, 2)] + [TestCase("a", "b")] + [TestCase(true, false)] + [TestCaseSource(nameof(GetTimeSpanData))] + [TestCaseSource(nameof(GetDateTimeData))] + public void TestGenericFromEnumerable(T expectedValue1, T expectedValue2) + { + var expectedList = new List { expectedValue1, expectedValue2 }; + var content = BinaryContentHelper.FromEnumerable(expectedList); + + var stream = new MemoryStream(); + content.WriteTo(stream, default); + stream.Position = 0; + + var document = JsonDocument.Parse(stream); + int count = 0; + foreach (var property in document.RootElement.EnumerateArray()) + { + if (typeof(T) == typeof(int)) + { + Assert.AreEqual(expectedList[count++], property.GetInt32()); + } + else if (typeof(T) == typeof(string)) + { + Assert.AreEqual(expectedList[count++], property.GetString()); + } + else if (typeof(T) == typeof(bool)) + { + Assert.AreEqual(expectedList[count++], property.GetBoolean()); + } + } + } + + [Test] + public void TestBinaryDataFromEnumerable() + { + var expectedList = new List { new BinaryData(1), new BinaryData("\"hello\""), null }; + var content = BinaryContentHelper.FromEnumerable(expectedList); + + var stream = new MemoryStream(); + content.WriteTo(stream, default); + stream.Position = 0; + + var document = JsonDocument.Parse(stream); + int count = 0; + foreach (var property in document.RootElement.EnumerateArray()) + { + if (property.ValueKind == JsonValueKind.Null) + { + Assert.IsNull(expectedList[count++]); + } + else + { + BinaryDataAssert.AreEqual(expectedList[count++], BinaryData.FromString(property.GetRawText())); + } + } + } + + [TestCase(1, 2)] + [TestCase("a", "b")] + [TestCase(true, false)] + [TestCaseSource(nameof(GetTimeSpanData))] + [TestCaseSource(nameof(GetDateTimeData))] + public void TestGenericFromDictionary(T expectedValue1, T expectedValue2) + { + var expectedDictionary = new Dictionary() + { + {"k1", expectedValue1 }, + {"k2", expectedValue2 } + }; + var content = BinaryContentHelper.FromDictionary(expectedDictionary); + + var stream = new MemoryStream(); + content.WriteTo(stream, default); + stream.Position = 0; + + var document = JsonDocument.Parse(stream); + int count = 1; + foreach (var property in document.RootElement.EnumerateObject()) + { + if (typeof(T) == typeof(int)) + { + Assert.AreEqual(expectedDictionary["k" + count++], property.Value.GetInt32()); + } + else if (typeof(T) == typeof(string)) + { + Assert.AreEqual(expectedDictionary["k" + count++], property.Value.GetString()); + } + else if (typeof(T) == typeof(bool)) + { + Assert.AreEqual(expectedDictionary["k" + count++], property.Value.GetBoolean()); + } + } + } + + [Test] + public void TestBinaryDataFromDictionary() + { + var expectedDictionary = new Dictionary() + { + {"k1", new BinaryData(1) }, + {"k2", new BinaryData("\"hello\"") }, + {"k3", null } + }; + + var content = BinaryContentHelper.FromDictionary(expectedDictionary); + + var stream = new MemoryStream(); + content.WriteTo(stream, default); + stream.Position = 0; + + var document = JsonDocument.Parse(stream); + int count = 1; + foreach (var property in document.RootElement.EnumerateObject()) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + Assert.IsNull(expectedDictionary["k" + count++]); + } + else + { + BinaryDataAssert.AreEqual(expectedDictionary["k" + count++], BinaryData.FromString(property.Value.GetRawText())); + } + } + } + + [TestCase("a")] + [TestCase(true)] + [TestCase(1)] + [TestCase(1.0)] + [TestCaseSource(nameof(GetOneDateTimeData))] + public void TestFromObject(T value) + { + var content = BinaryContentHelper.FromObject(value); + var stream = new MemoryStream(); + content.WriteTo(stream, default); + stream.Position = 0; + var document = JsonDocument.Parse(stream); + switch (value) + { + case string: + Assert.AreEqual(JsonValueKind.String, document.RootElement.ValueKind); + Assert.AreEqual($"\"{value}\"", document.RootElement.GetRawText()); + break; + case bool: + Assert.AreEqual(value, document.RootElement.GetBoolean()); + break; + case int: + Assert.AreEqual(value, document.RootElement.GetInt32()); + break; + case double: + Assert.AreEqual(value, document.RootElement.GetDouble()); + break; + case DateTimeOffset: + Assert.AreEqual(JsonValueKind.String, document.RootElement.ValueKind); + Assert.AreEqual(value, DateTimeOffset.Parse(document.RootElement.GetString())); + break; + } + } + + [TestCaseSource(nameof(BinaryDataCases))] + public void TestFromObjectForBinaryData(BinaryData value) + { + var content = BinaryContentHelper.FromObject(value); + var stream = new MemoryStream(); + content.WriteTo(stream, default); + stream.Position = 0; + var document = JsonDocument.Parse(stream); + BinaryDataAssert.AreEqual(value, BinaryData.FromString(document.RootElement.GetRawText())); + } + } +} diff --git a/test/UnbrandedProjects/Customized-TypeSpec/src/CustomizedTypeSpec.csproj b/test/UnbrandedProjects/Customized-TypeSpec/src/CustomizedTypeSpec.csproj index b90350c0337..7e7d2cb1f1b 100644 --- a/test/UnbrandedProjects/Customized-TypeSpec/src/CustomizedTypeSpec.csproj +++ b/test/UnbrandedProjects/Customized-TypeSpec/src/CustomizedTypeSpec.csproj @@ -10,7 +10,7 @@ - + diff --git a/test/UnbrandedProjects/NoTest-TypeSpec/src/NoTestTypeSpec.csproj b/test/UnbrandedProjects/NoTest-TypeSpec/src/NoTestTypeSpec.csproj index ff07340c596..bdee88d04af 100644 --- a/test/UnbrandedProjects/NoTest-TypeSpec/src/NoTestTypeSpec.csproj +++ b/test/UnbrandedProjects/NoTest-TypeSpec/src/NoTestTypeSpec.csproj @@ -10,7 +10,7 @@ - + diff --git a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/OpenAI.csproj b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/OpenAI.csproj index 95e032e4eac..efa70082fe8 100644 --- a/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/OpenAI.csproj +++ b/test/UnbrandedProjects/Platform-OpenAI-TypeSpec/src/OpenAI.csproj @@ -10,7 +10,7 @@ - + diff --git a/test/UnbrandedProjects/Unbranded-TypeSpec/Unbranded-TypeSpec.tsp b/test/UnbrandedProjects/Unbranded-TypeSpec/Unbranded-TypeSpec.tsp index 9202ca1d995..8a736e4af6c 100644 --- a/test/UnbrandedProjects/Unbranded-TypeSpec/Unbranded-TypeSpec.tsp +++ b/test/UnbrandedProjects/Unbranded-TypeSpec/Unbranded-TypeSpec.tsp @@ -352,3 +352,9 @@ op stillConvenient(): void; @head @convenientAPI(true) op headAsBoolean(@path id: string): void; + +@route("/headAsBoolean") +@doc("head as boolean.") +@put +@convenientAPI(true) +op handleArray(@body body: string[]): string[]; diff --git a/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/Internal/BinaryContentHelper.cs b/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/Internal/BinaryContentHelper.cs new file mode 100644 index 00000000000..e698542535d --- /dev/null +++ b/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/Internal/BinaryContentHelper.cs @@ -0,0 +1,119 @@ +// + +#nullable disable + +using System; +using System.ClientModel; +using System.Collections.Generic; +using System.Text.Json; + +namespace UnbrandedTypeSpec +{ + internal static class BinaryContentHelper + { + public static BinaryContent FromEnumerable(IEnumerable enumerable) + where T : notnull + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteStartArray(); + foreach (var item in enumerable) + { + content.JsonWriter.WriteObjectValue(item, ModelSerializationExtensions.WireOptions); + } + content.JsonWriter.WriteEndArray(); + + return content; + } + + public static BinaryContent FromEnumerable(IEnumerable enumerable) + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteStartArray(); + foreach (var item in enumerable) + { + if (item == null) + { + content.JsonWriter.WriteNullValue(); + } + else + { +#if NET6_0_OR_GREATER + content.JsonWriter.WriteRawValue(item); +#else + using (JsonDocument document = JsonDocument.Parse(item)) + { + JsonSerializer.Serialize(content.JsonWriter, document.RootElement); + } +#endif + } + } + content.JsonWriter.WriteEndArray(); + + return content; + } + + public static BinaryContent FromDictionary(IDictionary dictionary) + where TValue : notnull + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteStartObject(); + foreach (var item in dictionary) + { + content.JsonWriter.WritePropertyName(item.Key); + content.JsonWriter.WriteObjectValue(item.Value, ModelSerializationExtensions.WireOptions); + } + content.JsonWriter.WriteEndObject(); + + return content; + } + + public static BinaryContent FromDictionary(IDictionary dictionary) + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteStartObject(); + foreach (var item in dictionary) + { + content.JsonWriter.WritePropertyName(item.Key); + if (item.Value == null) + { + content.JsonWriter.WriteNullValue(); + } + else + { +#if NET6_0_OR_GREATER + content.JsonWriter.WriteRawValue(item.Value); +#else + using (JsonDocument document = JsonDocument.Parse(item.Value)) + { + JsonSerializer.Serialize(content.JsonWriter, document.RootElement); + } +#endif + } + } + content.JsonWriter.WriteEndObject(); + + return content; + } + + public static BinaryContent FromObject(object value) + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); + content.JsonWriter.WriteObjectValue(value, ModelSerializationExtensions.WireOptions); + return content; + } + + public static BinaryContent FromObject(BinaryData value) + { + Utf8JsonBinaryContent content = new Utf8JsonBinaryContent(); +#if NET6_0_OR_GREATER + content.JsonWriter.WriteRawValue(value); +#else + using (JsonDocument document = JsonDocument.Parse(value)) + { + JsonSerializer.Serialize(content.JsonWriter, document.RootElement); + } +#endif + return content; + } + } +} diff --git a/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/Internal/Utf8JsonBinaryContent.cs b/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/Internal/Utf8JsonBinaryContent.cs new file mode 100644 index 00000000000..ea26d5655b9 --- /dev/null +++ b/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/Internal/Utf8JsonBinaryContent.cs @@ -0,0 +1,52 @@ +// + +#nullable disable + +using System.ClientModel; +using System.IO; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; + +namespace UnbrandedTypeSpec +{ + internal class Utf8JsonBinaryContent : BinaryContent + { + private readonly MemoryStream _stream; + private readonly BinaryContent _content; + + public Utf8JsonBinaryContent() + { + _stream = new MemoryStream(); + _content = Create(_stream); + JsonWriter = new Utf8JsonWriter(_stream); + } + + public Utf8JsonWriter JsonWriter { get; } + + public override async Task WriteToAsync(Stream stream, CancellationToken cancellationToken = default) + { + await JsonWriter.FlushAsync().ConfigureAwait(false); + await _content.WriteToAsync(stream, cancellationToken).ConfigureAwait(false); + } + + public override void WriteTo(Stream stream, CancellationToken cancellationToken = default) + { + JsonWriter.Flush(); + _content.WriteTo(stream, cancellationToken); + } + + public override bool TryComputeLength(out long length) + { + length = JsonWriter.BytesCommitted + JsonWriter.BytesPending; + return true; + } + + public override void Dispose() + { + JsonWriter.Dispose(); + _content.Dispose(); + _stream.Dispose(); + } + } +} diff --git a/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecClient.cs b/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecClient.cs index 824ac94c97a..4d33ce6bc42 100644 --- a/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecClient.cs +++ b/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecClient.cs @@ -5,6 +5,8 @@ using System; using System.ClientModel; using System.ClientModel.Primitives; +using System.Collections.Generic; +using System.Text.Json; using System.Threading.Tasks; using UnbrandedTypeSpec.Models; @@ -1257,6 +1259,102 @@ public virtual ClientResult HeadAsBoolean(string id, RequestOptions option return ClientResult.FromValue(result.Value, result.GetRawResponse()); } + /// head as boolean. + /// The where T is of type to use. + /// is null. + public virtual async Task>> HandleArrayAsync(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = await HandleArrayAsync(content, null).ConfigureAwait(false); + IReadOnlyList value = default; + using var document = await JsonDocument.ParseAsync(result.GetRawResponse().ContentStream, default, default).ConfigureAwait(false); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetString()); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// head as boolean. + /// The where T is of type to use. + /// is null. + public virtual ClientResult> HandleArray(IEnumerable body) + { + Argument.AssertNotNull(body, nameof(body)); + + using BinaryContent content = BinaryContentHelper.FromEnumerable(body); + ClientResult result = HandleArray(content, null); + IReadOnlyList value = default; + using var document = JsonDocument.Parse(result.GetRawResponse().ContentStream); + List array = new List(); + foreach (var item in document.RootElement.EnumerateArray()) + { + array.Add(item.GetString()); + } + value = array; + return ClientResult.FromValue(value, result.GetRawResponse()); + } + + /// + /// [Protocol Method] head as boolean. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual async Task HandleArrayAsync(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateHandleArrayRequest(content, options); + return ClientResult.FromResponse(await _pipeline.ProcessMessageAsync(message, options).ConfigureAwait(false)); + } + + /// + /// [Protocol Method] head as boolean. + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request options, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + public virtual ClientResult HandleArray(BinaryContent content, RequestOptions options = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using PipelineMessage message = CreateHandleArrayRequest(content, options); + return ClientResult.FromResponse(_pipeline.ProcessMessage(message, options)); + } + internal PipelineMessage CreateSayHiRequest(string headParameter, string queryParameter, string optionalQuery, RequestOptions options) { var message = _pipeline.CreateMessage(); @@ -1636,6 +1734,26 @@ internal PipelineMessage CreateHeadAsBooleanRequest(string id, RequestOptions op return message; } + internal PipelineMessage CreateHandleArrayRequest(BinaryContent content, RequestOptions options) + { + var message = _pipeline.CreateMessage(); + message.ResponseClassifier = PipelineMessageClassifier200; + var request = message.Request; + request.Method = "PUT"; + var uri = new ClientUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/headAsBoolean", false); + request.Uri = uri.ToUri(); + request.Headers.Set("Accept", "application/json"); + request.Headers.Set("Content-Type", "application/json"); + request.Content = content; + if (options != null) + { + message.Apply(options); + } + return message; + } + private static PipelineMessageClassifier _pipelineMessageClassifier200; private static PipelineMessageClassifier PipelineMessageClassifier200 => _pipelineMessageClassifier200 ??= PipelineMessageClassifier.Create(stackalloc ushort[] { 200 }); private static PipelineMessageClassifier _pipelineMessageClassifier204; diff --git a/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/tspCodeModel.json b/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/tspCodeModel.json index 97127595a7e..e505ebb9e96 100644 --- a/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/tspCodeModel.json +++ b/test/UnbrandedProjects/Unbranded-TypeSpec/src/Generated/tspCodeModel.json @@ -3076,18 +3076,145 @@ "BufferResponse": true, "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true + }, + { + "$id": "316", + "Name": "handleArray", + "ResourceName": "UnbrandedTypeSpec", + "Description": "head as boolean.", + "Parameters": [ + { + "$ref": "145" + }, + { + "$id": "317", + "Name": "body", + "NameInRequest": "body", + "Type": { + "$id": "318", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "319", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "IsNullable": false + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Method" + }, + { + "$id": "320", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "321", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "322", + "Type": { + "$ref": "321" + }, + "Value": "application/json" + } + }, + { + "$id": "323", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "324", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "325", + "Type": { + "$ref": "324" + }, + "Value": "application/json" + } + } + ], + "Responses": [ + { + "$id": "326", + "StatusCodes": [ + 200 + ], + "BodyType": { + "$id": "327", + "Kind": "Array", + "Name": "Array", + "ElementType": { + "$id": "328", + "Kind": "Primitive", + "Name": "String", + "IsNullable": false + }, + "IsNullable": false + }, + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false, + "ContentTypes": [ + "application/json" + ] + } + ], + "HttpMethod": "PUT", + "RequestBodyMediaType": "Json", + "Uri": "{unbrandedTypeSpecUrl}", + "Path": "/headAsBoolean", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { - "$id": "316" + "$id": "329" }, "Creatable": true } ], "Auth": { - "$id": "317", + "$id": "330", "ApiKey": { - "$id": "318", + "$id": "331", "Name": "my-api-key" } } diff --git a/test/UnbrandedProjects/Unbranded-TypeSpec/src/UnbrandedTypeSpec.csproj b/test/UnbrandedProjects/Unbranded-TypeSpec/src/UnbrandedTypeSpec.csproj index 7a6faf4006f..691b74aad05 100644 --- a/test/UnbrandedProjects/Unbranded-TypeSpec/src/UnbrandedTypeSpec.csproj +++ b/test/UnbrandedProjects/Unbranded-TypeSpec/src/UnbrandedTypeSpec.csproj @@ -10,7 +10,7 @@ - +