From d5ff3b39159ac2168ff76606865605f4341aa2f8 Mon Sep 17 00:00:00 2001 From: Pavel Krymets Date: Wed, 18 Dec 2019 09:54:33 -0800 Subject: [PATCH] Support additional properties (#358) --- eng/Generate.ps1 | 2 +- .../ClientModels/ClientModelBuilderHelpers.cs | 2 +- .../ClientModels/ClientObject.cs | 4 +- .../ClientModels/ModelBuilder.cs | 29 +- .../CodeGen/ClientWriter.cs | 11 +- src/AutoRest.CSharp.V3/CodeGen/CodeWriter.cs | 2 +- .../CodeGen/JsonSerializerExtensions.cs | 81 ++++- src/AutoRest.CSharp.V3/CodeGen/ModelWriter.cs | 57 +++- .../CodeGen/SerializationWriter.cs | 310 +++++++++--------- .../Pipeline/Modifications.cs | 11 + .../JsonElementExtensions.cs | 65 ++++ .../Azure.Core.Shared/TypeFormatters.cs | 15 - .../Utf8JsonWriterExtensions.cs | 52 +++ .../additionalProperties.cs | 174 ++++++++++ .../AutoRest.TestServer.Tests/body-complex.cs | 134 +++----- .../Models/CatAPTrue.Serialization.cs | 80 +++++ .../Generated/Models/CatAPTrue.cs | 10 + .../Generated/Models/Error.Serialization.cs | 53 +++ .../Generated/Models/Error.cs | 11 + .../Models/PetAPInProperties.Serialization.cs | 85 +++++ .../Generated/Models/PetAPInProperties.cs | 15 + ...PInPropertiesWithAPString.Serialization.cs | 98 ++++++ .../Models/PetAPInPropertiesWithAPString.cs | 38 +++ .../Models/PetAPObject.Serialization.cs | 66 ++++ .../Generated/Models/PetAPObject.cs | 36 ++ .../Models/PetAPString.Serialization.cs | 66 ++++ .../Generated/Models/PetAPString.cs | 36 ++ .../Models/PetAPTrue.Serialization.cs | 66 ++++ .../Generated/Models/PetAPTrue.cs | 36 ++ .../Generated/Operations/PetsOperations.cs | 276 ++++++++++++++++ .../additionalProperties.csproj | 15 + .../Generated/Models/Error.Serialization.cs | 1 + .../Models/ArrayWrapper.Serialization.cs | 4 +- .../Generated/Models/Basic.Serialization.cs | 1 + .../Models/BooleanWrapper.Serialization.cs | 1 + .../Models/ByteWrapper.Serialization.cs | 1 + .../Generated/Models/Cat.Serialization.cs | 6 +- .../Models/Cookiecuttershark.Serialization.cs | 12 +- .../Models/DateWrapper.Serialization.cs | 9 +- .../Models/DatetimeWrapper.Serialization.cs | 9 +- .../Datetimerfc1123Wrapper.Serialization.cs | 9 +- .../Models/DictionaryWrapper.Serialization.cs | 4 +- .../Generated/Models/Dog.Serialization.cs | 3 +- .../Generated/Models/DotFish.Serialization.cs | 1 + .../Models/DotFishMarket.Serialization.cs | 7 +- .../Models/DotSalmon.Serialization.cs | 3 +- .../Models/DoubleWrapper.Serialization.cs | 1 + .../Models/DurationWrapper.Serialization.cs | 5 +- .../Generated/Models/Error.Serialization.cs | 1 + .../Generated/Models/Fish.Serialization.cs | 4 +- .../Models/FloatWrapper.Serialization.cs | 1 + .../Models/Goblinshark.Serialization.cs | 12 +- .../Models/IntWrapper.Serialization.cs | 1 + .../Models/LongWrapper.Serialization.cs | 1 + .../Models/MyBaseHelperType.Serialization.cs | 1 + .../Models/MyBaseType.Serialization.cs | 1 + .../Models/MyDerivedType.Serialization.cs | 3 +- .../Generated/Models/Pet.Serialization.cs | 1 + .../Models/ReadonlyObj.Serialization.cs | 1 + .../Generated/Models/Salmon.Serialization.cs | 6 +- .../Models/Sawshark.Serialization.cs | 12 +- .../Generated/Models/Shark.Serialization.cs | 10 +- .../Generated/Models/Siamese.Serialization.cs | 8 +- .../Models/SmartSalmon.Serialization.cs | 14 +- .../Generated/Models/SmartSalmon.cs | 26 +- .../Models/StringWrapper.Serialization.cs | 1 + .../Generated/Models/Error.Serialization.cs | 1 + .../Generated/Operations/DateOperations.cs | 16 +- .../Generated/Models/Error.Serialization.cs | 1 + .../Operations/Datetimerfc1123Operations.cs | 18 +- .../Generated/Models/Error.Serialization.cs | 1 + .../Operations/DatetimeOperations.cs | 38 +-- .../Generated/Models/Error.Serialization.cs | 1 + .../Operations/DurationOperations.cs | 8 +- .../Generated/Models/Error.Serialization.cs | 1 + .../Generated/Operations/IntOperations.cs | 8 +- .../Generated/Models/Error.Serialization.cs | 1 + .../Generated/Models/Error.Serialization.cs | 1 + .../Models/RefColorConstant.Serialization.cs | 1 + .../Generated/Operations/StringOperations.cs | 2 +- .../Generated/Models/Error.Serialization.cs | 1 + .../Generated/Models/Error.Serialization.cs | 1 + .../Generated/Models/Pet.Serialization.cs | 1 + .../Generated/Models/Error.Serialization.cs | 1 + .../Generated/Models/Error.Serialization.cs | 1 + .../Generated/Models/Error.Serialization.cs | 1 + .../Models/ChildProduct.Serialization.cs | 1 + .../Models/ConstantProduct.Serialization.cs | 1 + .../Generated/Models/Error.Serialization.cs | 1 + .../Generated/Models/Product.Serialization.cs | 4 +- test/scripts/TestList.txt | Bin 80 -> 2114 bytes 91 files changed, 1824 insertions(+), 404 deletions(-) create mode 100644 src/assets/Azure.Core.Shared/JsonElementExtensions.cs create mode 100644 test/AutoRest.TestServer.Tests/additionalProperties.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Models/CatAPTrue.Serialization.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Models/CatAPTrue.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Models/Error.Serialization.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Models/Error.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Models/PetAPInProperties.Serialization.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Models/PetAPInProperties.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Models/PetAPInPropertiesWithAPString.Serialization.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Models/PetAPInPropertiesWithAPString.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Models/PetAPObject.Serialization.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Models/PetAPObject.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Models/PetAPString.Serialization.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Models/PetAPString.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Models/PetAPTrue.Serialization.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Models/PetAPTrue.cs create mode 100644 test/TestServerProjects/additionalProperties/Generated/Operations/PetsOperations.cs create mode 100644 test/TestServerProjects/additionalProperties/additionalProperties.csproj diff --git a/eng/Generate.ps1 b/eng/Generate.ps1 index 0ea8d147..d439759f 100644 --- a/eng/Generate.ps1 +++ b/eng/Generate.ps1 @@ -39,7 +39,7 @@ $configurationPath = Join-Path $testServerDirectory 'readme.tests.md' $testServerSwaggerPath = Join-Path $repoRoot 'node_modules' '@microsoft.azure' 'autorest.testserver' 'swagger' $testNames = if ($name) { $name } else { - #'additionalProperties', + 'additionalProperties', #'azure-composite-swagger', #'azure-parameter-grouping', #'azure-report', diff --git a/src/AutoRest.CSharp.V3/ClientModels/ClientModelBuilderHelpers.cs b/src/AutoRest.CSharp.V3/ClientModels/ClientModelBuilderHelpers.cs index ecfe4a5c..577de56e 100644 --- a/src/AutoRest.CSharp.V3/ClientModels/ClientModelBuilderHelpers.cs +++ b/src/AutoRest.CSharp.V3/ClientModels/ClientModelBuilderHelpers.cs @@ -3,7 +3,6 @@ using System; using System.Globalization; -using AutoRest.CSharp.V3.Pipeline; using AutoRest.CSharp.V3.Pipeline.Generated; namespace AutoRest.CSharp.V3.ClientModels @@ -63,6 +62,7 @@ namespace AutoRest.CSharp.V3.ClientModels AllSchemaTypes.Unixtime => typeof(DateTimeOffset), AllSchemaTypes.Uri => typeof(Uri), AllSchemaTypes.Uuid => typeof(string), + AllSchemaTypes.Any => typeof(object), _ => null }; diff --git a/src/AutoRest.CSharp.V3/ClientModels/ClientObject.cs b/src/AutoRest.CSharp.V3/ClientModels/ClientObject.cs index dfdc503a..18d21f03 100644 --- a/src/AutoRest.CSharp.V3/ClientModels/ClientObject.cs +++ b/src/AutoRest.CSharp.V3/ClientModels/ClientObject.cs @@ -8,12 +8,13 @@ namespace AutoRest.CSharp.V3.ClientModels { internal class ClientObject : ClientModel, ISchemaTypeProvider { - public ClientObject(Schema schema, string name, SchemaTypeReference? inherits, IEnumerable properties, IEnumerable constants, ClientObjectDiscriminator? discriminator) + public ClientObject(Schema schema, string name, SchemaTypeReference? inherits, IEnumerable properties, ClientObjectDiscriminator? discriminator, DictionaryTypeReference? implementsDictionary) { Schema = schema; Name = name; Inherits = inherits; Discriminator = discriminator; + ImplementsDictionary = implementsDictionary; Properties = new List(properties); } @@ -22,5 +23,6 @@ namespace AutoRest.CSharp.V3.ClientModels public SchemaTypeReference? Inherits { get; } public IList Properties { get; } public ClientObjectDiscriminator? Discriminator { get; } + public DictionaryTypeReference? ImplementsDictionary { get; } } } diff --git a/src/AutoRest.CSharp.V3/ClientModels/ModelBuilder.cs b/src/AutoRest.CSharp.V3/ClientModels/ModelBuilder.cs index 7e7b870e..c0c59431 100644 --- a/src/AutoRest.CSharp.V3/ClientModels/ModelBuilder.cs +++ b/src/AutoRest.CSharp.V3/ClientModels/ModelBuilder.cs @@ -25,11 +25,28 @@ namespace AutoRest.CSharp.V3.ClientModels private static ClientModel BuildClientObject(ObjectSchema objectSchema) { - var inheritsFrom = objectSchema.Parents?.Immediate.OfType().SingleOrDefault(); - var inheritsFromTypeReference = inheritsFrom != null ? ClientModelBuilderHelpers.CreateType(inheritsFrom, false) : null; + ClientTypeReference? inheritsFromTypeReference = null; + DictionaryTypeReference? dictionaryElementTypeReference = null; + + foreach (ComplexSchema complexSchema in objectSchema.Parents!.Immediate) + { + switch (complexSchema) + { + case ObjectSchema parentObjectSchema: + 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); + + break; + } + } List properties = new List(); - List constants = new List(); foreach (Property property in objectSchema.Properties!) { @@ -41,7 +58,7 @@ namespace AutoRest.CSharp.V3.ClientModels if (schemaDiscriminator == null && objectSchema.DiscriminatorValue != null) { - schemaDiscriminator = objectSchema.Parents?.All.OfType().First(p => p.Discriminator != null).Discriminator; + schemaDiscriminator = objectSchema.Parents!.All.OfType().First(p => p.Discriminator != null).Discriminator; Debug.Assert(schemaDiscriminator != null); @@ -67,8 +84,8 @@ namespace AutoRest.CSharp.V3.ClientModels objectSchema.CSharpName(), (SchemaTypeReference?) inheritsFromTypeReference, properties.ToArray(), - constants.ToArray(), - discriminator + discriminator, + dictionaryElementTypeReference ); } diff --git a/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs b/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs index 098dd3a1..7bfcbed5 100644 --- a/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs +++ b/src/AutoRest.CSharp.V3/CodeGen/ClientWriter.cs @@ -115,12 +115,7 @@ namespace AutoRest.CSharp.V3.CodeGen writer.Line($"using var content = new {writer.Type(typeof(Utf8JsonRequestContent))}();"); writer.Line($"var writer = content.{nameof(Utf8JsonRequestContent.JsonWriter)};"); - //TODO: Workaround for JSON serialization not supporting the null constants ConstantOrParameter value = body.Value; - if (value.IsConstant && value.Constant.Value == null) - { - value = ClientModelBuilderHelpers.StringConstant(""); - } writer.ToSerializeCall(value.Type, body.Format, _typeFactory, w => WriteConstantOrParameter(w, value)); @@ -180,7 +175,11 @@ namespace AutoRest.CSharp.V3.CodeGen { if (constant.Value == null) { - writer.Literal(null); + // Cast helps the overload resolution + writer.Append("(") + .AppendType(_typeFactory.CreateType(constant.Type)) + .Append(")") + .Literal(null); return; } diff --git a/src/AutoRest.CSharp.V3/CodeGen/CodeWriter.cs b/src/AutoRest.CSharp.V3/CodeGen/CodeWriter.cs index 9a0c2371..41fcf394 100644 --- a/src/AutoRest.CSharp.V3/CodeGen/CodeWriter.cs +++ b/src/AutoRest.CSharp.V3/CodeGen/CodeWriter.cs @@ -33,7 +33,7 @@ namespace AutoRest.CSharp.V3.CodeGen } private string DefinitionLine(string? access, string? modifiers, string kind, string? name, string? implements = null) => - new[] { access ?? _definitionAccessDefault, modifiers, kind, name , implements != null ? $": {implements}" : null }.JoinIgnoreEmpty(" "); + new[] { access ?? _definitionAccessDefault, modifiers, kind, name , !string.IsNullOrWhiteSpace(implements)? $": {implements}" : null }.JoinIgnoreEmpty(" "); private CodeWriterScope Definition(string? access, string? modifiers, string kind, string? name, string? implements = null) { diff --git a/src/AutoRest.CSharp.V3/CodeGen/JsonSerializerExtensions.cs b/src/AutoRest.CSharp.V3/CodeGen/JsonSerializerExtensions.cs index 7f24aabd..b7c8aad5 100644 --- a/src/AutoRest.CSharp.V3/CodeGen/JsonSerializerExtensions.cs +++ b/src/AutoRest.CSharp.V3/CodeGen/JsonSerializerExtensions.cs @@ -29,14 +29,14 @@ namespace AutoRest.CSharp.V3.CodeGen var formatSpecifier = f.ToFormatSpecifier(); var valueText = $"{vn}{(nu ? ".Value" : string.Empty)}"; var formatText = formatSpecifier != null ? $", \"{formatSpecifier}\"" : string.Empty; - //TODO: Hack to call Azure.Core functionality without having the context of the namespaces specified to the file this is being written to. - return $"Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, {valueText}{formatText});"; + return $"writer.WriteStringValue({valueText}{formatText});"; }; //TODO: Do this by AllSchemaTypes so things like Date versus DateTime can be serialized properly. private static readonly Dictionary> TypeSerializers = new Dictionary> { { typeof(bool), (vn, nu, f) => $"writer.WriteBooleanValue({vn}{(nu ? ".Value" : string.Empty)});" }, + { typeof(object), (vn, nu, f) => $"writer.WriteObjectValue({vn});" }, { typeof(char), StringSerializer() }, { typeof(short), NumberSerializer }, { typeof(int), NumberSerializer }, @@ -54,12 +54,12 @@ namespace AutoRest.CSharp.V3.CodeGen private static Func? FormatDeserializer(string typeName) => (n, f) => { var formatSpecifier = f.ToFormatSpecifier(); - //TODO: Hack to call Azure.Core functionality without having the context of the namespaces specified to the file this is being written to. - return formatSpecifier != null ? $"Azure.Core.TypeFormatters.Get{typeName}({n}, \"{formatSpecifier}\")" : null; + return formatSpecifier != null ? $"{n}.Get{typeName}(\"{formatSpecifier}\")" : null; }; private static readonly Dictionary> TypeDeserializers = new Dictionary> { + { typeof(object), (n, f) => $"{n}.GetObject()" }, { typeof(bool), (n, f) => $"{n}.GetBoolean()" }, { typeof(char), (n, f) => $"{n}.GetString()" }, { typeof(short), (n, f) => $"{n}.GetInt16()" }, @@ -126,6 +126,9 @@ namespace AutoRest.CSharp.V3.CodeGen public static void ToSerializeCall(this CodeWriter writer, ClientTypeReference type, SerializationFormat format, TypeFactory typeFactory, CodeWriterDelegate name, CodeWriterDelegate? serializedName = null) { + // TODO: remove when serialization uses the full writer + writer.UseNamespace(new CSharpNamespace("Azure.Core")); + if (serializedName != null) { writer.Append("writer.WritePropertyName("); @@ -135,6 +138,28 @@ namespace AutoRest.CSharp.V3.CodeGen switch (type) { + case CollectionTypeReference array: + { + writer.Line("writer.WriteStartArray();"); + using (writer.ForEach($"var item in {CodeWriter.Materialize(name)}")) + { + writer.ToSerializeCall(array.ItemType, format, typeFactory, w => w.Append("item")); + } + writer.Line("writer.WriteEndArray();"); + + return; + } + case DictionaryTypeReference dictionary: + { + writer.Line("writer.WriteStartObject();"); + using (writer.ForEach($"var item in {CodeWriter.Materialize(name)}")) + { + writer.ToSerializeCall(dictionary.ValueType, format, typeFactory, w => w.Append("item.Value"), w => w.Append("item.Key")); + } + writer.Line("writer.WriteEndObject();"); + + return; + } case SchemaTypeReference schemaTypeReference: WriteSerializeSchemaTypeReference(writer, schemaTypeReference, typeFactory, name); return; @@ -201,19 +226,59 @@ namespace AutoRest.CSharp.V3.CodeGen writer.Append(TypeDeserializers[frameworkType](CodeWriter.Materialize(name), format) ?? "null"); } - public static void ToDeserializeCall(this CodeWriter writer, ClientTypeReference type, SerializationFormat format, TypeFactory typeFactory, CodeWriterDelegate name) + public static void ToDeserializeCall(this CodeWriter writer, ClientTypeReference type, SerializationFormat format, TypeFactory typeFactory, CodeWriterDelegate destination, CodeWriterDelegate element) + { + // TODO: remove when serialization uses the full writer + writer.UseNamespace(new CSharpNamespace("Azure.Core")); + + switch (type) + { + case CollectionTypeReference array: + { + using (writer.ForEach("var item in property.Value.EnumerateArray()")) + { + writer.Append(destination); + writer.Append(".Add("); + writer.ToDeserializeCall(array.ItemType, format, typeFactory, w => w.Append("item")); + writer.Line(");"); + } + + return; + } + case DictionaryTypeReference dictionary: + { + using (writer.ForEach("var item in property.Value.EnumerateObject()")) + { + writer.Append(destination); + writer.Append(".Add(item.Name, "); + writer.ToDeserializeCall(dictionary.ValueType, format, typeFactory, w => w.Append("item.Value")); + writer.Line(");"); + } + + return; + } + } + + writer.Append(destination); + writer.Append("="); + ToDeserializeCall(writer, type, format, typeFactory, element); + writer.SemicolonLine(); + } + + public static void ToDeserializeCall(this CodeWriter writer, ClientTypeReference type, SerializationFormat format, TypeFactory typeFactory, CodeWriterDelegate element) { CSharpType cSharpType = typeFactory.CreateType(type).WithNullable(false); + switch (type) { case SchemaTypeReference schemaTypeReference: - WriteDeserializeSchemaTypeReference(writer, cSharpType, schemaTypeReference, typeFactory, name); + WriteDeserializeSchemaTypeReference(writer, cSharpType, schemaTypeReference, typeFactory, element); return; case BinaryTypeReference _: - WriteDeserializeBinaryTypeReference(writer, name); + WriteDeserializeBinaryTypeReference(writer, element); return; default: - WriteDeserializeDefault(writer, cSharpType, format, name); + WriteDeserializeDefault(writer, cSharpType, format, element); return; } } diff --git a/src/AutoRest.CSharp.V3/CodeGen/ModelWriter.cs b/src/AutoRest.CSharp.V3/CodeGen/ModelWriter.cs index 3ca0a4fc..84e2c707 100644 --- a/src/AutoRest.CSharp.V3/CodeGen/ModelWriter.cs +++ b/src/AutoRest.CSharp.V3/CodeGen/ModelWriter.cs @@ -2,6 +2,8 @@ // 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.ComponentModel; using System.Linq; using AutoRest.CSharp.V3.ClientModels; @@ -43,13 +45,20 @@ namespace AutoRest.CSharp.V3.CodeGen var cs = _typeFactory.CreateType(schema); using (writer.Namespace(cs.Namespace)) { - string? implementsType = null; + List implementsTypes = new List(); if (schema.Inherits != null) { - implementsType = writer.Type(_typeFactory.CreateType(schema.Inherits)); + implementsTypes.Add(writer.Type(_typeFactory.CreateType(schema.Inherits))); } - using (writer.Class(null, "partial", schema.CSharpName(), implements: implementsType)) + if (schema.ImplementsDictionary != null) + { + var dictionaryType = _typeFactory.CreateInputType(schema.ImplementsDictionary); + implementsTypes.Add(writer.Type(dictionaryType)); + } + + + using (writer.Class(null, "partial", schema.CSharpName(), implements: string.Join(", ", implementsTypes))) { if (schema.Discriminator != null) { @@ -69,6 +78,48 @@ namespace AutoRest.CSharp.V3.CodeGen var initializer = !propertyType.IsNullable && NeedsInitialization(property.Type) ? $" = new {writer.Type(_typeFactory.CreateConcreteType(property.Type))}();" : null; writer.AutoProperty("public", propertyType, property.Name, property.IsReadOnly, initializer); } + + if (schema.ImplementsDictionary != null) + { + var implementationType = _typeFactory.CreateType(schema.ImplementsDictionary); + var fieldType = _typeFactory.CreateConcreteType(schema.ImplementsDictionary); + var keyType = _typeFactory.CreateType(schema.ImplementsDictionary.KeyType); + var itemType = _typeFactory.CreateType(schema.ImplementsDictionary.ValueType); + + var keyValuePairType = new CSharpType(typeof(KeyValuePair<,>), keyType, itemType); + var iEnumeratorKeyValuePairType = new CSharpType(typeof(IEnumerator<>), keyValuePairType); + var iCollectionKeyValuePairType = new CSharpType(typeof(ICollection<>), keyValuePairType); + var iCollectionKeyType = new CSharpType(typeof(ICollection<>), keyType); + var iCollectionItemType = new CSharpType(typeof(ICollection<>), itemType); + var iEnumerator = new CSharpType(typeof(IEnumerator)); + var iEnumerable = new CSharpType(typeof(IEnumerable)); + + string additionalProperties = "_additionalProperties"; + writer.Append("private readonly ").AppendType(implementationType).Space().Append(additionalProperties).Append("= new ").AppendType(fieldType).Append("()").SemicolonLine(); + + writer.Append("public ").AppendType(iEnumeratorKeyValuePairType).Append(" GetEnumerator() => _additionalProperties.GetEnumerator();").Line() + .AppendType(iEnumerator).Space().AppendType(iEnumerable).Append(".GetEnumerator() => _additionalProperties.GetEnumerator();").Line() + .Append("public ").AppendType(iCollectionKeyType).Append(" Keys => _additionalProperties.Keys;").Line() + .Append("public ").AppendType(iCollectionItemType).Append(" Values => _additionalProperties.Values;").Line() + .Append("public bool TryGetValue(string key, out ").AppendType(itemType).Append(" value) => _additionalProperties.TryGetValue(key, out value);").Line() + .Append("public void Add(").AppendType(keyType).Append(" key, ").AppendType(itemType).Append(" value) => _additionalProperties.Add(key, value);").Line() + .Append("public bool ContainsKey(").AppendType(keyType).Append(" key) => _additionalProperties.ContainsKey(key);").Line() + .Append("public bool Remove(").AppendType(keyType).Append(" key) => _additionalProperties.Remove(key);").Line() + .Append("public int Count => _additionalProperties.Count;").Line() + .Append("bool ").AppendType(iCollectionKeyValuePairType).Append(".IsReadOnly => _additionalProperties.IsReadOnly;").Line() + .Append("void ").AppendType(iCollectionKeyValuePairType).Append(".Add(").AppendType(keyValuePairType).Append(" value) => _additionalProperties.Add(value);").Line() + .Append("bool ").AppendType(iCollectionKeyValuePairType).Append(".Remove(").AppendType(keyValuePairType).Append(" value) => _additionalProperties.Remove(value);").Line() + .Append("bool ").AppendType(iCollectionKeyValuePairType).Append(".Contains(").AppendType(keyValuePairType).Append(" value) => _additionalProperties.Contains(value);").Line() + .Append("void ").AppendType(iCollectionKeyValuePairType).Append(".CopyTo(").AppendType(keyValuePairType).Append("[] destination, int offset) => _additionalProperties.CopyTo(destination, offset);").Line() + .Append("void ").AppendType(iCollectionKeyValuePairType).Append(".Clear() => _additionalProperties.Clear();").Line(); + + using (writer.Append("public ").AppendType(itemType).Append(" this[").AppendType(keyType).Append(" key]").Scope()) + { + writer + .Line("get => _additionalProperties[key];") + .Line("set => _additionalProperties[key] = value;"); + } + } } } } diff --git a/src/AutoRest.CSharp.V3/CodeGen/SerializationWriter.cs b/src/AutoRest.CSharp.V3/CodeGen/SerializationWriter.cs index 3757cb71..796110f1 100644 --- a/src/AutoRest.CSharp.V3/CodeGen/SerializationWriter.cs +++ b/src/AutoRest.CSharp.V3/CodeGen/SerializationWriter.cs @@ -2,6 +2,7 @@ // 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; @@ -32,35 +33,6 @@ namespace AutoRest.CSharp.V3.CodeGen } } - private void WriteProperty(CodeWriter writer, ClientTypeReference type, SerializationFormat format, string name, string serializedName) - { - if (type is CollectionTypeReference array) - { - writer.Line($"writer.WriteStartArray(\"{serializedName}\");"); - using (writer.ForEach($"var item in {name}")) - { - writer.ToSerializeCall(array.ItemType, format, _typeFactory, w => w.Append("item")); - } - writer.Line("writer.WriteEndArray();"); - - return; - } - - if (type is DictionaryTypeReference dictionary) - { - writer.Line($"writer.WriteStartObject(\"{serializedName}\");"); - using (writer.ForEach($"var item in {name}")) - { - writer.ToSerializeCall(dictionary.ValueType, format, _typeFactory, w => w.Append("item.Value"), w => w.Append("item.Key")); - } - writer.Line("writer.WriteEndObject();"); - - return; - } - - writer.ToSerializeCall(type, format, _typeFactory, w => w.Append(name), w => w.Literal(serializedName)); - } - private void ReadProperty(CodeWriter writer, ClientObjectProperty property) { var type = property.Type; @@ -69,58 +41,33 @@ namespace AutoRest.CSharp.V3.CodeGen 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) + if (propertyType.IsNullable && (type is DictionaryTypeReference || type is CollectionTypeReference)) { - WriteNullCheck(writer); - writer.Append($"result.{name} = new {writer.Type(_typeFactory.CreateConcreteType(property.Type))}()") .SemicolonLine(); } } - if (type is CollectionTypeReference array) - { - WriteInitialization(); - - using (writer.ForEach("var item in property.Value.EnumerateArray()")) - { - writer.Append($"result.{name}.Add("); - writer.ToDeserializeCall(array.ItemType, format, _typeFactory, w => w.Append("item")); - writer.Line(");"); - } - return; - } - if (type is DictionaryTypeReference dictionary) - { - WriteInitialization(); - - using (writer.ForEach("var item in property.Value.EnumerateObject()")) - { - writer.Append($"result.{name}.Add(item.Name, "); - writer.ToDeserializeCall(dictionary.ValueType, format, _typeFactory, w => w.Append("item.Value")); - writer.Line(");"); - } - return; - } - if (propertyType.IsNullable) { - WriteNullCheck(writer); + WriteNullCheck(); } - writer.Append($"result.{name} = "); - writer.ToDeserializeCall(type, format, _typeFactory, w => w.Append("property.Value")); - writer.Line(";"); + + WriteInitialization(); + + writer.ToDeserializeCall(type, format, _typeFactory, w=> w.Append($"result.{name}"), w => w.Append("property.Value")); } - private static void WriteNullCheck(CodeWriter writer) - { - using (writer.If($"property.Value.ValueKind == {writer.Type(typeof(JsonValueKind))}.Null")) - { - writer.Append("continue;"); - } - } //TODO: This is currently input schemas only. Does not handle output-style schemas. private void WriteObjectSerialization(CodeWriter writer, ClientObject model) @@ -131,108 +78,145 @@ namespace AutoRest.CSharp.V3.CodeGen { using (writer.Class(null, "partial", serializerName)) { - using (writer.Method("internal static", "void", "Serialize", writer.Pair(cs, "model"), writer.Pair(typeof(Utf8JsonWriter), "writer"))) + WriteSerialize(writer, model, cs); + + WriteDeserialize(writer, model, cs); + } + } + } + + private void WriteDeserialize(CodeWriter writer, ClientObject model, CSharpType cs) + { + var typeText = writer.Type(cs); + using (writer.Method("internal static", typeText, "Deserialize", writer.Pair(typeof(JsonElement), "element"))) + { + if (model.Discriminator?.HasDescendants == true) + { + using (writer.If($"element.TryGetProperty(\"{model.Discriminator.SerializedName}\", out {writer.Type(typeof(JsonElement))} discriminator)")) { - if (model.Discriminator?.HasDirectDescendants == true) + writer.Line("switch (discriminator.GetString())"); + using (writer.Scope()) { - writer.Line("switch (model)"); - using (writer.Scope()) + foreach (var implementation in model.Discriminator.Implementations) { - foreach (var implementation in model.Discriminator.Implementations) - { - if (!implementation.IsDirect) - { - continue; - } - - var type = _typeFactory.CreateType(implementation.Type); - var localName = type.Name.ToVariableName(); - writer.Append("case ").AppendType(type).Space().Append(localName).Append(":").Line(); - writer.ToSerializeCall(implementation.Type, SerializationFormat.Default, _typeFactory, w => w.Append(localName)); - writer.Line("return;"); - } + writer + .Append("case ") + .Literal(implementation.Key) + .Append(": return ") + .ToDeserializeCall(implementation.Type, SerializationFormat.Default, _typeFactory, + w => w.Append("element")); + writer.SemicolonLine(); } } - - writer.Line("writer.WriteStartObject();"); - - var currentType = model; - - while (currentType != null) - { - foreach (var property in currentType.Properties) - { - using (property.Type.IsNullable ? writer.If($"model.{ property.Name} != null") : default) - { - WriteProperty(writer, property.Type, property.Format, "model." + property.Name, property.SerializedName); - } - } - - if (currentType.Inherits == null) - { - break; - } - - currentType = (ClientObject)_typeFactory.ResolveReference(currentType.Inherits); - - writer.Line(); - } - - writer.Line("writer.WriteEndObject();"); - } - - var typeText = writer.Type(cs); - using (writer.Method("internal static", typeText, "Deserialize", writer.Pair(typeof(JsonElement), "element"))) - { - if (model.Discriminator?.HasDescendants == true) - { - using (writer.If($"element.TryGetProperty(\"{model.Discriminator.SerializedName}\", out {writer.Type(typeof(JsonElement))} discriminator)")) - { - writer.Line("switch (discriminator.GetString())"); - using (writer.Scope()) - { - foreach (var implementation in model.Discriminator.Implementations) - { - writer - .Append("case ") - .Literal(implementation.Key) - .Append(": return ") - .ToDeserializeCall(implementation.Type, SerializationFormat.Default, _typeFactory, w => w.Append("element")); - writer.SemicolonLine(); - } - } - } - } - - writer.Line($"var result = new {typeText}();"); - using (writer.ForEach("var property in element.EnumerateObject()")) - { - var currentType = model; - - while (currentType != null) - { - foreach (var property in currentType.Properties) - { - using (writer.If($"property.NameEquals(\"{property.SerializedName}\")")) - { - ReadProperty(writer, property); - writer.Line("continue;"); - } - } - - if (currentType.Inherits == null) - { - break; - } - - currentType = (ClientObject)_typeFactory.ResolveReference(currentType.Inherits); - - writer.Line(); - } - } - writer.Line("return result;"); } } + + 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.Append(");").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); + } + } + + private void WriteSerialize(CodeWriter writer, ClientObject model, CSharpType cs) + { + using (writer.Method("internal static", "void", "Serialize", writer.Pair(cs, "model"), writer.Pair(typeof(Utf8JsonWriter), "writer"))) + { + if (model.Discriminator?.HasDirectDescendants == true) + { + writer.Line("switch (model)"); + using (writer.Scope()) + { + foreach (var implementation in model.Discriminator.Implementations) + { + if (!implementation.IsDirect) + { + continue; + } + + var type = _typeFactory.CreateType(implementation.Type); + var localName = type.Name.ToVariableName(); + writer.Append("case ").AppendType(type).Space().Append(localName).Append(":").Line(); + writer.ToSerializeCall(implementation.Type, SerializationFormat.Default, _typeFactory, + w => w.Append(localName)); + writer.Line("return;"); + } + } + } + + 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($"model.{property.Name} != null") : default) + { + writer.ToSerializeCall( + property.Type, + property.Format, + _typeFactory, + w => w.Append("model.").Append(property.Name), + w => w.Literal(property.SerializedName)); + } + + implementsDictionary ??= currentType.ImplementsDictionary; + } + } + + if (implementsDictionary != null) + { + using (writer.ForEach("var item in model")) + { + writer.ToSerializeCall(implementsDictionary.ValueType, SerializationFormat.Default, _typeFactory, w => w.Append("item.Value"), w => w.Append("item.Key")); + } + } + + writer.Line("writer.WriteEndObject();"); } } diff --git a/src/AutoRest.CSharp.V3/Pipeline/Modifications.cs b/src/AutoRest.CSharp.V3/Pipeline/Modifications.cs index ef4ccc61..f26efe73 100644 --- a/src/AutoRest.CSharp.V3/Pipeline/Modifications.cs +++ b/src/AutoRest.CSharp.V3/Pipeline/Modifications.cs @@ -18,6 +18,17 @@ namespace AutoRest.CSharp.V3.Pipeline.Generated public ObjectSchema() { Properties = Array.Empty(); + Parents = new Relations(); + Children = new Relations(); + } + } + + internal partial class Relations + { + public Relations() + { + Immediate = Array.Empty(); + All = Array.Empty(); } } diff --git a/src/assets/Azure.Core.Shared/JsonElementExtensions.cs b/src/assets/Azure.Core.Shared/JsonElementExtensions.cs new file mode 100644 index 00000000..72116863 --- /dev/null +++ b/src/assets/Azure.Core.Shared/JsonElementExtensions.cs @@ -0,0 +1,65 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. See License.txt in the project root for license information. + +using System; +using System.Collections.Generic; +using System.Text.Json; +using System.Xml; + +namespace Azure.Core +{ + internal static class JsonElementExtensions + { + public static object? GetObject(in this JsonElement element) + { + switch (element.ValueKind) + { + case JsonValueKind.String: + return element.GetString(); + case JsonValueKind.Number: + if (element.TryGetInt32(out var value)) + { + return value; + } + return element.GetDouble(); + case JsonValueKind.True: + return true; + case JsonValueKind.False: + return false; + case JsonValueKind.Null: + return null; + case JsonValueKind.Object: + var dictionary = new Dictionary(); + foreach (JsonProperty jsonProperty in element.EnumerateObject()) + { + dictionary.Add(jsonProperty.Name, jsonProperty.Value.GetObject()); + } + return dictionary; + case JsonValueKind.Array: + var list = new List(); + foreach (JsonElement item in element.EnumerateArray()) + { + list.Add(item.GetObject()); + } + return list.ToArray(); + default: + throw new NotSupportedException("Not supported value kind " + element.ValueKind); + } + } + + public static DateTimeOffset GetDateTimeOffset(in this JsonElement element, string format) => format switch + { + "D" => element.GetDateTimeOffset(), + "S" => element.GetDateTimeOffset(), + "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) => format switch + { + "P" => XmlConvert.ToTimeSpan(element.GetString()), + _ => throw new ArgumentException("Format is not supported", nameof(format)) + }; + } +} diff --git a/src/assets/Azure.Core.Shared/TypeFormatters.cs b/src/assets/Azure.Core.Shared/TypeFormatters.cs index bafeec85..5ea7d779 100644 --- a/src/assets/Azure.Core.Shared/TypeFormatters.cs +++ b/src/assets/Azure.Core.Shared/TypeFormatters.cs @@ -29,21 +29,6 @@ namespace Azure.Core _ => throw new ArgumentException("Format is not supported", nameof(format)) }; - public static DateTimeOffset GetDateTimeOffset(JsonElement element, string format) => format switch - { - "D" => element.GetDateTimeOffset(), - "S" => element.GetDateTimeOffset(), - "R" => DateTimeOffset.Parse(element.GetString()), - "U" => DateTimeOffset.FromUnixTimeSeconds(element.GetInt64()), - _ => throw new ArgumentException("Format is not supported", nameof(format)) - }; - - public static TimeSpan GetTimeSpan(JsonElement element, string format) => format switch - { - "P" => XmlConvert.ToTimeSpan(element.GetString()), - _ => throw new ArgumentException("Format is not supported", nameof(format)) - }; - public static string ToBase64UrlString(byte[] value) { var numWholeOrPartialInputBlocks = checked(value.Length + 2) / 3; diff --git a/src/assets/Azure.Core.Shared/Utf8JsonWriterExtensions.cs b/src/assets/Azure.Core.Shared/Utf8JsonWriterExtensions.cs index 26dfdbd9..449ca047 100644 --- a/src/assets/Azure.Core.Shared/Utf8JsonWriterExtensions.cs +++ b/src/assets/Azure.Core.Shared/Utf8JsonWriterExtensions.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. See License.txt in the project root for license information. using System; +using System.Collections.Generic; using System.Text.Json; namespace Azure.Core @@ -13,5 +14,56 @@ namespace Azure.Core public static void WriteStringValue(this Utf8JsonWriter writer, TimeSpan value, string format) => writer.WriteStringValue(TypeFormatters.ToString(value, format)); + + public static void WriteObjectValue(this Utf8JsonWriter writer, object value) + { + switch (value) + { + case null: + writer.WriteNullValue(); + break; + case int i: + writer.WriteNumberValue(i); + break; + case decimal d: + writer.WriteNumberValue(d); + break; + case double d: + writer.WriteNumberValue(d); + break; + case float f: + writer.WriteNumberValue(f); + break; + case string s: + writer.WriteStringValue(s); + break; + case bool b: + writer.WriteBooleanValue(b); + break; + case DateTimeOffset dateTimeOffset: + writer.WriteStringValue(dateTimeOffset,"S"); + break; + case IEnumerable> enumerable: + writer.WriteStartObject(); + foreach (KeyValuePair pair in enumerable) + { + writer.WritePropertyName(pair.Key); + writer.WriteObjectValue(pair.Value); + } + writer.WriteEndObject(); + break; + case IEnumerable objectEnumerable: + writer.WriteStartArray(); + foreach (object item in objectEnumerable) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + break; + + default: + throw new NotSupportedException("Not supported type " + value.GetType()); + } + } } } diff --git a/test/AutoRest.TestServer.Tests/additionalProperties.cs b/test/AutoRest.TestServer.Tests/additionalProperties.cs new file mode 100644 index 00000000..7923a75c --- /dev/null +++ b/test/AutoRest.TestServer.Tests/additionalProperties.cs @@ -0,0 +1,174 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Threading.Tasks; +using additionalProperties; +using additionalProperties.Models.V100; +using AutoRest.TestServer.Tests.Infrastructure; +using NUnit.Framework; + +namespace AutoRest.TestServer.Tests +{ + public class AdditionalPropertiesTest : TestServerTestBase + { + public AdditionalPropertiesTest(TestServerVersion version) : base(version, "additionalProperties") { } + + [Test] + [IgnoreOnTestServer(TestServerVersion.V2, "No match")] + public Task AdditionalPropertiesInProperties() => Test(async (host, pipeline) => + { + var response = await PetsOperations.CreateAPInPropertiesAsync(ClientDiagnostics, pipeline, new PetAPInProperties() + { + Id = 4, + Name = "Bunny", + AdditionalProperties = new Dictionary() + { + { "height", 5.61f }, + { "weight", 599f }, + { "footsize", 11.5f } + } + }, host); + + var value = response.Value; + Assert.AreEqual(4, value.Id); + Assert.AreEqual("Bunny", value.Name); + Assert.AreEqual(5.61f, value.AdditionalProperties["height"]); + Assert.AreEqual(599f, value.AdditionalProperties["weight"]); + Assert.AreEqual(11.5f, value.AdditionalProperties["footsize"]); + }); + + [Test] + [IgnoreOnTestServer(TestServerVersion.V2, "No match")] + public Task AdditionalPropertiesInPropertiesWithAPTypeString() => Test(async (host, pipeline) => + { + PetAPInPropertiesWithAPString parameter = new PetAPInPropertiesWithAPString() + { + Id = 5, + Name = "Funny", + OdataLocation = "westus", + AdditionalProperties = new Dictionary() + { + { "height", 5.61f }, + { "weight", 599f }, + { "footsize", 11.5f } + }, + }; + + parameter["color"] = "red"; + parameter["city"] = "Seattle"; + parameter["food"] = "tikka masala"; + + var response = await PetsOperations.CreateAPInPropertiesWithAPStringAsync(ClientDiagnostics, pipeline, parameter, host); + + var value = response.Value; + Assert.AreEqual(5, value.Id); + Assert.AreEqual("Funny", value.Name); + Assert.AreEqual("westus", value.OdataLocation); + Assert.AreEqual(5.61f, value.AdditionalProperties["height"]); + Assert.AreEqual(599f, value.AdditionalProperties["weight"]); + Assert.AreEqual(11.5f, value.AdditionalProperties["footsize"]); + + Assert.AreEqual("red", value["color"]); + Assert.AreEqual("Seattle", value["city"]); + Assert.AreEqual("tikka masala", value["food"]); + }); + + [Test] + [IgnoreOnTestServer(TestServerVersion.V2, "No match")] + public Task AdditionalPropertiesSubclass() => Test(async (host, pipeline) => + { + CatAPTrue catApTrue = new CatAPTrue() + { + Id = 1, + Name = "Lisa", + Friendly = true, + }; + + catApTrue["birthdate"] = DateTimeOffset.Parse("2017-12-13T02:29:51Z"); + catApTrue["complexProperty"] = new Dictionary() + { + {"color", "Red"} + }; + + var response = await PetsOperations.CreateCatAPTrueAsync(ClientDiagnostics, pipeline, catApTrue, host); + + var value = response.Value; + Assert.AreEqual(1, value.Id); + Assert.AreEqual("Lisa", value.Name); + Assert.AreEqual(true, value.Status); + Assert.AreEqual(true, value.Friendly); + Assert.AreEqual("2017-12-13T02:29:51Z", value["birthdate"]); + Assert.AreEqual("Red", ((Dictionary)value["complexProperty"])["color"]); + }); + + [Test] + public Task AdditionalPropertiesTrue() => Test(async (host, pipeline) => + { + PetAPTrue catApTrue = new PetAPTrue() + { + Id = 1, + Name = "Puppy", + }; + + catApTrue["birthdate"] = DateTimeOffset.Parse("2017-12-13T02:29:51Z"); + catApTrue["complexProperty"] = new Dictionary() + { + {"color", "Red"} + }; + + var response = await PetsOperations.CreateAPTrueAsync(ClientDiagnostics, pipeline, catApTrue, host); + + var value = response.Value; + Assert.AreEqual(1, value.Id); + Assert.AreEqual("Puppy", value.Name); + Assert.AreEqual(true, value.Status); + Assert.AreEqual("2017-12-13T02:29:51Z", value["birthdate"]); + Assert.AreEqual("Red", ((Dictionary)value["complexProperty"])["color"]); + }); + + [Test] + [Ignore("https://github.com/Azure/autorest.csharp/issues/360")] + public Task AdditionalPropertiesTypeObject() => Test(async (host, pipeline) => + { + PetAPObject petApObject = new PetAPObject() + { + Id = 1, + Name = "Puppy", + }; + + petApObject["birthdate"] = DateTimeOffset.Parse("2017-12-13T02:29:51Z"); + petApObject["complexProperty"] = new Dictionary() + { + {"color", "Red"} + }; + + await PetsOperations.CreateAPObjectAsync(ClientDiagnostics, pipeline, petApObject, host); + + }); + + [Test] + public Task AdditionalPropertiesTypeString() => Test(async (host, pipeline) => + { + PetAPString petApObject = new PetAPString() + { + Id = 3, + Name = "Tommy" + }; + + petApObject["weight"] = "10 kg"; + petApObject["color"] = "red"; + petApObject["city"] = "Bombay"; + + var response = await PetsOperations.CreateAPStringAsync(ClientDiagnostics, pipeline, petApObject, host); + var value = response.Value; + Assert.AreEqual(3, value.Id); + Assert.AreEqual("Tommy", value.Name); + Assert.AreEqual(true, value.Status); + Assert.AreEqual("red", value["color"]); + Assert.AreEqual("10 kg", value["weight"]); + Assert.AreEqual("Bombay", value["city"]); + }); + } +} diff --git a/test/AutoRest.TestServer.Tests/body-complex.cs b/test/AutoRest.TestServer.Tests/body-complex.cs index 670bc79e..c11f6036 100644 --- a/test/AutoRest.TestServer.Tests/body-complex.cs +++ b/test/AutoRest.TestServer.Tests/body-complex.cs @@ -548,7 +548,6 @@ namespace AutoRest.TestServer.Tests }); [Test] - // TODO: Passes but without additional properties https://github.com/Azure/autorest.csharp/issues/348 public Task GetComplexPolymorphismComplicated() => Test(async (host, pipeline) => { var result = await PolymorphismOperations.GetComplicatedAsync(ClientDiagnostics, pipeline, host); @@ -585,97 +584,62 @@ namespace AutoRest.TestServer.Tests Assert.AreEqual(5, goblin.Jawsize); Assert.AreEqual("pinkish-gray", goblin.Color.ToString()); - /* - var rawSalmon = { - 'fishtype': 'smart_salmon', - 'location': 'alaska', - 'iswild': true, - 'species': 'king', - 'additionalProperty1': 1, - 'additionalProperty2': false, - 'additionalProperty3': "hello", - 'additionalProperty4': { a: 1, b: 2 }, - 'additionalProperty5': [1, 3], - 'length': 1.0, - 'siblings': [ - { - 'fishtype': 'shark', - 'age': 6, - 'birthday': '2012-01-05T01:00:00Z', - 'length': 20.0, - 'species': 'predator', - }, - { - 'fishtype': 'sawshark', - 'age': 105, - 'birthday': '1900-01-05T01:00:00Z', - 'length': 10.0, - 'picture': new Buffer([255, 255, 255, 255, 254]).toString('base64'), - 'species': 'dangerous', - }, - { - 'fishtype': 'goblin', - 'age': 1, - 'birthday': '2015-08-08T00:00:00Z', - 'length': 30.0, - 'species': 'scary', - 'jawsize': 5, - 'color':'pinkish-gray' - } - ] - }; - */ + Assert.AreEqual(1, value["additionalProperty1"]); + Assert.AreEqual(false, value["additionalProperty2"]); + Assert.AreEqual("hello", value["additionalProperty3"]); + Assert.AreEqual(new Dictionary() + { + {"a", 1}, + {"b", 2 } + }, value["additionalProperty4"]); + + Assert.AreEqual(new object[] { 1, 3 }, value["additionalProperty5"]); }); [Test] - [Ignore("https://github.com/Azure/autorest.csharp/issues/348")] + [IgnoreOnTestServer(TestServerVersion.V2, "No match")] public Task PutComplexPolymorphismComplicated() => TestStatus(async (host, pipeline) => { - /* - var rawSalmon = { - 'fishtype': 'smart_salmon', - 'location': 'alaska', - 'iswild': true, - 'species': 'king', - 'additionalProperty1': 1, - 'additionalProperty2': false, - 'additionalProperty3': "hello", - 'additionalProperty4': { a: 1, b: 2 }, - 'additionalProperty5': [1, 3], - 'length': 1.0, - 'siblings': [ - { - 'fishtype': 'shark', - 'age': 6, - 'birthday': '2012-01-05T01:00:00Z', - 'length': 20.0, - 'species': 'predator', - }, - { - 'fishtype': 'sawshark', - 'age': 105, - 'birthday': '1900-01-05T01:00:00Z', - 'length': 10.0, - 'picture': new Buffer([255, 255, 255, 255, 254]).toString('base64'), - 'species': 'dangerous', - }, - { - 'fishtype': 'goblin', - 'age': 1, - 'birthday': '2015-08-08T00:00:00Z', - 'length': 30.0, - 'species': 'scary', - 'jawsize': 5, - 'color':'pinkish-gray' - } - ] - }; - */ - var value = new Salmon + var value = new SmartSalmon() { - //Fishtype = "smart_salmon", - Location = "alaska" + Location = "alaska", + Iswild = true, + Species = "king", + Length = 1, + Siblings = new[] + { + new Shark + { + Age = 6, + Birthday = DateTimeOffset.Parse("2012-01-05T01:00:00Z"), + Length = 20, + Species = "predator" + }, + new Sawshark() + { + Age = 105, + Birthday = DateTimeOffset.Parse("1900-01-05T01:00:00Z"), + Picture = new byte[] {255, 255, 255, 255, 254}, + Length = 10, + Species = "dangerous" + }, + new Goblinshark() + { + Age = 1, + Birthday = DateTimeOffset.Parse("2015-08-08T00:00:00Z"), + Length = 30, + Species = "scary", + Jawsize = 5, + Color = "pinkish-gray" + } + } }; + value["additionalProperty1"] = 1; + value["additionalProperty2"] = false; + value["additionalProperty3"] = "hello"; + value["additionalProperty4"] = new Dictionary() {{"a", 1}, {"b", 2}}; + value["additionalProperty5"] = new object[] {1, 3}; + return await PolymorphismOperations.PutComplicatedAsync(ClientDiagnostics, pipeline, value, host); }); diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/CatAPTrue.Serialization.cs b/test/TestServerProjects/additionalProperties/Generated/Models/CatAPTrue.Serialization.cs new file mode 100644 index 00000000..4b09dfb4 --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Models/CatAPTrue.Serialization.cs @@ -0,0 +1,80 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; +using Azure.Core; + +namespace additionalProperties.Models.V100 +{ + public partial class CatAPTrueSerializer + { + internal static void Serialize(CatAPTrue model, Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (model.Friendly != null) + { + writer.WritePropertyName("friendly"); + writer.WriteBooleanValue(model.Friendly.Value); + } + writer.WritePropertyName("id"); + writer.WriteNumberValue(model.Id); + if (model.Name != null) + { + writer.WritePropertyName("name"); + writer.WriteStringValue(model.Name); + } + if (model.Status != null) + { + writer.WritePropertyName("status"); + writer.WriteBooleanValue(model.Status.Value); + } + foreach (var item in model) + { + writer.WritePropertyName(item.Key); + writer.WriteObjectValue(item.Value); + } + writer.WriteEndObject(); + } + internal static CatAPTrue Deserialize(JsonElement element) + { + var result = new CatAPTrue(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("friendly")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Friendly = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("id")) + { + result.Id = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("name")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Name = property.Value.GetString(); + continue; + } + if (property.NameEquals("status")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Status = property.Value.GetBoolean(); + continue; + } + result.Add(property.Name, property.Value.GetObject()); + } + return result; + } + } +} diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/CatAPTrue.cs b/test/TestServerProjects/additionalProperties/Generated/Models/CatAPTrue.cs new file mode 100644 index 00000000..5b969221 --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Models/CatAPTrue.cs @@ -0,0 +1,10 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace additionalProperties.Models.V100 +{ + public partial class CatAPTrue : PetAPTrue + { + public bool? Friendly { get; set; } + } +} diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/additionalProperties/Generated/Models/Error.Serialization.cs new file mode 100644 index 00000000..7b0ce3d0 --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Models/Error.Serialization.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; +using Azure.Core; + +namespace additionalProperties.Models.V100 +{ + public partial class ErrorSerializer + { + internal static void Serialize(Error model, Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (model.Status != null) + { + writer.WritePropertyName("status"); + writer.WriteNumberValue(model.Status.Value); + } + if (model.Message != null) + { + writer.WritePropertyName("message"); + writer.WriteStringValue(model.Message); + } + writer.WriteEndObject(); + } + internal static Error Deserialize(JsonElement element) + { + var result = new Error(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("status")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Status = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("message")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Message = property.Value.GetString(); + continue; + } + } + return result; + } + } +} diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/Error.cs b/test/TestServerProjects/additionalProperties/Generated/Models/Error.cs new file mode 100644 index 00000000..0bcb7567 --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Models/Error.cs @@ -0,0 +1,11 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +namespace additionalProperties.Models.V100 +{ + public partial class Error + { + public int? Status { get; set; } + public string? Message { get; set; } + } +} diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInProperties.Serialization.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInProperties.Serialization.cs new file mode 100644 index 00000000..9cbb2d08 --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInProperties.Serialization.cs @@ -0,0 +1,85 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace additionalProperties.Models.V100 +{ + public partial class PetAPInPropertiesSerializer + { + internal static void Serialize(PetAPInProperties model, Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("id"); + writer.WriteNumberValue(model.Id); + if (model.Name != null) + { + writer.WritePropertyName("name"); + writer.WriteStringValue(model.Name); + } + if (model.Status != null) + { + writer.WritePropertyName("status"); + writer.WriteBooleanValue(model.Status.Value); + } + if (model.AdditionalProperties != null) + { + writer.WritePropertyName("additionalProperties"); + writer.WriteStartObject(); + foreach (var item in model.AdditionalProperties) + { + writer.WritePropertyName(item.Key); + writer.WriteNumberValue(item.Value); + } + writer.WriteEndObject(); + } + writer.WriteEndObject(); + } + internal static PetAPInProperties Deserialize(JsonElement element) + { + var result = new PetAPInProperties(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id")) + { + result.Id = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("name")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Name = property.Value.GetString(); + continue; + } + if (property.NameEquals("status")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Status = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("additionalProperties")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.AdditionalProperties = new Dictionary(); + foreach (var item in property.Value.EnumerateObject()) + { + result.AdditionalProperties.Add(item.Name, item.Value.GetSingle()); + } + continue; + } + } + return result; + } + } +} diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInProperties.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInProperties.cs new file mode 100644 index 00000000..0e17c841 --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInProperties.cs @@ -0,0 +1,15 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections.Generic; + +namespace additionalProperties.Models.V100 +{ + public partial class PetAPInProperties + { + public int Id { get; set; } + public string? Name { get; set; } + public bool? Status { get; internal set; } + public IDictionary? AdditionalProperties { get; set; } + } +} diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInPropertiesWithAPString.Serialization.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInPropertiesWithAPString.Serialization.cs new file mode 100644 index 00000000..47bc705a --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInPropertiesWithAPString.Serialization.cs @@ -0,0 +1,98 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections.Generic; +using System.Text.Json; +using Azure.Core; + +namespace additionalProperties.Models.V100 +{ + public partial class PetAPInPropertiesWithAPStringSerializer + { + internal static void Serialize(PetAPInPropertiesWithAPString model, Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("id"); + writer.WriteNumberValue(model.Id); + if (model.Name != null) + { + writer.WritePropertyName("name"); + writer.WriteStringValue(model.Name); + } + if (model.Status != null) + { + writer.WritePropertyName("status"); + writer.WriteBooleanValue(model.Status.Value); + } + writer.WritePropertyName("@odata.location"); + writer.WriteStringValue(model.OdataLocation); + if (model.AdditionalProperties != null) + { + writer.WritePropertyName("additionalProperties"); + writer.WriteStartObject(); + foreach (var item in model.AdditionalProperties) + { + writer.WritePropertyName(item.Key); + writer.WriteNumberValue(item.Value); + } + writer.WriteEndObject(); + } + foreach (var item in model) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + internal static PetAPInPropertiesWithAPString Deserialize(JsonElement element) + { + var result = new PetAPInPropertiesWithAPString(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id")) + { + result.Id = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("name")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Name = property.Value.GetString(); + continue; + } + if (property.NameEquals("status")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Status = property.Value.GetBoolean(); + continue; + } + if (property.NameEquals("@odata.location")) + { + result.OdataLocation = property.Value.GetString(); + continue; + } + if (property.NameEquals("additionalProperties")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.AdditionalProperties = new Dictionary(); + foreach (var item in property.Value.EnumerateObject()) + { + result.AdditionalProperties.Add(item.Name, item.Value.GetSingle()); + } + continue; + } + result.Add(property.Name, property.Value.GetString()); + } + return result; + } + } +} diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInPropertiesWithAPString.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInPropertiesWithAPString.cs new file mode 100644 index 00000000..b28b9c7c --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPInPropertiesWithAPString.cs @@ -0,0 +1,38 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections; +using System.Collections.Generic; + +namespace additionalProperties.Models.V100 +{ + public partial class PetAPInPropertiesWithAPString : IDictionary + { + public int Id { get; set; } + public string? Name { get; set; } + public bool? Status { get; internal set; } + public string OdataLocation { get; set; } + public IDictionary? AdditionalProperties { get; set; } + private readonly IDictionary _additionalProperties = new Dictionary(); + public IEnumerator> GetEnumerator() => _additionalProperties.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => _additionalProperties.GetEnumerator(); + public ICollection Keys => _additionalProperties.Keys; + public ICollection Values => _additionalProperties.Values; + public bool TryGetValue(string key, out string value) => _additionalProperties.TryGetValue(key, out value); + public void Add(string key, string value) => _additionalProperties.Add(key, value); + public bool ContainsKey(string key) => _additionalProperties.ContainsKey(key); + public bool Remove(string key) => _additionalProperties.Remove(key); + public int Count => _additionalProperties.Count; + bool ICollection>.IsReadOnly => _additionalProperties.IsReadOnly; + void ICollection>.Add(KeyValuePair value) => _additionalProperties.Add(value); + bool ICollection>.Remove(KeyValuePair value) => _additionalProperties.Remove(value); + bool ICollection>.Contains(KeyValuePair value) => _additionalProperties.Contains(value); + void ICollection>.CopyTo(KeyValuePair[] destination, int offset) => _additionalProperties.CopyTo(destination, offset); + void ICollection>.Clear() => _additionalProperties.Clear(); + public string this[string key] + { + get => _additionalProperties[key]; + set => _additionalProperties[key] = value; + } + } +} diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPObject.Serialization.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPObject.Serialization.cs new file mode 100644 index 00000000..a5ce2b98 --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPObject.Serialization.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; +using Azure.Core; + +namespace additionalProperties.Models.V100 +{ + public partial class PetAPObjectSerializer + { + internal static void Serialize(PetAPObject model, Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("id"); + writer.WriteNumberValue(model.Id); + if (model.Name != null) + { + writer.WritePropertyName("name"); + writer.WriteStringValue(model.Name); + } + if (model.Status != null) + { + writer.WritePropertyName("status"); + writer.WriteBooleanValue(model.Status.Value); + } + foreach (var item in model) + { + writer.WritePropertyName(item.Key); + writer.WriteObjectValue(item.Value); + } + writer.WriteEndObject(); + } + internal static PetAPObject Deserialize(JsonElement element) + { + var result = new PetAPObject(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id")) + { + result.Id = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("name")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Name = property.Value.GetString(); + continue; + } + if (property.NameEquals("status")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Status = property.Value.GetBoolean(); + continue; + } + result.Add(property.Name, property.Value.GetObject()); + } + return result; + } + } +} diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPObject.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPObject.cs new file mode 100644 index 00000000..b8ad4476 --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPObject.cs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections; +using System.Collections.Generic; + +namespace additionalProperties.Models.V100 +{ + public partial class PetAPObject : IDictionary + { + public int Id { get; set; } + public string? Name { get; set; } + public bool? Status { get; internal set; } + private readonly IDictionary _additionalProperties = new Dictionary(); + public IEnumerator> GetEnumerator() => _additionalProperties.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => _additionalProperties.GetEnumerator(); + public ICollection Keys => _additionalProperties.Keys; + public ICollection Values => _additionalProperties.Values; + public bool TryGetValue(string key, out object value) => _additionalProperties.TryGetValue(key, out value); + public void Add(string key, object value) => _additionalProperties.Add(key, value); + public bool ContainsKey(string key) => _additionalProperties.ContainsKey(key); + public bool Remove(string key) => _additionalProperties.Remove(key); + public int Count => _additionalProperties.Count; + bool ICollection>.IsReadOnly => _additionalProperties.IsReadOnly; + void ICollection>.Add(KeyValuePair value) => _additionalProperties.Add(value); + bool ICollection>.Remove(KeyValuePair value) => _additionalProperties.Remove(value); + bool ICollection>.Contains(KeyValuePair value) => _additionalProperties.Contains(value); + void ICollection>.CopyTo(KeyValuePair[] destination, int offset) => _additionalProperties.CopyTo(destination, offset); + void ICollection>.Clear() => _additionalProperties.Clear(); + public object this[string key] + { + get => _additionalProperties[key]; + set => _additionalProperties[key] = value; + } + } +} diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPString.Serialization.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPString.Serialization.cs new file mode 100644 index 00000000..72bcda1e --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPString.Serialization.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; +using Azure.Core; + +namespace additionalProperties.Models.V100 +{ + public partial class PetAPStringSerializer + { + internal static void Serialize(PetAPString model, Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("id"); + writer.WriteNumberValue(model.Id); + if (model.Name != null) + { + writer.WritePropertyName("name"); + writer.WriteStringValue(model.Name); + } + if (model.Status != null) + { + writer.WritePropertyName("status"); + writer.WriteBooleanValue(model.Status.Value); + } + foreach (var item in model) + { + writer.WritePropertyName(item.Key); + writer.WriteStringValue(item.Value); + } + writer.WriteEndObject(); + } + internal static PetAPString Deserialize(JsonElement element) + { + var result = new PetAPString(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id")) + { + result.Id = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("name")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Name = property.Value.GetString(); + continue; + } + if (property.NameEquals("status")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Status = property.Value.GetBoolean(); + continue; + } + result.Add(property.Name, property.Value.GetString()); + } + return result; + } + } +} diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPString.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPString.cs new file mode 100644 index 00000000..85bdce5d --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPString.cs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections; +using System.Collections.Generic; + +namespace additionalProperties.Models.V100 +{ + public partial class PetAPString : IDictionary + { + public int Id { get; set; } + public string? Name { get; set; } + public bool? Status { get; internal set; } + private readonly IDictionary _additionalProperties = new Dictionary(); + public IEnumerator> GetEnumerator() => _additionalProperties.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => _additionalProperties.GetEnumerator(); + public ICollection Keys => _additionalProperties.Keys; + public ICollection Values => _additionalProperties.Values; + public bool TryGetValue(string key, out string value) => _additionalProperties.TryGetValue(key, out value); + public void Add(string key, string value) => _additionalProperties.Add(key, value); + public bool ContainsKey(string key) => _additionalProperties.ContainsKey(key); + public bool Remove(string key) => _additionalProperties.Remove(key); + public int Count => _additionalProperties.Count; + bool ICollection>.IsReadOnly => _additionalProperties.IsReadOnly; + void ICollection>.Add(KeyValuePair value) => _additionalProperties.Add(value); + bool ICollection>.Remove(KeyValuePair value) => _additionalProperties.Remove(value); + bool ICollection>.Contains(KeyValuePair value) => _additionalProperties.Contains(value); + void ICollection>.CopyTo(KeyValuePair[] destination, int offset) => _additionalProperties.CopyTo(destination, offset); + void ICollection>.Clear() => _additionalProperties.Clear(); + public string this[string key] + { + get => _additionalProperties[key]; + set => _additionalProperties[key] = value; + } + } +} diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPTrue.Serialization.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPTrue.Serialization.cs new file mode 100644 index 00000000..f277f64d --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPTrue.Serialization.cs @@ -0,0 +1,66 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Text.Json; +using Azure.Core; + +namespace additionalProperties.Models.V100 +{ + public partial class PetAPTrueSerializer + { + internal static void Serialize(PetAPTrue model, Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("id"); + writer.WriteNumberValue(model.Id); + if (model.Name != null) + { + writer.WritePropertyName("name"); + writer.WriteStringValue(model.Name); + } + if (model.Status != null) + { + writer.WritePropertyName("status"); + writer.WriteBooleanValue(model.Status.Value); + } + foreach (var item in model) + { + writer.WritePropertyName(item.Key); + writer.WriteObjectValue(item.Value); + } + writer.WriteEndObject(); + } + internal static PetAPTrue Deserialize(JsonElement element) + { + var result = new PetAPTrue(); + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("id")) + { + result.Id = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("name")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Name = property.Value.GetString(); + continue; + } + if (property.NameEquals("status")) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + result.Status = property.Value.GetBoolean(); + continue; + } + result.Add(property.Name, property.Value.GetObject()); + } + return result; + } + } +} diff --git a/test/TestServerProjects/additionalProperties/Generated/Models/PetAPTrue.cs b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPTrue.cs new file mode 100644 index 00000000..6a806108 --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Models/PetAPTrue.cs @@ -0,0 +1,36 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.Collections; +using System.Collections.Generic; + +namespace additionalProperties.Models.V100 +{ + public partial class PetAPTrue : IDictionary + { + public int Id { get; set; } + public string? Name { get; set; } + public bool? Status { get; internal set; } + private readonly IDictionary _additionalProperties = new Dictionary(); + public IEnumerator> GetEnumerator() => _additionalProperties.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => _additionalProperties.GetEnumerator(); + public ICollection Keys => _additionalProperties.Keys; + public ICollection Values => _additionalProperties.Values; + public bool TryGetValue(string key, out object value) => _additionalProperties.TryGetValue(key, out value); + public void Add(string key, object value) => _additionalProperties.Add(key, value); + public bool ContainsKey(string key) => _additionalProperties.ContainsKey(key); + public bool Remove(string key) => _additionalProperties.Remove(key); + public int Count => _additionalProperties.Count; + bool ICollection>.IsReadOnly => _additionalProperties.IsReadOnly; + void ICollection>.Add(KeyValuePair value) => _additionalProperties.Add(value); + bool ICollection>.Remove(KeyValuePair value) => _additionalProperties.Remove(value); + bool ICollection>.Contains(KeyValuePair value) => _additionalProperties.Contains(value); + void ICollection>.CopyTo(KeyValuePair[] destination, int offset) => _additionalProperties.CopyTo(destination, offset); + void ICollection>.Clear() => _additionalProperties.Clear(); + public object this[string key] + { + get => _additionalProperties[key]; + set => _additionalProperties[key] = value; + } + } +} diff --git a/test/TestServerProjects/additionalProperties/Generated/Operations/PetsOperations.cs b/test/TestServerProjects/additionalProperties/Generated/Operations/PetsOperations.cs new file mode 100644 index 00000000..28c594a1 --- /dev/null +++ b/test/TestServerProjects/additionalProperties/Generated/Operations/PetsOperations.cs @@ -0,0 +1,276 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Text.Json; +using System.Threading; +using System.Threading.Tasks; +using additionalProperties.Models.V100; +using Azure; +using Azure.Core; +using Azure.Core.Pipeline; + +namespace additionalProperties +{ + internal static class PetsOperations + { + public static async ValueTask> CreateAPTrueAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, PetAPTrue createParameters, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (createParameters == null) + { + throw new ArgumentNullException(nameof(createParameters)); + } + + using var scope = clientDiagnostics.CreateScope("additionalProperties.CreateAPTrue"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/additionalProperties/true", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + PetAPTrueSerializer.Serialize(createParameters, writer); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + { + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + var value = PetAPTrueSerializer.Deserialize(document.RootElement); + return Response.FromValue(value, response); + } + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> CreateCatAPTrueAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, CatAPTrue createParameters, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (createParameters == null) + { + throw new ArgumentNullException(nameof(createParameters)); + } + + using var scope = clientDiagnostics.CreateScope("additionalProperties.CreateCatAPTrue"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/additionalProperties/true-subclass", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + CatAPTrueSerializer.Serialize(createParameters, writer); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + { + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + var value = CatAPTrueSerializer.Deserialize(document.RootElement); + return Response.FromValue(value, response); + } + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> CreateAPObjectAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, PetAPObject createParameters, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (createParameters == null) + { + throw new ArgumentNullException(nameof(createParameters)); + } + + using var scope = clientDiagnostics.CreateScope("additionalProperties.CreateAPObject"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/additionalProperties/type/object", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + PetAPObjectSerializer.Serialize(createParameters, writer); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + { + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + var value = PetAPObjectSerializer.Deserialize(document.RootElement); + return Response.FromValue(value, response); + } + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> CreateAPStringAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, PetAPString createParameters, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (createParameters == null) + { + throw new ArgumentNullException(nameof(createParameters)); + } + + using var scope = clientDiagnostics.CreateScope("additionalProperties.CreateAPString"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/additionalProperties/type/string", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + PetAPStringSerializer.Serialize(createParameters, writer); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + { + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + var value = PetAPStringSerializer.Deserialize(document.RootElement); + return Response.FromValue(value, response); + } + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> CreateAPInPropertiesAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, PetAPInProperties createParameters, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (createParameters == null) + { + throw new ArgumentNullException(nameof(createParameters)); + } + + using var scope = clientDiagnostics.CreateScope("additionalProperties.CreateAPInProperties"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/additionalProperties/in/properties", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + PetAPInPropertiesSerializer.Serialize(createParameters, writer); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + { + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + var value = PetAPInPropertiesSerializer.Deserialize(document.RootElement); + return Response.FromValue(value, response); + } + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + public static async ValueTask> CreateAPInPropertiesWithAPStringAsync(ClientDiagnostics clientDiagnostics, HttpPipeline pipeline, PetAPInPropertiesWithAPString createParameters, string host = "http://localhost:3000", CancellationToken cancellationToken = default) + { + if (host == null) + { + throw new ArgumentNullException(nameof(host)); + } + if (createParameters == null) + { + throw new ArgumentNullException(nameof(createParameters)); + } + + using var scope = clientDiagnostics.CreateScope("additionalProperties.CreateAPInPropertiesWithAPString"); + scope.Start(); + try + { + var request = pipeline.CreateRequest(); + request.Method = RequestMethod.Put; + request.Uri.Reset(new Uri($"{host}")); + request.Uri.AppendPath("/additionalProperties/in/properties/with/additionalProperties/string", false); + request.Headers.Add("Content-Type", "application/json"); + using var content = new Utf8JsonRequestContent(); + var writer = content.JsonWriter; + PetAPInPropertiesWithAPStringSerializer.Serialize(createParameters, writer); + request.Content = content; + var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); + switch (response.Status) + { + case 200: + { + using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); + var value = PetAPInPropertiesWithAPStringSerializer.Deserialize(document.RootElement); + return Response.FromValue(value, response); + } + default: + throw new Exception(); + } + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + } +} diff --git a/test/TestServerProjects/additionalProperties/additionalProperties.csproj b/test/TestServerProjects/additionalProperties/additionalProperties.csproj new file mode 100644 index 00000000..409c8953 --- /dev/null +++ b/test/TestServerProjects/additionalProperties/additionalProperties.csproj @@ -0,0 +1,15 @@ + + + + netstandard2.0 + true + annotations + + + + + + + + + diff --git a/test/TestServerProjects/body-boolean/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-boolean/Generated/Models/Error.Serialization.cs index c7306cc9..5f6ac97f 100644 --- a/test/TestServerProjects/body-boolean/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-boolean/Generated/Models/Error.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_boolean.Models.V100 { diff --git a/test/TestServerProjects/body-complex/Generated/Models/ArrayWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/ArrayWrapper.Serialization.cs index 14225ec9..d1a61f0a 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/ArrayWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/ArrayWrapper.Serialization.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -13,7 +14,8 @@ namespace body_complex.Models.V20160229 writer.WriteStartObject(); if (model.Array != null) { - writer.WriteStartArray("array"); + writer.WritePropertyName("array"); + writer.WriteStartArray(); foreach (var item in model.Array) { writer.WriteStringValue(item); diff --git a/test/TestServerProjects/body-complex/Generated/Models/Basic.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Basic.Serialization.cs index 3e39bf80..29b4d47f 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Basic.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Basic.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { diff --git a/test/TestServerProjects/body-complex/Generated/Models/BooleanWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/BooleanWrapper.Serialization.cs index 070fe681..1b27dc8d 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/BooleanWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/BooleanWrapper.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { diff --git a/test/TestServerProjects/body-complex/Generated/Models/ByteWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/ByteWrapper.Serialization.cs index 0a822895..8ef463c9 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/ByteWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/ByteWrapper.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { diff --git a/test/TestServerProjects/body-complex/Generated/Models/Cat.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Cat.Serialization.cs index 09bde3b9..951e144c 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Cat.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Cat.Serialization.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -18,14 +19,14 @@ namespace body_complex.Models.V20160229 } if (model.Hates != null) { - writer.WriteStartArray("hates"); + writer.WritePropertyName("hates"); + writer.WriteStartArray(); foreach (var item in model.Hates) { DogSerializer.Serialize(item, writer); } writer.WriteEndArray(); } - if (model.Id != null) { writer.WritePropertyName("id"); @@ -65,7 +66,6 @@ namespace body_complex.Models.V20160229 } continue; } - if (property.NameEquals("id")) { if (property.Value.ValueKind == JsonValueKind.Null) diff --git a/test/TestServerProjects/body-complex/Generated/Models/Cookiecuttershark.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Cookiecuttershark.Serialization.cs index 8a523877..adce71dd 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Cookiecuttershark.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Cookiecuttershark.Serialization.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -11,15 +12,13 @@ namespace body_complex.Models.V20160229 internal static void Serialize(Cookiecuttershark model, Utf8JsonWriter writer) { writer.WriteStartObject(); - if (model.Age != null) { writer.WritePropertyName("age"); writer.WriteNumberValue(model.Age.Value); } writer.WritePropertyName("birthday"); - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, model.Birthday, "S"); - + writer.WriteStringValue(model.Birthday, "S"); writer.WritePropertyName("fishtype"); writer.WriteStringValue(model.Fishtype); if (model.Species != null) @@ -31,7 +30,8 @@ namespace body_complex.Models.V20160229 writer.WriteNumberValue(model.Length); if (model.Siblings != null) { - writer.WriteStartArray("siblings"); + writer.WritePropertyName("siblings"); + writer.WriteStartArray(); foreach (var item in model.Siblings) { FishSerializer.Serialize(item, writer); @@ -45,7 +45,6 @@ namespace body_complex.Models.V20160229 var result = new Cookiecuttershark(); foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("age")) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -57,10 +56,9 @@ namespace body_complex.Models.V20160229 } if (property.NameEquals("birthday")) { - result.Birthday = Azure.Core.TypeFormatters.GetDateTimeOffset(property.Value, "S"); + result.Birthday = property.Value.GetDateTimeOffset("S"); continue; } - if (property.NameEquals("fishtype")) { result.Fishtype = property.Value.GetString(); diff --git a/test/TestServerProjects/body-complex/Generated/Models/DateWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DateWrapper.Serialization.cs index 54c4becf..0d7af13a 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DateWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DateWrapper.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -13,12 +14,12 @@ namespace body_complex.Models.V20160229 if (model.Field != null) { writer.WritePropertyName("field"); - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, model.Field.Value, "D"); + writer.WriteStringValue(model.Field.Value, "D"); } if (model.Leap != null) { writer.WritePropertyName("leap"); - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, model.Leap.Value, "D"); + writer.WriteStringValue(model.Leap.Value, "D"); } writer.WriteEndObject(); } @@ -33,7 +34,7 @@ namespace body_complex.Models.V20160229 { continue; } - result.Field = Azure.Core.TypeFormatters.GetDateTimeOffset(property.Value, "D"); + result.Field = property.Value.GetDateTimeOffset("D"); continue; } if (property.NameEquals("leap")) @@ -42,7 +43,7 @@ namespace body_complex.Models.V20160229 { continue; } - result.Leap = Azure.Core.TypeFormatters.GetDateTimeOffset(property.Value, "D"); + result.Leap = property.Value.GetDateTimeOffset("D"); continue; } } diff --git a/test/TestServerProjects/body-complex/Generated/Models/DatetimeWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DatetimeWrapper.Serialization.cs index 60ce48b9..22dd082c 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DatetimeWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DatetimeWrapper.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -13,12 +14,12 @@ namespace body_complex.Models.V20160229 if (model.Field != null) { writer.WritePropertyName("field"); - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, model.Field.Value, "S"); + writer.WriteStringValue(model.Field.Value, "S"); } if (model.Now != null) { writer.WritePropertyName("now"); - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, model.Now.Value, "S"); + writer.WriteStringValue(model.Now.Value, "S"); } writer.WriteEndObject(); } @@ -33,7 +34,7 @@ namespace body_complex.Models.V20160229 { continue; } - result.Field = Azure.Core.TypeFormatters.GetDateTimeOffset(property.Value, "S"); + result.Field = property.Value.GetDateTimeOffset("S"); continue; } if (property.NameEquals("now")) @@ -42,7 +43,7 @@ namespace body_complex.Models.V20160229 { continue; } - result.Now = Azure.Core.TypeFormatters.GetDateTimeOffset(property.Value, "S"); + result.Now = property.Value.GetDateTimeOffset("S"); continue; } } diff --git a/test/TestServerProjects/body-complex/Generated/Models/Datetimerfc1123Wrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Datetimerfc1123Wrapper.Serialization.cs index 2c983b08..6a4ee5cb 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Datetimerfc1123Wrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Datetimerfc1123Wrapper.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -13,12 +14,12 @@ namespace body_complex.Models.V20160229 if (model.Field != null) { writer.WritePropertyName("field"); - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, model.Field.Value, "R"); + writer.WriteStringValue(model.Field.Value, "R"); } if (model.Now != null) { writer.WritePropertyName("now"); - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, model.Now.Value, "R"); + writer.WriteStringValue(model.Now.Value, "R"); } writer.WriteEndObject(); } @@ -33,7 +34,7 @@ namespace body_complex.Models.V20160229 { continue; } - result.Field = Azure.Core.TypeFormatters.GetDateTimeOffset(property.Value, "R"); + result.Field = property.Value.GetDateTimeOffset("R"); continue; } if (property.NameEquals("now")) @@ -42,7 +43,7 @@ namespace body_complex.Models.V20160229 { continue; } - result.Now = Azure.Core.TypeFormatters.GetDateTimeOffset(property.Value, "R"); + result.Now = property.Value.GetDateTimeOffset("R"); continue; } } diff --git a/test/TestServerProjects/body-complex/Generated/Models/DictionaryWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DictionaryWrapper.Serialization.cs index d926435f..b0001d65 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DictionaryWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DictionaryWrapper.Serialization.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -13,7 +14,8 @@ namespace body_complex.Models.V20160229 writer.WriteStartObject(); if (model.DefaultProgram != null) { - writer.WriteStartObject("defaultProgram"); + writer.WritePropertyName("defaultProgram"); + writer.WriteStartObject(); foreach (var item in model.DefaultProgram) { writer.WritePropertyName(item.Key); diff --git a/test/TestServerProjects/body-complex/Generated/Models/Dog.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Dog.Serialization.cs index 08e93944..370f0206 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Dog.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Dog.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -15,7 +16,6 @@ namespace body_complex.Models.V20160229 writer.WritePropertyName("food"); writer.WriteStringValue(model.Food); } - if (model.Id != null) { writer.WritePropertyName("id"); @@ -42,7 +42,6 @@ namespace body_complex.Models.V20160229 result.Food = property.Value.GetString(); continue; } - if (property.NameEquals("id")) { if (property.Value.ValueKind == JsonValueKind.Null) diff --git a/test/TestServerProjects/body-complex/Generated/Models/DotFish.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DotFish.Serialization.cs index 4a39fb58..0574f008 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DotFish.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DotFish.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { diff --git a/test/TestServerProjects/body-complex/Generated/Models/DotFishMarket.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DotFishMarket.Serialization.cs index 00b479da..32644cdf 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DotFishMarket.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DotFishMarket.Serialization.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -18,7 +19,8 @@ namespace body_complex.Models.V20160229 } if (model.Salmons != null) { - writer.WriteStartArray("salmons"); + writer.WritePropertyName("salmons"); + writer.WriteStartArray(); foreach (var item in model.Salmons) { DotSalmonSerializer.Serialize(item, writer); @@ -32,7 +34,8 @@ namespace body_complex.Models.V20160229 } if (model.Fishes != null) { - writer.WriteStartArray("fishes"); + writer.WritePropertyName("fishes"); + writer.WriteStartArray(); foreach (var item in model.Fishes) { DotFishSerializer.Serialize(item, writer); diff --git a/test/TestServerProjects/body-complex/Generated/Models/DotSalmon.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DotSalmon.Serialization.cs index e56f3725..1a9bdeb3 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DotSalmon.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DotSalmon.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -20,7 +21,6 @@ namespace body_complex.Models.V20160229 writer.WritePropertyName("iswild"); writer.WriteBooleanValue(model.Iswild.Value); } - writer.WritePropertyName("fish.type"); writer.WriteStringValue(model.FishType); if (model.Species != null) @@ -53,7 +53,6 @@ namespace body_complex.Models.V20160229 result.Iswild = property.Value.GetBoolean(); continue; } - if (property.NameEquals("fish.type")) { result.FishType = property.Value.GetString(); diff --git a/test/TestServerProjects/body-complex/Generated/Models/DoubleWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DoubleWrapper.Serialization.cs index e98037cd..f94d4174 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DoubleWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DoubleWrapper.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { diff --git a/test/TestServerProjects/body-complex/Generated/Models/DurationWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DurationWrapper.Serialization.cs index 571fc647..a02c8676 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DurationWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DurationWrapper.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -13,7 +14,7 @@ namespace body_complex.Models.V20160229 if (model.Field != null) { writer.WritePropertyName("field"); - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, model.Field.Value, "P"); + writer.WriteStringValue(model.Field.Value, "P"); } writer.WriteEndObject(); } @@ -28,7 +29,7 @@ namespace body_complex.Models.V20160229 { continue; } - result.Field = Azure.Core.TypeFormatters.GetTimeSpan(property.Value, "P"); + result.Field = property.Value.GetTimeSpan("P"); continue; } } diff --git a/test/TestServerProjects/body-complex/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Error.Serialization.cs index cb3578b3..e7ca08f1 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Error.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { diff --git a/test/TestServerProjects/body-complex/Generated/Models/Fish.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Fish.Serialization.cs index aead7d17..94b6ebaa 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Fish.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Fish.Serialization.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -31,7 +32,8 @@ namespace body_complex.Models.V20160229 writer.WriteNumberValue(model.Length); if (model.Siblings != null) { - writer.WriteStartArray("siblings"); + writer.WritePropertyName("siblings"); + writer.WriteStartArray(); foreach (var item in model.Siblings) { FishSerializer.Serialize(item, writer); diff --git a/test/TestServerProjects/body-complex/Generated/Models/FloatWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/FloatWrapper.Serialization.cs index 0470ad74..92dd7423 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/FloatWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/FloatWrapper.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { diff --git a/test/TestServerProjects/body-complex/Generated/Models/Goblinshark.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Goblinshark.Serialization.cs index 21376047..f2c00c53 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Goblinshark.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Goblinshark.Serialization.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -21,15 +22,13 @@ namespace body_complex.Models.V20160229 writer.WritePropertyName("color"); writer.WriteStringValue(model.Color.ToString()); } - if (model.Age != null) { writer.WritePropertyName("age"); writer.WriteNumberValue(model.Age.Value); } writer.WritePropertyName("birthday"); - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, model.Birthday, "S"); - + writer.WriteStringValue(model.Birthday, "S"); writer.WritePropertyName("fishtype"); writer.WriteStringValue(model.Fishtype); if (model.Species != null) @@ -41,7 +40,8 @@ namespace body_complex.Models.V20160229 writer.WriteNumberValue(model.Length); if (model.Siblings != null) { - writer.WriteStartArray("siblings"); + writer.WritePropertyName("siblings"); + writer.WriteStartArray(); foreach (var item in model.Siblings) { FishSerializer.Serialize(item, writer); @@ -73,7 +73,6 @@ namespace body_complex.Models.V20160229 result.Color = new GoblinSharkColor(property.Value.GetString()); continue; } - if (property.NameEquals("age")) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -85,10 +84,9 @@ namespace body_complex.Models.V20160229 } if (property.NameEquals("birthday")) { - result.Birthday = Azure.Core.TypeFormatters.GetDateTimeOffset(property.Value, "S"); + result.Birthday = property.Value.GetDateTimeOffset("S"); continue; } - if (property.NameEquals("fishtype")) { result.Fishtype = property.Value.GetString(); diff --git a/test/TestServerProjects/body-complex/Generated/Models/IntWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/IntWrapper.Serialization.cs index 9c756942..c0eed83d 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/IntWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/IntWrapper.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { diff --git a/test/TestServerProjects/body-complex/Generated/Models/LongWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/LongWrapper.Serialization.cs index 925ee679..514d9bd2 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/LongWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/LongWrapper.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { diff --git a/test/TestServerProjects/body-complex/Generated/Models/MyBaseHelperType.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/MyBaseHelperType.Serialization.cs index cd094e3f..d2899e29 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/MyBaseHelperType.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/MyBaseHelperType.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { diff --git a/test/TestServerProjects/body-complex/Generated/Models/MyBaseType.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/MyBaseType.Serialization.cs index 48419211..3cdd685e 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/MyBaseType.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/MyBaseType.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { diff --git a/test/TestServerProjects/body-complex/Generated/Models/MyDerivedType.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/MyDerivedType.Serialization.cs index a2ea7a17..a8dc629d 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/MyDerivedType.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/MyDerivedType.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -15,7 +16,6 @@ namespace body_complex.Models.V20160229 writer.WritePropertyName("propD1"); writer.WriteStringValue(model.PropD1); } - writer.WritePropertyName("kind"); writer.WriteStringValue(model.Kind); if (model.PropB1 != null) @@ -44,7 +44,6 @@ namespace body_complex.Models.V20160229 result.PropD1 = property.Value.GetString(); continue; } - if (property.NameEquals("kind")) { result.Kind = property.Value.GetString(); diff --git a/test/TestServerProjects/body-complex/Generated/Models/Pet.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Pet.Serialization.cs index 92156231..00308282 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Pet.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Pet.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { diff --git a/test/TestServerProjects/body-complex/Generated/Models/ReadonlyObj.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/ReadonlyObj.Serialization.cs index 78d4bd38..05efd5db 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/ReadonlyObj.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/ReadonlyObj.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { diff --git a/test/TestServerProjects/body-complex/Generated/Models/Salmon.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Salmon.Serialization.cs index c0b63841..412aff05 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Salmon.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Salmon.Serialization.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -27,7 +28,6 @@ namespace body_complex.Models.V20160229 writer.WritePropertyName("iswild"); writer.WriteBooleanValue(model.Iswild.Value); } - writer.WritePropertyName("fishtype"); writer.WriteStringValue(model.Fishtype); if (model.Species != null) @@ -39,7 +39,8 @@ namespace body_complex.Models.V20160229 writer.WriteNumberValue(model.Length); if (model.Siblings != null) { - writer.WriteStartArray("siblings"); + writer.WritePropertyName("siblings"); + writer.WriteStartArray(); foreach (var item in model.Siblings) { FishSerializer.Serialize(item, writer); @@ -78,7 +79,6 @@ namespace body_complex.Models.V20160229 result.Iswild = property.Value.GetBoolean(); continue; } - if (property.NameEquals("fishtype")) { result.Fishtype = property.Value.GetString(); diff --git a/test/TestServerProjects/body-complex/Generated/Models/Sawshark.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Sawshark.Serialization.cs index 20102641..55e5782c 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Sawshark.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Sawshark.Serialization.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -16,15 +17,13 @@ namespace body_complex.Models.V20160229 writer.WritePropertyName("picture"); writer.WriteBase64StringValue(model.Picture); } - if (model.Age != null) { writer.WritePropertyName("age"); writer.WriteNumberValue(model.Age.Value); } writer.WritePropertyName("birthday"); - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, model.Birthday, "S"); - + writer.WriteStringValue(model.Birthday, "S"); writer.WritePropertyName("fishtype"); writer.WriteStringValue(model.Fishtype); if (model.Species != null) @@ -36,7 +35,8 @@ namespace body_complex.Models.V20160229 writer.WriteNumberValue(model.Length); if (model.Siblings != null) { - writer.WriteStartArray("siblings"); + writer.WritePropertyName("siblings"); + writer.WriteStartArray(); foreach (var item in model.Siblings) { FishSerializer.Serialize(item, writer); @@ -59,7 +59,6 @@ namespace body_complex.Models.V20160229 result.Picture = property.Value.GetBytesFromBase64(); continue; } - if (property.NameEquals("age")) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -71,10 +70,9 @@ namespace body_complex.Models.V20160229 } if (property.NameEquals("birthday")) { - result.Birthday = Azure.Core.TypeFormatters.GetDateTimeOffset(property.Value, "S"); + result.Birthday = property.Value.GetDateTimeOffset("S"); continue; } - if (property.NameEquals("fishtype")) { result.Fishtype = property.Value.GetString(); diff --git a/test/TestServerProjects/body-complex/Generated/Models/Shark.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Shark.Serialization.cs index 94ba1bc6..8c086073 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Shark.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Shark.Serialization.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -29,8 +30,7 @@ namespace body_complex.Models.V20160229 writer.WriteNumberValue(model.Age.Value); } writer.WritePropertyName("birthday"); - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, model.Birthday, "S"); - + writer.WriteStringValue(model.Birthday, "S"); writer.WritePropertyName("fishtype"); writer.WriteStringValue(model.Fishtype); if (model.Species != null) @@ -42,7 +42,8 @@ namespace body_complex.Models.V20160229 writer.WriteNumberValue(model.Length); if (model.Siblings != null) { - writer.WriteStartArray("siblings"); + writer.WritePropertyName("siblings"); + writer.WriteStartArray(); foreach (var item in model.Siblings) { FishSerializer.Serialize(item, writer); @@ -76,10 +77,9 @@ namespace body_complex.Models.V20160229 } if (property.NameEquals("birthday")) { - result.Birthday = Azure.Core.TypeFormatters.GetDateTimeOffset(property.Value, "S"); + result.Birthday = property.Value.GetDateTimeOffset("S"); continue; } - if (property.NameEquals("fishtype")) { result.Fishtype = property.Value.GetString(); diff --git a/test/TestServerProjects/body-complex/Generated/Models/Siamese.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/Siamese.Serialization.cs index 0a8b565a..c644cd1f 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/Siamese.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/Siamese.Serialization.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -16,7 +17,6 @@ namespace body_complex.Models.V20160229 writer.WritePropertyName("breed"); writer.WriteStringValue(model.Breed); } - if (model.Color != null) { writer.WritePropertyName("color"); @@ -24,14 +24,14 @@ namespace body_complex.Models.V20160229 } if (model.Hates != null) { - writer.WriteStartArray("hates"); + writer.WritePropertyName("hates"); + writer.WriteStartArray(); foreach (var item in model.Hates) { DogSerializer.Serialize(item, writer); } writer.WriteEndArray(); } - if (model.Id != null) { writer.WritePropertyName("id"); @@ -58,7 +58,6 @@ namespace body_complex.Models.V20160229 result.Breed = property.Value.GetString(); continue; } - if (property.NameEquals("color")) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -81,7 +80,6 @@ namespace body_complex.Models.V20160229 } continue; } - if (property.NameEquals("id")) { if (property.Value.ValueKind == JsonValueKind.Null) diff --git a/test/TestServerProjects/body-complex/Generated/Models/SmartSalmon.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/SmartSalmon.Serialization.cs index d5406a19..6155878a 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/SmartSalmon.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/SmartSalmon.Serialization.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { @@ -16,7 +17,6 @@ namespace body_complex.Models.V20160229 writer.WritePropertyName("college_degree"); writer.WriteStringValue(model.CollegeDegree); } - if (model.Location != null) { writer.WritePropertyName("location"); @@ -27,7 +27,6 @@ namespace body_complex.Models.V20160229 writer.WritePropertyName("iswild"); writer.WriteBooleanValue(model.Iswild.Value); } - writer.WritePropertyName("fishtype"); writer.WriteStringValue(model.Fishtype); if (model.Species != null) @@ -39,13 +38,19 @@ namespace body_complex.Models.V20160229 writer.WriteNumberValue(model.Length); if (model.Siblings != null) { - writer.WriteStartArray("siblings"); + writer.WritePropertyName("siblings"); + writer.WriteStartArray(); foreach (var item in model.Siblings) { FishSerializer.Serialize(item, writer); } writer.WriteEndArray(); } + foreach (var item in model) + { + writer.WritePropertyName(item.Key); + writer.WriteObjectValue(item.Value); + } writer.WriteEndObject(); } internal static SmartSalmon Deserialize(JsonElement element) @@ -62,7 +67,6 @@ namespace body_complex.Models.V20160229 result.CollegeDegree = property.Value.GetString(); continue; } - if (property.NameEquals("location")) { if (property.Value.ValueKind == JsonValueKind.Null) @@ -81,7 +85,6 @@ namespace body_complex.Models.V20160229 result.Iswild = property.Value.GetBoolean(); continue; } - if (property.NameEquals("fishtype")) { result.Fishtype = property.Value.GetString(); @@ -114,6 +117,7 @@ namespace body_complex.Models.V20160229 } continue; } + result.Add(property.Name, property.Value.GetObject()); } return result; } diff --git a/test/TestServerProjects/body-complex/Generated/Models/SmartSalmon.cs b/test/TestServerProjects/body-complex/Generated/Models/SmartSalmon.cs index 8915a4a2..8e893ee9 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/SmartSalmon.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/SmartSalmon.cs @@ -1,14 +1,38 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System.Collections; +using System.Collections.Generic; + namespace body_complex.Models.V20160229 { - public partial class SmartSalmon : Salmon + public partial class SmartSalmon : Salmon, IDictionary { public SmartSalmon() { Fishtype = "smart_salmon"; } public string? CollegeDegree { get; set; } + private readonly IDictionary _additionalProperties = new Dictionary(); + public IEnumerator> GetEnumerator() => _additionalProperties.GetEnumerator(); + IEnumerator IEnumerable.GetEnumerator() => _additionalProperties.GetEnumerator(); + public ICollection Keys => _additionalProperties.Keys; + public ICollection Values => _additionalProperties.Values; + public bool TryGetValue(string key, out object value) => _additionalProperties.TryGetValue(key, out value); + public void Add(string key, object value) => _additionalProperties.Add(key, value); + public bool ContainsKey(string key) => _additionalProperties.ContainsKey(key); + public bool Remove(string key) => _additionalProperties.Remove(key); + public int Count => _additionalProperties.Count; + bool ICollection>.IsReadOnly => _additionalProperties.IsReadOnly; + void ICollection>.Add(KeyValuePair value) => _additionalProperties.Add(value); + bool ICollection>.Remove(KeyValuePair value) => _additionalProperties.Remove(value); + bool ICollection>.Contains(KeyValuePair value) => _additionalProperties.Contains(value); + void ICollection>.CopyTo(KeyValuePair[] destination, int offset) => _additionalProperties.CopyTo(destination, offset); + void ICollection>.Clear() => _additionalProperties.Clear(); + public object this[string key] + { + get => _additionalProperties[key]; + set => _additionalProperties[key] = value; + } } } diff --git a/test/TestServerProjects/body-complex/Generated/Models/StringWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/StringWrapper.Serialization.cs index 3413eae7..51bd94ed 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/StringWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/StringWrapper.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_complex.Models.V20160229 { diff --git a/test/TestServerProjects/body-date/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-date/Generated/Models/Error.Serialization.cs index 1def305f..9e3912d9 100644 --- a/test/TestServerProjects/body-date/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-date/Generated/Models/Error.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_date.Models.V100 { diff --git a/test/TestServerProjects/body-date/Generated/Operations/DateOperations.cs b/test/TestServerProjects/body-date/Generated/Operations/DateOperations.cs index 8e7e7543..a46aab83 100644 --- a/test/TestServerProjects/body-date/Generated/Operations/DateOperations.cs +++ b/test/TestServerProjects/body-date/Generated/Operations/DateOperations.cs @@ -34,7 +34,7 @@ namespace body_date case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "D"); + var value = document.RootElement.GetDateTimeOffset("D"); return Response.FromValue(value, response); } default: @@ -68,7 +68,7 @@ namespace body_date case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "D"); + var value = document.RootElement.GetDateTimeOffset("D"); return Response.FromValue(value, response); } default: @@ -102,7 +102,7 @@ namespace body_date case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "D"); + var value = document.RootElement.GetDateTimeOffset("D"); return Response.FromValue(value, response); } default: @@ -136,7 +136,7 @@ namespace body_date case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "D"); + var value = document.RootElement.GetDateTimeOffset("D"); return Response.FromValue(value, response); } default: @@ -167,7 +167,7 @@ namespace body_date request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); var writer = content.JsonWriter; - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, dateBody, "D"); + writer.WriteStringValue(dateBody, "D"); request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); switch (response.Status) @@ -205,7 +205,7 @@ namespace body_date case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "D"); + var value = document.RootElement.GetDateTimeOffset("D"); return Response.FromValue(value, response); } default: @@ -236,7 +236,7 @@ namespace body_date request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); var writer = content.JsonWriter; - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, dateBody, "D"); + writer.WriteStringValue(dateBody, "D"); request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); switch (response.Status) @@ -274,7 +274,7 @@ namespace body_date case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "D"); + var value = document.RootElement.GetDateTimeOffset("D"); return Response.FromValue(value, response); } default: 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 d4c82370..9f9ab83d 100644 --- a/test/TestServerProjects/body-datetime-rfc1123/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-datetime-rfc1123/Generated/Models/Error.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_datetime_rfc1123.Models.V100 { diff --git a/test/TestServerProjects/body-datetime-rfc1123/Generated/Operations/Datetimerfc1123Operations.cs b/test/TestServerProjects/body-datetime-rfc1123/Generated/Operations/Datetimerfc1123Operations.cs index ca334f42..9c1780c8 100644 --- a/test/TestServerProjects/body-datetime-rfc1123/Generated/Operations/Datetimerfc1123Operations.cs +++ b/test/TestServerProjects/body-datetime-rfc1123/Generated/Operations/Datetimerfc1123Operations.cs @@ -34,7 +34,7 @@ namespace body_datetime_rfc1123 case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "R"); + var value = document.RootElement.GetDateTimeOffset("R"); return Response.FromValue(value, response); } default: @@ -68,7 +68,7 @@ namespace body_datetime_rfc1123 case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "R"); + var value = document.RootElement.GetDateTimeOffset("R"); return Response.FromValue(value, response); } default: @@ -102,7 +102,7 @@ namespace body_datetime_rfc1123 case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "R"); + var value = document.RootElement.GetDateTimeOffset("R"); return Response.FromValue(value, response); } default: @@ -136,7 +136,7 @@ namespace body_datetime_rfc1123 case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "R"); + var value = document.RootElement.GetDateTimeOffset("R"); return Response.FromValue(value, response); } default: @@ -167,7 +167,7 @@ namespace body_datetime_rfc1123 request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); var writer = content.JsonWriter; - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, datetimeBody, "R"); + writer.WriteStringValue(datetimeBody, "R"); request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); switch (response.Status) @@ -205,7 +205,7 @@ namespace body_datetime_rfc1123 case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "R"); + var value = document.RootElement.GetDateTimeOffset("R"); return Response.FromValue(value, response); } default: @@ -239,7 +239,7 @@ namespace body_datetime_rfc1123 case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "R"); + var value = document.RootElement.GetDateTimeOffset("R"); return Response.FromValue(value, response); } default: @@ -270,7 +270,7 @@ namespace body_datetime_rfc1123 request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); var writer = content.JsonWriter; - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, datetimeBody, "R"); + writer.WriteStringValue(datetimeBody, "R"); request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); switch (response.Status) @@ -308,7 +308,7 @@ namespace body_datetime_rfc1123 case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "R"); + var value = document.RootElement.GetDateTimeOffset("R"); return Response.FromValue(value, response); } default: diff --git a/test/TestServerProjects/body-datetime/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-datetime/Generated/Models/Error.Serialization.cs index 79b7d91b..3cc839f4 100644 --- a/test/TestServerProjects/body-datetime/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-datetime/Generated/Models/Error.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_datetime.Models.V100 { diff --git a/test/TestServerProjects/body-datetime/Generated/Operations/DatetimeOperations.cs b/test/TestServerProjects/body-datetime/Generated/Operations/DatetimeOperations.cs index caaf4ac5..ec72b3fc 100644 --- a/test/TestServerProjects/body-datetime/Generated/Operations/DatetimeOperations.cs +++ b/test/TestServerProjects/body-datetime/Generated/Operations/DatetimeOperations.cs @@ -34,7 +34,7 @@ namespace body_datetime case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "S"); + var value = document.RootElement.GetDateTimeOffset("S"); return Response.FromValue(value, response); } default: @@ -68,7 +68,7 @@ namespace body_datetime case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "S"); + var value = document.RootElement.GetDateTimeOffset("S"); return Response.FromValue(value, response); } default: @@ -102,7 +102,7 @@ namespace body_datetime case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "S"); + var value = document.RootElement.GetDateTimeOffset("S"); return Response.FromValue(value, response); } default: @@ -136,7 +136,7 @@ namespace body_datetime case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "S"); + var value = document.RootElement.GetDateTimeOffset("S"); return Response.FromValue(value, response); } default: @@ -167,7 +167,7 @@ namespace body_datetime request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); var writer = content.JsonWriter; - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, datetimeBody, "S"); + writer.WriteStringValue(datetimeBody, "S"); request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); switch (response.Status) @@ -205,7 +205,7 @@ namespace body_datetime case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "S"); + var value = document.RootElement.GetDateTimeOffset("S"); return Response.FromValue(value, response); } default: @@ -239,7 +239,7 @@ namespace body_datetime case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "S"); + var value = document.RootElement.GetDateTimeOffset("S"); return Response.FromValue(value, response); } default: @@ -270,7 +270,7 @@ namespace body_datetime request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); var writer = content.JsonWriter; - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, datetimeBody, "S"); + writer.WriteStringValue(datetimeBody, "S"); request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); switch (response.Status) @@ -308,7 +308,7 @@ namespace body_datetime case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "S"); + var value = document.RootElement.GetDateTimeOffset("S"); return Response.FromValue(value, response); } default: @@ -342,7 +342,7 @@ namespace body_datetime case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "S"); + var value = document.RootElement.GetDateTimeOffset("S"); return Response.FromValue(value, response); } default: @@ -373,7 +373,7 @@ namespace body_datetime request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); var writer = content.JsonWriter; - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, datetimeBody, "S"); + writer.WriteStringValue(datetimeBody, "S"); request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); switch (response.Status) @@ -411,7 +411,7 @@ namespace body_datetime case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "S"); + var value = document.RootElement.GetDateTimeOffset("S"); return Response.FromValue(value, response); } default: @@ -445,7 +445,7 @@ namespace body_datetime case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "S"); + var value = document.RootElement.GetDateTimeOffset("S"); return Response.FromValue(value, response); } default: @@ -476,7 +476,7 @@ namespace body_datetime request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); var writer = content.JsonWriter; - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, datetimeBody, "S"); + writer.WriteStringValue(datetimeBody, "S"); request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); switch (response.Status) @@ -514,7 +514,7 @@ namespace body_datetime case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "S"); + var value = document.RootElement.GetDateTimeOffset("S"); return Response.FromValue(value, response); } default: @@ -545,7 +545,7 @@ namespace body_datetime request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); var writer = content.JsonWriter; - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, datetimeBody, "S"); + writer.WriteStringValue(datetimeBody, "S"); request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); switch (response.Status) @@ -583,7 +583,7 @@ namespace body_datetime case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "S"); + var value = document.RootElement.GetDateTimeOffset("S"); return Response.FromValue(value, response); } default: @@ -614,7 +614,7 @@ namespace body_datetime request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); var writer = content.JsonWriter; - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, datetimeBody, "S"); + writer.WriteStringValue(datetimeBody, "S"); request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); switch (response.Status) @@ -652,7 +652,7 @@ namespace body_datetime case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "S"); + var value = document.RootElement.GetDateTimeOffset("S"); return Response.FromValue(value, response); } default: diff --git a/test/TestServerProjects/body-duration/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-duration/Generated/Models/Error.Serialization.cs index 0e38e16a..f204ee60 100644 --- a/test/TestServerProjects/body-duration/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-duration/Generated/Models/Error.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_duration.Models.V100 { diff --git a/test/TestServerProjects/body-duration/Generated/Operations/DurationOperations.cs b/test/TestServerProjects/body-duration/Generated/Operations/DurationOperations.cs index 660281e0..cf73d7d8 100644 --- a/test/TestServerProjects/body-duration/Generated/Operations/DurationOperations.cs +++ b/test/TestServerProjects/body-duration/Generated/Operations/DurationOperations.cs @@ -34,7 +34,7 @@ namespace body_duration case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetTimeSpan(document.RootElement, "P"); + var value = document.RootElement.GetTimeSpan("P"); return Response.FromValue(value, response); } default: @@ -65,7 +65,7 @@ namespace body_duration request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); var writer = content.JsonWriter; - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, durationBody, "P"); + writer.WriteStringValue(durationBody, "P"); request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); switch (response.Status) @@ -103,7 +103,7 @@ namespace body_duration case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetTimeSpan(document.RootElement, "P"); + var value = document.RootElement.GetTimeSpan("P"); return Response.FromValue(value, response); } default: @@ -137,7 +137,7 @@ namespace body_duration case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetTimeSpan(document.RootElement, "P"); + var value = document.RootElement.GetTimeSpan("P"); return Response.FromValue(value, response); } default: diff --git a/test/TestServerProjects/body-integer/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-integer/Generated/Models/Error.Serialization.cs index 80bcc333..246a4019 100644 --- a/test/TestServerProjects/body-integer/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-integer/Generated/Models/Error.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_integer.Models.V100 { diff --git a/test/TestServerProjects/body-integer/Generated/Operations/IntOperations.cs b/test/TestServerProjects/body-integer/Generated/Operations/IntOperations.cs index 6bac0d79..d5342409 100644 --- a/test/TestServerProjects/body-integer/Generated/Operations/IntOperations.cs +++ b/test/TestServerProjects/body-integer/Generated/Operations/IntOperations.cs @@ -378,7 +378,7 @@ namespace body_integer case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "U"); + var value = document.RootElement.GetDateTimeOffset("U"); return Response.FromValue(value, response); } default: @@ -409,7 +409,7 @@ namespace body_integer request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); var writer = content.JsonWriter; - Azure.Core.Utf8JsonWriterExtensions.WriteStringValue(writer, intBody, "U"); + writer.WriteStringValue(intBody, "U"); request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); switch (response.Status) @@ -447,7 +447,7 @@ namespace body_integer case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "U"); + var value = document.RootElement.GetDateTimeOffset("U"); return Response.FromValue(value, response); } default: @@ -481,7 +481,7 @@ namespace body_integer case 200: { using var document = await JsonDocument.ParseAsync(response.ContentStream, default, cancellationToken).ConfigureAwait(false); - var value = Azure.Core.TypeFormatters.GetDateTimeOffset(document.RootElement, "U"); + var value = document.RootElement.GetDateTimeOffset("U"); return Response.FromValue(value, response); } default: diff --git a/test/TestServerProjects/body-number/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-number/Generated/Models/Error.Serialization.cs index 8ef36b45..383ff483 100644 --- a/test/TestServerProjects/body-number/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-number/Generated/Models/Error.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_number.Models.V100 { diff --git a/test/TestServerProjects/body-string/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/body-string/Generated/Models/Error.Serialization.cs index 0e3acdec..74619777 100644 --- a/test/TestServerProjects/body-string/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/body-string/Generated/Models/Error.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_string.Models.V100 { diff --git a/test/TestServerProjects/body-string/Generated/Models/RefColorConstant.Serialization.cs b/test/TestServerProjects/body-string/Generated/Models/RefColorConstant.Serialization.cs index aeee1895..96e632bb 100644 --- a/test/TestServerProjects/body-string/Generated/Models/RefColorConstant.Serialization.cs +++ b/test/TestServerProjects/body-string/Generated/Models/RefColorConstant.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace body_string.Models.V100 { diff --git a/test/TestServerProjects/body-string/Generated/Operations/StringOperations.cs b/test/TestServerProjects/body-string/Generated/Operations/StringOperations.cs index 2ea5f410..eee33796 100644 --- a/test/TestServerProjects/body-string/Generated/Operations/StringOperations.cs +++ b/test/TestServerProjects/body-string/Generated/Operations/StringOperations.cs @@ -65,7 +65,7 @@ namespace body_string request.Headers.Add("Content-Type", "application/json"); using var content = new Utf8JsonRequestContent(); var writer = content.JsonWriter; - writer.WriteStringValue(""); + writer.WriteStringValue((string?)null); request.Content = content; var response = await pipeline.SendRequestAsync(request, cancellationToken).ConfigureAwait(false); switch (response.Status) 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 36637367..4bf316da 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 @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace custom_baseUrl_more_options.Models.V100 { diff --git a/test/TestServerProjects/custom-baseUrl/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/custom-baseUrl/Generated/Models/Error.Serialization.cs index 74751987..224d7f45 100644 --- a/test/TestServerProjects/custom-baseUrl/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/custom-baseUrl/Generated/Models/Error.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace custom_baseUrl.Models.V100 { 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 1ded5c89..0d2cd25f 100644 --- a/test/TestServerProjects/extensible-enums-swagger/Generated/Models/Pet.Serialization.cs +++ b/test/TestServerProjects/extensible-enums-swagger/Generated/Models/Pet.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace extensible_enums_swagger.Models.V20160707 { diff --git a/test/TestServerProjects/header/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/header/Generated/Models/Error.Serialization.cs index f8adfc9c..7331c609 100644 --- a/test/TestServerProjects/header/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/header/Generated/Models/Error.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace header.Models.V100 { 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 f8255426..d44ed785 100644 --- a/test/TestServerProjects/url-multi-collectionFormat/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/url-multi-collectionFormat/Generated/Models/Error.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace url_multi_collectionFormat.Models.V100 { diff --git a/test/TestServerProjects/url/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/url/Generated/Models/Error.Serialization.cs index 426aca4d..657eebe9 100644 --- a/test/TestServerProjects/url/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/url/Generated/Models/Error.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace url.Models.V100 { diff --git a/test/TestServerProjects/validation/Generated/Models/ChildProduct.Serialization.cs b/test/TestServerProjects/validation/Generated/Models/ChildProduct.Serialization.cs index e1ec8a37..c031cce5 100644 --- a/test/TestServerProjects/validation/Generated/Models/ChildProduct.Serialization.cs +++ b/test/TestServerProjects/validation/Generated/Models/ChildProduct.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace validation.Models.V100 { diff --git a/test/TestServerProjects/validation/Generated/Models/ConstantProduct.Serialization.cs b/test/TestServerProjects/validation/Generated/Models/ConstantProduct.Serialization.cs index 604ad60a..87863cdf 100644 --- a/test/TestServerProjects/validation/Generated/Models/ConstantProduct.Serialization.cs +++ b/test/TestServerProjects/validation/Generated/Models/ConstantProduct.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace validation.Models.V100 { diff --git a/test/TestServerProjects/validation/Generated/Models/Error.Serialization.cs b/test/TestServerProjects/validation/Generated/Models/Error.Serialization.cs index 96feabde..478afc84 100644 --- a/test/TestServerProjects/validation/Generated/Models/Error.Serialization.cs +++ b/test/TestServerProjects/validation/Generated/Models/Error.Serialization.cs @@ -2,6 +2,7 @@ // Licensed under the MIT License. using System.Text.Json; +using Azure.Core; namespace validation.Models.V100 { diff --git a/test/TestServerProjects/validation/Generated/Models/Product.Serialization.cs b/test/TestServerProjects/validation/Generated/Models/Product.Serialization.cs index 71eaed3a..58d47d7e 100644 --- a/test/TestServerProjects/validation/Generated/Models/Product.Serialization.cs +++ b/test/TestServerProjects/validation/Generated/Models/Product.Serialization.cs @@ -3,6 +3,7 @@ using System.Collections.Generic; using System.Text.Json; +using Azure.Core; namespace validation.Models.V100 { @@ -13,7 +14,8 @@ namespace validation.Models.V100 writer.WriteStartObject(); if (model.DisplayNames != null) { - writer.WriteStartArray("display_names"); + writer.WritePropertyName("display_names"); + writer.WriteStartArray(); foreach (var item in model.DisplayNames) { writer.WriteStringValue(item); diff --git a/test/scripts/TestList.txt b/test/scripts/TestList.txt index 9408881b11a2cb57d76cbe4e7f579999b366ab8f..72b7ca5dff5cf1dcf7b3722f2f052e0fa2cc9747 100644 GIT binary patch literal 2114 zcmeH{!D_-l5QhJAq3_@^Lg@>LLJt;tQZUeict}&JsnLeDK}CFZ+ixaFKyoP-3MDK{ zHaj!_4&Tns*XdR_>RgPeV$HSDr)Fxh7b^9lT$xfLVYPjTKlI z=mp<5-6w2K`;oe+^fhqRDuW4839}?F@{{&Nr+7qKpln&*@mFxBonl$7`PNDYtckWv z%dF1#UXPyJN<-~XoD+Y}JaUaK-c7bH>OE|M7|Sf+-C>rTp1bAf9>%VT-(T^4b^;6T zY0RzdotN1MHMMgEwETZw-xGfyDYalP!|Jx>YCY!Kz7bQYC2y|fS#|8|c~(7O UL^pqjYf3L@+5Rru|K4A}0jK?2V*mgE literal 80 zcmWN{+X;X$5Cp(hwiUq&w1QwZcyM`;+o0v^_sqfJ=^}JnKzxPAbi=I?nQqm@{6h#W YRR+rJ6+6oxVsk$)wlu8=`qEhX0JtR{MgRZ+