diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs index 249dd6a1b13..ae2f057c709 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs @@ -26,7 +26,6 @@ namespace Microsoft.Generator.CSharp.ClientModel.Providers /// internal class MrwSerializationTypeDefinition : TypeProvider { - private const string PrivateAdditionalPropertiesPropertyDescription = "Keeps track of any properties unknown to the library."; private const string PrivateAdditionalPropertiesPropertyName = "_serializedAdditionalRawData"; private const string JsonModelWriteCoreMethodName = "JsonModelWriteCore"; private const string JsonModelCreateCoreMethodName = "JsonModelCreateCore"; @@ -34,7 +33,6 @@ internal class MrwSerializationTypeDefinition : TypeProvider private const string PersistableModelCreateCoreMethodName = "PersistableModelCreateCore"; private const string WriteAction = "writing"; private const string ReadAction = "reading"; - private const string AdditionalRawDataVarName = "serializedAdditionalRawData"; private readonly ParameterProvider _utf8JsonWriterParameter = new("writer", $"The JSON writer.", typeof(Utf8JsonWriter)); private readonly ParameterProvider _utf8JsonReaderParameter = new("reader", $"The JSON reader.", typeof(Utf8JsonReader), isRef: true); private readonly ParameterProvider _serializationOptionsParameter = @@ -46,22 +44,19 @@ internal class MrwSerializationTypeDefinition : TypeProvider private readonly ScopedApi _mrwOptionsParameterSnippet; private readonly ScopedApi _jsonElementParameterSnippet; private readonly ScopedApi _isNotEqualToWireConditionSnippet; - private readonly CSharpType _privateAdditionalRawDataPropertyType = typeof(IDictionary); private readonly CSharpType _jsonModelTInterface; private readonly CSharpType? _jsonModelObjectInterface; private readonly CSharpType _persistableModelTInterface; private readonly CSharpType? _persistableModelObjectInterface; - private TypeProvider _model; + private readonly ModelProvider _model; private readonly InputModelType _inputModel; private readonly FieldProvider? _rawDataField; private readonly bool _isStruct; private ConstructorProvider? _serializationConstructor; // Flag to determine if the model should override the serialization methods private readonly bool _shouldOverrideMethods; - // TODO -- we should not be needing this if we resolve https://github.com/microsoft/typespec/issues/3796 - private readonly MrwSerializationTypeDefinition? _baseSerializationProvider; - public MrwSerializationTypeDefinition(InputModelType inputModel, TypeProvider modelProvider) + public MrwSerializationTypeDefinition(InputModelType inputModel, ModelProvider modelProvider) { _model = modelProvider; _inputModel = inputModel; @@ -71,11 +66,7 @@ public MrwSerializationTypeDefinition(InputModelType inputModel, TypeProvider mo _jsonModelObjectInterface = _isStruct ? (CSharpType)typeof(IJsonModel) : null; _persistableModelTInterface = new CSharpType(typeof(IPersistableModel<>), _model.Type); _persistableModelObjectInterface = _isStruct ? (CSharpType)typeof(IPersistableModel) : null; - - if (inputModel.BaseModel is not null) - _baseSerializationProvider = ClientModelPlugin.Instance.TypeFactory.CreateSerializations(inputModel.BaseModel, modelProvider).OfType().FirstOrDefault(); - - _rawDataField = BuildRawDataField(); + _rawDataField = _model.Fields.FirstOrDefault(f => f.Name == PrivateAdditionalPropertiesPropertyName); _shouldOverrideMethods = _model.Type.BaseType != null && _model.Type.BaseType is { IsFrameworkType: false }; _utf8JsonWriterSnippet = _utf8JsonWriterParameter.As(); _mrwOptionsParameterSnippet = _serializationOptionsParameter.As(); @@ -86,25 +77,15 @@ public MrwSerializationTypeDefinition(InputModelType inputModel, TypeProvider mo protected override string GetNamespace() => _model.Type.Namespace; protected override TypeSignatureModifiers GetDeclarationModifiers() => _model.DeclarationModifiers; - private ConstructorProvider SerializationConstructor => _serializationConstructor ??= BuildSerializationConstructor(); + private ConstructorProvider SerializationConstructor => _serializationConstructor ??= _model.FullConstructor; protected override string BuildRelativeFilePath() => Path.Combine("src", "Generated", "Models", $"{Name}.Serialization.cs"); protected override string BuildName() => _model.Name; - /// - /// Builds the fields for the model by adding the raw data field for serialization. - /// - /// The list of for the model. - protected override FieldProvider[] BuildFields() - { - return _rawDataField != null ? [_rawDataField] : Array.Empty(); - } - protected override ConstructorProvider[] BuildConstructors() { List constructors = new(); - bool serializationCtorParamsMatch = false; bool ctorWithNoParamsExist = false; foreach (var ctor in _model.Constructors) @@ -116,21 +97,6 @@ protected override ConstructorProvider[] BuildConstructors() { ctorWithNoParamsExist = true; } - - if (!serializationCtorParamsMatch) - { - // Check if the model constructor parameters match the serialization constructor parameters - if (initializationCtorParams.SequenceEqual(SerializationConstructor.Signature.Parameters)) - { - serializationCtorParamsMatch = true; - } - } - } - - // Add the serialization constructor if it doesn't match any of the existing constructors - if (!serializationCtorParamsMatch) - { - constructors.Add(SerializationConstructor); } // Add an empty constructor if the model doesn't have one @@ -139,39 +105,7 @@ protected override ConstructorProvider[] BuildConstructors() constructors.Add(BuildEmptyConstructor()); } - return constructors.ToArray(); - } - - /// - /// Builds the raw data field for the model to be used for serialization. - /// - /// The constructed if the model should generate the field. - private FieldProvider? BuildRawDataField() - { - if (_isStruct) - { - return null; - } - - // check if there is a raw data field on my base, if so, we do not have to have one here - if (_baseSerializationProvider?._rawDataField != null) - { - return null; - } - - var modifiers = FieldModifiers.Private; - if (!_model.DeclarationModifiers.HasFlag(TypeSignatureModifiers.Sealed)) - { - modifiers |= FieldModifiers.Protected; - } - - var rawDataField = new FieldProvider( - modifiers: modifiers, - type: _privateAdditionalRawDataPropertyType, - description: FormattableStringHelpers.FromString(PrivateAdditionalPropertiesPropertyDescription), - name: PrivateAdditionalPropertiesPropertyName); - - return rawDataField; + return [.. constructors]; } /// @@ -527,28 +461,6 @@ internal MethodProvider BuildPersistableModelGetFormatFromOptionsObjectDeclarati ); } - /// - /// Builds the serialization constructor for the model. - /// - /// The constructed serialization constructor. - internal ConstructorProvider BuildSerializationConstructor() - { - var (serializationCtorParameters, serializationCtorInitializer) = BuildSerializationConstructorParameters(); - - return new ConstructorProvider( - signature: new ConstructorSignature( - Type, - $"Initializes a new instance of {Type:C}", - MethodSignatureModifiers.Internal, - serializationCtorParameters, - Initializer: serializationCtorInitializer), - bodyStatements: new MethodBodyStatement[] - { - GetPropertyInitializers() - }, - this); - } - private MethodBodyStatement[] BuildJsonModelWriteMethodBody(MethodProvider jsonModelWriteCoreMethod) { var coreMethodSignature = jsonModelWriteCoreMethod.Signature; @@ -699,7 +611,6 @@ private ValueExpression[] GetSerializationCtorParameterValues() { var parameters = SerializationConstructor.Signature.Parameters; ValueExpression[] serializationCtorParameters = new ValueExpression[parameters.Count]; - var serializationCtorParameterValues = new Dictionary(parameters.Count); // Map property variable names to their corresponding parameter values for (int i = 0; i < parameters.Count; i++) @@ -771,7 +682,7 @@ private List BuildDeserializePropertiesStatements(ScopedApi // deserialize the raw data properties if (_rawDataField != null) { - var elementType = _privateAdditionalRawDataPropertyType.Arguments[1].FrameworkType; + var elementType = _rawDataField.Type.Arguments[1].FrameworkType; var rawDataDeserializationValue = GetValueTypeDeserializationExpression(elementType, jsonProperty.Value(), SerializationFormat.Default); propertyDeserializationStatements.Add(new IfStatement(_isNotEqualToWireConditionSnippet) { @@ -959,44 +870,6 @@ private static MethodBodyStatement NullCheckCollectionItemIfRequired( ? new IfElseStatement(arrayItemVar.ValueKindEqualsNull(), assignNull, deserializeValue) : deserializeValue; - /// - /// Builds the parameters for the serialization constructor by iterating through the input model properties. - /// It then adds raw data field to the constructor if it doesn't already exist in the list of constructed parameters. - /// - /// The list of parameters for the serialization parameter. - private (IReadOnlyList Parameters, ConstructorInitializer? Initializer) BuildSerializationConstructorParameters() - { - var baseConstructor = _baseSerializationProvider?.SerializationConstructor.Signature; - var baseParameters = baseConstructor?.Parameters ?? []; - var parameterCapacity = baseParameters.Count + _inputModel.Properties.Count; - var parameterNames = baseParameters.Select(p => p.Name).ToHashSet(); - var constructorParameters = new List(parameterCapacity); - - // add the base parameters - constructorParameters.AddRange(baseParameters); - - // construct the initializer using the parameters from base signature - var constructorInitializer = new ConstructorInitializer(true, baseParameters); - - foreach (var property in _model.Properties) - { - // skip those non-spec properties - if (property.WireInfo == null) - { - continue; - } - constructorParameters.Add(property.AsParameter); - } - - // Append the raw data field if it doesn't already exist in the constructor parameters - if (_rawDataField != null) - { - constructorParameters.Add(_rawDataField.AsParameter); - } - - return (constructorParameters, constructorInitializer); - } - private ConstructorProvider BuildEmptyConstructor() { var accessibility = _isStruct ? MethodSignatureModifiers.Public : MethodSignatureModifiers.Internal; diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmTypeFactory.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmTypeFactory.cs index 65b5ed3fa84..48c0cbed76f 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmTypeFactory.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/src/ScmTypeFactory.cs @@ -32,7 +32,11 @@ protected override IReadOnlyList CreateSerializationsCore(InputTyp switch (inputType) { case InputModelType inputModel when inputModel.Usage.HasFlag(InputModelTypeUsage.Json): - return [new MrwSerializationTypeDefinition(inputModel, typeProvider)]; + if (typeProvider is ModelProvider modelProvider) + { + return [new MrwSerializationTypeDefinition(inputModel, modelProvider)]; + } + return []; case InputEnumType { IsExtensible: true } inputEnumType: if (ClientModelPlugin.Instance.TypeFactory.CreateCSharpType(inputEnumType)?.UnderlyingEnumType.Equals(typeof(string)) == true) { diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/JsonModelCoreTests.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/JsonModelCoreTests.cs index 059503adf90..2cd534cbe9a 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/JsonModelCoreTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/JsonModelCoreTests.cs @@ -16,13 +16,13 @@ public class JsonModelCoreTests public JsonModelCoreTests() { MockHelpers.LoadMockPlugin(createSerializationsCore: (inputType, typeProvider) - => inputType is InputModelType modeltype ? [new MockMrwProvider(modeltype, typeProvider)] : []); + => inputType is InputModelType modeltype ? [new MockMrwProvider(modeltype, (typeProvider as ModelProvider)!)] : []); } private class MockMrwProvider : MrwSerializationTypeDefinition { - public MockMrwProvider(InputModelType inputModel, TypeProvider typeProvider) - : base(inputModel, typeProvider) + public MockMrwProvider(InputModelType inputModel, ModelProvider modelProvider) + : base(inputModel, modelProvider) { } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/MrwSerializationConstructorTests.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/MrwSerializationConstructorTests.cs deleted file mode 100644 index 0fefcd0ed6f..00000000000 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/MrwSerializationConstructorTests.cs +++ /dev/null @@ -1,84 +0,0 @@ -// Copyright (c) Microsoft Corporation. All rights reserved. -// Licensed under the MIT License. - -using System; -using System.Collections.Generic; -using Microsoft.Generator.CSharp.ClientModel.Providers; -using Microsoft.Generator.CSharp.Input; -using Microsoft.Generator.CSharp.Primitives; -using Microsoft.Generator.CSharp.Providers; -using NUnit.Framework; - -namespace Microsoft.Generator.CSharp.ClientModel.Tests.Providers.MrwSerializationTypeDefinitions -{ - public class MrwSerializationConstructorTests - { - public MrwSerializationConstructorTests() - { - MockHelpers.LoadMockPlugin(createSerializationsCore: (inputType, typeProvider) - => inputType is InputModelType modeltype ? [new MockMrwProvider(modeltype, typeProvider)] : []); - } - - private class MockMrwProvider : MrwSerializationTypeDefinition - { - public MockMrwProvider(InputModelType inputModel, TypeProvider typeProvider) - : base(inputModel, typeProvider) - { - } - - protected override MethodProvider[] BuildMethods() => []; - - protected override FieldProvider[] BuildFields() => []; - } - - [Test] - public void TestBuildConstructors() - { - var baseProperties = new List - { - new InputModelProperty("prop1", "prop1", string.Empty, InputPrimitiveType.String, true, false, false), - new InputModelProperty("prop2", "prop2", string.Empty, InputPrimitiveType.String, false, false, false), - }; - var derivedProperties = new List - { - new InputModelProperty("prop3", "prop3", string.Empty, InputPrimitiveType.String, true, false, false), - new InputModelProperty("prop4", "prop4", string.Empty, InputPrimitiveType.String, false, false, false), - }; - var inputBase = new InputModelType("baseModel", "baseModel", null, null, null, InputModelTypeUsage.Input, baseProperties, null, new List(), null, null, new Dictionary(), null, false); - var inputDerived = new InputModelType("derivedModel", "derivedModel", null, null, null, InputModelTypeUsage.Input, derivedProperties, inputBase, new List(), null, null, new Dictionary(), null, false); - ((List)inputBase.DerivedModels).Add(inputDerived); - - var (baseModel, baseSerialization) = MrwSerializationTypeDefinitionTests.CreateModelAndSerialization(inputBase); - var (derivedModel, derivedSerialization) = MrwSerializationTypeDefinitionTests.CreateModelAndSerialization(inputDerived); - - var baseCtors = baseSerialization.Constructors; - var derivedCtors = derivedSerialization.Constructors; - Assert.AreEqual(2, baseCtors.Count); - Assert.AreEqual(2, derivedCtors.Count); - // the second ctor of the ctors should be parameterless - Assert.AreEqual(0, baseCtors[1].Signature.Parameters.Count); - Assert.AreEqual(0, derivedCtors[1].Signature.Parameters.Count); - // the first ctor should contain certain number of parameters - var baseParameters = baseCtors[0].Signature.Parameters; - var derivedParameters = derivedCtors[0].Signature.Parameters; - Assert.AreEqual(3, baseParameters.Count); // 2 properties + raw data - Assert.AreEqual(5, derivedParameters.Count); // 4 properties + raw data - Assert.AreEqual("prop1", baseParameters[0].Name); - Assert.AreEqual(new CSharpType(typeof(string)), baseParameters[0].Type); - Assert.AreEqual("prop2", baseParameters[1].Name); - Assert.AreEqual(new CSharpType(typeof(string), true), baseParameters[1].Type); - Assert.AreEqual("serializedAdditionalRawData", baseParameters[2].Name); - Assert.AreEqual(new CSharpType(typeof(IDictionary)), baseParameters[2].Type); - Assert.AreEqual("prop1", baseParameters[0].Name); - Assert.AreEqual(new CSharpType(typeof(string)), derivedParameters[0].Type); - Assert.AreEqual("prop2", baseParameters[1].Name); - Assert.AreEqual(new CSharpType(typeof(string), true), derivedParameters[1].Type); - Assert.AreEqual("serializedAdditionalRawData", derivedParameters[2].Name); - Assert.AreEqual(new CSharpType(typeof(IDictionary)), derivedParameters[2].Type); - Assert.AreEqual("prop3", derivedParameters[3].Name); - Assert.AreEqual(new CSharpType(typeof(string)), derivedParameters[3].Type); - Assert.AreEqual("prop4", derivedParameters[4].Name); - Assert.AreEqual(new CSharpType(typeof(string), true), derivedParameters[4].Type); - } - } -} diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/MrwSerializationTypeDefinitionTests.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/MrwSerializationTypeDefinitionTests.cs index 759151f6167..0ffd7305f24 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/MrwSerializationTypeDefinitionTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/MrwSerializationTypeDefinitionTests.cs @@ -22,10 +22,10 @@ internal class MrwSerializationTypeDefinitionTests public MrwSerializationTypeDefinitionTests() { MockHelpers.LoadMockPlugin(createSerializationsCore: (inputType, typeProvider) => - inputType is InputModelType modelType ? [new MrwSerializationTypeDefinition(modelType, typeProvider)] : []); + inputType is InputModelType modelType ? [new MrwSerializationTypeDefinition(modelType, (typeProvider as ModelProvider)!)] : []); } - internal static (TypeProvider Model, MrwSerializationTypeDefinition Serialization) CreateModelAndSerialization(InputModelType inputModel) + internal static (ModelProvider Model, MrwSerializationTypeDefinition Serialization) CreateModelAndSerialization(InputModelType inputModel) { var model = ClientModelPlugin.Instance.TypeFactory.CreateModel(inputModel); var serializations = model!.SerializationProviders; @@ -33,7 +33,7 @@ internal static (TypeProvider Model, MrwSerializationTypeDefinition Serializatio Assert.AreEqual(1, serializations.Count); Assert.IsInstanceOf(serializations[0]); - return (model, (MrwSerializationTypeDefinition)serializations[0]); + return ((model as ModelProvider)!, (MrwSerializationTypeDefinition)serializations[0]); } [Test] @@ -471,37 +471,15 @@ public void TestBuildPersistableModelGetFormatMethodObjectDeclaration() Assert.AreEqual(1, bodyExpression?.Arguments.Count); } - [Test] - public void TestBuildSerializationConstructor() - { - var inputModel = new InputModelType("mockInputModel", "mockNamespace", "public", null, null, InputModelTypeUsage.Input | InputModelTypeUsage.Output, Array.Empty(), null, new List(), null, null, new Dictionary(), null, false); - var (model, serialization) = CreateModelAndSerialization(inputModel); - var constructor = serialization.BuildSerializationConstructor(); - - Assert.IsNotNull(constructor); - var constructorSignature = constructor?.Signature; - Assert.IsNotNull(constructorSignature); - Assert.AreEqual(1, constructorSignature?.Parameters.Count); - - var param = constructorSignature?.Parameters[0]; - Assert.IsNotNull(param); - Assert.AreEqual("serializedAdditionalRawData", param?.Name); - } - [Test] public void TestBuildFields() { var inputModel = new InputModelType("mockInputModel", "mockNamespace", "public", null, null, InputModelTypeUsage.Input | InputModelTypeUsage.Output, Array.Empty(), null, new List(), null, null, new Dictionary(), null, false); - var (model, serialization) = CreateModelAndSerialization(inputModel); + var (_, serialization) = CreateModelAndSerialization(inputModel); var fields = serialization.Fields; - // Assert Assert.IsNotNull(fields); - Assert.AreEqual(1, fields.Count); - Assert.AreEqual("_serializedAdditionalRawData", fields[0].Name); - - var type = fields[0].Type; - Assert.IsTrue(type.IsCollection); + Assert.AreEqual(0, fields.Count); } [Test] @@ -517,17 +495,13 @@ public void TestBuildConstructor_ValidateConstructors() var inputModel = new InputModelType("TestModel", "TestModel", "public", null, "Test model.", InputModelTypeUsage.Input | InputModelTypeUsage.Output, properties, null, Array.Empty(), null, null, new Dictionary(), null, false); - var (model, serialization) = CreateModelAndSerialization(inputModel); + var (_, serialization) = CreateModelAndSerialization(inputModel); var ctors = serialization.Constructors; Assert.IsNotNull(ctors); - Assert.AreEqual(2, ctors.Count); - - var serializationCtor = ctors[0]; - Assert.AreEqual(MethodSignatureModifiers.Internal, serializationCtor.Signature.Modifiers); - Assert.AreEqual(5, serializationCtor.Signature.Parameters.Count); + Assert.AreEqual(1, ctors.Count); - var emptyCtor = ctors[1]; + var emptyCtor = ctors[0]; Assert.AreEqual(MethodSignatureModifiers.Internal, emptyCtor.Signature.Modifiers); Assert.AreEqual(0, emptyCtor.Signature.Parameters.Count); } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/PersistableModelCoreTests.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/PersistableModelCoreTests.cs index 9f5464b422a..7f95019d948 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/PersistableModelCoreTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp.ClientModel/test/Providers/MrwSerializationTypeDefinitions/PersistableModelCoreTests.cs @@ -16,13 +16,13 @@ public class PersistableModelCoreTests public PersistableModelCoreTests() { MockHelpers.LoadMockPlugin(createSerializationsCore: (inputType, typeProvider) - => inputType is InputModelType modeltype ? [new MockMrwProvider(modeltype, typeProvider)] : []); + => inputType is InputModelType modeltype ? [new MockMrwProvider(modeltype, (typeProvider as ModelProvider)!)] : []); } private class MockMrwProvider : MrwSerializationTypeDefinition { - public MockMrwProvider(InputModelType inputModel, TypeProvider typeProvider) - : base(inputModel, typeProvider) + public MockMrwProvider(InputModelType inputModel, ModelProvider modelProvider) + : base(inputModel, modelProvider) { } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/ModelFactoryProvider.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/ModelFactoryProvider.cs index 8fff3afcd54..d0a98fd7edf 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/ModelFactoryProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/ModelFactoryProvider.cs @@ -17,6 +17,7 @@ namespace Microsoft.Generator.CSharp.Providers internal class ModelFactoryProvider : TypeProvider { private const string ModelFactorySuffix = "ModelFactory"; + private const string AdditionalRawDataParameterName = "serializedAdditionalRawData"; private readonly IEnumerable _models; @@ -66,17 +67,18 @@ protected override MethodProvider[] BuildMethods() var methods = new List(_models.Count()); foreach (var model in _models) { - var modelProvider = CodeModelPlugin.Instance.TypeFactory.CreateModel(model); + var modelProvider = CodeModelPlugin.Instance.TypeFactory.CreateModel(model) as ModelProvider; if (modelProvider is null || modelProvider.DeclarationModifiers.HasFlag(TypeSignatureModifiers.Internal)) continue; + var modelCtor = modelProvider.FullConstructor; var signature = new MethodSignature( modelProvider.Name, null, MethodSignatureModifiers.Static | MethodSignatureModifiers.Public, modelProvider.Type, $"A new {modelProvider.Type:C} instance for mocking.", - GetParameters(modelProvider)); + GetParameters(modelCtor)); var docs = new XmlDocProvider(); docs.Summary = modelProvider.XmlDocs?.Summary; @@ -98,7 +100,7 @@ .. GetCollectionInitialization(signature), return [.. methods]; } - private IReadOnlyList GetCtorParams(MethodSignature signature) + private static IReadOnlyList GetCtorParams(MethodSignature signature) { var expressions = new List(signature.Parameters.Count); foreach (var param in signature.Parameters) @@ -112,6 +114,7 @@ private IReadOnlyList GetCtorParams(MethodSignature signature) expressions.Add(param); } } + expressions.Add(Null); return [.. expressions]; } @@ -133,20 +136,21 @@ private IReadOnlyList GetCollectionInitialization(MethodSig return [.. statements]; } - private IReadOnlyList GetParameters(TypeProvider modelProvider) + private static IReadOnlyList GetParameters(ConstructorProvider modelFullConstructor) { - var parameters = new List(modelProvider.Properties.Count); - foreach (var property in modelProvider.Properties) + var modelCtorParams = modelFullConstructor.Signature.Parameters; + var parameters = new List(modelCtorParams.Count); + foreach (var param in modelCtorParams) { - if (property.Modifiers.HasFlag(MethodSignatureModifiers.Internal)) + if (param.Name.Equals(AdditionalRawDataParameterName)) continue; - parameters.Add(GetModelFactoryParam(property.AsParameter)); + parameters.Add(GetModelFactoryParam(param)); } return [.. parameters]; } - private ParameterProvider GetModelFactoryParam(ParameterProvider parameter) + private static ParameterProvider GetModelFactoryParam(ParameterProvider parameter) { return new ParameterProvider( parameter.Name, diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/ModelProvider.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/ModelProvider.cs index 88591d9c2a9..9a9c6fbb08b 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/ModelProvider.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/src/Providers/ModelProvider.cs @@ -16,12 +16,19 @@ namespace Microsoft.Generator.CSharp.Providers { public sealed class ModelProvider : TypeProvider { + private const string PrivateAdditionalPropertiesPropertyDescription = "Keeps track of any properties unknown to the library."; + private const string PrivateAdditionalPropertiesPropertyName = "_serializedAdditionalRawData"; private readonly InputModelType _inputModel; protected override FormattableString Description { get; } private readonly bool _isStruct; private readonly TypeSignatureModifiers _declarationModifiers; + private readonly CSharpType _privateAdditionalRawDataPropertyType = typeof(IDictionary); + private readonly Lazy? _baseTypeProvider; + private FieldProvider? _rawDataField; + private ModelProvider? _baseModelProvider; + private ConstructorProvider? _fullConstructor; public ModelProvider(InputModelType inputModel) { @@ -29,6 +36,7 @@ public ModelProvider(InputModelType inputModel) Description = inputModel.Description != null ? FormattableStringHelpers.FromString(inputModel.Description) : $"The {Name}."; _declarationModifiers = TypeSignatureModifiers.Partial | (inputModel.ModelAsStruct ? TypeSignatureModifiers.ReadOnly | TypeSignatureModifiers.Struct : TypeSignatureModifiers.Class); + if (inputModel.Access == "internal") { _declarationModifiers |= TypeSignatureModifiers.Internal; @@ -40,17 +48,25 @@ public ModelProvider(InputModelType inputModel) _declarationModifiers |= TypeSignatureModifiers.Abstract; } + if (inputModel.BaseModel is not null) + { + _baseTypeProvider = new(() => CodeModelPlugin.Instance.TypeFactory.CreateModel(inputModel.BaseModel)); + } + _isStruct = inputModel.ModelAsStruct; } + private ModelProvider? BaseModelProvider + => _baseModelProvider ??= (_baseTypeProvider?.Value is ModelProvider baseModelProvider ? baseModelProvider : null); + private FieldProvider? RawDataField => _rawDataField ??= BuildRawDataField(); + + public ConstructorProvider FullConstructor => _fullConstructor ??= BuildFullConstructor(); + protected override string GetNamespace() => CodeModelPlugin.Instance.Configuration.ModelNamespace; protected override CSharpType? GetBaseType() { - if (_inputModel.BaseModel == null) - return null; - - return CodeModelPlugin.Instance.TypeFactory.CreateModel(_inputModel.BaseModel)?.Type; + return BaseModelProvider?.Type; } protected override TypeProvider[] BuildSerializationProviders() @@ -64,6 +80,15 @@ protected override TypeProvider[] BuildSerializationProviders() protected override TypeSignatureModifiers GetDeclarationModifiers() => _declarationModifiers; + /// + /// Builds the fields for the model by adding the raw data field. + /// + /// The list of for the model. + protected override FieldProvider[] BuildFields() + { + return RawDataField != null ? [RawDataField] : []; + } + protected override PropertyProvider[] BuildProperties() { var propertiesCount = _inputModel.Properties.Count; @@ -86,7 +111,7 @@ protected override ConstructorProvider[] BuildConstructors() { if (_inputModel.IsUnknownDiscriminatorModel) { - return []; + return [FullConstructor]; } // Build the initialization constructor @@ -95,7 +120,7 @@ protected override ConstructorProvider[] BuildConstructors() : _inputModel.Usage.HasFlag(InputModelTypeUsage.Input) ? MethodSignatureModifiers.Public : MethodSignatureModifiers.Internal; - var (constructorParameters, constructorInitializer) = BuildConstructorParameters(); + var (constructorParameters, constructorInitializer) = BuildConstructorParameters(true); var constructor = new ConstructorProvider( signature: new ConstructorSignature( @@ -106,28 +131,64 @@ protected override ConstructorProvider[] BuildConstructors() Initializer: constructorInitializer), bodyStatements: new MethodBodyStatement[] { - GetPropertyInitializers(constructorParameters) + GetPropertyInitializers(true, parameters: constructorParameters) }, this); + if (!constructorParameters.SequenceEqual(FullConstructor.Signature.Parameters)) + { + return [constructor, FullConstructor]; + } + return [constructor]; } - // TODO -- figure out how to reuse this piece of code because similar code exists in MrwSerializationDefinition as well https://github.com/microsoft/typespec/issues/3871 - private (IReadOnlyList Parameters, ConstructorInitializer? Initializer) BuildConstructorParameters() + /// + /// Builds the internal constructor for the model which contains all public properties + /// as parameters. + /// + private ConstructorProvider BuildFullConstructor() { - // we need to find all the properties on our base model, we add the reverse because our convention is to have the properties from base model first. - var baseProperties = _inputModel.GetAllBaseModels().Reverse().SelectMany(model => CodeModelPlugin.Instance.TypeFactory.CreateModel(model)?.Properties ?? []); - var basePropertyCount = baseProperties.Count(); - var parameterCapacity = basePropertyCount + Properties.Count; - var baseParameters = new List(basePropertyCount); - var constructorParameters = new List(parameterCapacity); - - // add the base parameters + var (ctorParameters, ctorInitializer) = BuildConstructorParameters(false); + + return new ConstructorProvider( + signature: new ConstructorSignature( + Type, + $"Initializes a new instance of {Type:C}", + MethodSignatureModifiers.Internal, + ctorParameters, + Initializer: ctorInitializer), + bodyStatements: new MethodBodyStatement[] + { + GetPropertyInitializers(false) + }, + this); + } + + private (IReadOnlyList Parameters, ConstructorInitializer? Initializer) BuildConstructorParameters( + bool isPrimaryConstructor) + { + var baseParameters = new List(); + var constructorParameters = new List(); + IEnumerable baseProperties = []; + + if (isPrimaryConstructor) + { + baseProperties = _inputModel.GetAllBaseModels() + .Reverse() + .SelectMany(model => CodeModelPlugin.Instance.TypeFactory.CreateModel(model)?.Properties ?? []); + } + else if (BaseModelProvider?.FullConstructor.Signature != null) + { + baseParameters.AddRange(BaseModelProvider.FullConstructor.Signature.Parameters); + } + + // add the base parameters, if any foreach (var property in baseProperties) { - AddInitializationParameter(baseParameters, property, _isStruct); + AddInitializationParameterForCtor(baseParameters, property, _isStruct, isPrimaryConstructor); } + constructorParameters.AddRange(baseParameters); // construct the initializer using the parameters from base signature @@ -135,19 +196,32 @@ protected override ConstructorProvider[] BuildConstructors() foreach (var property in Properties) { - AddInitializationParameter(constructorParameters, property, _isStruct); + AddInitializationParameterForCtor(constructorParameters, property, _isStruct, isPrimaryConstructor); + } + + if (RawDataField != null && !isPrimaryConstructor) + { + constructorParameters.Add(RawDataField.AsParameter); } return (constructorParameters, constructorInitializer); + } - static void AddInitializationParameter(List parameters, PropertyProvider property, bool isStruct) + private static void AddInitializationParameterForCtor( + List parameters, + PropertyProvider property, + bool isStruct, + bool isPrimaryConstructor) + { + // We only add those properties with wire info indicating they are coming from specs. + if (property.WireInfo is not { } wireInfo) { - // we only add those properties with wire info indicating they are coming from specs. - if (property.WireInfo is not { } wireInfo) - { - return; - } - if (isStruct || (wireInfo is { IsRequired: true, IsDiscriminator: false } && !property.Type.IsLiteral)) + return; + } + + if (isPrimaryConstructor) + { + if (isStruct || (wireInfo.IsRequired && !wireInfo.IsDiscriminator && !property.Type.IsLiteral)) { if (!wireInfo.IsReadOnly) { @@ -155,18 +229,35 @@ static void AddInitializationParameter(List parameters, Prope } } } + else + { + // For the serialization constructor, we always add the property as a parameter + parameters.Add(property.AsParameter); + } } - private MethodBodyStatement GetPropertyInitializers(IReadOnlyList parameters) + private MethodBodyStatement GetPropertyInitializers( + bool isPrimaryConstructor, + IReadOnlyList? parameters = null) { - List methodBodyStatements = new(); - - Dictionary parameterMap = parameters.ToDictionary( - parameter => parameter.Name, - parameter => parameter); + List methodBodyStatements = new(Properties.Count + 1); + Dictionary parameterMap = parameters?.ToDictionary(p => p.Name) ?? []; foreach (var property in Properties) { + // skip those non-spec properties + if (property.WireInfo == null) + { + continue; + } + + if (!isPrimaryConstructor) + { + // always add the property for the serialization constructor + methodBodyStatements.Add(property.Assign(property.AsParameter).Terminate()); + continue; + } + ValueExpression? initializationValue = null; if (parameterMap.TryGetValue(property.AsParameter.Name, out var parameter) || _isStruct) @@ -194,7 +285,39 @@ private MethodBodyStatement GetPropertyInitializers(IReadOnlyList + /// Builds the raw data field for the model to be used for serialization. + /// + /// The constructed if the model should generate the field. + private FieldProvider? BuildRawDataField() + { + // check if there is a raw data field on my base, if so, we do not have to have one here + if (BaseModelProvider?.RawDataField != null) + { + return null; + } + + var modifiers = FieldModifiers.Private; + if (!DeclarationModifiers.HasFlag(TypeSignatureModifiers.Sealed)) + { + modifiers |= FieldModifiers.Protected; + } + + var rawDataField = new FieldProvider( + modifiers: modifiers, + type: _privateAdditionalRawDataPropertyType, + description: FormattableStringHelpers.FromString(PrivateAdditionalPropertiesPropertyDescription), + name: PrivateAdditionalPropertiesPropertyName); + + return rawDataField; + } } } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviderTests.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviderTests.cs index 9be72c0d4b5..4384435efc7 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviderTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Providers/ModelProviderTests.cs @@ -102,7 +102,7 @@ public static IEnumerable BuildProperties_ValidatePropertySettersT }; [Test] - public void BuildConstructor_ValidateConstructors() + public void TestBuildConstructor_ValidateConstructors() { var properties = new List{ new InputModelProperty("requiredString", "requiredString", "", InputPrimitiveType.String, true, false, false), @@ -132,15 +132,20 @@ public void BuildConstructor_ValidateConstructors() var ctors = modelTypeProvider.Constructors; Assert.IsNotNull(ctors); - Assert.AreEqual(1, ctors.Count); + Assert.AreEqual(2, ctors.Count); - var initializationCtor = ctors[0]; - Assert.AreEqual(MethodSignatureModifiers.Public, initializationCtor.Signature.Modifiers); + var initializationCtor = ctors.FirstOrDefault(c => c.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Public)); + Assert.IsNotNull(initializationCtor); + Assert.AreEqual(MethodSignatureModifiers.Public, initializationCtor!.Signature.Modifiers); Assert.AreEqual(3, initializationCtor.Signature.Parameters.Count); + + var secondaryCtor = ctors.FirstOrDefault(c => c.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Internal)); + Assert.IsNotNull(secondaryCtor); + Assert.AreEqual(6, secondaryCtor!.Signature.Parameters.Count); } [Test] - public void BuildConstructor_ValidateConstructorsInDerivedModel() + public void TestBuildConstructor_ValidateConstructorsInDerivedModel() { var baseProperties = new List { @@ -163,15 +168,18 @@ public void BuildConstructor_ValidateConstructorsInDerivedModel() Assert.NotNull(baseModel); var baseCtors = baseModel!.Constructors; - Assert.AreEqual(1, baseCtors.Count); + Assert.AreEqual(2, baseCtors.Count); Assert.NotNull(derivedModel); var derivedCtors = derivedModel!.Constructors; - Assert.AreEqual(1, derivedCtors.Count); + Assert.AreEqual(2, derivedCtors.Count); + + var baseCtor = baseCtors.FirstOrDefault(c => c.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Public)); + var derivedCtor = derivedCtors.FirstOrDefault(c => c.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Public)); + Assert.NotNull(baseCtor); + Assert.NotNull(derivedCtor); - var baseCtor = baseCtors[0]; - var derivedCtor = derivedCtors[0]; - var baseParameters = baseCtor.Signature.Parameters; - var derivedParameters = derivedCtor.Signature.Parameters; + var baseParameters = baseCtor!.Signature.Parameters; + var derivedParameters = derivedCtor!.Signature.Parameters; Assert.AreEqual(1, baseParameters.Count); Assert.AreEqual("prop1", baseParameters[0].Name); Assert.AreEqual(new CSharpType(typeof(string)), baseParameters[0].Type); @@ -180,6 +188,53 @@ public void BuildConstructor_ValidateConstructorsInDerivedModel() Assert.AreEqual(new CSharpType(typeof(string)), derivedParameters[0].Type); Assert.AreEqual("prop3", derivedParameters[1].Name); Assert.AreEqual(new CSharpType(typeof(string)), derivedParameters[1].Type); + + // validate the secondary constructor + var secondaryCtor = baseCtors.FirstOrDefault(c => c.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Internal)); + var derivedSecondaryCtor = derivedCtors.FirstOrDefault(c => c.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Internal)); + Assert.NotNull(secondaryCtor); + Assert.NotNull(derivedSecondaryCtor); + + var secondaryCtorParameters = secondaryCtor!.Signature.Parameters; + var derivedSecondaryCtorParams = derivedSecondaryCtor!.Signature.Parameters; + + // validate secondary constructor + Assert.AreEqual(3, secondaryCtorParameters.Count); // 2 properties + 1 additionalRawData + Assert.AreEqual("prop1", secondaryCtorParameters[0].Name); + Assert.AreEqual(new CSharpType(typeof(string)), secondaryCtorParameters[0].Type); + Assert.AreEqual("prop2", secondaryCtorParameters[1].Name); + Assert.AreEqual(new CSharpType(typeof(string), true), secondaryCtorParameters[1].Type); + Assert.AreEqual("serializedAdditionalRawData", secondaryCtorParameters[2].Name); + Assert.AreEqual(new CSharpType(typeof(IDictionary)), secondaryCtorParameters[2].Type); + // validate derived secondary constructor + Assert.AreEqual(5, derivedSecondaryCtorParams.Count); // all base props + 2 properties + 1 additionalRawData + Assert.AreEqual("prop1", derivedSecondaryCtorParams[0].Name); + Assert.AreEqual(new CSharpType(typeof(string)), derivedSecondaryCtorParams[0].Type); + Assert.AreEqual("prop2", derivedSecondaryCtorParams[1].Name); + Assert.AreEqual(new CSharpType(typeof(string), true), derivedSecondaryCtorParams[1].Type); + Assert.AreEqual("serializedAdditionalRawData", derivedSecondaryCtorParams[2].Name); + Assert.AreEqual(new CSharpType(typeof(IDictionary)), derivedSecondaryCtorParams[2].Type); + Assert.AreEqual("prop3", derivedSecondaryCtorParams[3].Name); + Assert.AreEqual(new CSharpType(typeof(string)), derivedSecondaryCtorParams[3].Type); + Assert.AreEqual("prop4", derivedSecondaryCtorParams[4].Name); + Assert.AreEqual(new CSharpType(typeof(string), true), derivedSecondaryCtorParams[4].Type); + } + + [Test] + public void TestBuildSecondaryConstructor() + { + var inputModel = new InputModelType("TestModel", "TestModel", "public", null, "Test model.", InputModelTypeUsage.Input | InputModelTypeUsage.Output, [], null, Array.Empty(), null, null, new Dictionary(), null, false); + var modelTypeProvider = new ModelProvider(inputModel); + var secondaryConstructor = modelTypeProvider.Constructors.FirstOrDefault(c => c.Signature.Modifiers.HasFlag(MethodSignatureModifiers.Internal)); + + Assert.IsNotNull(secondaryConstructor); + var constructorSignature = secondaryConstructor?.Signature; + Assert.IsNotNull(constructorSignature); + Assert.AreEqual(1, constructorSignature?.Parameters.Count); + + var param = constructorSignature?.Parameters[0]; + Assert.IsNotNull(param); + Assert.AreEqual("serializedAdditionalRawData", param?.Name); } [Test] @@ -225,5 +280,21 @@ public void BuildModelAsStruct() var modelTypeProvider = new ModelProvider(inputModel); Assert.AreEqual(TypeSignatureModifiers.Public | TypeSignatureModifiers.Struct | TypeSignatureModifiers.Partial | TypeSignatureModifiers.ReadOnly, modelTypeProvider.DeclarationModifiers); } + + [Test] + public void TestBuildFields() + { + var inputModel = new InputModelType("TestModel", "TestModel", "public", null, "Test model.", InputModelTypeUsage.Input | InputModelTypeUsage.Output, [], null, Array.Empty(), null, null, new Dictionary(), null, false); + var modelTypeProvider = new ModelProvider(inputModel); + var fields = modelTypeProvider.Fields; + + // Assert + Assert.IsNotNull(fields); + Assert.AreEqual(1, fields.Count); + Assert.AreEqual("_serializedAdditionalRawData", fields[0].Name); + + var type = fields[0].Type; + Assert.IsTrue(type.IsCollection); + } } } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Writers/TestData/TypeProviderWriterTests/TypeProviderWriter_WriteModel.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Writers/TestData/TypeProviderWriterTests/TypeProviderWriter_WriteModel.cs index 135ea17a8e7..d73f1b3e763 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Writers/TestData/TypeProviderWriterTests/TypeProviderWriter_WriteModel.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Writers/TestData/TypeProviderWriterTests/TypeProviderWriter_WriteModel.cs @@ -3,6 +3,7 @@ #nullable disable using System; +using System.Collections.Generic; using Sample; namespace Sample.Models @@ -10,6 +11,9 @@ namespace Sample.Models /// Test model. public partial class TestModel { + /// Keeps track of any properties unknown to the library. + private global::System.Collections.Generic.IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// Required string, illustrating a reference type property. /// Required int, illustrating a value type property. @@ -22,6 +26,13 @@ public TestModel(string requiredString, int requiredInt) RequiredInt = requiredInt; } + internal TestModel(string requiredString, int requiredInt, global::System.Collections.Generic.IDictionary serializedAdditionalRawData) + { + RequiredString = requiredString; + RequiredInt = requiredInt; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + /// Required string, illustrating a reference type property. public string RequiredString { get; set; } diff --git a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Writers/TestData/TypeProviderWriterTests/TypeProviderWriter_WriteModelAsStruct.cs b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Writers/TestData/TypeProviderWriterTests/TypeProviderWriter_WriteModelAsStruct.cs index cefc259e49e..5947efd6e6e 100644 --- a/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Writers/TestData/TypeProviderWriterTests/TypeProviderWriter_WriteModelAsStruct.cs +++ b/packages/http-client-csharp/generator/Microsoft.Generator.CSharp/test/Writers/TestData/TypeProviderWriterTests/TypeProviderWriter_WriteModelAsStruct.cs @@ -3,6 +3,7 @@ #nullable disable using System; +using System.Collections.Generic; using Sample; namespace Sample.Models @@ -10,6 +11,9 @@ namespace Sample.Models /// Test model. public readonly partial struct TestModel { + /// Keeps track of any properties unknown to the library. + private global::System.Collections.Generic.IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// Required string, illustrating a reference type property. /// Required int, illustrating a value type property. @@ -22,6 +26,13 @@ public TestModel(string requiredString, int requiredInt) RequiredInt = requiredInt; } + internal TestModel(string requiredString, int requiredInt, global::System.Collections.Generic.IDictionary serializedAdditionalRawData) + { + RequiredString = requiredString; + RequiredInt = requiredInt; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + /// Required string, illustrating a reference type property. public string RequiredString { get; set; } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/AnonymousBodyRequest.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/AnonymousBodyRequest.Serialization.cs index e8f5bf92130..ae451492ff2 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/AnonymousBodyRequest.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/AnonymousBodyRequest.Serialization.cs @@ -14,27 +14,6 @@ namespace UnbrandedTypeSpec.Models /// public partial class AnonymousBodyRequest : IJsonModel { - /// Keeps track of any properties unknown to the library. - private IDictionary _serializedAdditionalRawData; - - internal AnonymousBodyRequest(string name, BinaryData requiredUnion, AnonymousBodyRequestRequiredLiteralString requiredLiteralString, AnonymousBodyRequestRequiredLiteralInt requiredLiteralInt, AnonymousBodyRequestRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, AnonymousBodyRequestOptionalLiteralString? optionalLiteralString, AnonymousBodyRequestOptionalLiteralInt? optionalLiteralInt, AnonymousBodyRequestOptionalLiteralFloat? optionalLiteralFloat, bool? optionalLiteralBool, string requiredBadDescription, IList optionalNullableList, IList requiredNullableList, IDictionary serializedAdditionalRawData) - { - Name = name; - RequiredUnion = requiredUnion; - RequiredLiteralString = requiredLiteralString; - RequiredLiteralInt = requiredLiteralInt; - RequiredLiteralFloat = requiredLiteralFloat; - RequiredLiteralBool = requiredLiteralBool; - OptionalLiteralString = optionalLiteralString; - OptionalLiteralInt = optionalLiteralInt; - OptionalLiteralFloat = optionalLiteralFloat; - OptionalLiteralBool = optionalLiteralBool; - RequiredBadDescription = requiredBadDescription; - OptionalNullableList = optionalNullableList; - RequiredNullableList = requiredNullableList; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - internal AnonymousBodyRequest() { } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/AnonymousBodyRequest.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/AnonymousBodyRequest.cs index f27d4508cd4..f3990e0ab41 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/AnonymousBodyRequest.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/AnonymousBodyRequest.cs @@ -13,6 +13,9 @@ namespace UnbrandedTypeSpec.Models /// The AnonymousBodyRequest. public partial class AnonymousBodyRequest { + /// Keeps track of any properties unknown to the library. + private IDictionary _serializedAdditionalRawData; + internal AnonymousBodyRequest(string name, BinaryData requiredUnion, string requiredBadDescription, IEnumerable requiredNullableList) { Name = name; @@ -22,6 +25,24 @@ internal AnonymousBodyRequest(string name, BinaryData requiredUnion, string requ RequiredNullableList = requiredNullableList?.ToList(); } + internal AnonymousBodyRequest(string name, BinaryData requiredUnion, AnonymousBodyRequestRequiredLiteralString requiredLiteralString, AnonymousBodyRequestRequiredLiteralInt requiredLiteralInt, AnonymousBodyRequestRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, AnonymousBodyRequestOptionalLiteralString? optionalLiteralString, AnonymousBodyRequestOptionalLiteralInt? optionalLiteralInt, AnonymousBodyRequestOptionalLiteralFloat? optionalLiteralFloat, bool? optionalLiteralBool, string requiredBadDescription, IList optionalNullableList, IList requiredNullableList, IDictionary serializedAdditionalRawData) + { + Name = name; + RequiredUnion = requiredUnion; + RequiredLiteralString = requiredLiteralString; + RequiredLiteralInt = requiredLiteralInt; + RequiredLiteralFloat = requiredLiteralFloat; + RequiredLiteralBool = requiredLiteralBool; + OptionalLiteralString = optionalLiteralString; + OptionalLiteralInt = optionalLiteralInt; + OptionalLiteralFloat = optionalLiteralFloat; + OptionalLiteralBool = optionalLiteralBool; + RequiredBadDescription = requiredBadDescription; + OptionalNullableList = optionalNullableList; + RequiredNullableList = requiredNullableList; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + /// name of the Thing. public string Name { get; set; } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Friend.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Friend.Serialization.cs index aaa33a52caf..52185a7693f 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Friend.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Friend.Serialization.cs @@ -14,15 +14,6 @@ namespace UnbrandedTypeSpec.Models /// public partial class Friend : IJsonModel { - /// Keeps track of any properties unknown to the library. - private IDictionary _serializedAdditionalRawData; - - internal Friend(string name, IDictionary serializedAdditionalRawData) - { - Name = name; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - internal Friend() { } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Friend.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Friend.cs index c0c5278ef2f..57cf2e65c65 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Friend.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Friend.cs @@ -2,16 +2,28 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace UnbrandedTypeSpec.Models { /// this is not a friendly model but with a friendly name. public partial class Friend { + /// Keeps track of any properties unknown to the library. + private IDictionary _serializedAdditionalRawData; + internal Friend(string name) { Name = name; } + internal Friend(string name, IDictionary serializedAdditionalRawData) + { + Name = name; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + /// name of the NotFriend. public string Name { get; set; } } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/FriendlyModelRequest.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/FriendlyModelRequest.Serialization.cs index 8d3368c78d7..bee8747b3c3 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/FriendlyModelRequest.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/FriendlyModelRequest.Serialization.cs @@ -14,15 +14,6 @@ namespace UnbrandedTypeSpec.Models /// public partial class FriendlyModelRequest : IJsonModel { - /// Keeps track of any properties unknown to the library. - private IDictionary _serializedAdditionalRawData; - - internal FriendlyModelRequest(string name, IDictionary serializedAdditionalRawData) - { - Name = name; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - internal FriendlyModelRequest() { } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/FriendlyModelRequest.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/FriendlyModelRequest.cs index f00cb7192a5..f48ffdeca89 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/FriendlyModelRequest.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/FriendlyModelRequest.cs @@ -2,16 +2,28 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace UnbrandedTypeSpec.Models { /// The FriendlyModelRequest. public partial class FriendlyModelRequest { + /// Keeps track of any properties unknown to the library. + private IDictionary _serializedAdditionalRawData; + internal FriendlyModelRequest(string name) { Name = name; } + internal FriendlyModelRequest(string name, IDictionary serializedAdditionalRawData) + { + Name = name; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + /// name of the NotFriend. public string Name { get; set; } } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.Serialization.cs index 96283583f4a..f89d12b6d7c 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.Serialization.cs @@ -14,17 +14,6 @@ namespace UnbrandedTypeSpec.Models /// public partial class ModelWithRequiredNullableProperties : IJsonModel { - /// Keeps track of any properties unknown to the library. - private IDictionary _serializedAdditionalRawData; - - internal ModelWithRequiredNullableProperties(int? requiredNullablePrimitive, StringExtensibleEnum? requiredExtensibleEnum, StringFixedEnum? requiredFixedEnum, IDictionary serializedAdditionalRawData) - { - RequiredNullablePrimitive = requiredNullablePrimitive; - RequiredExtensibleEnum = requiredExtensibleEnum; - RequiredFixedEnum = requiredFixedEnum; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - internal ModelWithRequiredNullableProperties() { } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.cs index e84593a20e9..cc3b5f7026b 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.cs @@ -2,11 +2,17 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace UnbrandedTypeSpec.Models { /// A model with a few required nullable properties. public partial class ModelWithRequiredNullableProperties { + /// Keeps track of any properties unknown to the library. + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// required nullable primitive type. /// required nullable extensible enum type. @@ -18,6 +24,14 @@ public ModelWithRequiredNullableProperties(int? requiredNullablePrimitive, Strin RequiredFixedEnum = requiredFixedEnum; } + internal ModelWithRequiredNullableProperties(int? requiredNullablePrimitive, StringExtensibleEnum? requiredExtensibleEnum, StringFixedEnum? requiredFixedEnum, IDictionary serializedAdditionalRawData) + { + RequiredNullablePrimitive = requiredNullablePrimitive; + RequiredExtensibleEnum = requiredExtensibleEnum; + RequiredFixedEnum = requiredFixedEnum; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + /// required nullable primitive type. public int? RequiredNullablePrimitive { get; set; } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedModel.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedModel.Serialization.cs index 0cd9837d553..edae0338742 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedModel.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedModel.Serialization.cs @@ -14,15 +14,6 @@ namespace UnbrandedTypeSpec.Models /// public partial class ProjectedModel : IJsonModel { - /// Keeps track of any properties unknown to the library. - private IDictionary _serializedAdditionalRawData; - - internal ProjectedModel(string name, IDictionary serializedAdditionalRawData) - { - Name = name; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - internal ProjectedModel() { } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedModel.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedModel.cs index df2d716f954..243219cc974 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedModel.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedModel.cs @@ -2,16 +2,28 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace UnbrandedTypeSpec.Models { /// this is a model with a projected name. public partial class ProjectedModel { + /// Keeps track of any properties unknown to the library. + private IDictionary _serializedAdditionalRawData; + internal ProjectedModel(string name) { Name = name; } + internal ProjectedModel(string name, IDictionary serializedAdditionalRawData) + { + Name = name; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + /// name of the ModelWithProjectedName. public string Name { get; set; } } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedNameModelRequest.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedNameModelRequest.Serialization.cs index 619c0189d22..84ca8f84e3f 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedNameModelRequest.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedNameModelRequest.Serialization.cs @@ -14,15 +14,6 @@ namespace UnbrandedTypeSpec.Models /// public partial class ProjectedNameModelRequest : IJsonModel { - /// Keeps track of any properties unknown to the library. - private IDictionary _serializedAdditionalRawData; - - internal ProjectedNameModelRequest(string name, IDictionary serializedAdditionalRawData) - { - Name = name; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - internal ProjectedNameModelRequest() { } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedNameModelRequest.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedNameModelRequest.cs index a27f7d042f2..6c0c9696d56 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedNameModelRequest.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ProjectedNameModelRequest.cs @@ -2,16 +2,28 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace UnbrandedTypeSpec.Models { /// The ProjectedNameModelRequest. public partial class ProjectedNameModelRequest { + /// Keeps track of any properties unknown to the library. + private IDictionary _serializedAdditionalRawData; + internal ProjectedNameModelRequest(string name) { Name = name; } + internal ProjectedNameModelRequest(string name, IDictionary serializedAdditionalRawData) + { + Name = name; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + /// name of the ModelWithProjectedName. public string Name { get; set; } } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ReturnsAnonymousModelResponse.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ReturnsAnonymousModelResponse.Serialization.cs index bc74620661e..6cef383a25e 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ReturnsAnonymousModelResponse.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ReturnsAnonymousModelResponse.Serialization.cs @@ -14,14 +14,6 @@ namespace UnbrandedTypeSpec.Models /// public partial class ReturnsAnonymousModelResponse : IJsonModel { - /// Keeps track of any properties unknown to the library. - private IDictionary _serializedAdditionalRawData; - - internal ReturnsAnonymousModelResponse(IDictionary serializedAdditionalRawData) - { - _serializedAdditionalRawData = serializedAdditionalRawData; - } - void IJsonModel.Write(Utf8JsonWriter writer, ModelReaderWriterOptions options) { writer.WriteStartObject(); diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ReturnsAnonymousModelResponse.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ReturnsAnonymousModelResponse.cs index d83a56f3465..d6210b21e66 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ReturnsAnonymousModelResponse.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ReturnsAnonymousModelResponse.cs @@ -2,13 +2,24 @@ #nullable disable +using System; +using System.Collections.Generic; + namespace UnbrandedTypeSpec.Models { /// The ReturnsAnonymousModelResponse. public partial class ReturnsAnonymousModelResponse { + /// Keeps track of any properties unknown to the library. + private IDictionary _serializedAdditionalRawData; + internal ReturnsAnonymousModelResponse() { } + + internal ReturnsAnonymousModelResponse(IDictionary serializedAdditionalRawData) + { + _serializedAdditionalRawData = serializedAdditionalRawData; + } } } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs index 8cdfca05185..dae9fe23026 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs @@ -14,38 +14,6 @@ namespace UnbrandedTypeSpec.Models /// public partial class RoundTripModel : IJsonModel { - /// Keeps track of any properties unknown to the library. - private IDictionary _serializedAdditionalRawData; - - internal RoundTripModel(string requiredString, int requiredInt, IList requiredCollection, IDictionary requiredDictionary, Thing requiredModel, IntExtensibleEnum? intExtensibleEnum, IList intExtensibleEnumCollection, FloatExtensibleEnum? floatExtensibleEnum, FloatExtensibleEnumWithIntValue? floatExtensibleEnumWithIntValue, IList floatExtensibleEnumCollection, FloatFixedEnum? floatFixedEnum, FloatFixedEnumWithIntValue? floatFixedEnumWithIntValue, IList floatFixedEnumCollection, IntFixedEnum? intFixedEnum, IList intFixedEnumCollection, StringFixedEnum? stringFixedEnum, BinaryData requiredUnknown, BinaryData optionalUnknown, IDictionary requiredRecordUnknown, IDictionary optionalRecordUnknown, IReadOnlyDictionary readOnlyRequiredRecordUnknown, IReadOnlyDictionary readOnlyOptionalRecordUnknown, ModelWithRequiredNullableProperties modelWithRequiredNullable, BinaryData requiredBytes, IDictionary serializedAdditionalRawData) - { - RequiredString = requiredString; - RequiredInt = requiredInt; - RequiredCollection = requiredCollection; - RequiredDictionary = requiredDictionary; - RequiredModel = requiredModel; - IntExtensibleEnum = intExtensibleEnum; - IntExtensibleEnumCollection = intExtensibleEnumCollection; - FloatExtensibleEnum = floatExtensibleEnum; - FloatExtensibleEnumWithIntValue = floatExtensibleEnumWithIntValue; - FloatExtensibleEnumCollection = floatExtensibleEnumCollection; - FloatFixedEnum = floatFixedEnum; - FloatFixedEnumWithIntValue = floatFixedEnumWithIntValue; - FloatFixedEnumCollection = floatFixedEnumCollection; - IntFixedEnum = intFixedEnum; - IntFixedEnumCollection = intFixedEnumCollection; - StringFixedEnum = stringFixedEnum; - RequiredUnknown = requiredUnknown; - OptionalUnknown = optionalUnknown; - RequiredRecordUnknown = requiredRecordUnknown; - OptionalRecordUnknown = optionalRecordUnknown; - ReadOnlyRequiredRecordUnknown = readOnlyRequiredRecordUnknown; - ReadOnlyOptionalRecordUnknown = readOnlyOptionalRecordUnknown; - ModelWithRequiredNullable = modelWithRequiredNullable; - RequiredBytes = requiredBytes; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - internal RoundTripModel() { } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/RoundTripModel.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/RoundTripModel.cs index 676eba05dfb..7bd748f8af0 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/RoundTripModel.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/RoundTripModel.cs @@ -13,6 +13,9 @@ namespace UnbrandedTypeSpec.Models /// this is a roundtrip model. public partial class RoundTripModel { + /// Keeps track of any properties unknown to the library. + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// Required string, illustrating a reference type property. /// Required int, illustrating a value type property. @@ -53,6 +56,35 @@ public RoundTripModel(string requiredString, int requiredInt, IEnumerable requiredCollection, IDictionary requiredDictionary, Thing requiredModel, IntExtensibleEnum? intExtensibleEnum, IList intExtensibleEnumCollection, FloatExtensibleEnum? floatExtensibleEnum, FloatExtensibleEnumWithIntValue? floatExtensibleEnumWithIntValue, IList floatExtensibleEnumCollection, FloatFixedEnum? floatFixedEnum, FloatFixedEnumWithIntValue? floatFixedEnumWithIntValue, IList floatFixedEnumCollection, IntFixedEnum? intFixedEnum, IList intFixedEnumCollection, StringFixedEnum? stringFixedEnum, BinaryData requiredUnknown, BinaryData optionalUnknown, IDictionary requiredRecordUnknown, IDictionary optionalRecordUnknown, IReadOnlyDictionary readOnlyRequiredRecordUnknown, IReadOnlyDictionary readOnlyOptionalRecordUnknown, ModelWithRequiredNullableProperties modelWithRequiredNullable, BinaryData requiredBytes, IDictionary serializedAdditionalRawData) + { + RequiredString = requiredString; + RequiredInt = requiredInt; + RequiredCollection = requiredCollection; + RequiredDictionary = requiredDictionary; + RequiredModel = requiredModel; + IntExtensibleEnum = intExtensibleEnum; + IntExtensibleEnumCollection = intExtensibleEnumCollection; + FloatExtensibleEnum = floatExtensibleEnum; + FloatExtensibleEnumWithIntValue = floatExtensibleEnumWithIntValue; + FloatExtensibleEnumCollection = floatExtensibleEnumCollection; + FloatFixedEnum = floatFixedEnum; + FloatFixedEnumWithIntValue = floatFixedEnumWithIntValue; + FloatFixedEnumCollection = floatFixedEnumCollection; + IntFixedEnum = intFixedEnum; + IntFixedEnumCollection = intFixedEnumCollection; + StringFixedEnum = stringFixedEnum; + RequiredUnknown = requiredUnknown; + OptionalUnknown = optionalUnknown; + RequiredRecordUnknown = requiredRecordUnknown; + OptionalRecordUnknown = optionalRecordUnknown; + ReadOnlyRequiredRecordUnknown = readOnlyRequiredRecordUnknown; + ReadOnlyOptionalRecordUnknown = readOnlyOptionalRecordUnknown; + ModelWithRequiredNullable = modelWithRequiredNullable; + RequiredBytes = requiredBytes; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + /// Required string, illustrating a reference type property. public string RequiredString { get; set; } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.Serialization.cs index effd4fc052a..323d56091b3 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.Serialization.cs @@ -14,27 +14,6 @@ namespace UnbrandedTypeSpec.Models /// public partial class Thing : IJsonModel { - /// Keeps track of any properties unknown to the library. - private IDictionary _serializedAdditionalRawData; - - internal Thing(string name, BinaryData requiredUnion, ThingRequiredLiteralString requiredLiteralString, ThingRequiredLiteralInt requiredLiteralInt, ThingRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, ThingOptionalLiteralString? optionalLiteralString, ThingOptionalLiteralInt? optionalLiteralInt, ThingOptionalLiteralFloat? optionalLiteralFloat, bool? optionalLiteralBool, string requiredBadDescription, IList optionalNullableList, IList requiredNullableList, IDictionary serializedAdditionalRawData) - { - Name = name; - RequiredUnion = requiredUnion; - RequiredLiteralString = requiredLiteralString; - RequiredLiteralInt = requiredLiteralInt; - RequiredLiteralFloat = requiredLiteralFloat; - RequiredLiteralBool = requiredLiteralBool; - OptionalLiteralString = optionalLiteralString; - OptionalLiteralInt = optionalLiteralInt; - OptionalLiteralFloat = optionalLiteralFloat; - OptionalLiteralBool = optionalLiteralBool; - RequiredBadDescription = requiredBadDescription; - OptionalNullableList = optionalNullableList; - RequiredNullableList = requiredNullableList; - _serializedAdditionalRawData = serializedAdditionalRawData; - } - internal Thing() { } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.cs index 2b045c194d3..35c8e19739d 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.cs @@ -13,6 +13,9 @@ namespace UnbrandedTypeSpec.Models /// A model with a few properties of literal types. public partial class Thing { + /// Keeps track of any properties unknown to the library. + private IDictionary _serializedAdditionalRawData; + /// Initializes a new instance of . /// name of the Thing. /// required Union. @@ -32,6 +35,24 @@ public Thing(string name, BinaryData requiredUnion, string requiredBadDescriptio RequiredNullableList = requiredNullableList?.ToList(); } + internal Thing(string name, BinaryData requiredUnion, ThingRequiredLiteralString requiredLiteralString, ThingRequiredLiteralInt requiredLiteralInt, ThingRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, ThingOptionalLiteralString? optionalLiteralString, ThingOptionalLiteralInt? optionalLiteralInt, ThingOptionalLiteralFloat? optionalLiteralFloat, bool? optionalLiteralBool, string requiredBadDescription, IList optionalNullableList, IList requiredNullableList, IDictionary serializedAdditionalRawData) + { + Name = name; + RequiredUnion = requiredUnion; + RequiredLiteralString = requiredLiteralString; + RequiredLiteralInt = requiredLiteralInt; + RequiredLiteralFloat = requiredLiteralFloat; + RequiredLiteralBool = requiredLiteralBool; + OptionalLiteralString = optionalLiteralString; + OptionalLiteralInt = optionalLiteralInt; + OptionalLiteralFloat = optionalLiteralFloat; + OptionalLiteralBool = optionalLiteralBool; + RequiredBadDescription = requiredBadDescription; + OptionalNullableList = optionalNullableList; + RequiredNullableList = requiredNullableList; + _serializedAdditionalRawData = serializedAdditionalRawData; + } + /// name of the Thing. public string Name { get; set; }