From 3cd5465b41f8ad8e7f4d3abb7e90d2f1597b017e Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Mon, 23 Dec 2019 09:31:39 -0800 Subject: [PATCH] Add serialization model and unify all generator code in one place (#371) --- .../ClientModels/ClientBuilder.cs | 7 +- .../ClientModels/ClientModelBuilderHelpers.cs | 28 ++ .../ClientModels/ClientObject.cs | 5 +- .../ClientModels/ClientObjectDiscriminator.cs | 1 - .../ClientModels/ClientObjectProperty.cs | 9 +- .../ClientModels/ModelBuilder.cs | 75 +++- .../ClientModels/RequestBody.cs | 8 +- .../ClientModels/ResponseBody.cs | 12 +- .../Serialization/JsonArraySerialization.cs | 17 + .../JsonDynamicPropertiesSerialization.cs | 15 + .../Serialization/JsonObjectSerialization.cs | 19 + .../JsonPropertySerialization.cs | 21 ++ .../Serialization/JsonSerialization.cs | 11 + .../Serialization/JsonValueSerialization.cs | 18 + .../CodeGen/ClientWriter.cs | 15 +- .../CodeGen/JsonSerializerExtensions.cs | 337 +++++++++++------- .../CodeGen/SerializationWriter.cs | 119 +------ .../JsonElementExtensions.cs | 6 +- .../Utf8JsonWriterExtensions.cs | 4 +- test/AutoRest.TestServer.Tests/BodyArray.cs | 38 +- .../Models/CatAPTrue.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Models/PetAPInProperties.Serialization.cs | 6 +- ...PInPropertiesWithAPString.Serialization.cs | 6 +- .../Models/PetAPObject.Serialization.cs | 2 +- .../Models/PetAPString.Serialization.cs | 2 +- .../Models/PetAPTrue.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Product.Serialization.cs | 2 +- .../Generated/Operations/ArrayOperations.cs | 44 +-- .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Models/ArrayWrapper.Serialization.cs | 2 +- .../Generated/Models/Basic.Serialization.cs | 2 +- .../Models/BooleanWrapper.Serialization.cs | 2 +- .../Models/ByteWrapper.Serialization.cs | 2 +- .../Generated/Models/Cat.Serialization.cs | 2 +- .../Models/Cookiecuttershark.Serialization.cs | 2 +- .../Models/DateWrapper.Serialization.cs | 2 +- .../Models/DatetimeWrapper.Serialization.cs | 2 +- .../Datetimerfc1123Wrapper.Serialization.cs | 2 +- .../Models/DictionaryWrapper.Serialization.cs | 6 +- .../Generated/Models/Dog.Serialization.cs | 2 +- .../Generated/Models/DotFish.Serialization.cs | 2 +- .../Models/DotFishMarket.Serialization.cs | 2 +- .../Models/DotSalmon.Serialization.cs | 2 +- .../Models/DoubleWrapper.Serialization.cs | 2 +- .../Models/DurationWrapper.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Fish.Serialization.cs | 2 +- .../Models/FloatWrapper.Serialization.cs | 2 +- .../Models/Goblinshark.Serialization.cs | 2 +- .../Models/IntWrapper.Serialization.cs | 2 +- .../Models/LongWrapper.Serialization.cs | 2 +- .../Models/MyBaseHelperType.Serialization.cs | 2 +- .../Models/MyBaseType.Serialization.cs | 2 +- .../Models/MyDerivedType.Serialization.cs | 2 +- .../Generated/Models/Pet.Serialization.cs | 2 +- .../Models/ReadonlyObj.Serialization.cs | 2 +- .../Generated/Models/Salmon.Serialization.cs | 2 +- .../Models/Sawshark.Serialization.cs | 2 +- .../Generated/Models/Shark.Serialization.cs | 2 +- .../Generated/Models/Siamese.Serialization.cs | 2 +- .../Models/SmartSalmon.Serialization.cs | 2 +- .../Models/StringWrapper.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Widget.Serialization.cs | 2 +- .../Operations/DictionaryOperations.cs | 228 ++++++------ .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Models/RefColorConstant.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Pet.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Models/ChildProduct.Serialization.cs | 2 +- .../Models/ConstantProduct.Serialization.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 2 +- .../Generated/Models/Product.Serialization.cs | 13 +- 86 files changed, 677 insertions(+), 511 deletions(-) create mode 100644 src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonArraySerialization.cs create mode 100644 src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonDynamicPropertiesSerialization.cs create mode 100644 src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonObjectSerialization.cs create mode 100644 src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonPropertySerialization.cs create mode 100644 src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonSerialization.cs create mode 100644 src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonValueSerialization.cs diff --git a/src/AutoRest.CSharp.V3/ClientModels/ClientBuilder.cs b/src/AutoRest.CSharp.V3/ClientModels/ClientBuilder.cs index 791857c6..b084e04a 100644 --- a/src/AutoRest.CSharp.V3/ClientModels/ClientBuilder.cs +++ b/src/AutoRest.CSharp.V3/ClientModels/ClientBuilder.cs @@ -6,6 +6,7 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; using System.Text; +using AutoRest.CSharp.V3.ClientModels.Serialization; using AutoRest.CSharp.V3.Pipeline; using AutoRest.CSharp.V3.Pipeline.Generated; using AutoRest.CSharp.V3.Plugins; @@ -55,7 +56,7 @@ namespace AutoRest.CSharp.V3.ClientModels switch (requestParameter.Schema) { case ConstantSchema constant: - constantOrParameter = ClientModelBuilderHelpers.ParseClientConstant(constant.Value.Value, ClientModelBuilderHelpers.CreateType(constant.ValueType, constant.Value.Value == null)); + constantOrParameter = ClientModelBuilderHelpers.ParseClientConstant(constant); valueSchema = constant.ValueType; break; case BinarySchema _: @@ -97,7 +98,7 @@ namespace AutoRest.CSharp.V3.ClientModels pathParameters.Add(serializedName, new PathSegment(constantOrParameter.Value, true, serializationFormat)); break; case ParameterLocation.Body when constantOrParameter is ConstantOrParameter constantOrParameterValue: - body = new RequestBody(constantOrParameterValue, serializationFormat); + body = new RequestBody(constantOrParameterValue, ClientModelBuilderHelpers.CreateSerialization(requestParameter.Schema, requestParameter.IsNullable())); break; case ParameterLocation.Uri: uriParameters[defaultName] = constantOrParameter.Value; @@ -130,7 +131,7 @@ namespace AutoRest.CSharp.V3.ClientModels { var schema = schemaResponse.Schema is ConstantSchema constantSchema ? constantSchema.ValueType : schemaResponse.Schema; var responseType = ClientModelBuilderHelpers.CreateType(schema, isNullable: false); - responseBody = new ResponseBody(responseType, ClientModelBuilderHelpers.GetSerializationFormat(schema)); + responseBody = new ResponseBody(responseType, ClientModelBuilderHelpers.CreateSerialization(schema, false)); } ClientMethodResponse clientResponse = new ClientMethodResponse( diff --git a/src/AutoRest.CSharp.V3/ClientModels/ClientModelBuilderHelpers.cs b/src/AutoRest.CSharp.V3/ClientModels/ClientModelBuilderHelpers.cs index 577de56e..edcb9013 100644 --- a/src/AutoRest.CSharp.V3/ClientModels/ClientModelBuilderHelpers.cs +++ b/src/AutoRest.CSharp.V3/ClientModels/ClientModelBuilderHelpers.cs @@ -3,6 +3,7 @@ using System; using System.Globalization; +using AutoRest.CSharp.V3.ClientModels.Serialization; using AutoRest.CSharp.V3.Pipeline.Generated; namespace AutoRest.CSharp.V3.ClientModels @@ -13,6 +14,7 @@ namespace AutoRest.CSharp.V3.ClientModels public static ClientTypeReference CreateType(Schema schema, bool isNullable) => schema switch { + ConstantSchema constantSchema => CreateType(constantSchema.ValueType, isNullable), BinarySchema _ => (ClientTypeReference)new BinaryTypeReference(isNullable), ByteArraySchema _ => new BinaryTypeReference(isNullable), //https://devblogs.microsoft.com/dotnet/do-more-with-patterns-in-c-8-0/ @@ -83,5 +85,31 @@ namespace AutoRest.CSharp.V3.ClientModels } }; + public static ClientConstant ParseClientConstant(ConstantSchema constant) + { + return ParseClientConstant(constant.Value.Value, CreateType(constant.ValueType, constant.Value.Value == null)); + } + + public static JsonSerialization CreateSerialization(Schema schema, bool isNullable) + { + switch (schema) + { + case ConstantSchema constantSchema: + return CreateSerialization(constantSchema.ValueType, constantSchema.Value.Value == null); + case ArraySchema arraySchema: + return new JsonArraySerialization(CreateType(arraySchema, false), CreateSerialization(arraySchema.ElementType, false)); + case DictionarySchema dictionarySchema: + + var dictionaryElementTypeReference = new DictionaryTypeReference( + new FrameworkTypeReference(typeof(string)), + CreateType(dictionarySchema.ElementType, false), + false); + + return new JsonObjectSerialization(dictionaryElementTypeReference, Array.Empty(), + new JsonDynamicPropertiesSerialization(CreateSerialization(dictionarySchema.ElementType, false))); + default: + return new JsonValueSerialization(CreateType(schema, isNullable), GetSerializationFormat(schema)); + } + } } } diff --git a/src/AutoRest.CSharp.V3/ClientModels/ClientObject.cs b/src/AutoRest.CSharp.V3/ClientModels/ClientObject.cs index 18d21f03..f2362f85 100644 --- a/src/AutoRest.CSharp.V3/ClientModels/ClientObject.cs +++ b/src/AutoRest.CSharp.V3/ClientModels/ClientObject.cs @@ -2,25 +2,28 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System.Collections.Generic; +using AutoRest.CSharp.V3.ClientModels.Serialization; using AutoRest.CSharp.V3.Pipeline.Generated; namespace AutoRest.CSharp.V3.ClientModels { internal class ClientObject : ClientModel, ISchemaTypeProvider { - public ClientObject(Schema schema, string name, SchemaTypeReference? inherits, IEnumerable properties, ClientObjectDiscriminator? discriminator, DictionaryTypeReference? implementsDictionary) + public ClientObject(Schema schema, string name, SchemaTypeReference? inherits, IEnumerable properties, ClientObjectDiscriminator? discriminator, DictionaryTypeReference? implementsDictionary, JsonObjectSerialization serialization) { Schema = schema; Name = name; Inherits = inherits; Discriminator = discriminator; ImplementsDictionary = implementsDictionary; + Serialization = serialization; Properties = new List(properties); } public override string Name { get; } public Schema Schema { get; } public SchemaTypeReference? Inherits { get; } + public JsonObjectSerialization Serialization { get; } public IList Properties { get; } public ClientObjectDiscriminator? Discriminator { get; } public DictionaryTypeReference? ImplementsDictionary { get; } diff --git a/src/AutoRest.CSharp.V3/ClientModels/ClientObjectDiscriminator.cs b/src/AutoRest.CSharp.V3/ClientModels/ClientObjectDiscriminator.cs index ddbb86c0..a71f3c93 100644 --- a/src/AutoRest.CSharp.V3/ClientModels/ClientObjectDiscriminator.cs +++ b/src/AutoRest.CSharp.V3/ClientModels/ClientObjectDiscriminator.cs @@ -24,6 +24,5 @@ namespace AutoRest.CSharp.V3.ClientModels } public bool HasDescendants => Implementations.Any(); - public bool HasDirectDescendants => Implementations.Any(i => i.IsDirect); } } diff --git a/src/AutoRest.CSharp.V3/ClientModels/ClientObjectProperty.cs b/src/AutoRest.CSharp.V3/ClientModels/ClientObjectProperty.cs index 1808b0c0..c0f169c1 100644 --- a/src/AutoRest.CSharp.V3/ClientModels/ClientObjectProperty.cs +++ b/src/AutoRest.CSharp.V3/ClientModels/ClientObjectProperty.cs @@ -5,14 +5,11 @@ namespace AutoRest.CSharp.V3.ClientModels { internal class ClientObjectProperty { - public ClientObjectProperty(string name, ClientTypeReference type, bool isReadOnly, string serializedName, - SerializationFormat format = SerializationFormat.Default, ClientConstant? defaultValue = null) + public ClientObjectProperty(string name, ClientTypeReference type, bool isReadOnly, ClientConstant? defaultValue = null) { Name = name; Type = type; IsReadOnly = isReadOnly; - SerializedName = serializedName; - Format = format; DefaultValue = defaultValue; } @@ -20,7 +17,5 @@ namespace AutoRest.CSharp.V3.ClientModels public ClientConstant? DefaultValue { get; } public ClientTypeReference Type { get; } public bool IsReadOnly { get; } - public string SerializedName { get; set; } - public SerializationFormat Format { get; } - } + } } diff --git a/src/AutoRest.CSharp.V3/ClientModels/ModelBuilder.cs b/src/AutoRest.CSharp.V3/ClientModels/ModelBuilder.cs index c0c59431..343e482a 100644 --- a/src/AutoRest.CSharp.V3/ClientModels/ModelBuilder.cs +++ b/src/AutoRest.CSharp.V3/ClientModels/ModelBuilder.cs @@ -2,11 +2,14 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using System.Collections; using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using AutoRest.CSharp.V3.ClientModels.Serialization; using AutoRest.CSharp.V3.Pipeline.Generated; using AutoRest.CSharp.V3.Plugins; +using Microsoft.VisualBasic; namespace AutoRest.CSharp.V3.ClientModels { @@ -26,7 +29,7 @@ namespace AutoRest.CSharp.V3.ClientModels private static ClientModel BuildClientObject(ObjectSchema objectSchema) { ClientTypeReference? inheritsFromTypeReference = null; - DictionaryTypeReference? dictionaryElementTypeReference = null; + DictionarySchema? inheritedDictionarySchema = null; foreach (ComplexSchema complexSchema in objectSchema.Parents!.Immediate) { @@ -36,21 +39,26 @@ namespace AutoRest.CSharp.V3.ClientModels inheritsFromTypeReference = ClientModelBuilderHelpers.CreateType(parentObjectSchema, false); break; case DictionarySchema dictionarySchema: - var dictionaryElementType = dictionarySchema.ElementType; - dictionaryElementTypeReference = new DictionaryTypeReference( - new FrameworkTypeReference(typeof(string)), - ClientModelBuilderHelpers.CreateType(dictionaryElementType, false), - false); - + inheritedDictionarySchema = dictionarySchema; break; } } List properties = new List(); + List serializationProperties = new List(); foreach (Property property in objectSchema.Properties!) { - properties.Add(CreateProperty(property)); + ClientObjectProperty clientObjectProperty = CreateProperty(property); + properties.Add(clientObjectProperty); + } + + foreach (var schema in EnumerateHierarchy(objectSchema)) + { + foreach (Property property in schema.Properties!) + { + serializationProperties.Add(CreateSerialization(property)); + } } Discriminator? schemaDiscriminator = objectSchema.Discriminator; @@ -79,13 +87,60 @@ namespace AutoRest.CSharp.V3.ClientModels ); } + var schemaTypeReference = ClientModelBuilderHelpers.CreateType(objectSchema, false); + return new ClientObject( objectSchema, objectSchema.CSharpName(), (SchemaTypeReference?) inheritsFromTypeReference, properties.ToArray(), discriminator, - dictionaryElementTypeReference + inheritedDictionarySchema == null ? null : CreateDictionaryType(inheritedDictionarySchema), + new JsonObjectSerialization(schemaTypeReference, serializationProperties.ToArray(), CreateAdditionalProperties(objectSchema)) + ); + } + + private static JsonDynamicPropertiesSerialization? CreateAdditionalProperties(ObjectSchema objectSchema) + { + var inheritedDictionarySchema = objectSchema.Parents!.All.OfType().FirstOrDefault(); + + if (inheritedDictionarySchema == null) + { + return null; + } + + return new JsonDynamicPropertiesSerialization( + ClientModelBuilderHelpers.CreateSerialization(inheritedDictionarySchema.ElementType, false) + ); + } + + private static DictionaryTypeReference CreateDictionaryType(DictionarySchema inheritedDictionarySchema) + { + return new DictionaryTypeReference( + new FrameworkTypeReference(typeof(string)), + ClientModelBuilderHelpers.CreateType(inheritedDictionarySchema.ElementType, false), + false); + } + + private static IEnumerable EnumerateHierarchy(ObjectSchema schema) + { + yield return schema; + foreach (ComplexSchema parent in schema.Parents!.All) + { + if (parent is ObjectSchema objectSchema) + { + yield return objectSchema; + } + } + } + + private static JsonPropertySerialization CreateSerialization(Property property) + { + return new JsonPropertySerialization( + property.SerializedName, + property.CSharpName(), + ClientModelBuilderHelpers.CreateSerialization(property.Schema, property.IsNullable()), + ClientModelBuilderHelpers.CreateType(property.Schema, property.IsNullable()) ); } @@ -130,8 +185,6 @@ namespace AutoRest.CSharp.V3.ClientModels return new ClientObjectProperty(property.CSharpName(), type, isReadOnly, - property.SerializedName, - ClientModelBuilderHelpers.GetSerializationFormat(property.Schema), defaultValue); } } diff --git a/src/AutoRest.CSharp.V3/ClientModels/RequestBody.cs b/src/AutoRest.CSharp.V3/ClientModels/RequestBody.cs index 6515587f..d06156c9 100644 --- a/src/AutoRest.CSharp.V3/ClientModels/RequestBody.cs +++ b/src/AutoRest.CSharp.V3/ClientModels/RequestBody.cs @@ -1,17 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. +using AutoRest.CSharp.V3.ClientModels.Serialization; + namespace AutoRest.CSharp.V3.ClientModels { internal class RequestBody { public ConstantOrParameter Value { get; } - public SerializationFormat Format { get; } + public JsonSerialization Serialization { get; } - public RequestBody(ConstantOrParameter value, SerializationFormat format = SerializationFormat.Default) + public RequestBody(ConstantOrParameter value, JsonSerialization serialization) { Value = value; - Format = format; + Serialization = serialization; } } } diff --git a/src/AutoRest.CSharp.V3/ClientModels/ResponseBody.cs b/src/AutoRest.CSharp.V3/ClientModels/ResponseBody.cs index aa8aae79..f0300a8b 100644 --- a/src/AutoRest.CSharp.V3/ClientModels/ResponseBody.cs +++ b/src/AutoRest.CSharp.V3/ClientModels/ResponseBody.cs @@ -1,17 +1,19 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. See License.txt in the project root for license information. +using AutoRest.CSharp.V3.ClientModels.Serialization; + namespace AutoRest.CSharp.V3.ClientModels { internal class ResponseBody { - public ClientTypeReference Value { get; } - public SerializationFormat Format { get; } - - public ResponseBody(ClientTypeReference value, SerializationFormat format = SerializationFormat.Default) + public ResponseBody(ClientTypeReference value, JsonSerialization serialization) { + Serialization = serialization; Value = value; - Format = format; } + + public JsonSerialization Serialization { get; } + public ClientTypeReference Value { get; } } } diff --git a/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonArraySerialization.cs b/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonArraySerialization.cs new file mode 100644 index 00000000..d708dc2d --- /dev/null +++ b/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonArraySerialization.cs @@ -0,0 +1,17 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +namespace AutoRest.CSharp.V3.ClientModels.Serialization +{ + internal class JsonArraySerialization: JsonSerialization + { + public JsonArraySerialization(ClientTypeReference type, JsonSerialization valueSerialization) + { + Type = type; + ValueSerialization = valueSerialization; + } + + public override ClientTypeReference Type { get; } + public JsonSerialization ValueSerialization { get; } + } +} diff --git a/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonDynamicPropertiesSerialization.cs b/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonDynamicPropertiesSerialization.cs new file mode 100644 index 00000000..44a2eda8 --- /dev/null +++ b/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonDynamicPropertiesSerialization.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +namespace AutoRest.CSharp.V3.ClientModels.Serialization +{ + internal class JsonDynamicPropertiesSerialization + { + public JsonDynamicPropertiesSerialization(JsonSerialization valueSerialization) + { + ValueSerialization = valueSerialization; + } + + public JsonSerialization ValueSerialization { get; } + } +} diff --git a/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonObjectSerialization.cs b/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonObjectSerialization.cs new file mode 100644 index 00000000..5c4b0fed --- /dev/null +++ b/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonObjectSerialization.cs @@ -0,0 +1,19 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +namespace AutoRest.CSharp.V3.ClientModels.Serialization +{ + internal class JsonObjectSerialization: JsonSerialization + { + public JsonObjectSerialization(ClientTypeReference type, JsonPropertySerialization[] properties, JsonDynamicPropertiesSerialization? additionalProperties) + { + Type = type; + Properties = properties; + AdditionalProperties = additionalProperties; + } + + public override ClientTypeReference Type { get; } + public JsonPropertySerialization[] Properties { get; } + public JsonDynamicPropertiesSerialization? AdditionalProperties { get; } + } +} diff --git a/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonPropertySerialization.cs b/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonPropertySerialization.cs new file mode 100644 index 00000000..105867ee --- /dev/null +++ b/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonPropertySerialization.cs @@ -0,0 +1,21 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +namespace AutoRest.CSharp.V3.ClientModels.Serialization +{ + internal class JsonPropertySerialization + { + public JsonPropertySerialization(string name, string memberName, JsonSerialization valueSerialization, ClientTypeReference type) + { + Name = name; + MemberName = memberName; + ValueSerialization = valueSerialization; + Type = type; + } + + public string Name { get; } + public string MemberName { get; } + public ClientTypeReference Type { get; } + public JsonSerialization ValueSerialization { get; } + } +} diff --git a/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonSerialization.cs b/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonSerialization.cs new file mode 100644 index 00000000..bafb2914 --- /dev/null +++ b/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonSerialization.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + + +namespace AutoRest.CSharp.V3.ClientModels.Serialization +{ + internal abstract class JsonSerialization + { + public abstract ClientTypeReference Type { get; } + } +} diff --git a/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonValueSerialization.cs b/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonValueSerialization.cs new file mode 100644 index 00000000..b981cbec --- /dev/null +++ b/src/AutoRest.CSharp.V3/ClientModels/Serialization/JsonValueSerialization.cs @@ -0,0 +1,18 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + + +namespace AutoRest.CSharp.V3.ClientModels.Serialization +{ + internal class JsonValueSerialization: JsonSerialization + { + public JsonValueSerialization(ClientTypeReference type, SerializationFormat format) + { + Type = type; + Format = format; + } + + public override ClientTypeReference Type { get; } + public SerializationFormat Format { get; } + } +} diff --git a/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs b/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs index 4f75f881..d3be6586 100644 --- a/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs +++ b/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs @@ -8,10 +8,12 @@ using System.Text.Json; using System.Threading; using System.Threading.Tasks; using AutoRest.CSharp.V3.ClientModels; +using AutoRest.CSharp.V3.ClientModels.Serialization; using AutoRest.CSharp.V3.Utilities; using Azure; using Azure.Core; using Azure.Core.Pipeline; +using YamlDotNet.Serialization; using SerializationFormat = AutoRest.CSharp.V3.ClientModels.SerializationFormat; namespace AutoRest.CSharp.V3.CodeGen @@ -117,8 +119,7 @@ namespace AutoRest.CSharp.V3.CodeGen ConstantOrParameter value = body.Value; writer.ToSerializeCall( - value.Type, - body.Format, + body.Serialization, _typeFactory, w => WriteConstantOrParameter(w, value), writerName: w => w.Append($"content.{nameof(Utf8JsonRequestContent.JsonWriter)}")); @@ -223,7 +224,8 @@ namespace AutoRest.CSharp.V3.CodeGen private CodeWriter.CodeWriterScope? WriteValueNullCheck(CodeWriter writer, ConstantOrParameter value) { - if (value.IsConstant) return default; + if (value.IsConstant) + return default; var type = _typeFactory.CreateType(value.Type); if (type.IsNullable) @@ -298,17 +300,16 @@ namespace AutoRest.CSharp.V3.CodeGen using (responseBody != null ? writer.Scope() : default) { - string? valueVariable = null; + string valueVariable = "value"; if (responseBody != null) { writer.Line($"using var document = await {writer.Type(typeof(JsonDocument))}.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false);"); writer.ToDeserializeCall( - responseBody.Value, - responseBody.Format, + responseBody.Serialization, _typeFactory, w => w.Append($"document.RootElement"), - out valueVariable + ref valueVariable ); } diff --git a/src/AutoRest.CSharp.V3/CodeGen/JsonSerializerExtensions.cs b/src/AutoRest.CSharp.V3/CodeGen/JsonSerializerExtensions.cs index 5c216676..f65eb709 100644 --- a/src/AutoRest.CSharp.V3/CodeGen/JsonSerializerExtensions.cs +++ b/src/AutoRest.CSharp.V3/CodeGen/JsonSerializerExtensions.cs @@ -2,137 +2,158 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using System.Text.Json; using AutoRest.CSharp.V3.ClientModels; +using AutoRest.CSharp.V3.ClientModels.Serialization; namespace AutoRest.CSharp.V3.CodeGen { internal static class JsonSerializerExtensions { - public static void ToSerializeCall(this CodeWriter writer, ClientTypeReference type, SerializationFormat format, TypeFactory typeFactory, CodeWriterDelegate name, CodeWriterDelegate? serializedName = null, CodeWriterDelegate? writerName = null) + public static void ToSerializeCall(this CodeWriter writer, JsonSerialization serialization, TypeFactory typeFactory, CodeWriterDelegate name, CodeWriterDelegate? writerName = null) { writerName ??= w => w.AppendRaw("writer"); - if (serializedName != null) - { - writer.Line($"{writerName}.WritePropertyName({serializedName});"); - } - + var type = serialization.Type; CSharpType implementationType = typeFactory.CreateType(type); - switch (type) + switch (serialization) { - case CollectionTypeReference array: + case JsonArraySerialization array: writer.Line($"{writerName}.WriteStartArray();"); string collectionItemVariable = writer.GetTemporaryVariable("item"); writer.Line($"foreach (var {collectionItemVariable:D} in {name})"); using (writer.Scope()) { writer.ToSerializeCall( - array.ItemType, - format, + array.ValueSerialization, typeFactory, w => w.AppendRaw(collectionItemVariable), - serializedName: null, writerName); } writer.Line($"{writerName}.WriteEndArray();"); return; - case DictionaryTypeReference dictionary: + case JsonObjectSerialization dictionary: writer.Line($"{writerName}.WriteStartObject();"); string itemVariable = writer.GetTemporaryVariable("item"); - writer.Line($"foreach (var {itemVariable:D} in {name})"); - using (writer.Scope()) + + foreach (JsonPropertySerialization property in dictionary.Properties) { - writer.ToSerializeCall( - dictionary.ValueType, - format, - typeFactory, - w => w.Append($"{itemVariable}.Value"), - w => w.Append($"{itemVariable}.Key"), - writerName); + using (property.Type.IsNullable ? writer.If($"{property.MemberName} != null") : default) + { + writer.Line($"{writerName}.WritePropertyName({property.Name:L});"); + writer.ToSerializeCall( + property.ValueSerialization, + typeFactory, + w => w.Append($"{property.MemberName}")); + } + } + + if (dictionary.AdditionalProperties != null) + { + writer.Line($"foreach (var {itemVariable:D} in {name})"); + using (writer.Scope()) + { + writer.Line($"{writerName}.WritePropertyName({itemVariable}.Key);"); + writer.ToSerializeCall( + dictionary.AdditionalProperties.ValueSerialization, + typeFactory, + w => w.Append($"{itemVariable}.Value"), + writerName); + } } writer.Line($"{writerName}.WriteEndObject();"); return; - case SchemaTypeReference schemaTypeReference: - switch (typeFactory.ResolveReference(schemaTypeReference)) + case JsonValueSerialization valueSerialization: + switch (valueSerialization.Type) { - case ClientObject _: - writer.Line($"{writerName}.WriteObjectValue({name});"); + case SchemaTypeReference schemaTypeReference: + switch (typeFactory.ResolveReference(schemaTypeReference)) + { + case ClientObject _: + writer.Line($"{writerName}.WriteObjectValue({name});"); + return; + + case ClientEnum clientEnum: + writer.Append($"{writerName}.WriteStringValue({name}") + .AppendNullableValue(implementationType) + .AppendRaw(clientEnum.IsStringBased ? ".ToString()" : ".ToSerialString()") + .Line($");"); + return; + } return; - case ClientEnum clientEnum: - writer.Append($"{writerName}.WriteStringValue({name}") - .AppendNullableValue(implementationType) - .AppendRaw(clientEnum.IsStringBased ? ".ToString()" : ".ToSerialString()") - .Line($");"); + case BinaryTypeReference _: + writer.Line($"{writerName}.WriteBase64StringValue({name});"); return; - } - return; - case BinaryTypeReference _: - writer.Line($"{writerName}.WriteBase64StringValue({name});"); - return; + case FrameworkTypeReference frameworkTypeReference: + var frameworkType = frameworkTypeReference.Type; + bool writeFormat = false; - case FrameworkTypeReference frameworkTypeReference: - var frameworkType = frameworkTypeReference.Type; - bool writeFormat = false; + writer.Append($"{writerName}."); + if (frameworkType == typeof(decimal) || + frameworkType == typeof(double) || + frameworkType == typeof(float) || + frameworkType == typeof(long) || + frameworkType == typeof(int) || + frameworkType == typeof(short)) + { + writer.AppendRaw("WriteNumberValue"); + } + else if (frameworkType == typeof(object)) + { + writer.AppendRaw("WriteObjectValue"); + } + else if (frameworkType == typeof(string) || + frameworkType == typeof(char)) + { + writer.AppendRaw("WriteStringValue"); + } + else if (frameworkType == typeof(bool)) + { + writer.AppendRaw("WriteBooleanValue"); + } + else if (frameworkType == typeof(DateTimeOffset) || + frameworkType == typeof(DateTime) || + frameworkType == typeof(TimeSpan)) + { + writer.AppendRaw("WriteStringValue"); + writeFormat = true; + } - writer.Append($"{writerName}."); - if (frameworkType == typeof(decimal) || - frameworkType == typeof(double) || - frameworkType == typeof(float) || - frameworkType == typeof(long) || - frameworkType == typeof(int) || - frameworkType == typeof(short)) - { - writer.AppendRaw("WriteNumberValue"); - } - else if (frameworkType == typeof(object)) - { - writer.AppendRaw("WriteObjectValue"); - } - else if (frameworkType == typeof(string) || - frameworkType == typeof(char)) - { - writer.AppendRaw("WriteStringValue"); - } - else if (frameworkType == typeof(bool)) - { - writer.AppendRaw("WriteBooleanValue"); - } - else if (frameworkType == typeof(DateTimeOffset) || - frameworkType == typeof(DateTime) || - frameworkType == typeof(TimeSpan)) - { - writer.AppendRaw("WriteStringValue"); - writeFormat = true; - } + writer.Append($"({name}") + .AppendNullableValue(implementationType); - writer.Append($"({name}") - .AppendNullableValue(implementationType); + if (writeFormat && valueSerialization.Format.ToFormatSpecifier() is string formatString) + { + writer.Append($", {formatString:L}"); + } - if (writeFormat && format.ToFormatSpecifier() is string formatString) - { - writer.Append($", {formatString:L}"); + writer.LineRaw(");"); + return; + default: + throw new NotSupportedException(); } - - writer.LineRaw(");"); - return; + default: + throw new NotSupportedException(); } } - public static void ToDeserializeCall(this CodeWriter writer, ClientTypeReference type, SerializationFormat format, TypeFactory typeFactory, CodeWriterDelegate element, out string destination) + public static void ToDeserializeCall(this CodeWriter writer, JsonSerialization serialization, TypeFactory typeFactory, CodeWriterDelegate element, ref string destination) { - destination = writer.GetTemporaryVariable("value"); + var type = serialization.Type; - if (CanDeserializeAsExpression(type)) + destination = writer.GetTemporaryVariable(destination); + + if (serialization is JsonValueSerialization valueSerialization) { writer.Append($"var {destination:D} =") - .ToDeserializeCall(type, format, typeFactory, element); + .ToDeserializeCall(valueSerialization, typeFactory, element); writer.LineRaw(";"); } else @@ -141,105 +162,131 @@ namespace AutoRest.CSharp.V3.CodeGen writer .Line($"{typeFactory.CreateType(type)} {destination:D} = new {typeFactory.CreateConcreteType(type)}();") - .ToDeserializeCall(type, format, typeFactory, w=>w.AppendRaw(s), element); + .ToDeserializeCall(serialization, typeFactory, w => w.AppendRaw(s), element); } } - private static bool CanDeserializeAsExpression(ClientTypeReference type) + public static void ToDeserializeCall(this CodeWriter writer, JsonSerialization serialization, TypeFactory typeFactory, CodeWriterDelegate destination, CodeWriterDelegate element) { - return !(type is CollectionTypeReference || type is DictionaryTypeReference); - } - - public static void ToDeserializeCall(this CodeWriter writer, ClientTypeReference type, SerializationFormat format, TypeFactory typeFactory, CodeWriterDelegate destination, CodeWriterDelegate element) - { - switch (type) + switch (serialization) { - case CollectionTypeReference array: + case JsonArraySerialization array: string collectionItemVariable = writer.GetTemporaryVariable("item"); writer.Line($"foreach (var {collectionItemVariable:D} in {element}.EnumerateArray())"); using (writer.Scope()) { - if (CanDeserializeAsExpression(array.ItemType)) + if (array.ValueSerialization is JsonValueSerialization valueSerialization) { writer.Append($"{destination}.Add("); writer.ToDeserializeCall( - array.ItemType, - format, + valueSerialization, typeFactory, w => w.AppendRaw(collectionItemVariable)); writer.Line($");"); } else { + var itemVariableName = "value"; writer.ToDeserializeCall( - array.ItemType, - format, + array.ValueSerialization, typeFactory, w => w.AppendRaw(collectionItemVariable), - out var temp); + ref itemVariableName); - writer.Append($"{destination}.Add({temp});"); + writer.Append($"{destination}.Add({itemVariableName});"); } } return; - case DictionaryTypeReference dictionary: - string itemVariable = writer.GetTemporaryVariable("item"); + case JsonObjectSerialization dictionary: + string itemVariable = writer.GetTemporaryVariable("property"); writer.Line($"foreach (var {itemVariable:D} in {element}.EnumerateObject())"); using (writer.Scope()) { - if (CanDeserializeAsExpression(dictionary.ValueType)) + foreach (JsonPropertySerialization property in dictionary.Properties) { - writer.Append($"{destination}.Add({itemVariable}.Name, "); - writer.ToDeserializeCall( - dictionary.ValueType, - format, - typeFactory, - w => w.Append($"{itemVariable}.Value")); - writer.Line($");"); + ReadProperty(writer, itemVariable, destination, property, typeFactory); } - else - { - writer.ToDeserializeCall( - dictionary.ValueType, - format, - typeFactory, - w => w.Append($"{itemVariable}.Value"), - out var temp); - writer.Append($"{destination}.Add({itemVariable}.Name, {temp});"); + if (dictionary.AdditionalProperties is JsonDynamicPropertiesSerialization additionalProperties) + { + + if (additionalProperties.ValueSerialization is JsonValueSerialization valueSerialization) + { + writer.Append($"{destination}.Add({itemVariable}.Name, "); + writer.ToDeserializeCall( + valueSerialization, + typeFactory, + w => w.Append($"{itemVariable}.Value")); + writer.Line($");"); + } + else + { + var itemVariableName = "value"; + writer.ToDeserializeCall( + additionalProperties.ValueSerialization, + typeFactory, + w => w.Append($"{itemVariable}.Value"), + ref itemVariableName); + + writer.Append($"{destination}.Add({itemVariable}.Name, {itemVariableName});"); + } } } - return; } writer.Append($"{destination} = "); - ToDeserializeCall(writer, type, format, typeFactory, element); + ToDeserializeCall(writer, (JsonValueSerialization)serialization, typeFactory, element); writer.Line($";"); } - public static void ToDeserializeCall(this CodeWriter writer, ClientTypeReference type, SerializationFormat format, TypeFactory typeFactory, CodeWriterDelegate element) + private static void ReadProperty(CodeWriter writer, string itemVariable, CodeWriterDelegate destination, JsonPropertySerialization property, TypeFactory typeFactory) { - CSharpType cSharpType = typeFactory.CreateType(type).WithNullable(false); + var type = property.Type; + var name = property.MemberName; - switch (type) + CSharpType propertyType = typeFactory.CreateType(type); + + void WriteNullCheck() + { + using (writer.If($"{itemVariable}.Value.ValueKind == {writer.Type(typeof(JsonValueKind))}.Null")) + { + writer.Append($"continue;"); + } + } + + void WriteInitialization() + { + if (propertyType.IsNullable && (type is DictionaryTypeReference || type is CollectionTypeReference)) + { + writer.Line($"{destination}.{name} = new {writer.Type(typeFactory.CreateConcreteType(property.Type))}();"); + } + } + + + writer.Append($"if({itemVariable}.NameEquals({property.Name:L}))"); + using (writer.Scope()) + { + if (propertyType.IsNullable) + { + WriteNullCheck(); + } + + WriteInitialization(); + + writer.ToDeserializeCall(property.ValueSerialization, typeFactory, w => w.Append($"{destination}.{name}"), w => w.Append($"{itemVariable}.Value")); + writer.Line($"continue;"); + } + + } + + public static void ToDeserializeCall(this CodeWriter writer, JsonValueSerialization serialization, TypeFactory typeFactory, CodeWriterDelegate element) + { + switch (serialization.Type) { case SchemaTypeReference schemaTypeReference: - switch (typeFactory.ResolveReference(schemaTypeReference)) - { - case ClientObject _: - writer.Append($"{cSharpType}.Deserialize{cSharpType.Name}({element})"); - break; - - case ClientEnum clientEnum when clientEnum.IsStringBased: - writer.Append($"new {cSharpType}({element}.GetString())"); - break; - - case ClientEnum clientEnum when !clientEnum.IsStringBased: - writer.Append($"{element}.GetString().To{cSharpType}()"); - break; - } + writer.ToDeserializeCall(schemaTypeReference, typeFactory, element); return; case BinaryTypeReference _: @@ -285,7 +332,7 @@ namespace AutoRest.CSharp.V3.CodeGen writer.AppendRaw("("); - if (includeFormat && format.ToFormatSpecifier() is string formatString) + if (includeFormat && serialization.Format.ToFormatSpecifier() is string formatString) { writer.Literal(formatString); } @@ -295,6 +342,26 @@ namespace AutoRest.CSharp.V3.CodeGen } } + public static void ToDeserializeCall(this CodeWriter writer, SchemaTypeReference type, TypeFactory typeFactory, CodeWriterDelegate element) + { + CSharpType cSharpType = typeFactory.CreateType(type).WithNullable(false); + + switch (typeFactory.ResolveReference(type)) + { + case ClientObject _: + writer.Append($"{cSharpType}.Deserialize{cSharpType.Name}({element})"); + break; + + case ClientEnum clientEnum when clientEnum.IsStringBased: + writer.Append($"new {cSharpType}({element}.GetString())"); + break; + + case ClientEnum clientEnum when !clientEnum.IsStringBased: + writer.Append($"{element}.GetString().To{cSharpType}()"); + break; + } + } + public static string? ToFormatSpecifier(this SerializationFormat format) => format switch { SerializationFormat.DateTime_RFC1123 => "R", diff --git a/src/AutoRest.CSharp.V3/CodeGen/SerializationWriter.cs b/src/AutoRest.CSharp.V3/CodeGen/SerializationWriter.cs index cce0245d..02fed5a8 100644 --- a/src/AutoRest.CSharp.V3/CodeGen/SerializationWriter.cs +++ b/src/AutoRest.CSharp.V3/CodeGen/SerializationWriter.cs @@ -2,12 +2,10 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; -using System.Collections.Generic; using System.Linq; using System.Text.Json; using AutoRest.CSharp.V3.ClientModels; using AutoRest.CSharp.V3.Plugins; -using AutoRest.CSharp.V3.Utilities; using Azure.Core; namespace AutoRest.CSharp.V3.CodeGen @@ -34,40 +32,6 @@ namespace AutoRest.CSharp.V3.CodeGen } } - private void ReadProperty(CodeWriter writer, ClientObjectProperty property) - { - var type = property.Type; - var name = property.Name; - var format = property.Format; - - CSharpType propertyType = _typeFactory.CreateType(type); - - void WriteNullCheck() - { - using (writer.If($"property.Value.ValueKind == {writer.Type(typeof(JsonValueKind))}.Null")) - { - writer.Append($"continue;"); - } - } - - void WriteInitialization() - { - if (propertyType.IsNullable && (type is DictionaryTypeReference || type is CollectionTypeReference)) - { - writer.Line($"result.{name} = new {writer.Type(_typeFactory.CreateConcreteType(property.Type))}();"); - } - } - - if (propertyType.IsNullable) - { - WriteNullCheck(); - } - - WriteInitialization(); - - writer.ToDeserializeCall(type, format, _typeFactory, w=> w.Append($"result.{name}"), w => w.Append($"property.Value")); - } - //TODO: This is currently input schemas only. Does not handle output-style schemas. private void WriteObjectSerialization(CodeWriter writer, ClientObject model) @@ -100,59 +64,16 @@ namespace AutoRest.CSharp.V3.CodeGen { writer .Append($"case {implementation.Key:L}: return ") - .ToDeserializeCall(implementation.Type, SerializationFormat.Default, _typeFactory, w => w.Append($"element")); + .ToDeserializeCall(implementation.Type, _typeFactory, w => w.Append($"element")); writer.Line($";"); } } } } - writer.Line($"var result = new {typeText}();"); - using (writer.ForEach("var property in element.EnumerateObject()")) - { - DictionaryTypeReference? implementsDictionary = null; - - foreach (ClientObject currentType in WalkInheritance(model)) - { - foreach (var property in currentType.Properties) - { - using (writer.If($"property.NameEquals(\"{property.SerializedName}\")")) - { - ReadProperty(writer, property); - writer.Line($"continue;"); - } - } - - implementsDictionary ??= currentType.ImplementsDictionary; - } - - if (implementsDictionary != null) - { - writer.Append($"result.Add(property.Name, "); - writer.ToDeserializeCall(implementsDictionary.ValueType, SerializationFormat.Default, _typeFactory, w => w.Append($"property.Value")); - writer.Line($");"); - } - } - - - writer.Line($"return result;"); - } - } - - private IEnumerable WalkInheritance(ClientObject model) - { - var currentType = model; - - while (currentType != null) - { - yield return currentType; - - if (currentType.Inherits == null) - { - yield break; - } - - currentType = (ClientObject)_typeFactory.ResolveReference(currentType.Inherits); + var resultVariable = "result"; + writer.ToDeserializeCall(model.Serialization, _typeFactory, w=>w.AppendRaw("element"), ref resultVariable); + writer.Line($"return {resultVariable};"); } } @@ -161,37 +82,7 @@ namespace AutoRest.CSharp.V3.CodeGen writer.Append($"void {typeof(IUtf8JsonSerializable)}.{nameof(IUtf8JsonSerializable.Write)}({typeof(Utf8JsonWriter)} writer)"); using (writer.Scope()) { - writer.Line($"writer.WriteStartObject();"); - - DictionaryTypeReference? implementsDictionary = null; - - foreach (ClientObject currentType in WalkInheritance(model)) - { - foreach (var property in currentType.Properties) - { - using (property.Type.IsNullable ? writer.If($"{property.Name} != null") : default) - { - writer.ToSerializeCall( - property.Type, - property.Format, - _typeFactory, - w => w.Append($"{property.Name}"), - w => w.Literal(property.SerializedName)); - } - - implementsDictionary ??= currentType.ImplementsDictionary; - } - } - - if (implementsDictionary != null) - { - using (writer.ForEach("var item in this")) - { - writer.ToSerializeCall(implementsDictionary.ValueType, SerializationFormat.Default, _typeFactory, w => w.Append($"item.Value"), w => w.Append($"item.Key")); - } - } - - writer.Line($"writer.WriteEndObject();"); + writer.ToSerializeCall(model.Serialization, _typeFactory, w => w.AppendRaw("this")); } } diff --git a/src/assets/Azure.Core.Shared/JsonElementExtensions.cs b/src/assets/Azure.Core.Shared/JsonElementExtensions.cs index c813af2d..30637abb 100644 --- a/src/assets/Azure.Core.Shared/JsonElementExtensions.cs +++ b/src/assets/Azure.Core.Shared/JsonElementExtensions.cs @@ -47,16 +47,16 @@ namespace Azure.Core } } - public static DateTimeOffset GetDateTimeOffset(in this JsonElement element, string format = "S") => format switch + public static DateTimeOffset GetDateTimeOffset(in this JsonElement element, string format) => format switch { "D" => element.GetDateTimeOffset(), - "S" => element.GetDateTimeOffset(), + "S" => DateTimeOffset.Parse(element.GetString()), "R" => DateTimeOffset.Parse(element.GetString()), "U" => DateTimeOffset.FromUnixTimeSeconds(element.GetInt64()), _ => throw new ArgumentException("Format is not supported", nameof(format)) }; - public static TimeSpan GetTimeSpan(in this JsonElement element, string format = "P") => format switch + public static TimeSpan GetTimeSpan(in this JsonElement element, string format) => format switch { "P" => XmlConvert.ToTimeSpan(element.GetString()), _ => throw new ArgumentException("Format is not supported", nameof(format)) diff --git a/src/assets/Azure.Core.Shared/Utf8JsonWriterExtensions.cs b/src/assets/Azure.Core.Shared/Utf8JsonWriterExtensions.cs index b95b682d..8b129c7f 100644 --- a/src/assets/Azure.Core.Shared/Utf8JsonWriterExtensions.cs +++ b/src/assets/Azure.Core.Shared/Utf8JsonWriterExtensions.cs @@ -9,10 +9,10 @@ namespace Azure.Core { internal static class Utf8JsonWriterExtensions { - public static void WriteStringValue(this Utf8JsonWriter writer, DateTimeOffset value, string format = "S") => + public static void WriteStringValue(this Utf8JsonWriter writer, DateTimeOffset value, string format) => writer.WriteStringValue(TypeFormatters.ToString(value, format)); - public static void WriteStringValue(this Utf8JsonWriter writer, TimeSpan value, string format = "P") => + public static void WriteStringValue(this Utf8JsonWriter writer, TimeSpan value, string format) => writer.WriteStringValue(TypeFormatters.ToString(value, format)); public static void WriteObjectValue(this Utf8JsonWriter writer, IUtf8JsonSerializable value) diff --git a/test/AutoRest.TestServer.Tests/BodyArray.cs b/test/AutoRest.TestServer.Tests/BodyArray.cs index d8e72592..4a311e2f 100644 --- a/test/AutoRest.TestServer.Tests/BodyArray.cs +++ b/test/AutoRest.TestServer.Tests/BodyArray.cs @@ -170,17 +170,27 @@ namespace AutoRest.TestServer.Tests }); [Test] - [Ignore("https://github.com/Azure/autorest.csharp/issues/368")] public Task GetArrayDateTimeRfc1123Valid() => Test(async (host, pipeline) => { var result = await ArrayOperations.GetDateTimeRfc1123ValidAsync(ClientDiagnostics, pipeline, host); + CollectionAssert.AreEqual(new[] + { + DateTimeOffset.Parse("2000-12-01 00:00:01+00:00"), + DateTimeOffset.Parse("1980-01-02 00:11:35+00:00"), + DateTimeOffset.Parse("1492-10-12 10:15:01+00:00"), + }, result.Value); }); [Test] - [Ignore("https://github.com/Azure/autorest.csharp/issues/368")] public Task GetArrayDateTimeValid() => Test(async (host, pipeline) => { var result = await ArrayOperations.GetDateTimeValidAsync(ClientDiagnostics, pipeline, host); + CollectionAssert.AreEqual(new[] + { + DateTimeOffset.Parse("2000-12-01 00:00:01+00:00"), + DateTimeOffset.Parse("1980-01-02 00:11:35+00:00"), + DateTimeOffset.Parse("1492-10-12 10:15:01+00:00"), + }, result.Value); }); [Test] @@ -459,22 +469,28 @@ namespace AutoRest.TestServer.Tests new[] { new Product() { Integer = 1, String = "2" }, new Product() { Integer = 3, String = "4" }, new Product() { Integer = 5, String = "6" }}, host)); [Test] - [Ignore("https://github.com/Azure/autorest.csharp/issues/368")] public Task PutArrayDateTimeRfc1123Valid() => TestStatus(async (host, pipeline) => await ArrayOperations.PutDateTimeRfc1123ValidAsync(ClientDiagnostics, pipeline, - new DateTimeOffset[] { }, host)); + new[] { + DateTimeOffset.Parse("2000-12-01 00:00:01+00:00"), + DateTimeOffset.Parse("1980-01-02 00:11:35+00:00"), + DateTimeOffset.Parse("1492-10-12 10:15:01+00:00"), + }, host)); [Test] - [Ignore("https://github.com/Azure/autorest.csharp/issues/368")] - public Task PutArrayDateTimeValid() => TestStatus(async (host, pipeline) => await ArrayOperations.PutDateValidAsync(ClientDiagnostics, pipeline, - new DateTimeOffset[] { }, host)); + [IgnoreOnTestServer(TestServerVersion.V2, "no match")] + public Task PutArrayDateTimeValid() => TestStatus(async (host, pipeline) => await ArrayOperations.PutDateTimeValidAsync(ClientDiagnostics, pipeline, + new[] { + DateTimeOffset.Parse("2000-12-01 00:00:01+00:00"), + DateTimeOffset.Parse("1980-01-02 00:11:35+00:00"), + DateTimeOffset.Parse("1492-10-12 10:15:01+00:00"), + }, host)); [Test] - [Ignore("https://github.com/Azure/autorest.csharp/issues/368")] public Task PutArrayDateValid() => TestStatus(async (host, pipeline) => await ArrayOperations.PutDateValidAsync(ClientDiagnostics, pipeline, new[] { - DateTimeOffset.Parse("2000-12-01"), - DateTimeOffset.Parse("1980-01-02"), - DateTimeOffset.Parse("1492-10-12") + DateTimeOffset.Parse("2000-12-01 00:00:01+00:00"), + DateTimeOffset.Parse("1980-01-02 00:11:35+00:00"), + DateTimeOffset.Parse("1492-10-12 10:15:01+00:00"), }, host)); [Test] diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/CatAPTrue.Serialization.cs b/test/TestServerProjects/additionalProperties/Generated/Models/CatAPTrue.Serialization.cs index 20624fe5..d5d2846c 100644 --- a/test/TestServerProjects/additionalProperties/Generated/Models/CatAPTrue.Serialization.cs +++ b/test/TestServerProjects/additionalProperties/Generated/Models/CatAPTrue.Serialization.cs @@ -37,7 +37,7 @@ namespace additionalProperties.Models.V100 } internal static CatAPTrue DeserializeCatAPTrue(JsonElement element) { - var result = new CatAPTrue(); + CatAPTrue result = new CatAPTrue(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("friendly")) diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/additionalProperties/Generated/Models/Error.Serialization.cs index 7cde90df..69eab133 100644 --- a/test/TestServerProjects/additionalProperties/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/additionalProperties/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace additionalProperties.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInProperties.Serialization.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInProperties.Serialization.cs index 52f38c56..24089d64 100644 --- a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInProperties.Serialization.cs +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInProperties.Serialization.cs @@ -39,7 +39,7 @@ namespace additionalProperties.Models.V100 } internal static PetAPInProperties DeserializePetAPInProperties(JsonElement element) { - var result = new PetAPInProperties(); + PetAPInProperties result = new PetAPInProperties(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) @@ -72,9 +72,9 @@ namespace additionalProperties.Models.V100 continue; } result.AdditionalProperties = new Dictionary(); - foreach (var item in property.Value.EnumerateObject()) + foreach (var property0 in property.Value.EnumerateObject()) { - result.AdditionalProperties.Add(item.Name, item.Value.GetSingle()); + result.AdditionalProperties.Add(property0.Name, property0.Value.GetSingle()); } continue; } diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInPropertiesWithAPString.Serialization.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInPropertiesWithAPString.Serialization.cs index f4a15fcd..0d15c353 100644 --- a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInPropertiesWithAPString.Serialization.cs +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInPropertiesWithAPString.Serialization.cs @@ -46,7 +46,7 @@ namespace additionalProperties.Models.V100 } internal static PetAPInPropertiesWithAPString DeserializePetAPInPropertiesWithAPString(JsonElement element) { - var result = new PetAPInPropertiesWithAPString(); + PetAPInPropertiesWithAPString result = new PetAPInPropertiesWithAPString(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) @@ -84,9 +84,9 @@ namespace additionalProperties.Models.V100 continue; } result.AdditionalProperties = new Dictionary(); - foreach (var item in property.Value.EnumerateObject()) + foreach (var property0 in property.Value.EnumerateObject()) { - result.AdditionalProperties.Add(item.Name, item.Value.GetSingle()); + result.AdditionalProperties.Add(property0.Name, property0.Value.GetSingle()); } continue; } diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPObject.Serialization.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPObject.Serialization.cs index 3ed73dfe..d2e137be 100644 --- a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPObject.Serialization.cs +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPObject.Serialization.cs @@ -32,7 +32,7 @@ namespace additionalProperties.Models.V100 } internal static PetAPObject DeserializePetAPObject(JsonElement element) { - var result = new PetAPObject(); + PetAPObject result = new PetAPObject(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPString.Serialization.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPString.Serialization.cs index bf20911b..fbdb1aeb 100644 --- a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPString.Serialization.cs +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPString.Serialization.cs @@ -32,7 +32,7 @@ namespace additionalProperties.Models.V100 } internal static PetAPString DeserializePetAPString(JsonElement element) { - var result = new PetAPString(); + PetAPString result = new PetAPString(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPTrue.Serialization.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPTrue.Serialization.cs index 3401ba52..351dc2b5 100644 --- a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPTrue.Serialization.cs +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPTrue.Serialization.cs @@ -32,7 +32,7 @@ namespace additionalProperties.Models.V100 } internal static PetAPTrue DeserializePetAPTrue(JsonElement element) { - var result = new PetAPTrue(); + PetAPTrue result = new PetAPTrue(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) diff --git a/test/TestServerProjects/body-array/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-array/Generated/Models/Error.Serialization.cs index e15e1b3f..c27f3308 100644 --- a/test/TestServerProjects/body-array/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-array/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace body_array.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/body-array/Generated/Models/Product.Serialization.cs b/test/TestServerProjects/body-array/Generated/Models/Product.Serialization.cs index d8c01302..9684afc1 100644 --- a/test/TestServerProjects/body-array/Generated/Models/Product.Serialization.cs +++ b/test/TestServerProjects/body-array/Generated/Models/Product.Serialization.cs @@ -25,7 +25,7 @@ namespace body_array.Models.V100 } internal static Product DeserializeProduct(JsonElement element) { - var result = new Product(); + Product result = new Product(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("integer")) diff --git a/test/TestServerProjects/body-array/Generated/Operations/ArrayOperations.cs b/test/TestServerProjects/body-array/Generated/Operations/ArrayOperations.cs index 386beb78..74fc64c9 100644 --- a/test/TestServerProjects/body-array/Generated/Operations/ArrayOperations.cs +++ b/test/TestServerProjects/body-array/Generated/Operations/ArrayOperations.cs @@ -1419,7 +1419,7 @@ namespace body_array ICollection value = new List(); foreach (var item in document.RootElement.EnumerateArray()) { - value.Add(item.GetDateTimeOffset()); + value.Add(item.GetDateTimeOffset("D")); } return Response.FromValue(value, response); } @@ -1457,7 +1457,7 @@ namespace body_array content.JsonWriter.WriteStartArray(); foreach (var item in arrayBody) { - content.JsonWriter.WriteStringValue(item); + content.JsonWriter.WriteStringValue(item, "D"); } content.JsonWriter.WriteEndArray(); request.Content = content; @@ -1500,7 +1500,7 @@ namespace body_array ICollection value = new List(); foreach (var item in document.RootElement.EnumerateArray()) { - value.Add(item.GetDateTimeOffset()); + value.Add(item.GetDateTimeOffset("D")); } return Response.FromValue(value, response); } @@ -1538,7 +1538,7 @@ namespace body_array ICollection value = new List(); foreach (var item in document.RootElement.EnumerateArray()) { - value.Add(item.GetDateTimeOffset()); + value.Add(item.GetDateTimeOffset("D")); } return Response.FromValue(value, response); } @@ -1576,7 +1576,7 @@ namespace body_array ICollection value = new List(); foreach (var item in document.RootElement.EnumerateArray()) { - value.Add(item.GetDateTimeOffset()); + value.Add(item.GetDateTimeOffset("S")); } return Response.FromValue(value, response); } @@ -1614,7 +1614,7 @@ namespace body_array content.JsonWriter.WriteStartArray(); foreach (var item in arrayBody) { - content.JsonWriter.WriteStringValue(item); + content.JsonWriter.WriteStringValue(item, "S"); } content.JsonWriter.WriteEndArray(); request.Content = content; @@ -1657,7 +1657,7 @@ namespace body_array ICollection value = new List(); foreach (var item in document.RootElement.EnumerateArray()) { - value.Add(item.GetDateTimeOffset()); + value.Add(item.GetDateTimeOffset("S")); } return Response.FromValue(value, response); } @@ -1695,7 +1695,7 @@ namespace body_array ICollection value = new List(); foreach (var item in document.RootElement.EnumerateArray()) { - value.Add(item.GetDateTimeOffset()); + value.Add(item.GetDateTimeOffset("S")); } return Response.FromValue(value, response); } @@ -1733,7 +1733,7 @@ namespace body_array ICollection value = new List(); foreach (var item in document.RootElement.EnumerateArray()) { - value.Add(item.GetDateTimeOffset()); + value.Add(item.GetDateTimeOffset("R")); } return Response.FromValue(value, response); } @@ -1771,7 +1771,7 @@ namespace body_array content.JsonWriter.WriteStartArray(); foreach (var item in arrayBody) { - content.JsonWriter.WriteStringValue(item); + content.JsonWriter.WriteStringValue(item, "R"); } content.JsonWriter.WriteEndArray(); request.Content = content; @@ -1814,7 +1814,7 @@ namespace body_array ICollection value = new List(); foreach (var item in document.RootElement.EnumerateArray()) { - value.Add(item.GetTimeSpan()); + value.Add(item.GetTimeSpan("P")); } return Response.FromValue(value, response); } @@ -1852,7 +1852,7 @@ namespace body_array content.JsonWriter.WriteStartArray(); foreach (var item in arrayBody) { - content.JsonWriter.WriteStringValue(item); + content.JsonWriter.WriteStringValue(item, "P"); } content.JsonWriter.WriteEndArray(); request.Content = content; @@ -2549,9 +2549,9 @@ namespace body_array foreach (var item in document.RootElement.EnumerateArray()) { IDictionary value0 = new Dictionary(); - foreach (var item0 in item.EnumerateObject()) + foreach (var property in item.EnumerateObject()) { - value0.Add(item0.Name, item0.Value.GetString()); + value0.Add(property.Name, property.Value.GetString()); } value.Add(value0); } @@ -2592,9 +2592,9 @@ namespace body_array foreach (var item in document.RootElement.EnumerateArray()) { IDictionary value0 = new Dictionary(); - foreach (var item0 in item.EnumerateObject()) + foreach (var property in item.EnumerateObject()) { - value0.Add(item0.Name, item0.Value.GetString()); + value0.Add(property.Name, property.Value.GetString()); } value.Add(value0); } @@ -2635,9 +2635,9 @@ namespace body_array foreach (var item in document.RootElement.EnumerateArray()) { IDictionary value0 = new Dictionary(); - foreach (var item0 in item.EnumerateObject()) + foreach (var property in item.EnumerateObject()) { - value0.Add(item0.Name, item0.Value.GetString()); + value0.Add(property.Name, property.Value.GetString()); } value.Add(value0); } @@ -2678,9 +2678,9 @@ namespace body_array foreach (var item in document.RootElement.EnumerateArray()) { IDictionary value0 = new Dictionary(); - foreach (var item0 in item.EnumerateObject()) + foreach (var property in item.EnumerateObject()) { - value0.Add(item0.Name, item0.Value.GetString()); + value0.Add(property.Name, property.Value.GetString()); } value.Add(value0); } @@ -2721,9 +2721,9 @@ namespace body_array foreach (var item in document.RootElement.EnumerateArray()) { IDictionary value0 = new Dictionary(); - foreach (var item0 in item.EnumerateObject()) + foreach (var property in item.EnumerateObject()) { - value0.Add(item0.Name, item0.Value.GetString()); + value0.Add(property.Name, property.Value.GetString()); } value.Add(value0); } diff --git a/test/TestServerProjects/body-boolean/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-boolean/Generated/Models/Error.Serialization.cs index acb3e737..ca5ac048 100644 --- a/test/TestServerProjects/body-boolean/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-boolean/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace body_boolean.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/body-byte/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-byte/Generated/Models/Error.Serialization.cs index b5ae6e90..97740598 100644 --- a/test/TestServerProjects/body-byte/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-byte/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace body_byte.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/ArrayWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/ArrayWrapper.Serialization.cs index 2e7ff22d..0561d96b 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/ArrayWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/ArrayWrapper.Serialization.cs @@ -26,7 +26,7 @@ namespace body_complex.Models.V20160229 } internal static ArrayWrapper DeserializeArrayWrapper(JsonElement element) { - var result = new ArrayWrapper(); + ArrayWrapper result = new ArrayWrapper(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("array")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/Basic.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Basic.Serialization.cs index ed8a7555..ad9fddd4 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Basic.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Basic.Serialization.cs @@ -30,7 +30,7 @@ namespace body_complex.Models.V20160229 } internal static Basic DeserializeBasic(JsonElement element) { - var result = new Basic(); + Basic result = new Basic(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/BooleanWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/BooleanWrapper.Serialization.cs index 542106b8..d024ca65 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/BooleanWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/BooleanWrapper.Serialization.cs @@ -25,7 +25,7 @@ namespace body_complex.Models.V20160229 } internal static BooleanWrapper DeserializeBooleanWrapper(JsonElement element) { - var result = new BooleanWrapper(); + BooleanWrapper result = new BooleanWrapper(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("field_true")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/ByteWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/ByteWrapper.Serialization.cs index 7bfe95e7..cf2b42ff 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/ByteWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/ByteWrapper.Serialization.cs @@ -20,7 +20,7 @@ namespace body_complex.Models.V20160229 } internal static ByteWrapper DeserializeByteWrapper(JsonElement element) { - var result = new ByteWrapper(); + ByteWrapper result = new ByteWrapper(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("field")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/Cat.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Cat.Serialization.cs index abe910d8..ae0948f9 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Cat.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Cat.Serialization.cs @@ -41,7 +41,7 @@ namespace body_complex.Models.V20160229 } internal static Cat DeserializeCat(JsonElement element) { - var result = new Cat(); + Cat result = new Cat(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("color")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/Cookiecuttershark.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Cookiecuttershark.Serialization.cs index b1c0b25c..0f24bacc 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Cookiecuttershark.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Cookiecuttershark.Serialization.cs @@ -42,7 +42,7 @@ namespace body_complex.Models.V20160229 } internal static Cookiecuttershark DeserializeCookiecuttershark(JsonElement element) { - var result = new Cookiecuttershark(); + Cookiecuttershark result = new Cookiecuttershark(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("age")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/DateWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DateWrapper.Serialization.cs index 8f74a49a..8732932d 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DateWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DateWrapper.Serialization.cs @@ -25,7 +25,7 @@ namespace body_complex.Models.V20160229 } internal static DateWrapper DeserializeDateWrapper(JsonElement element) { - var result = new DateWrapper(); + DateWrapper result = new DateWrapper(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("field")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/DatetimeWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DatetimeWrapper.Serialization.cs index 9c425e51..60b16680 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DatetimeWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DatetimeWrapper.Serialization.cs @@ -25,7 +25,7 @@ namespace body_complex.Models.V20160229 } internal static DatetimeWrapper DeserializeDatetimeWrapper(JsonElement element) { - var result = new DatetimeWrapper(); + DatetimeWrapper result = new DatetimeWrapper(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("field")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/Datetimerfc1123Wrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Datetimerfc1123Wrapper.Serialization.cs index c4e5c05e..23b74d31 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Datetimerfc1123Wrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Datetimerfc1123Wrapper.Serialization.cs @@ -25,7 +25,7 @@ namespace body_complex.Models.V20160229 } internal static Datetimerfc1123Wrapper DeserializeDatetimerfc1123Wrapper(JsonElement element) { - var result = new Datetimerfc1123Wrapper(); + Datetimerfc1123Wrapper result = new Datetimerfc1123Wrapper(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("field")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/DictionaryWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DictionaryWrapper.Serialization.cs index 486abf0b..aa627cfc 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DictionaryWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DictionaryWrapper.Serialization.cs @@ -27,7 +27,7 @@ namespace body_complex.Models.V20160229 } internal static DictionaryWrapper DeserializeDictionaryWrapper(JsonElement element) { - var result = new DictionaryWrapper(); + DictionaryWrapper result = new DictionaryWrapper(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("defaultProgram")) @@ -37,9 +37,9 @@ namespace body_complex.Models.V20160229 continue; } result.DefaultProgram = new Dictionary(); - foreach (var item in property.Value.EnumerateObject()) + foreach (var property0 in property.Value.EnumerateObject()) { - result.DefaultProgram.Add(item.Name, item.Value.GetString()); + result.DefaultProgram.Add(property0.Name, property0.Value.GetString()); } continue; } diff --git a/test/TestServerProjects/body-complex/Generated/Models/Dog.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Dog.Serialization.cs index f50342c7..1841ca8f 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Dog.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Dog.Serialization.cs @@ -30,7 +30,7 @@ namespace body_complex.Models.V20160229 } internal static Dog DeserializeDog(JsonElement element) { - var result = new Dog(); + Dog result = new Dog(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("food")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/DotFish.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DotFish.Serialization.cs index 22a26240..a56aafd1 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DotFish.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DotFish.Serialization.cs @@ -29,7 +29,7 @@ namespace body_complex.Models.V20160229 case "DotSalmon": return DotSalmon.DeserializeDotSalmon(element); } } - var result = new DotFish(); + DotFish result = new DotFish(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("fish.type")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/DotFishMarket.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DotFishMarket.Serialization.cs index c2a6ed74..ade8c1ab 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DotFishMarket.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DotFishMarket.Serialization.cs @@ -46,7 +46,7 @@ namespace body_complex.Models.V20160229 } internal static DotFishMarket DeserializeDotFishMarket(JsonElement element) { - var result = new DotFishMarket(); + DotFishMarket result = new DotFishMarket(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("sampleSalmon")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/DotSalmon.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DotSalmon.Serialization.cs index e7b0d0b7..b6743467 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DotSalmon.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DotSalmon.Serialization.cs @@ -32,7 +32,7 @@ namespace body_complex.Models.V20160229 } internal static DotSalmon DeserializeDotSalmon(JsonElement element) { - var result = new DotSalmon(); + DotSalmon result = new DotSalmon(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("location")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/DoubleWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DoubleWrapper.Serialization.cs index 653cdd22..d527ff49 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DoubleWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DoubleWrapper.Serialization.cs @@ -25,7 +25,7 @@ namespace body_complex.Models.V20160229 } internal static DoubleWrapper DeserializeDoubleWrapper(JsonElement element) { - var result = new DoubleWrapper(); + DoubleWrapper result = new DoubleWrapper(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("field1")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/DurationWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DurationWrapper.Serialization.cs index 69ef5d56..561fa137 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DurationWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DurationWrapper.Serialization.cs @@ -20,7 +20,7 @@ namespace body_complex.Models.V20160229 } internal static DurationWrapper DeserializeDurationWrapper(JsonElement element) { - var result = new DurationWrapper(); + DurationWrapper result = new DurationWrapper(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("field")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Error.Serialization.cs index aeefd9a2..fda8138a 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace body_complex.Models.V20160229 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/Fish.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Fish.Serialization.cs index 335f4e53..3e2ec3ff 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Fish.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Fish.Serialization.cs @@ -47,7 +47,7 @@ namespace body_complex.Models.V20160229 case "smart_salmon": return SmartSalmon.DeserializeSmartSalmon(element); } } - var result = new Fish(); + Fish result = new Fish(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("fishtype")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/FloatWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/FloatWrapper.Serialization.cs index 838ea61b..0dafac2c 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/FloatWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/FloatWrapper.Serialization.cs @@ -25,7 +25,7 @@ namespace body_complex.Models.V20160229 } internal static FloatWrapper DeserializeFloatWrapper(JsonElement element) { - var result = new FloatWrapper(); + FloatWrapper result = new FloatWrapper(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("field1")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/Goblinshark.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Goblinshark.Serialization.cs index db170d03..b2543b59 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Goblinshark.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Goblinshark.Serialization.cs @@ -52,7 +52,7 @@ namespace body_complex.Models.V20160229 } internal static Goblinshark DeserializeGoblinshark(JsonElement element) { - var result = new Goblinshark(); + Goblinshark result = new Goblinshark(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("jawsize")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/IntWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/IntWrapper.Serialization.cs index 56cfd8e3..79583b90 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/IntWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/IntWrapper.Serialization.cs @@ -25,7 +25,7 @@ namespace body_complex.Models.V20160229 } internal static IntWrapper DeserializeIntWrapper(JsonElement element) { - var result = new IntWrapper(); + IntWrapper result = new IntWrapper(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("field1")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/LongWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/LongWrapper.Serialization.cs index 3171e897..2df7de64 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/LongWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/LongWrapper.Serialization.cs @@ -25,7 +25,7 @@ namespace body_complex.Models.V20160229 } internal static LongWrapper DeserializeLongWrapper(JsonElement element) { - var result = new LongWrapper(); + LongWrapper result = new LongWrapper(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("field1")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/MyBaseHelperType.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/MyBaseHelperType.Serialization.cs index 40fed2f6..3c5363bd 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/MyBaseHelperType.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/MyBaseHelperType.Serialization.cs @@ -20,7 +20,7 @@ namespace body_complex.Models.V20160229 } internal static MyBaseHelperType DeserializeMyBaseHelperType(JsonElement element) { - var result = new MyBaseHelperType(); + MyBaseHelperType result = new MyBaseHelperType(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("propBH1")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/MyBaseType.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/MyBaseType.Serialization.cs index 10da4832..28716368 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/MyBaseType.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/MyBaseType.Serialization.cs @@ -34,7 +34,7 @@ namespace body_complex.Models.V20160229 case "Kind1": return MyDerivedType.DeserializeMyDerivedType(element); } } - var result = new MyBaseType(); + MyBaseType result = new MyBaseType(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("kind")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/MyDerivedType.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/MyDerivedType.Serialization.cs index 2545ff3a..f77606a1 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/MyDerivedType.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/MyDerivedType.Serialization.cs @@ -32,7 +32,7 @@ namespace body_complex.Models.V20160229 } internal static MyDerivedType DeserializeMyDerivedType(JsonElement element) { - var result = new MyDerivedType(); + MyDerivedType result = new MyDerivedType(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("propD1")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/Pet.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Pet.Serialization.cs index 6b71ac18..9eb95492 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Pet.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Pet.Serialization.cs @@ -25,7 +25,7 @@ namespace body_complex.Models.V20160229 } internal static Pet DeserializePet(JsonElement element) { - var result = new Pet(); + Pet result = new Pet(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/ReadonlyObj.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/ReadonlyObj.Serialization.cs index b8e7deef..f438ee69 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/ReadonlyObj.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/ReadonlyObj.Serialization.cs @@ -25,7 +25,7 @@ namespace body_complex.Models.V20160229 } internal static ReadonlyObj DeserializeReadonlyObj(JsonElement element) { - var result = new ReadonlyObj(); + ReadonlyObj result = new ReadonlyObj(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("id")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/Salmon.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Salmon.Serialization.cs index f9ff7e7e..c4533977 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Salmon.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Salmon.Serialization.cs @@ -52,7 +52,7 @@ namespace body_complex.Models.V20160229 case "smart_salmon": return SmartSalmon.DeserializeSmartSalmon(element); } } - var result = new Salmon(); + Salmon result = new Salmon(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("location")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/Sawshark.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Sawshark.Serialization.cs index 2f72ae33..b8ad425a 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Sawshark.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Sawshark.Serialization.cs @@ -47,7 +47,7 @@ namespace body_complex.Models.V20160229 } internal static Sawshark DeserializeSawshark(JsonElement element) { - var result = new Sawshark(); + Sawshark result = new Sawshark(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("picture")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/Shark.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Shark.Serialization.cs index 66ed1fa7..b03831e4 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Shark.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Shark.Serialization.cs @@ -51,7 +51,7 @@ namespace body_complex.Models.V20160229 case "sawshark": return Sawshark.DeserializeSawshark(element); } } - var result = new Shark(); + Shark result = new Shark(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("age")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/Siamese.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Siamese.Serialization.cs index 4bcc1232..b80e92ab 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Siamese.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Siamese.Serialization.cs @@ -46,7 +46,7 @@ namespace body_complex.Models.V20160229 } internal static Siamese DeserializeSiamese(JsonElement element) { - var result = new Siamese(); + Siamese result = new Siamese(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("breed")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/SmartSalmon.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/SmartSalmon.Serialization.cs index bbe474e9..75dc6264 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/SmartSalmon.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/SmartSalmon.Serialization.cs @@ -55,7 +55,7 @@ namespace body_complex.Models.V20160229 } internal static SmartSalmon DeserializeSmartSalmon(JsonElement element) { - var result = new SmartSalmon(); + SmartSalmon result = new SmartSalmon(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("college_degree")) diff --git a/test/TestServerProjects/body-complex/Generated/Models/StringWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/StringWrapper.Serialization.cs index 495f171d..57480555 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/StringWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/StringWrapper.Serialization.cs @@ -30,7 +30,7 @@ namespace body_complex.Models.V20160229 } internal static StringWrapper DeserializeStringWrapper(JsonElement element) { - var result = new StringWrapper(); + StringWrapper result = new StringWrapper(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("field")) diff --git a/test/TestServerProjects/body-date/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-date/Generated/Models/Error.Serialization.cs index e200f959..64c6b95d 100644 --- a/test/TestServerProjects/body-date/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-date/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace body_date.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/body-datetime-rfc1123/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-datetime-rfc1123/Generated/Models/Error.Serialization.cs index e32863fe..96725fbf 100644 --- a/test/TestServerProjects/body-datetime-rfc1123/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-datetime-rfc1123/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace body_datetime_rfc1123.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/body-datetime/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-datetime/Generated/Models/Error.Serialization.cs index 73239108..fe8c629d 100644 --- a/test/TestServerProjects/body-datetime/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-datetime/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace body_datetime.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/body-dictionary/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-dictionary/Generated/Models/Error.Serialization.cs index b4f1e7a2..517723cf 100644 --- a/test/TestServerProjects/body-dictionary/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-dictionary/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace body_dictionary.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/body-dictionary/Generated/Models/Widget.Serialization.cs b/test/TestServerProjects/body-dictionary/Generated/Models/Widget.Serialization.cs index 3a055100..82b40fd4 100644 --- a/test/TestServerProjects/body-dictionary/Generated/Models/Widget.Serialization.cs +++ b/test/TestServerProjects/body-dictionary/Generated/Models/Widget.Serialization.cs @@ -25,7 +25,7 @@ namespace body_dictionary.Models.V100 } internal static Widget DeserializeWidget(JsonElement element) { - var result = new Widget(); + Widget result = new Widget(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("integer")) diff --git a/test/TestServerProjects/body-dictionary/Generated/Operations/DictionaryOperations.cs b/test/TestServerProjects/body-dictionary/Generated/Operations/DictionaryOperations.cs index 833be94f..ed0771d3 100644 --- a/test/TestServerProjects/body-dictionary/Generated/Operations/DictionaryOperations.cs +++ b/test/TestServerProjects/body-dictionary/Generated/Operations/DictionaryOperations.cs @@ -37,9 +37,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetInt32()); + value.Add(property.Name, property.Value.GetInt32()); } return Response.FromValue(value, response); } @@ -75,9 +75,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetInt32()); + value.Add(property.Name, property.Value.GetInt32()); } return Response.FromValue(value, response); } @@ -157,9 +157,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetString()); + value.Add(property.Name, property.Value.GetString()); } return Response.FromValue(value, response); } @@ -195,9 +195,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetString()); + value.Add(property.Name, property.Value.GetString()); } return Response.FromValue(value, response); } @@ -233,9 +233,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetString()); + value.Add(property.Name, property.Value.GetString()); } return Response.FromValue(value, response); } @@ -271,9 +271,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetString()); + value.Add(property.Name, property.Value.GetString()); } return Response.FromValue(value, response); } @@ -309,9 +309,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetBoolean()); + value.Add(property.Name, property.Value.GetBoolean()); } return Response.FromValue(value, response); } @@ -391,9 +391,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetBoolean()); + value.Add(property.Name, property.Value.GetBoolean()); } return Response.FromValue(value, response); } @@ -429,9 +429,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetBoolean()); + value.Add(property.Name, property.Value.GetBoolean()); } return Response.FromValue(value, response); } @@ -467,9 +467,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetInt32()); + value.Add(property.Name, property.Value.GetInt32()); } return Response.FromValue(value, response); } @@ -549,9 +549,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetInt32()); + value.Add(property.Name, property.Value.GetInt32()); } return Response.FromValue(value, response); } @@ -587,9 +587,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetInt32()); + value.Add(property.Name, property.Value.GetInt32()); } return Response.FromValue(value, response); } @@ -625,9 +625,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetInt64()); + value.Add(property.Name, property.Value.GetInt64()); } return Response.FromValue(value, response); } @@ -707,9 +707,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetInt64()); + value.Add(property.Name, property.Value.GetInt64()); } return Response.FromValue(value, response); } @@ -745,9 +745,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetInt64()); + value.Add(property.Name, property.Value.GetInt64()); } return Response.FromValue(value, response); } @@ -783,9 +783,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetSingle()); + value.Add(property.Name, property.Value.GetSingle()); } return Response.FromValue(value, response); } @@ -865,9 +865,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetSingle()); + value.Add(property.Name, property.Value.GetSingle()); } return Response.FromValue(value, response); } @@ -903,9 +903,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetSingle()); + value.Add(property.Name, property.Value.GetSingle()); } return Response.FromValue(value, response); } @@ -941,9 +941,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetDouble()); + value.Add(property.Name, property.Value.GetDouble()); } return Response.FromValue(value, response); } @@ -1023,9 +1023,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetDouble()); + value.Add(property.Name, property.Value.GetDouble()); } return Response.FromValue(value, response); } @@ -1061,9 +1061,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetDouble()); + value.Add(property.Name, property.Value.GetDouble()); } return Response.FromValue(value, response); } @@ -1099,9 +1099,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetString()); + value.Add(property.Name, property.Value.GetString()); } return Response.FromValue(value, response); } @@ -1181,9 +1181,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetString()); + value.Add(property.Name, property.Value.GetString()); } return Response.FromValue(value, response); } @@ -1219,9 +1219,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetString()); + value.Add(property.Name, property.Value.GetString()); } return Response.FromValue(value, response); } @@ -1257,9 +1257,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetDateTimeOffset()); + value.Add(property.Name, property.Value.GetDateTimeOffset("D")); } return Response.FromValue(value, response); } @@ -1298,7 +1298,7 @@ namespace body_dictionary foreach (var item in arrayBody) { content.JsonWriter.WritePropertyName(item.Key); - content.JsonWriter.WriteStringValue(item.Value); + content.JsonWriter.WriteStringValue(item.Value, "D"); } content.JsonWriter.WriteEndObject(); request.Content = content; @@ -1339,9 +1339,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetDateTimeOffset()); + value.Add(property.Name, property.Value.GetDateTimeOffset("D")); } return Response.FromValue(value, response); } @@ -1377,9 +1377,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetDateTimeOffset()); + value.Add(property.Name, property.Value.GetDateTimeOffset("D")); } return Response.FromValue(value, response); } @@ -1415,9 +1415,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetDateTimeOffset()); + value.Add(property.Name, property.Value.GetDateTimeOffset("S")); } return Response.FromValue(value, response); } @@ -1456,7 +1456,7 @@ namespace body_dictionary foreach (var item in arrayBody) { content.JsonWriter.WritePropertyName(item.Key); - content.JsonWriter.WriteStringValue(item.Value); + content.JsonWriter.WriteStringValue(item.Value, "S"); } content.JsonWriter.WriteEndObject(); request.Content = content; @@ -1497,9 +1497,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetDateTimeOffset()); + value.Add(property.Name, property.Value.GetDateTimeOffset("S")); } return Response.FromValue(value, response); } @@ -1535,9 +1535,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetDateTimeOffset()); + value.Add(property.Name, property.Value.GetDateTimeOffset("S")); } return Response.FromValue(value, response); } @@ -1573,9 +1573,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetDateTimeOffset()); + value.Add(property.Name, property.Value.GetDateTimeOffset("R")); } return Response.FromValue(value, response); } @@ -1614,7 +1614,7 @@ namespace body_dictionary foreach (var item in arrayBody) { content.JsonWriter.WritePropertyName(item.Key); - content.JsonWriter.WriteStringValue(item.Value); + content.JsonWriter.WriteStringValue(item.Value, "R"); } content.JsonWriter.WriteEndObject(); request.Content = content; @@ -1655,9 +1655,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetTimeSpan()); + value.Add(property.Name, property.Value.GetTimeSpan("P")); } return Response.FromValue(value, response); } @@ -1696,7 +1696,7 @@ namespace body_dictionary foreach (var item in arrayBody) { content.JsonWriter.WritePropertyName(item.Key); - content.JsonWriter.WriteStringValue(item.Value); + content.JsonWriter.WriteStringValue(item.Value, "P"); } content.JsonWriter.WriteEndObject(); request.Content = content; @@ -1737,9 +1737,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetBytesFromBase64()); + value.Add(property.Name, property.Value.GetBytesFromBase64()); } return Response.FromValue(value, response); } @@ -1819,9 +1819,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetBytesFromBase64()); + value.Add(property.Name, property.Value.GetBytesFromBase64()); } return Response.FromValue(value, response); } @@ -1857,9 +1857,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetBytesFromBase64()); + value.Add(property.Name, property.Value.GetBytesFromBase64()); } return Response.FromValue(value, response); } @@ -1895,9 +1895,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, Widget.DeserializeWidget(item.Value)); + value.Add(property.Name, Widget.DeserializeWidget(property.Value)); } return Response.FromValue(value, response); } @@ -1933,9 +1933,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, Widget.DeserializeWidget(item.Value)); + value.Add(property.Name, Widget.DeserializeWidget(property.Value)); } return Response.FromValue(value, response); } @@ -1971,9 +1971,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, Widget.DeserializeWidget(item.Value)); + value.Add(property.Name, Widget.DeserializeWidget(property.Value)); } return Response.FromValue(value, response); } @@ -2009,9 +2009,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, Widget.DeserializeWidget(item.Value)); + value.Add(property.Name, Widget.DeserializeWidget(property.Value)); } return Response.FromValue(value, response); } @@ -2047,9 +2047,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, Widget.DeserializeWidget(item.Value)); + value.Add(property.Name, Widget.DeserializeWidget(property.Value)); } return Response.FromValue(value, response); } @@ -2129,14 +2129,14 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary> value = new Dictionary>(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { ICollection value0 = new List(); - foreach (var item0 in item.Value.EnumerateArray()) + foreach (var item in property.Value.EnumerateArray()) { - value0.Add(item0.GetString()); + value0.Add(item.GetString()); } - value.Add(item.Name, value0); + value.Add(property.Name, value0); } return Response.FromValue(value, response); } @@ -2172,14 +2172,14 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary> value = new Dictionary>(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { ICollection value0 = new List(); - foreach (var item0 in item.Value.EnumerateArray()) + foreach (var item in property.Value.EnumerateArray()) { - value0.Add(item0.GetString()); + value0.Add(item.GetString()); } - value.Add(item.Name, value0); + value.Add(property.Name, value0); } return Response.FromValue(value, response); } @@ -2215,14 +2215,14 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary> value = new Dictionary>(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { ICollection value0 = new List(); - foreach (var item0 in item.Value.EnumerateArray()) + foreach (var item in property.Value.EnumerateArray()) { - value0.Add(item0.GetString()); + value0.Add(item.GetString()); } - value.Add(item.Name, value0); + value.Add(property.Name, value0); } return Response.FromValue(value, response); } @@ -2258,14 +2258,14 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary> value = new Dictionary>(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { ICollection value0 = new List(); - foreach (var item0 in item.Value.EnumerateArray()) + foreach (var item in property.Value.EnumerateArray()) { - value0.Add(item0.GetString()); + value0.Add(item.GetString()); } - value.Add(item.Name, value0); + value.Add(property.Name, value0); } return Response.FromValue(value, response); } @@ -2301,14 +2301,14 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary> value = new Dictionary>(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { ICollection value0 = new List(); - foreach (var item0 in item.Value.EnumerateArray()) + foreach (var item in property.Value.EnumerateArray()) { - value0.Add(item0.GetString()); + value0.Add(item.GetString()); } - value.Add(item.Name, value0); + value.Add(property.Name, value0); } return Response.FromValue(value, response); } @@ -2393,9 +2393,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetObject()); + value.Add(property.Name, property.Value.GetObject()); } return Response.FromValue(value, response); } @@ -2431,9 +2431,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetObject()); + value.Add(property.Name, property.Value.GetObject()); } return Response.FromValue(value, response); } @@ -2469,9 +2469,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetObject()); + value.Add(property.Name, property.Value.GetObject()); } return Response.FromValue(value, response); } @@ -2507,9 +2507,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetObject()); + value.Add(property.Name, property.Value.GetObject()); } return Response.FromValue(value, response); } @@ -2545,9 +2545,9 @@ namespace body_dictionary { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); IDictionary value = new Dictionary(); - foreach (var item in document.RootElement.EnumerateObject()) + foreach (var property in document.RootElement.EnumerateObject()) { - value.Add(item.Name, item.Value.GetObject()); + value.Add(property.Name, property.Value.GetObject()); } return Response.FromValue(value, response); } diff --git a/test/TestServerProjects/body-duration/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-duration/Generated/Models/Error.Serialization.cs index 67bbf9ec..e51d1fe7 100644 --- a/test/TestServerProjects/body-duration/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-duration/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace body_duration.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/body-integer/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-integer/Generated/Models/Error.Serialization.cs index b52a89c7..48ebe6fa 100644 --- a/test/TestServerProjects/body-integer/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-integer/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace body_integer.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/body-number/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-number/Generated/Models/Error.Serialization.cs index ccf858c4..83b6e771 100644 --- a/test/TestServerProjects/body-number/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-number/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace body_number.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/body-string/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-string/Generated/Models/Error.Serialization.cs index f7d014aa..f7bb7545 100644 --- a/test/TestServerProjects/body-string/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-string/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace body_string.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/body-string/Generated/Models/RefColorConstant.Serialization.cs b/test/TestServerProjects/body-string/Generated/Models/RefColorConstant.Serialization.cs index 369bc22a..52179ccc 100644 --- a/test/TestServerProjects/body-string/Generated/Models/RefColorConstant.Serialization.cs +++ b/test/TestServerProjects/body-string/Generated/Models/RefColorConstant.Serialization.cs @@ -22,7 +22,7 @@ namespace body_string.Models.V100 } internal static RefColorConstant DeserializeRefColorConstant(JsonElement element) { - var result = new RefColorConstant(); + RefColorConstant result = new RefColorConstant(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("ColorConstant")) diff --git a/test/TestServerProjects/custom-baseUrl-more-options/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/custom-baseUrl-more-options/Generated/Models/Error.Serialization.cs index 49ec9e62..75e12e06 100644 --- a/test/TestServerProjects/custom-baseUrl-more-options/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/custom-baseUrl-more-options/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace custom_baseUrl_more_options.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/custom-baseUrl/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/custom-baseUrl/Generated/Models/Error.Serialization.cs index 235f2346..162faf15 100644 --- a/test/TestServerProjects/custom-baseUrl/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/custom-baseUrl/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace custom_baseUrl.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/extensible-enums-swagger/Generated/Models/Pet.Serialization.cs b/test/TestServerProjects/extensible-enums-swagger/Generated/Models/Pet.Serialization.cs index b3344da1..7f160a5f 100644 --- a/test/TestServerProjects/extensible-enums-swagger/Generated/Models/Pet.Serialization.cs +++ b/test/TestServerProjects/extensible-enums-swagger/Generated/Models/Pet.Serialization.cs @@ -27,7 +27,7 @@ namespace extensible_enums_swagger.Models.V20160707 } internal static Pet DeserializePet(JsonElement element) { - var result = new Pet(); + Pet result = new Pet(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("name")) diff --git a/test/TestServerProjects/header/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/header/Generated/Models/Error.Serialization.cs index d37f7646..42f16034 100644 --- a/test/TestServerProjects/header/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/header/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace header.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/url-multi-collectionFormat/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/url-multi-collectionFormat/Generated/Models/Error.Serialization.cs index d02eafd6..38d84a29 100644 --- a/test/TestServerProjects/url-multi-collectionFormat/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/url-multi-collectionFormat/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace url_multi_collectionFormat.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/url/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/url/Generated/Models/Error.Serialization.cs index 30b1531f..9a7e3840 100644 --- a/test/TestServerProjects/url/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/url/Generated/Models/Error.Serialization.cs @@ -25,7 +25,7 @@ namespace url.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("status")) diff --git a/test/TestServerProjects/validation/Generated/Models/ChildProduct.Serialization.cs b/test/TestServerProjects/validation/Generated/Models/ChildProduct.Serialization.cs index 7519075e..86e59a60 100644 --- a/test/TestServerProjects/validation/Generated/Models/ChildProduct.Serialization.cs +++ b/test/TestServerProjects/validation/Generated/Models/ChildProduct.Serialization.cs @@ -22,7 +22,7 @@ namespace validation.Models.V100 } internal static ChildProduct DeserializeChildProduct(JsonElement element) { - var result = new ChildProduct(); + ChildProduct result = new ChildProduct(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("constProperty")) diff --git a/test/TestServerProjects/validation/Generated/Models/ConstantProduct.Serialization.cs b/test/TestServerProjects/validation/Generated/Models/ConstantProduct.Serialization.cs index 7b3a358d..92cbfd3c 100644 --- a/test/TestServerProjects/validation/Generated/Models/ConstantProduct.Serialization.cs +++ b/test/TestServerProjects/validation/Generated/Models/ConstantProduct.Serialization.cs @@ -19,7 +19,7 @@ namespace validation.Models.V100 } internal static ConstantProduct DeserializeConstantProduct(JsonElement element) { - var result = new ConstantProduct(); + ConstantProduct result = new ConstantProduct(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("constProperty")) diff --git a/test/TestServerProjects/validation/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/validation/Generated/Models/Error.Serialization.cs index 7a40051b..6d3fbcbf 100644 --- a/test/TestServerProjects/validation/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/validation/Generated/Models/Error.Serialization.cs @@ -30,7 +30,7 @@ namespace validation.Models.V100 } internal static Error DeserializeError(JsonElement element) { - var result = new Error(); + Error result = new Error(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("code")) diff --git a/test/TestServerProjects/validation/Generated/Models/Product.Serialization.cs b/test/TestServerProjects/validation/Generated/Models/Product.Serialization.cs index 40a0e0b5..9776b9b8 100644 --- a/test/TestServerProjects/validation/Generated/Models/Product.Serialization.cs +++ b/test/TestServerProjects/validation/Generated/Models/Product.Serialization.cs @@ -40,13 +40,16 @@ namespace validation.Models.V100 writer.WriteNumberValue(ConstInt); writer.WritePropertyName("constString"); writer.WriteStringValue(ConstString); - writer.WritePropertyName("constStringAsEnum"); - writer.WriteStringValue(ConstStringAsEnum); + if (ConstStringAsEnum != null) + { + writer.WritePropertyName("constStringAsEnum"); + writer.WriteStringValue(ConstStringAsEnum); + } writer.WriteEndObject(); } internal static Product DeserializeProduct(JsonElement element) { - var result = new Product(); + Product result = new Product(); foreach (var property in element.EnumerateObject()) { if (property.NameEquals("display_names")) @@ -102,6 +105,10 @@ namespace validation.Models.V100 } if (property.NameEquals("constStringAsEnum")) { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } result.ConstStringAsEnum = property.Value.GetString(); continue; }