diff --git a/src/AutoRest.CSharp/Common/AutoRest/Plugins/Configuration.cs b/src/AutoRest.CSharp/Common/AutoRest/Plugins/Configuration.cs index 0d89f53d19c..74b1af9d7a6 100644 --- a/src/AutoRest.CSharp/Common/AutoRest/Plugins/Configuration.cs +++ b/src/AutoRest.CSharp/Common/AutoRest/Plugins/Configuration.cs @@ -49,6 +49,7 @@ public static class Options public const string PublicDiscriminatorProperty = "public-discriminator-property"; public const string ShouldTreatBase64AsBinaryData = "should-treat-base64-as-binary-data"; public const string MethodsToKeepClientDefaultValue = "methods-to-keep-client-default-value"; + public const string DeserializeNullCollectionAsNullValue = "deserialize-null-collection-as-null-value"; public const string UseCoreDataFactoryReplacements = "use-core-datafactory-replacements"; } @@ -76,6 +77,7 @@ public static void Initialize( bool disablePaginationTopRenaming, bool generateModelFactory, bool publicDiscriminatorProperty, + bool deserializeNullCollectionAsNullValue, bool useCoreDataFactoryReplacements, IReadOnlyList modelFactoryForHlc, UnreferencedTypesHandlingOption unreferencedTypesHandling, @@ -106,6 +108,7 @@ public static void Initialize( SingleTopLevelClient = singleTopLevelClient; GenerateModelFactory = generateModelFactory; PublicDiscriminatorProperty = publicDiscriminatorProperty; + DeserializeNullCollectionAsNullValue = deserializeNullCollectionAsNullValue; UnreferencedTypesHandling = unreferencedTypesHandling; UseOverloadsBetweenProtocolAndConvenience = useOverloadsBetweenProtocolAndConvenience; KeepNonOverloadableProtocolSignature = keepNonOverloadableProtocolSignature; @@ -237,6 +240,12 @@ public static void Initialize( /// If true, the discriminator property will be public. If false (default), the discriminator property will be internal. /// public static bool PublicDiscriminatorProperty { get; private set; } + + /// + /// Whether we should deserialize null collections in the payload as null values if this sets to true. + /// Default value is false, where we will construct an empty collection (ChangeTrackingList or ChangeTrackingDictionary) if we get null value for collections in the payload + /// + public static bool DeserializeNullCollectionAsNullValue { get; private set; } public static bool UseOverloadsBetweenProtocolAndConvenience { get; private set; } public static bool KeepNonOverloadableProtocolSignature { get; private set; } @@ -288,6 +297,7 @@ public static void Initialize(IPluginCommunication autoRest, string defaultNames disablePaginationTopRenaming: GetOptionBoolValue(autoRest, Options.DisablePaginationTopRenaming), generateModelFactory: GetOptionBoolValue(autoRest, Options.GenerateModelFactory), publicDiscriminatorProperty: GetOptionBoolValue(autoRest, Options.PublicDiscriminatorProperty), + deserializeNullCollectionAsNullValue: GetOptionBoolValue(autoRest, Options.DeserializeNullCollectionAsNullValue), modelFactoryForHlc: autoRest.GetValue(Options.ModelFactoryForHlc).GetAwaiter().GetResult() ?? Array.Empty(), unreferencedTypesHandling: GetOptionEnumValue(autoRest, Options.UnreferencedTypesHandling), useOverloadsBetweenProtocolAndConvenience: GetOptionBoolValue(autoRest, Options.UseOverloadsBetweenProtocolAndConvenience), @@ -367,6 +377,8 @@ private static bool GetOptionBoolValue(IPluginCommunication autoRest, string opt return false; case Options.ShouldTreatBase64AsBinaryData: return true; + case Options.DeserializeNullCollectionAsNullValue: + return false; case Options.UseCoreDataFactoryReplacements: return true; default: @@ -438,6 +450,7 @@ internal static void LoadConfiguration(JsonElement root, string? projectPath, st ReadOption(root, Options.DisablePaginationTopRenaming), ReadOption(root, Options.GenerateModelFactory), ReadOption(root, Options.PublicDiscriminatorProperty), + ReadOption(root, Options.DeserializeNullCollectionAsNullValue), ReadOption(root, Options.UseCoreDataFactoryReplacements), oldModelFactoryEntries, ReadEnumOption(root, Options.UnreferencedTypesHandling), diff --git a/src/AutoRest.CSharp/Common/Generation/Writers/CodeWriterExtensions.cs b/src/AutoRest.CSharp/Common/Generation/Writers/CodeWriterExtensions.cs index b284520fa78..33187d5d0dd 100644 --- a/src/AutoRest.CSharp/Common/Generation/Writers/CodeWriterExtensions.cs +++ b/src/AutoRest.CSharp/Common/Generation/Writers/CodeWriterExtensions.cs @@ -5,6 +5,8 @@ using System.Collections.Generic; using System.Diagnostics; using System.Linq; +using System.Text.Json; +using AutoRest.CSharp.Common.Output.Models; using AutoRest.CSharp.Generation.Types; using AutoRest.CSharp.Output.Models; using AutoRest.CSharp.Output.Models.Requests; @@ -15,11 +17,9 @@ using AutoRest.CSharp.Output.Models.Types; using AutoRest.CSharp.Utilities; using Azure; -using AutoRest.CSharp.Common.Output.Models; using Azure.Core; -using static AutoRest.CSharp.Output.Models.MethodSignatureModifiers; -using System.Text.Json; using Azure.Core.Pipeline; +using static AutoRest.CSharp.Output.Models.MethodSignatureModifiers; namespace AutoRest.CSharp.Generation.Writers { @@ -143,7 +143,7 @@ public static CodeWriter WriteFieldDeclarations(this CodeWriter writer, IEnumera public static IDisposable WriteMethodDeclaration(this CodeWriter writer, MethodSignatureBase methodBase, params string[] disabledWarnings) { - if (methodBase.Attributes is {} attributes) + if (methodBase.Attributes is { } attributes) { foreach (var attribute in attributes) { @@ -620,6 +620,9 @@ internal static string GetConversion(CodeWriter writer, CSharpType from, CSharpT } var propertyName = property.PropertyName; + if (TypeFactory.IsCollectionType(property.ValueType) && property.IsRequired) + return writer.Scope($"if ({propertyName} != null && {typeof(Optional)}.{nameof(Optional.IsCollectionDefined)}({propertyName}))"); + return writer.Scope($"if ({propertyName} != null)"); } diff --git a/src/AutoRest.CSharp/Common/Generation/Writers/JsonCodeWriterExtensions.cs b/src/AutoRest.CSharp/Common/Generation/Writers/JsonCodeWriterExtensions.cs index c431b563fc5..3dcab7b824e 100644 --- a/src/AutoRest.CSharp/Common/Generation/Writers/JsonCodeWriterExtensions.cs +++ b/src/AutoRest.CSharp/Common/Generation/Writers/JsonCodeWriterExtensions.cs @@ -365,7 +365,24 @@ private static void DeserializeIntoObjectProperties(this CodeWriter writer, IEnu var emptyStringCheck = GetEmptyStringCheckClause(property, itemVariable, shouldTreatEmptyStringAsNull); using (writer.Scope($"if ({itemVariable}.Value.ValueKind == {typeof(JsonValueKind)}.Null{emptyStringCheck})")) { - writer.Line($"{propertyVariables[property].Declaration} = null;"); + if (Configuration.DeserializeNullCollectionAsNullValue) + { + // we will assign null to everything if we have this configuration on + writer.Line($"{propertyVariables[property].Declaration} = null;"); + } + else + { + // we only assign null when it is not a collection if we have this configuration off + if (!TypeFactory.IsCollectionType(property.ValueType)) + { + writer.Line($"{propertyVariables[property].Declaration} = null;"); + } + else if (property.IsRequired) + { + // specially when it is required, we assign ChangeTrackingList because for optional lists we are already doing that + writer.Line($"{propertyVariables[property].Declaration} = new {TypeFactory.GetPropertyImplementationType(property.ValueType)}();"); + } + } writer.Append($"continue;"); } } diff --git a/src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs b/src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs index b15b2c138bb..306a69bab5f 100644 --- a/src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs +++ b/src/AutoRest.CSharp/Common/Input/CodeModelConverter.cs @@ -246,7 +246,8 @@ private InputModelType GetOrCreateModel(ObjectSchema schema, SchemaUsageProvider : null, DerivedModels: derived, DiscriminatorValue: schema.DiscriminatorValue, - DiscriminatorPropertyName: schema.Discriminator?.Property.SerializedName); + DiscriminatorPropertyName: schema.Discriminator?.Property.SerializedName, + IsNullable: false); _modelsCache[schema] = model; _modelPropertiesCache[schema] = properties; @@ -380,8 +381,8 @@ private static InputType CreateType(Schema schema, string? format, IReadOnlyDict ChoiceSchema choiceSchema => CreateEnumType(choiceSchema, choiceSchema.ChoiceType, choiceSchema.Choices, true), SealedChoiceSchema choiceSchema => CreateEnumType(choiceSchema, choiceSchema.ChoiceType, choiceSchema.Choices, false), - ArraySchema array when IsDPG => new InputListType(array.Name, CreateType(array.ElementType, modelsCache, array.NullableItems ?? false)), - DictionarySchema dictionary when IsDPG => new InputDictionaryType(dictionary.Name, InputPrimitiveType.String, CreateType(dictionary.ElementType, modelsCache, dictionary.NullableItems ?? false)), + ArraySchema array when IsDPG => new InputListType(array.Name, CreateType(array.ElementType, modelsCache, array.NullableItems ?? false), false), + DictionarySchema dictionary when IsDPG => new InputDictionaryType(dictionary.Name, InputPrimitiveType.String, CreateType(dictionary.ElementType, modelsCache, dictionary.NullableItems ?? false), false), ObjectSchema objectSchema when IsDPG && modelsCache != null => modelsCache[objectSchema], AnySchema when IsDPG => InputIntrinsicType.Unknown, @@ -411,7 +412,7 @@ private static InputLiteralType CreateLiteralType(ConstantSchema constantSchema, _ => rawValue }; - return new InputLiteralType("Literal", valueType, normalizedValue); + return new InputLiteralType("Literal", valueType, normalizedValue, false); } public static InputEnumType CreateEnumType(Schema schema, PrimitiveSchema choiceType, IEnumerable choices, bool isExtensible) => new( diff --git a/src/AutoRest.CSharp/Common/Input/InputTypes/InputDictionaryType.cs b/src/AutoRest.CSharp/Common/Input/InputTypes/InputDictionaryType.cs index ce336a6dd82..061afdd2bbd 100644 --- a/src/AutoRest.CSharp/Common/Input/InputTypes/InputDictionaryType.cs +++ b/src/AutoRest.CSharp/Common/Input/InputTypes/InputDictionaryType.cs @@ -3,4 +3,4 @@ namespace AutoRest.CSharp.Common.Input; -internal record InputDictionaryType(string Name, InputType KeyType, InputType ValueType, bool IsNullable = false) : InputType(Name, IsNullable) { } +internal record InputDictionaryType(string Name, InputType KeyType, InputType ValueType, bool IsNullable) : InputType(Name, IsNullable) { } diff --git a/src/AutoRest.CSharp/Common/Input/InputTypes/InputListType.cs b/src/AutoRest.CSharp/Common/Input/InputTypes/InputListType.cs index 9589b8f1063..8deb7410c45 100644 --- a/src/AutoRest.CSharp/Common/Input/InputTypes/InputListType.cs +++ b/src/AutoRest.CSharp/Common/Input/InputTypes/InputListType.cs @@ -3,4 +3,4 @@ namespace AutoRest.CSharp.Common.Input; -internal record InputListType(string Name, InputType ElementType, bool IsNullable = false) : InputType(Name, IsNullable) { } +internal record InputListType(string Name, InputType ElementType, bool IsNullable) : InputType(Name, IsNullable) { } diff --git a/src/AutoRest.CSharp/Common/Input/InputTypes/InputLiteralType.cs b/src/AutoRest.CSharp/Common/Input/InputTypes/InputLiteralType.cs index a5b5c45d245..10bba53e995 100644 --- a/src/AutoRest.CSharp/Common/Input/InputTypes/InputLiteralType.cs +++ b/src/AutoRest.CSharp/Common/Input/InputTypes/InputLiteralType.cs @@ -3,4 +3,4 @@ namespace AutoRest.CSharp.Common.Input; -internal record InputLiteralType(string Name, InputType LiteralValueType, object Value, bool IsNullable = false) : InputType(Name, IsNullable); +internal record InputLiteralType(string Name, InputType LiteralValueType, object Value, bool IsNullable) : InputType(Name, IsNullable); diff --git a/src/AutoRest.CSharp/Common/Input/InputTypes/InputModelType.cs b/src/AutoRest.CSharp/Common/Input/InputTypes/InputModelType.cs index cd2d7aa9dc0..958959b3341 100644 --- a/src/AutoRest.CSharp/Common/Input/InputTypes/InputModelType.cs +++ b/src/AutoRest.CSharp/Common/Input/InputTypes/InputModelType.cs @@ -5,8 +5,8 @@ namespace AutoRest.CSharp.Common.Input { - internal record InputModelType(string Name, string? Namespace, string? Accessibility, string? Deprecated, string? Description, InputModelTypeUsage Usage, IReadOnlyList Properties, InputModelType? BaseModel, IReadOnlyList DerivedModels, string? DiscriminatorValue, string? DiscriminatorPropertyName) - : InputType(Name) + internal record InputModelType(string Name, string? Namespace, string? Accessibility, string? Deprecated, string? Description, InputModelTypeUsage Usage, IReadOnlyList Properties, InputModelType? BaseModel, IReadOnlyList DerivedModels, string? DiscriminatorValue, string? DiscriminatorPropertyName, bool IsNullable) + : InputType(Name, IsNullable) { /// /// Indicates if this model is the Unknown derived version of a model with discriminator diff --git a/src/AutoRest.CSharp/Common/Input/InputTypes/InputParameter.cs b/src/AutoRest.CSharp/Common/Input/InputTypes/InputParameter.cs index 579b8ee43cb..69dbd0cf66b 100644 --- a/src/AutoRest.CSharp/Common/Input/InputTypes/InputParameter.cs +++ b/src/AutoRest.CSharp/Common/Input/InputTypes/InputParameter.cs @@ -31,7 +31,7 @@ public InputParameter() : this( Name: string.Empty, NameInRequest: string.Empty, Description: null, - Type: new InputPrimitiveType(InputTypeKind.Object), + Type: new InputPrimitiveType(InputTypeKind.Object, false), Location: RequestLocation.None, DefaultValue: null, VirtualParameter: null, diff --git a/src/AutoRest.CSharp/Common/Input/InputTypes/InputPrimitiveType.cs b/src/AutoRest.CSharp/Common/Input/InputTypes/InputPrimitiveType.cs index 4f2d26c539e..2ad251b0f54 100644 --- a/src/AutoRest.CSharp/Common/Input/InputTypes/InputPrimitiveType.cs +++ b/src/AutoRest.CSharp/Common/Input/InputTypes/InputPrimitiveType.cs @@ -3,8 +3,10 @@ namespace AutoRest.CSharp.Common.Input; -internal record InputPrimitiveType(InputTypeKind Kind, bool IsNullable = false) : InputType(Kind.ToString(), IsNullable) +internal record InputPrimitiveType(InputTypeKind Kind, bool IsNullable) : InputType(Kind.ToString(), IsNullable) { + private InputPrimitiveType(InputTypeKind kind) : this(kind, false) { } + public static InputPrimitiveType AzureLocation { get; } = new(InputTypeKind.AzureLocation); public static InputPrimitiveType BinaryData { get; } = new(InputTypeKind.BinaryData); public static InputPrimitiveType Boolean { get; } = new(InputTypeKind.Boolean); diff --git a/src/AutoRest.CSharp/Common/Input/InputTypes/InputType.cs b/src/AutoRest.CSharp/Common/Input/InputTypes/InputType.cs index 1039086e103..efcce3d3efd 100644 --- a/src/AutoRest.CSharp/Common/Input/InputTypes/InputType.cs +++ b/src/AutoRest.CSharp/Common/Input/InputTypes/InputType.cs @@ -3,4 +3,4 @@ namespace AutoRest.CSharp.Common.Input; -internal abstract record InputType(string Name, bool IsNullable = false) { } +internal abstract record InputType(string Name, bool IsNullable) { } diff --git a/src/AutoRest.CSharp/Common/Input/InputTypes/InputUnionType.cs b/src/AutoRest.CSharp/Common/Input/InputTypes/InputUnionType.cs index 128256b4efa..80d29c99b23 100644 --- a/src/AutoRest.CSharp/Common/Input/InputTypes/InputUnionType.cs +++ b/src/AutoRest.CSharp/Common/Input/InputTypes/InputUnionType.cs @@ -5,4 +5,4 @@ namespace AutoRest.CSharp.Common.Input; -internal record InputUnionType(string Name, IReadOnlyList UnionItemTypes, bool IsNullable = false) : InputType(Name, IsNullable); +internal record InputUnionType(string Name, IReadOnlyList UnionItemTypes, bool IsNullable) : InputType(Name, IsNullable); diff --git a/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputDictionaryTypeConverter.cs b/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputDictionaryTypeConverter.cs index 0be990b31bb..b69b6d0e644 100644 --- a/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputDictionaryTypeConverter.cs +++ b/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputDictionaryTypeConverter.cs @@ -25,12 +25,14 @@ public override void Write(Utf8JsonWriter writer, InputDictionaryType value, Jso public static InputDictionaryType CreateDictionaryType(ref Utf8JsonReader reader, string? id, string? name, JsonSerializerOptions options) { var isFirstProperty = id == null && name == null; + bool isNullable = false; InputType? keyType = null; InputType? valueType = null; while (reader.TokenType != JsonTokenType.EndObject) { var isKnownProperty = reader.TryReadReferenceId(ref isFirstProperty, ref id) - || reader.TryReadString(nameof(InputListType.Name), ref name) + || reader.TryReadString(nameof(InputDictionaryType.Name), ref name) + || reader.TryReadBoolean(nameof(InputDictionaryType.IsNullable), ref isNullable) || reader.TryReadWithConverter(nameof(InputDictionaryType.KeyType), options, ref keyType) || reader.TryReadWithConverter(nameof(InputDictionaryType.ValueType), options, ref valueType); @@ -43,7 +45,7 @@ public static InputDictionaryType CreateDictionaryType(ref Utf8JsonReader reader keyType = keyType ?? throw new JsonException("Dictionary must have key type"); valueType = valueType ?? throw new JsonException("Dictionary must have value type"); - return new InputDictionaryType(name ?? "Dictionary", keyType, valueType); + return new InputDictionaryType(name ?? "Dictionary", keyType, valueType, isNullable); } } } diff --git a/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputEnumTypeConverter.cs b/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputEnumTypeConverter.cs index 74f238fa8ad..012335fb548 100644 --- a/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputEnumTypeConverter.cs +++ b/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputEnumTypeConverter.cs @@ -26,6 +26,7 @@ public override void Write(Utf8JsonWriter writer, InputEnumType value, JsonSeria public static InputEnumType CreateEnumType(ref Utf8JsonReader reader, string? id, string? name, JsonSerializerOptions options, ReferenceResolver resolver) { var isFirstProperty = id == null && name == null; + bool isNullable = false; string? ns = null; string? accessibility = null; string? deprecated = null; @@ -39,6 +40,7 @@ public static InputEnumType CreateEnumType(ref Utf8JsonReader reader, string? id { var isKnownProperty = reader.TryReadReferenceId(ref isFirstProperty, ref id) || reader.TryReadString(nameof(InputEnumType.Name), ref name) + || reader.TryReadBoolean(nameof(InputEnumType.IsNullable), ref isNullable) || reader.TryReadString(nameof(InputEnumType.Namespace), ref ns) || reader.TryReadString(nameof(InputEnumType.Accessibility), ref accessibility) || reader.TryReadString(nameof(InputEnumType.Deprecated), ref deprecated) @@ -98,7 +100,7 @@ public static InputEnumType CreateEnumType(ref Utf8JsonReader reader, string? id } valueType = currentType ?? throw new JsonException("Enum value type must be set."); - var enumType = new InputEnumType(name, ns, accessibility, deprecated, description, usage, valueType, NormalizeValues(allowedValues, valueType), isExtendable); + var enumType = new InputEnumType(name, ns, accessibility, deprecated, description, usage, valueType, NormalizeValues(allowedValues, valueType), isExtendable, IsNullable: isNullable); if (id != null) { resolver.AddReference(id, enumType); diff --git a/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputListTypeConverter.cs b/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputListTypeConverter.cs index 64165073bdd..d54a19f1775 100644 --- a/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputListTypeConverter.cs +++ b/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputListTypeConverter.cs @@ -25,11 +25,13 @@ public override void Write(Utf8JsonWriter writer, InputListType value, JsonSeria public static InputListType CreateListType(ref Utf8JsonReader reader, string? id, string? name, JsonSerializerOptions options) { var isFirstProperty = id == null && name == null; + bool isNullable = false; InputType? elementType = null; while (reader.TokenType != JsonTokenType.EndObject) { var isKnownProperty = reader.TryReadReferenceId(ref isFirstProperty, ref id) || reader.TryReadString(nameof(InputListType.Name), ref name) + || reader.TryReadBoolean(nameof(InputListType.IsNullable), ref isNullable) || reader.TryReadWithConverter(nameof(InputListType.ElementType), options, ref elementType); if (!isKnownProperty) @@ -39,7 +41,7 @@ public static InputListType CreateListType(ref Utf8JsonReader reader, string? id } elementType = elementType ?? throw new JsonException("List must have element type"); - return new InputListType(name ?? "List", elementType); + return new InputListType(name ?? "List", elementType, isNullable); } } } diff --git a/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputLiteralTypeConverter.cs b/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputLiteralTypeConverter.cs index 1c5c00bb1ce..d3ac17fadb1 100644 --- a/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputLiteralTypeConverter.cs +++ b/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputLiteralTypeConverter.cs @@ -26,6 +26,7 @@ public override void Write(Utf8JsonWriter writer, InputLiteralType value, JsonSe public static InputLiteralType CreateInputLiteralType(ref Utf8JsonReader reader, string? id, string? name, JsonSerializerOptions options, ReferenceResolver resolver) { var isFirstProperty = id == null && name == null; + bool isNullable = false; Object? value = null; InputType? type = null; @@ -33,6 +34,7 @@ public static InputLiteralType CreateInputLiteralType(ref Utf8JsonReader reader, { var isKnownProperty = reader.TryReadReferenceId(ref isFirstProperty, ref id) || reader.TryReadString(nameof(InputListType.Name), ref name) + || reader.TryReadBoolean(nameof(InputListType.IsNullable), ref isNullable) || reader.TryReadWithConverter(nameof(InputLiteralType.LiteralValueType), options, ref type); if (isKnownProperty) @@ -56,7 +58,7 @@ public static InputLiteralType CreateInputLiteralType(ref Utf8JsonReader reader, value = value ?? throw new JsonException("InputConstant must have value"); - var literalType = new InputLiteralType(name, type, value); + var literalType = new InputLiteralType(name, type, value, isNullable); if (id != null) { diff --git a/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputModelTypeConverter.cs b/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputModelTypeConverter.cs index 9a7ff9842f4..86f649e198a 100644 --- a/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputModelTypeConverter.cs +++ b/src/AutoRest.CSharp/Common/Input/InputTypes/Serialization/TypeSpecInputModelTypeConverter.cs @@ -30,7 +30,7 @@ public static InputModelType CreateModelType(ref Utf8JsonReader reader, string? { var isFirstProperty = id == null && name == null; var properties = new List(); - + bool isNullable = false; string? ns = null; string? accessibility = null; string? deprecated = null; @@ -44,6 +44,7 @@ public static InputModelType CreateModelType(ref Utf8JsonReader reader, string? { var isKnownProperty = reader.TryReadReferenceId(ref isFirstProperty, ref id) || reader.TryReadString(nameof(InputType.Name), ref name) + || reader.TryReadBoolean(nameof(InputModelType.IsNullable), ref isNullable) || reader.TryReadString(nameof(InputModelType.Namespace), ref ns) || reader.TryReadString(nameof(InputModelType.Accessibility), ref accessibility) || reader.TryReadString(nameof(InputModelType.Deprecated), ref deprecated) @@ -60,7 +61,7 @@ public static InputModelType CreateModelType(ref Utf8JsonReader reader, string? if (reader.GetString() == nameof(InputModelType.Properties)) { - model = CreateInputModelTypeInstance(id, name, ns, accessibility, deprecated, description, usageString, discriminatorValue, discriminatorPropertyName, baseModel, properties, resolver); + model = CreateInputModelTypeInstance(id, name, ns, accessibility, deprecated, description, usageString, discriminatorValue, discriminatorPropertyName, baseModel, properties, isNullable, resolver); reader.Read(); CreateProperties(ref reader, properties, options); if (reader.TokenType != JsonTokenType.EndObject) @@ -74,10 +75,10 @@ public static InputModelType CreateModelType(ref Utf8JsonReader reader, string? } } - return model ?? CreateInputModelTypeInstance(id, name, ns, accessibility, deprecated, description, usageString, discriminatorValue, discriminatorPropertyName, baseModel, properties, resolver); + return model ?? CreateInputModelTypeInstance(id, name, ns, accessibility, deprecated, description, usageString, discriminatorValue, discriminatorPropertyName, baseModel, properties, isNullable, resolver); } - private static InputModelType CreateInputModelTypeInstance(string? id, string? name, string? ns, string? accessibility, string? deprecated, string? description, string? usageString, string? discriminatorValue, string? discriminatorPropertyValue, InputModelType? baseModel, List properties, ReferenceResolver resolver) + private static InputModelType CreateInputModelTypeInstance(string? id, string? name, string? ns, string? accessibility, string? deprecated, string? description, string? usageString, string? discriminatorValue, string? discriminatorPropertyValue, InputModelType? baseModel, List properties, bool isNullable, ReferenceResolver resolver) { name = name ?? throw new JsonException("Model must have name"); InputModelTypeUsage usage = InputModelTypeUsage.None; @@ -85,7 +86,7 @@ private static InputModelType CreateInputModelTypeInstance(string? id, string? n { Enum.TryParse(usageString, ignoreCase: true, out usage); } - var model = new InputModelType(name, ns, accessibility, deprecated, description, usage, properties, baseModel, new List(), discriminatorValue, discriminatorPropertyValue); + var model = new InputModelType(name, ns, accessibility, deprecated, description, usage, properties, baseModel, new List(), discriminatorValue, discriminatorPropertyValue, IsNullable: isNullable); if (id != null) { resolver.AddReference(id, model); diff --git a/src/AutoRest.CSharp/Common/Output/Models/Types/ModelTypeProviderFields.cs b/src/AutoRest.CSharp/Common/Output/Models/Types/ModelTypeProviderFields.cs index fa8403e3bf0..cf3d2ab40d9 100644 --- a/src/AutoRest.CSharp/Common/Output/Models/Types/ModelTypeProviderFields.cs +++ b/src/AutoRest.CSharp/Common/Output/Models/Types/ModelTypeProviderFields.cs @@ -116,21 +116,41 @@ public ModelTypeProviderFields(InputModelType inputModel, TypeFactory typeFactor public IEnumerator GetEnumerator() => _fields.GetEnumerator(); IEnumerator IEnumerable.GetEnumerator() => GetEnumerator(); + private static bool ShouldPropertyOmitSetter(InputModelType inputModel, InputModelProperty property, CSharpType type) + { + if (property.IsDiscriminator) + { + // discriminator properties should be writeable because we need to set values to the discriminators in the public ctor of derived classes. + return false; + } + if (property.Type is InputLiteralType && property.IsRequired) + { + // we should remove the setter of required constant + return true; + } + + var propertyShouldOmitSetter = !inputModel.Usage.HasFlag(InputModelTypeUsage.Input) || property.IsReadOnly; + + if (TypeFactory.IsCollectionType(type)) + { + // nullable collection should be settable + // one exception is in the property bag, we never let them to be settable. + propertyShouldOmitSetter |= !property.Type.IsNullable || inputModel.IsPropertyBag; + } + else + { + // In mixed models required properties are not readonly + propertyShouldOmitSetter |= property.IsRequired && + inputModel.Usage.HasFlag(InputModelTypeUsage.Input) && + !inputModel.Usage.HasFlag(InputModelTypeUsage.Output); + } + + return propertyShouldOmitSetter; + } + private static FieldDeclaration CreateField(string fieldName, CSharpType originalType, InputModelType inputModel, InputModelProperty inputModelProperty, bool optionalViaNullability) { - var propertyIsCollection = inputModelProperty.Type is InputDictionaryType or InputListType || - // This is a temporary work around as we don't convert collection type to InputListType or InputDictionaryType in MPG for now - inputModelProperty.Type is CodeModelType type && (type.Schema is ArraySchema or DictionarySchema); - var propertyIsRequiredInNonRoundTripModel = inputModel.Usage is InputModelTypeUsage.Input or InputModelTypeUsage.Output && inputModelProperty.IsRequired; - var propertyIsOptionalInOutputModel = inputModel.Usage is InputModelTypeUsage.Output && !inputModelProperty.IsRequired; - var propertyIsLiteralType = inputModelProperty.Type is InputLiteralType; - var propertyIsDiscriminator = inputModelProperty.IsDiscriminator; - var propertyShouldOmitSetter = !propertyIsDiscriminator && // if a property is a discriminator, it should always has its setter - (inputModelProperty.IsReadOnly || // a property will not have setter when it is readonly - (propertyIsLiteralType && inputModelProperty.IsRequired) || // a property will not have setter when it is required literal type - propertyIsCollection || // a property will not have setter when it is a collection - propertyIsRequiredInNonRoundTripModel || // a property will explicitly omit its setter when it is useless - propertyIsOptionalInOutputModel); // a property will explicitly omit its setter when it is useless + var propertyShouldOmitSetter = ShouldPropertyOmitSetter(inputModel, inputModelProperty, originalType); var valueType = originalType; if (optionalViaNullability) @@ -140,7 +160,7 @@ private static FieldDeclaration CreateField(string fieldName, CSharpType origina FieldModifiers fieldModifiers; FieldModifiers? setterModifiers = null; - if (propertyIsDiscriminator) + if (inputModelProperty.IsDiscriminator) { fieldModifiers = Configuration.PublicDiscriminatorProperty ? Public : Internal; setterModifiers = Configuration.PublicDiscriminatorProperty ? Internal | Protected : null; diff --git a/src/AutoRest.CSharp/Common/Output/Models/Types/SchemaObjectType.cs b/src/AutoRest.CSharp/Common/Output/Models/Types/SchemaObjectType.cs index c555cda0609..74c830ec288 100644 --- a/src/AutoRest.CSharp/Common/Output/Models/Types/SchemaObjectType.cs +++ b/src/AutoRest.CSharp/Common/Output/Models/Types/SchemaObjectType.cs @@ -457,19 +457,19 @@ protected ObjectTypeProperty CreateProperty(Property property) bool isCollection = TypeFactory.IsCollectionType(type); - bool isReadOnly = IsStruct || + bool propertyShouldOmitSetter = IsStruct || !_usage.HasFlag(SchemaTypeUsage.Input) || property.IsReadOnly; if (isCollection) { - isReadOnly |= !property.IsNullable; + propertyShouldOmitSetter |= !property.IsNullable; } else { // In mixed models required properties are not readonly - isReadOnly |= property.IsRequired && + propertyShouldOmitSetter |= property.IsRequired && _usage.HasFlag(SchemaTypeUsage.Input) && !_usage.HasFlag(SchemaTypeUsage.Output); } @@ -477,19 +477,19 @@ protected ObjectTypeProperty CreateProperty(Property property) // we should remove the setter of required constant if (property.Schema is ConstantSchema && property.IsRequired) { - isReadOnly = true; + propertyShouldOmitSetter = true; } if (property.IsDiscriminator == true) { // Discriminator properties should be writeable - isReadOnly = false; + propertyShouldOmitSetter = false; } var objectTypeProperty = new ObjectTypeProperty( memberDeclaration, BuilderHelpers.EscapeXmlDocDescription(property.Language.Default.Description), - isReadOnly, + propertyShouldOmitSetter, property, valueType, optionalViaNullability, diff --git a/src/AutoRest.CSharp/LowLevel/Output/DpgOutputLibraryBuilder.cs b/src/AutoRest.CSharp/LowLevel/Output/DpgOutputLibraryBuilder.cs index 18fa8171d81..4b83cac6200 100644 --- a/src/AutoRest.CSharp/LowLevel/Output/DpgOutputLibraryBuilder.cs +++ b/src/AutoRest.CSharp/LowLevel/Output/DpgOutputLibraryBuilder.cs @@ -130,7 +130,8 @@ private void CreateModels(IDictionary models, actualBase, Array.Empty(), "Unknown", //TODO: do we need to support extensible enum / int values? - null) + null, + false) { IsUnknownDiscriminatorModel = true }; diff --git a/src/AutoRest.CSharp/Mgmt/Output/Models/MgmtPropertyBag.cs b/src/AutoRest.CSharp/Mgmt/Output/Models/MgmtPropertyBag.cs index a4a2d985969..72f2d465b33 100644 --- a/src/AutoRest.CSharp/Mgmt/Output/Models/MgmtPropertyBag.cs +++ b/src/AutoRest.CSharp/Mgmt/Output/Models/MgmtPropertyBag.cs @@ -43,9 +43,7 @@ protected override TypeProvider EnsurePackModel() foreach (var parameter in _paramsToKeep) { var inputParameter = _operation.Parameters.FirstOrDefault(p => string.Equals(p.Name, parameter.Name, StringComparison.OrdinalIgnoreCase)); - string? description = parameter.Description; - if (description == null) - description = $"The {parameter.Name}"; + string? description = parameter.Description ?? $"The {parameter.Name}"; var property = new InputModelProperty(parameter.Name, null, description, inputParameter!.Type, parameter.DefaultValue == null, false, false) { DefaultValue = GetDefaultValue(parameter) @@ -64,7 +62,8 @@ protected override TypeProvider EnsurePackModel() null, Array.Empty(), null, - null) + null, + false) { IsPropertyBag = true }; diff --git a/src/TypeSpec.Extension/Emitter.Csharp/src/emitter.ts b/src/TypeSpec.Extension/Emitter.Csharp/src/emitter.ts index da7e37c71fd..266967a1ff1 100644 --- a/src/TypeSpec.Extension/Emitter.Csharp/src/emitter.ts +++ b/src/TypeSpec.Extension/Emitter.Csharp/src/emitter.ts @@ -149,7 +149,9 @@ export async function $onEmit(context: EmitContext) { ) : undefined, "methods-to-keep-client-default-value": - options["methods-to-keep-client-default-value"] + options["methods-to-keep-client-default-value"], + "deserialize-null-collection-as-null-value": + options["deserialize-null-collection-as-null-value"] } as Configuration; await program.host.writeFile( diff --git a/src/TypeSpec.Extension/Emitter.Csharp/src/options.ts b/src/TypeSpec.Extension/Emitter.Csharp/src/options.ts index d04b146d8c7..a6cd3606369 100644 --- a/src/TypeSpec.Extension/Emitter.Csharp/src/options.ts +++ b/src/TypeSpec.Extension/Emitter.Csharp/src/options.ts @@ -27,6 +27,7 @@ export type NetEmitterOptions = { "models-to-treat-empty-string-as-null"?: string[]; "additional-intrinsic-types-to-treat-empty-string-as-null"?: string[]; "methods-to-keep-client-default-value"?: string[]; + "deserialize-null-collection-as-null-value"?: boolean; logLevel?: string; "package-dir"?: string; } & SdkEmitterOptions; @@ -84,6 +85,10 @@ export const NetEmitterOptionsSchema: JSONSchemaType = { nullable: true, items: { type: "string" } }, + "deserialize-null-collection-as-null-value": { + type: "boolean", + nullable: true + }, logLevel: { type: "string", enum: [ @@ -116,6 +121,7 @@ const defaultOptions = { "models-to-treat-empty-string-as-null": undefined, "additional-intrinsic-types-to-treat-empty-string-as-null": [], "methods-to-keep-client-default-value": undefined, + "deserialize-null-collection-as-null-value": undefined, logLevel: LoggerLevel.INFO }; diff --git a/src/TypeSpec.Extension/Emitter.Csharp/src/type/configuration.ts b/src/TypeSpec.Extension/Emitter.Csharp/src/type/configuration.ts index 49e891c7b11..4e9eeacb03d 100644 --- a/src/TypeSpec.Extension/Emitter.Csharp/src/type/configuration.ts +++ b/src/TypeSpec.Extension/Emitter.Csharp/src/type/configuration.ts @@ -15,4 +15,5 @@ export interface Configuration { "models-to-treat-empty-string-as-null"?: string[]; "additional-intrinsic-types-to-treat-empty-string-as-null"?: string[]; "methods-to-keep-client-default-value"?: string[]; + "deserialize-null-collection-as-null-value"?: boolean; } diff --git a/test/AutoRest.TestServer.Tests/Common/Utilities/NamedTypeSymbolExtensionsTests.cs b/test/AutoRest.TestServer.Tests/Common/Utilities/NamedTypeSymbolExtensionsTests.cs index 675af550e6f..d7de5ba6622 100644 --- a/test/AutoRest.TestServer.Tests/Common/Utilities/NamedTypeSymbolExtensionsTests.cs +++ b/test/AutoRest.TestServer.Tests/Common/Utilities/NamedTypeSymbolExtensionsTests.cs @@ -92,6 +92,7 @@ public void Method(int? nullableInt, List intList, List nullableIntLi disablePaginationTopRenaming: false, generateModelFactory: false, publicDiscriminatorProperty: false, + deserializeNullCollectionAsNullValue: false, useCoreDataFactoryReplacements: true, modelFactoryForHlc: Array.Empty(), unreferencedTypesHandling: Configuration.UnreferencedTypesHandlingOption.RemoveOrInternalize, @@ -152,12 +153,12 @@ public void IsSameType_PrimitiveTypes() public void IsSameType_ModelTypes() { // Different namespace - var input = new InputModelType("MetadataModel", "", null, null, null, InputModelTypeUsage.RoundTrip, null, null, null, null, null); + var input = new InputModelType("MetadataModel", "", null, null, null, InputModelTypeUsage.RoundTrip, null, null, null, null, null, false); CSharpType modelType = new CSharpType(new ModelTypeProvider(input, "", null)); Assert.IsFalse(_modelSymbol.IsSameType(modelType)); // Same namespace - input = new InputModelType("MetadataModel", "NamedTypeSymbolExtensionsTests", null, null, null, InputModelTypeUsage.RoundTrip, null, null, null, null, null); + input = new InputModelType("MetadataModel", "NamedTypeSymbolExtensionsTests", null, null, null, InputModelTypeUsage.RoundTrip, null, null, null, null, null, false); modelType = new CSharpType(new ModelTypeProvider(input, "NamedTypeSymbolExtensionsTests", null)); Assert.IsTrue(_modelSymbol.IsSameType(modelType)); } diff --git a/test/AutoRest.TestServer.Tests/Mgmt/Unit/MgmtRestOperationTests.cs b/test/AutoRest.TestServer.Tests/Mgmt/Unit/MgmtRestOperationTests.cs index fd9ed20cb1d..4cbf0863c86 100644 --- a/test/AutoRest.TestServer.Tests/Mgmt/Unit/MgmtRestOperationTests.cs +++ b/test/AutoRest.TestServer.Tests/Mgmt/Unit/MgmtRestOperationTests.cs @@ -67,6 +67,7 @@ public void Setup() disablePaginationTopRenaming: false, generateModelFactory: true, publicDiscriminatorProperty: false, + deserializeNullCollectionAsNullValue: false, modelFactoryForHlc: Array.Empty(), unreferencedTypesHandling: Configuration.UnreferencedTypesHandlingOption.RemoveOrInternalize, useOverloadsBetweenProtocolAndConvenience: true, diff --git a/test/AutoRest.TestServer.Tests/ModelShapeTests.cs b/test/AutoRest.TestServer.Tests/ModelShapeTests.cs index ad7e22d94bf..7d605849e22 100644 --- a/test/AutoRest.TestServer.Tests/ModelShapeTests.cs +++ b/test/AutoRest.TestServer.Tests/ModelShapeTests.cs @@ -245,24 +245,26 @@ public void NullablePropertiesSerializedAsEmptyLists() public void NullablePropertiesDeserializedAsNullsWithUndefined() { var model = MixedModel.DeserializeMixedModel(JsonDocument.Parse("{}").RootElement); - Assert.Null(model.RequiredNullableIntList); - Assert.Null(model.RequiredNullableStringList); + Assert.IsNull(model.RequiredNullableIntList); + Assert.IsNull(model.RequiredNullableStringList); } [Test] - public void NullablePropertiesDeserializedAsNullsWithNulls() + public void NullablePropertiesDeserializedAsUndefinedWithNulls() { var model = MixedModel.DeserializeMixedModel(JsonDocument.Parse("{\"RequiredNullableIntList\":null, \"RequiredNullableStringList\": null}").RootElement); - Assert.Null(model.RequiredNullableIntList); - Assert.Null(model.RequiredNullableStringList); + Assert.IsNotNull(model.RequiredNullableIntList); + Assert.IsFalse(Optional.IsCollectionDefined(model.RequiredNullableIntList)); + Assert.IsNotNull(model.RequiredNullableStringList); + Assert.IsFalse(Optional.IsCollectionDefined(model.RequiredNullableStringList)); } [Test] public void NullablePropertiesDeserializedAsValues() { var model = MixedModel.DeserializeMixedModel(JsonDocument.Parse("{\"RequiredNullableIntList\":[1,2,3], \"RequiredNullableStringList\": [\"a\", \"b\"]}").RootElement); - Assert.AreEqual(new[] {1, 2, 3}, model.RequiredNullableIntList); - Assert.AreEqual(new[] {"a", "b"}, model.RequiredNullableStringList); + Assert.AreEqual(new[] { 1, 2, 3 }, model.RequiredNullableIntList); + Assert.AreEqual(new[] { "a", "b" }, model.RequiredNullableStringList); } [Test] @@ -474,19 +476,19 @@ public void ModelWithCustomizedNullableJsonElementPropertyDeserializesValue() [Test] public void ModelWithCustomizedNullableJsonElementPropertySerializesNull() { - JsonAsserts.AssertSerialization("{\"ModelProperty\":null}", new ModelWithNullableObjectProperty() { ModelProperty = JsonDocument.Parse("null").RootElement}); + JsonAsserts.AssertSerialization("{\"ModelProperty\":null}", new ModelWithNullableObjectProperty() { ModelProperty = JsonDocument.Parse("null").RootElement }); } [Test] public void ModelWithCustomizedNullableJsonElementPropertySerializesUndefined() { - JsonAsserts.AssertSerialization("{}", new ModelWithNullableObjectProperty() { ModelProperty = default}); + JsonAsserts.AssertSerialization("{}", new ModelWithNullableObjectProperty() { ModelProperty = default }); } [Test] public void ModelWithCustomizedNullableJsonElementPropertySerializesValue() { - JsonAsserts.AssertSerialization("{\"ModelProperty\":1}", new ModelWithNullableObjectProperty() { ModelProperty = JsonDocument.Parse("1").RootElement}); + JsonAsserts.AssertSerialization("{\"ModelProperty\":1}", new ModelWithNullableObjectProperty() { ModelProperty = JsonDocument.Parse("1").RootElement }); } [Test] @@ -520,7 +522,7 @@ public void ModelFactory_InstantiatesMixedModelWithReadonlyProperty() { const string stringValue = "stringValue"; var readonlyModel = new ReadonlyModel(stringValue); - var readonlyModelList = new List {readonlyModel}; + var readonlyModelList = new List { readonlyModel }; var expectedModel = new MixedModelWithReadonlyProperty(readonlyModel, readonlyModelList.ToList()); var actualModel = ModelShapesModelFactory.MixedModelWithReadonlyProperty(readonlyModel, readonlyModelList); diff --git a/test/AutoRest.TestServer.Tests/ModelsTypeSpecTests.cs b/test/AutoRest.TestServer.Tests/ModelsTypeSpecTests.cs new file mode 100644 index 00000000000..f0313b2042b --- /dev/null +++ b/test/AutoRest.TestServer.Tests/ModelsTypeSpecTests.cs @@ -0,0 +1,439 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System; +using System.Collections.Generic; +using System.Linq; +using System.Reflection; +using System.Text.Json; +using AutoRest.TestServer.Tests.Infrastructure; +using Azure.Core; +using NUnit.Framework; +using ModelsTypeSpec.Models; + +namespace AutoRest.TestServer.Tests +{ + public class ModelsTypeSpecTests + { + [Test] + public void InputModelsHaveOnlyOnePublicCtor() + { + Assert.AreEqual(1, typeof(InputModel).GetConstructors().Length); + } + + [Test] + public void RequiredPropertiesAreSetableInMixedModels() + { + var requiredInt = TypeAsserts.HasProperty(typeof(RoundTripModel), nameof(RoundTripModel.RequiredInt), BindingFlags.Public | BindingFlags.Instance); + var requiredString = TypeAsserts.HasProperty(typeof(RoundTripModel), nameof(RoundTripModel.RequiredString), BindingFlags.Public | BindingFlags.Instance); + + Assert.NotNull(requiredInt.SetMethod); + Assert.NotNull(requiredString.SetMethod); + } + + [Test] + public void RequiredPropertiesAreNotSetableInInputModels() + { + var requiredInt = TypeAsserts.HasProperty(typeof(InputModel), nameof(InputModel.RequiredInt), BindingFlags.Public | BindingFlags.Instance); + var requiredString = TypeAsserts.HasProperty(typeof(InputModel), nameof(InputModel.RequiredString), BindingFlags.Public | BindingFlags.Instance); + + Assert.Null(requiredInt.SetMethod); + Assert.Null(requiredString.SetMethod); + } + + [Test] + public void RequiredListsAreReadOnly() + { + var requiredIntList = TypeAsserts.HasProperty(typeof(InputModel), nameof(InputModel.RequiredIntList), BindingFlags.Public | BindingFlags.Instance); + var requiredStringList = TypeAsserts.HasProperty(typeof(InputModel), nameof(InputModel.RequiredStringList), BindingFlags.Public | BindingFlags.Instance); + + Assert.Null(requiredIntList.SetMethod); + Assert.Null(requiredStringList.SetMethod); + } + + [Test] + public void RequiredNullableListsOnInputsAreWriteable() + { + var requiredIntList = TypeAsserts.HasProperty(typeof(InputModel), nameof(InputModel.RequiredNullableIntList), BindingFlags.Public | BindingFlags.Instance); + var requiredStringList = TypeAsserts.HasProperty(typeof(InputModel), nameof(InputModel.RequiredNullableStringList), BindingFlags.Public | BindingFlags.Instance); + + Assert.NotNull(requiredIntList.SetMethod); + Assert.NotNull(requiredStringList.SetMethod); + } + + [Test] + public void RequiredNullableListsOnMixedAreWriteableAndNullByDefault() + { + var requiredIntList = TypeAsserts.HasProperty(typeof(RoundTripModel), nameof(RoundTripModel.RequiredNullableIntList), BindingFlags.Public | BindingFlags.Instance); + var requiredStringList = TypeAsserts.HasProperty(typeof(RoundTripModel), nameof(RoundTripModel.RequiredNullableStringList), BindingFlags.Public | BindingFlags.Instance); + + Assert.NotNull(requiredIntList.SetMethod); + Assert.NotNull(requiredStringList.SetMethod); + } + + [Test] + public void NotRequiredNullableListsAreSetable() + { + var requiredIntList = TypeAsserts.HasProperty(typeof(RoundTripModel), nameof(RoundTripModel.NonRequiredNullableIntList), BindingFlags.Public | BindingFlags.Instance); + var requiredStringList = TypeAsserts.HasProperty(typeof(RoundTripModel), nameof(RoundTripModel.NonRequiredNullableStringList), BindingFlags.Public | BindingFlags.Instance); + + Assert.NotNull(requiredIntList.SetMethod); + Assert.NotNull(requiredStringList.SetMethod); + } + + [Test] + public void NotRequiredNullableListsAreNotNullByDefault() + { + var inputModel = CreateInputModel(); + + Assert.NotNull(inputModel.NonRequiredNullableIntList); + Assert.NotNull(inputModel.NonRequiredNullableStringList); + } + + + [Test] + public void NotRequiredNullablePropertiesOmitedByDefault() + { + var inputModel = CreateInputModel(); + + var element = JsonAsserts.AssertSerializes(inputModel); + Assert.False(element.TryGetProperty("nonRequiredNullableInt", out _)); + Assert.False(element.TryGetProperty("nonRequiredNullableString", out _)); + Assert.False(element.TryGetProperty("nonRequiredNullableIntList", out _)); + Assert.False(element.TryGetProperty("nonRequiredNullableStringList", out _)); + } + + [Test] + public void NotRequiredNullableListsSerializedAsNull() + { + var inputModel = CreateInputModel(); + inputModel.NonRequiredNullableIntList = null; + inputModel.NonRequiredNullableStringList = null; + + var element = JsonAsserts.AssertSerializes(inputModel); + Assert.AreEqual(JsonValueKind.Null, element.GetProperty("nonRequiredNullableIntList").ValueKind); + Assert.AreEqual(JsonValueKind.Null, element.GetProperty("nonRequiredNullableStringList").ValueKind); + } + + [Test] + public void NotRequiredNullableListsSerializedEmptyWhenCleared() + { + var inputModel = CreateInputModel(); + inputModel.NonRequiredNullableIntList.Clear(); + inputModel.NonRequiredNullableStringList.Clear(); + + var element = JsonAsserts.AssertSerializes(inputModel); + Assert.AreEqual(JsonValueKind.Array, element.GetProperty("nonRequiredNullableIntList").ValueKind); + Assert.AreEqual(JsonValueKind.Array, element.GetProperty("nonRequiredNullableStringList").ValueKind); + } + + [Test] + public void NotRequiredNullablePropertiesSerializeWhenSet() + { + var inputModel = CreateInputModel(); + inputModel.NonRequiredNullableInt = 1; + inputModel.NonRequiredNullableString = "2"; + + var element = JsonAsserts.AssertSerializes(inputModel); + Assert.AreEqual(1, element.GetProperty("nonRequiredNullableInt").GetInt32()); + Assert.AreEqual("2", element.GetProperty("nonRequiredNullableString").GetString()); + } + + [Test] + public void NotRequiredNullablePropertiesDeserializedWithNulls() + { + var model = RoundTripModel.DeserializeRoundTripModel(JsonDocument.Parse("{\"NonRequiredNullableInt\":null, \"NonRequiredNullableString\": null}").RootElement); + Assert.Null(model.NonRequiredNullableInt); + Assert.Null(model.NonRequiredNullableString); + } + + [Test] + public void NotRequiredNullablePropertiesDeserializedWithNullsWhenUndefined() + { + var model = RoundTripModel.DeserializeRoundTripModel(JsonDocument.Parse("{}").RootElement); + Assert.Null(model.NonRequiredNullableInt); + Assert.Null(model.NonRequiredNullableString); + } + + [Test] + public void NotRequiredNullablePropertiesDeserializedWithValues() + { + var model = RoundTripModel.DeserializeRoundTripModel(JsonDocument.Parse("{\"nonRequiredNullableInt\":1, \"nonRequiredNullableString\": \"2\"}").RootElement); + Assert.AreEqual(1, model.NonRequiredNullableInt); + Assert.AreEqual("2", model.NonRequiredNullableString); + } + + [Test] + public void NullablePropertiesCanBeInitializedWithNull() + { + var inputModel = new InputModel( + "string", + 1, + null, + null, + new BaseModel(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + new Dictionary(), + Array.Empty(), + Array.Empty(), + null, + null, + null + ); + + Assert.IsNull(inputModel.RequiredNullableInt); + Assert.IsNull(inputModel.RequiredNullableString); + Assert.IsNull(inputModel.RequiredNullableIntList); + Assert.IsNull(inputModel.RequiredNullableStringList); + } + + [Test] + public void NullablePropertiesSerializedAsNulls() + { + var inputModel = new InputModel( + "string", + 1, + null, + null, + new BaseModel(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + new Dictionary(), + Array.Empty(), + Array.Empty(), + null, + null, + null + ); + + var element = JsonAsserts.AssertSerializes(inputModel); + Assert.AreEqual(JsonValueKind.Null, element.GetProperty("requiredNullableString").ValueKind); + Assert.AreEqual(JsonValueKind.Null, element.GetProperty("requiredNullableInt").ValueKind); + Assert.AreEqual(JsonValueKind.Null, element.GetProperty("requiredNullableStringList").ValueKind); + Assert.AreEqual(JsonValueKind.Null, element.GetProperty("requiredNullableIntList").ValueKind); + } + + [Test] + public void NullablePropertiesSerializedAsEmptyLists() + { + var inputModel = new InputModel( + "string", + 1, + null, + null, + new BaseModel(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + new Dictionary(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + Array.Empty() + ); + + var element = JsonAsserts.AssertSerializes(inputModel); + Assert.AreEqual(JsonValueKind.Array, element.GetProperty("requiredNullableStringList").ValueKind); + Assert.AreEqual(0, element.GetProperty("requiredNullableStringList").GetArrayLength()); + Assert.AreEqual(JsonValueKind.Array, element.GetProperty("requiredNullableIntList").ValueKind); + Assert.AreEqual(0, element.GetProperty("requiredNullableIntList").GetArrayLength()); + } + + [Test] + public void NullablePropertiesDeserializedAsNullsWithUndefined() + { + var model = RoundTripModel.DeserializeRoundTripModel(JsonDocument.Parse("{}").RootElement); + Assert.IsNull(model.RequiredNullableIntList); + Assert.IsNull(model.RequiredNullableStringList); + } + + [Test] + public void NullablePropertiesDeserializedAsUndefinedWithNulls() + { + var model = RoundTripModel.DeserializeRoundTripModel(JsonDocument.Parse("{\"requiredNullableIntList\":null, \"requiredNullableStringList\": null}").RootElement); + Assert.IsNotNull(model.RequiredNullableIntList); + Assert.IsFalse(Optional.IsCollectionDefined(model.RequiredNullableIntList)); + Assert.IsNotNull(model.RequiredNullableStringList); + Assert.IsFalse(Optional.IsCollectionDefined(model.RequiredNullableStringList)); + } + + [Test] + public void NullablePropertiesDeserializedAsValues() + { + var model = RoundTripModel.DeserializeRoundTripModel(JsonDocument.Parse("{\"requiredNullableIntList\":[1,2,3], \"requiredNullableStringList\": [\"a\", \"b\"]}").RootElement); + Assert.AreEqual(new[] { 1, 2, 3 }, model.RequiredNullableIntList); + Assert.AreEqual(new[] { "a", "b" }, model.RequiredNullableStringList); + } + + [Test] + public void InputModelDoesntSerializeOptionalCollections() + { + var inputModel = CreateInputModel(); + + // Perform non mutating operations + _ = inputModel.NonRequiredIntList.Count; + _ = inputModel.NonRequiredStringList.Count; + _ = inputModel.NonRequiredIntList.Count(); + _ = inputModel.NonRequiredStringList.Count(); + _ = inputModel.NonRequiredIntList.IsReadOnly; + _ = inputModel.NonRequiredStringList.IsReadOnly; + _ = inputModel.NonRequiredIntList.Remove(1); + _ = inputModel.NonRequiredStringList.Remove("s"); + + var element = JsonAsserts.AssertSerializes(inputModel); + + Assert.False(element.TryGetProperty("nonRequiredStringList", out _)); + Assert.False(element.TryGetProperty("nonRequiredIntList", out _)); + } + + [Test] + public void InputModelSerializeOptionalCollectionAfterMutation() + { + var inputModel = CreateInputModel(); + + inputModel.NonRequiredIntList.Add(1); + inputModel.NonRequiredStringList.Add("1"); + + var element = JsonAsserts.AssertSerializes(inputModel); + + Assert.AreEqual("[1]", element.GetProperty("nonRequiredIntList").ToString()); + Assert.AreEqual("[\"1\"]", element.GetProperty("nonRequiredStringList").ToString()); + } + + [Test] + public void InputModelSerializeOptionalEmptyCollectionAfterMutation() + { + var inputModel = CreateInputModel(); + + inputModel.NonRequiredIntList.Add(1); + inputModel.NonRequiredIntList.Clear(); + inputModel.NonRequiredStringList.Add("1"); + inputModel.NonRequiredStringList.Clear(); + + var element = JsonAsserts.AssertSerializes(inputModel); + + Assert.AreEqual("[]", element.GetProperty("nonRequiredIntList").ToString()); + Assert.AreEqual("[]", element.GetProperty("nonRequiredStringList").ToString()); + } + + [Test] + public void InputModelDoesntSerializeOptionalCollectionAfterReset() + { + var inputModel = CreateInputModel(); + + inputModel.NonRequiredIntList.Add(1); + (inputModel.NonRequiredIntList as ChangeTrackingList).Reset(); + inputModel.NonRequiredStringList.Add("1"); + (inputModel.NonRequiredStringList as ChangeTrackingList).Reset(); + + var element = JsonAsserts.AssertSerializes(inputModel); + + Assert.False(element.TryGetProperty("nonRequiredStringList", out _)); + Assert.False(element.TryGetProperty("nonRequiredIntList", out _)); + } + + [Test] + public void RequiredNullableCollectionsSerializeAsNull() + { + var inputModel = CreateInputModel(); + + Assert.NotNull(inputModel.RequiredNullableIntList); + Assert.NotNull(inputModel.RequiredNullableStringList); + + inputModel.RequiredNullableIntList = null; + inputModel.RequiredNullableStringList = null; + + var element = JsonAsserts.AssertSerializes(inputModel); + + Assert.AreEqual(JsonValueKind.Null, element.GetProperty("requiredNullableIntList").ValueKind); + Assert.AreEqual(JsonValueKind.Null, element.GetProperty("requiredNullableStringList").ValueKind); + } + + [Test] + public void ReadonlyPropertiesAreReadonly() + { + var required = TypeAsserts.HasProperty(typeof(RoundTripModel), "RequiredReadonlyInt", BindingFlags.Public | BindingFlags.Instance); + var nonRequired = TypeAsserts.HasProperty(typeof(RoundTripModel), "NonRequiredReadonlyInt", BindingFlags.Public | BindingFlags.Instance); + + Assert.AreEqual(typeof(int), required.PropertyType); + Assert.AreEqual(typeof(int?), nonRequired.PropertyType); + Assert.Null(required.SetMethod); + Assert.Null(nonRequired.SetMethod); + } + + [Test] + public void ReadonlyPropertiesAreDeserialized() + { + var model = RoundTripModel.DeserializeRoundTripModel(JsonDocument.Parse("{\"requiredReadonlyInt\":1, \"nonRequiredReadonlyInt\": 2}").RootElement); + Assert.AreEqual(1, model.RequiredReadonlyInt); + Assert.AreEqual(2, model.NonRequiredReadonlyInt); + } + + private static InputModel CreateInputModel() + { + return new InputModel( + "string", + 1, + null, + null, + new BaseModel(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + new Dictionary(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + Array.Empty() + ); + } + + [Test] + public void InputCollectionPropertiesCanBeMutatedAfterConstruction() + { + var inputModel = new InputModel( + "string", + 1, + null, + null, + new BaseModel(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + new Dictionary(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + Array.Empty(), + Array.Empty() + ); + + inputModel.RequiredIntList.Add(1); + + Assert.AreEqual(1, inputModel.RequiredIntList.Count); + } + + [Test] + public void ReadOnlyPropertiesAreReadOnly() + { + var property = TypeAsserts.HasProperty(typeof(RoundTripReadOnlyModel), "RequiredReadonlyString", BindingFlags.Public | BindingFlags.Instance); + var listProperty = TypeAsserts.HasProperty(typeof(RoundTripReadOnlyModel), "RequiredReadOnlyModelList", BindingFlags.Public | BindingFlags.Instance); + + Assert.Null(property.SetMethod); + Assert.Null(listProperty.SetMethod); + Assert.AreEqual(typeof(IReadOnlyList), listProperty.PropertyType); + } + + [Test] + public void OptionalPropertyWithNullIsAccepted() + { + var model = RoundTripModel.DeserializeRoundTripModel(JsonDocument.Parse("{\"RequiredReadonlyInt\":1, \"NonRequiredReadonlyInt\": 2,\"NonRequiredInt\": null}").RootElement); + Assert.Null(model.NonRequiredInt); + } + } +} diff --git a/test/AutoRest.TestServer.Tests/body-complex.cs b/test/AutoRest.TestServer.Tests/body-complex.cs index 354719624b7..b0dc33da672 100644 --- a/test/AutoRest.TestServer.Tests/body-complex.cs +++ b/test/AutoRest.TestServer.Tests/body-complex.cs @@ -10,6 +10,7 @@ using System.Threading.Tasks; using System.Xml; using AutoRest.TestServer.Tests.Infrastructure; +using Azure.Core; using Azure.Core.Pipeline; using body_complex; using body_complex.Models; @@ -412,7 +413,9 @@ public Task GetComplexDictionaryNull() => Test(async (host, pipeline) => { var result = await new DictionaryClient(ClientDiagnostics, pipeline, host).GetNullAsync(); Assert.AreEqual(200, result.GetRawResponse().Status); - Assert.AreEqual(null, result.Value.DefaultProgram); + // the DefaultProgram should be undefined here + Assert.IsNotNull(result.Value.DefaultProgram); + Assert.IsFalse(Optional.IsCollectionDefined(result.Value.DefaultProgram)); }); [Test] diff --git a/test/AutoRest.TestServer.Tests/flat-array.cs b/test/AutoRest.TestServer.Tests/flat-array.cs index 7446d60e877..d5535d363a7 100644 --- a/test/AutoRest.TestServer.Tests/flat-array.cs +++ b/test/AutoRest.TestServer.Tests/flat-array.cs @@ -14,7 +14,7 @@ namespace AutoRest.TestServer.Tests { public class FlatArray : InProcTestBase { - private async Task TestCore (Func testProc) + private async Task TestCore(Func testProc) { var requestMemoryStream = new MemoryStream(); using var testServer = new InProcTestServer(async content => @@ -32,7 +32,7 @@ private async Task TestCore (Func [Test] public async Task FlatArray_NullSerialized() { - var doc = await TestCore (async c => await c.OperationAsync ()); + var doc = await TestCore(async c => await c.OperationAsync()); JsonElement items = doc.RootElement.GetProperty("items"); Assert.NotNull(items); Assert.AreEqual(JsonValueKind.Null, items.ValueKind); @@ -41,7 +41,7 @@ public async Task FlatArray_NullSerialized() [Test] public async Task FlatArray_EmptySerialized() { - var doc = await TestCore (async c => await c.OperationAsync(Enumerable.Empty())); + var doc = await TestCore(async c => await c.OperationAsync(Enumerable.Empty())); JsonElement items = doc.RootElement.GetProperty("items"); Assert.NotNull(items); Assert.AreEqual(0, items.GetArrayLength()); @@ -50,15 +50,15 @@ public async Task FlatArray_EmptySerialized() [Test] public async Task FlatArray_NullSerializedNotNullable() { - var doc = await TestCore (async c => await c.OperationNotNullAsync ()); - Assert.IsFalse(doc.RootElement.TryGetProperty ("items", out JsonElement value)); + var doc = await TestCore(async c => await c.OperationNotNullAsync()); + Assert.IsFalse(doc.RootElement.TryGetProperty("items", out JsonElement value)); } [Test] public async Task FlatArray_EmptySerializedNotNullable() { - var doc = await TestCore (async c => await c.OperationNotNullAsync(Enumerable.Empty())); - Assert.IsFalse(doc.RootElement.TryGetProperty ("items", out JsonElement value)); + var doc = await TestCore(async c => await c.OperationNotNullAsync(Enumerable.Empty())); + Assert.IsFalse(doc.RootElement.TryGetProperty("items", out JsonElement value)); } } } diff --git a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/CollectionWritingTests.cs b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/CollectionWritingTests.cs index e84b40eb49c..5709a8ea52a 100644 --- a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/CollectionWritingTests.cs +++ b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/CollectionWritingTests.cs @@ -17,7 +17,7 @@ public void RoundTripPrimitiveCollectionProperties(string expectedModelCodes, st // refer to the original CADL file: https://github.com/Azure/cadl-ranch/blob/main/packages/cadl-ranch-specs/http/models/primitive-properties/main.cadl var input = new InputModelType("RoundTripModel", "Cadl.TestServer.CollectionPropertiesBasic.Models", "public", null, "Round-trip model with collection properties", InputModelTypeUsage.RoundTrip, new List { RequiredStringListProperty, RequiredIntListProperty }, - null, new List(), null, null); + null, new List(), null, null, false); var model = new ModelTypeProvider(input, "test", null, CadlTypeFactory); ValidateGeneratedCodes(model, expectedModelCodes, expectedSerializationCodes); @@ -29,7 +29,7 @@ public void InputPrimitiveCollectionProperties(string expectedModelCodes, string // refer to the original CADL file: https://github.com/Azure/cadl-ranch/blob/main/packages/cadl-ranch-specs/http/models/collections-basic/main.cadl#L16-L24 var input = new InputModelType("InputModel", "Cadl.TestServer.CollectionPropertiesBasic.Models", "public", null, "Input model with collection properties", InputModelTypeUsage.Input, new List { RequiredStringListProperty, RequiredIntListProperty }, - null, new List(), null, null); + null, new List(), null, null, false); var model = new ModelTypeProvider(input, "test", null, CadlTypeFactory); ValidateGeneratedCodes(model, expectedModelCodes, expectedSerializationCodes); @@ -41,7 +41,7 @@ public void OutputPrimitiveCollectionProperties(string expectedModelCodes, strin // refer to the original CADL file: https://github.com/Azure/cadl-ranch/blob/main/packages/cadl-ranch-specs/http/models/collections-basic/main.cadl#L26-L34 var input = new InputModelType("OutputModel", "Cadl.TestServer.CollectionPropertiesBasic.Models", "public", null, "Output model with collection properties", InputModelTypeUsage.Output, new List { RequiredStringListProperty, RequiredIntListProperty }, - null, new List(), null, null); + null, new List(), null, null, false); var model = new ModelTypeProvider(input, "test", null, CadlTypeFactory); ValidateGeneratedCodes(model, expectedModelCodes, expectedSerializationCodes); @@ -54,14 +54,14 @@ public void ModelTypeCollectionProperties(string expectedModelCodes, string expe var elementModelType = new InputModelType("SimpleModel", "Cadl.TestServer.ModelCollectionProperties.Models", "public", null, "Simple model that will appear in a collection.", InputModelTypeUsage.RoundTrip, new List { RequiredStringProperty, RequiredIntProperty }, - null, new List(), null, null); + null, new List(), null, null, false); var collectionModelType = new InputModelType("ModelCollectionModel", "Cadl.TestServer.ModelCollectionProperties.Models", "public", null, "Simple model with model collection properties", InputModelTypeUsage.RoundTrip, new List{ - new InputModelProperty("requiredModelCollection", "requiredModelCollection", "Required collection of models.", new InputListType("requiredModelCollection", elementModelType), true, false, false), - new InputModelProperty("optionalModelCollection", "optionalModelCollection", "Optional collection of models.", new InputListType("optionalModelCollection", elementModelType), false, false, false), + new InputModelProperty("requiredModelCollection", "requiredModelCollection", "Required collection of models.", new InputListType("requiredModelCollection", elementModelType, false), true, false, false), + new InputModelProperty("optionalModelCollection", "optionalModelCollection", "Optional collection of models.", new InputListType("optionalModelCollection", elementModelType, false), false, false, false), }, - null, new List(), null, null); + null, new List(), null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.ModelCollectionProperties.Models", null, new List(), new List(), new List { elementModelType, collectionModelType }, new List(), new InputAuth()), default).Build(true); @@ -76,14 +76,14 @@ public void ModelType2DCollectionProperties(string expectedModelCodes, string ex var elementModelType = new InputModelType("SimpleModel", "Cadl.TestServer.ModelCollectionProperties.Models", "public", null, "Simple model that will appear in a collection.", InputModelTypeUsage.RoundTrip, new List { RequiredStringProperty, RequiredIntProperty }, - null, new List(), null, null); + null, new List(), null, null, false); var collectionModelType = new InputModelType("ModelCollectionModel", "Cadl.TestServer.ModelCollectionProperties.Models", "public", null, "Simple model with model collection properties", InputModelTypeUsage.RoundTrip, new List{ - new InputModelProperty("required2DCollection", "required2DCollection", "Required collection of models.", new InputListType("required2DCollection", new InputListType("requiredModelCollection", elementModelType)), true, false, false), - new InputModelProperty("optional2DCollection", "optional2DCollection", "Optional collection of models.", new InputListType("optional2DCollection", new InputListType("optionalModelCollection", elementModelType)), false, false, false), + new InputModelProperty("required2DCollection", "required2DCollection", "Required collection of models.", new InputListType("required2DCollection", new InputListType("requiredModelCollection", elementModelType, false), false), true, false, false), + new InputModelProperty("optional2DCollection", "optional2DCollection", "Optional collection of models.", new InputListType("optional2DCollection", new InputListType("optionalModelCollection", elementModelType, false), false), false, false, false), }, - null, new List(), null, null); + null, new List(), null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.ModelCollectionProperties.Models", null, new List(), new List(), new List { elementModelType, collectionModelType }, new List(), new InputAuth()), default).Build(true); diff --git a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/DictionaryWritingTests.cs b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/DictionaryWritingTests.cs index 90c6e394b10..4734bddc629 100644 --- a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/DictionaryWritingTests.cs +++ b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/DictionaryWritingTests.cs @@ -12,7 +12,7 @@ public class DictionaryWritingTests : ModelGenerationTestBase public void RoundTripDictionaryProperties(string expectedModelCodes, string expectedSerializationCodes) { var model = new InputModelType("RoundTripModel", "Cadl.TestServer.DictionaryProperties.Models", "public", null, "Round-trip model with dictionary properties", InputModelTypeUsage.RoundTrip, - DictionaryProperties, null, new List(), null, null); + DictionaryProperties, null, new List(), null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.DictionaryProperties.Models", null, new List(), new List(), new List { model, ElementModelType }, new List(), new InputAuth()), default).Build(true); @@ -24,7 +24,7 @@ public void RoundTripDictionaryProperties(string expectedModelCodes, string expe public void InputDictionaryProperties(string expectedModelCodes, string expectedSerializationCodes) { var model = new InputModelType("InputModel", "Cadl.TestServer.DictionaryProperties.Models", "public", null, "Input model with dictionary properties", InputModelTypeUsage.Input, - DictionaryProperties, null, new List(), null, null); + DictionaryProperties, null, new List(), null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.DictionaryProperties.Models", null, new List(), new List(), new List { model, ElementModelType }, new List(), new InputAuth()), default).Build(true); @@ -37,8 +37,7 @@ public void InputDictionaryProperties(string expectedModelCodes, string expected public void OutputDictionaryProperties(string expectedModelCodes, string expectedSerializationCodes) { var model = new InputModelType("OutputModel", "Cadl.TestServer.DictionaryProperties.Models", "public", null, "Output model with dictionary properties", InputModelTypeUsage.Output, - DictionaryProperties, null, new List(), null, null); - + DictionaryProperties, null, new List(), null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.DictionaryProperties.Models", null, new List(), new List(), new List { model, ElementModelType }, new List(), new InputAuth()), default).Build(true); @@ -48,13 +47,13 @@ public void OutputDictionaryProperties(string expectedModelCodes, string expecte private static readonly IReadOnlyList DictionaryProperties = new List { - new InputModelProperty("requiredStringDictionary", "requiredStringDictionary", "Required dictionary of strings, illustrating a dictionary of reference types.", new InputDictionaryType("requiredStringDictionary", InputPrimitiveType.String, InputPrimitiveType.String), true, false, false), - new InputModelProperty("requiredIntDictionary", "requiredIntDictionary", "Required dictionary of ints, illustrating a dictionary of value types.", new InputDictionaryType("requiredIntDictionary", InputPrimitiveType.String, InputPrimitiveType.Int32), true, false, false), - new InputModelProperty("requiredModelDictionary", "requiredModelDictionary", "Required dictionary of models, illustrating a dictionary of model types.", new InputDictionaryType("requiredIntDictionary", InputPrimitiveType.String, ElementModelType), true, false, false), + new InputModelProperty("requiredStringDictionary", "requiredStringDictionary", "Required dictionary of strings, illustrating a dictionary of reference types.", new InputDictionaryType("requiredStringDictionary", InputPrimitiveType.String, InputPrimitiveType.String, false), true, false, false), + new InputModelProperty("requiredIntDictionary", "requiredIntDictionary", "Required dictionary of ints, illustrating a dictionary of value types.", new InputDictionaryType("requiredIntDictionary", InputPrimitiveType.String, InputPrimitiveType.Int32, false), true, false, false), + new InputModelProperty("requiredModelDictionary", "requiredModelDictionary", "Required dictionary of models, illustrating a dictionary of model types.", new InputDictionaryType("requiredIntDictionary", InputPrimitiveType.String, ElementModelType, false), true, false, false), new InputModelProperty("requiredModelDictionaryDictionary", "requiredModelDictionaryDictionary", "Required dictionary of dictionary of models, illustrating a dictionary of dictionary types.", - new InputDictionaryType("requiredModelDictionaryDictionary", InputPrimitiveType.String, new InputDictionaryType("requiredModelDictionary", InputPrimitiveType.String, ElementModelType)), true, false, false), + new InputDictionaryType("requiredModelDictionaryDictionary", InputPrimitiveType.String, new InputDictionaryType("requiredModelDictionary", InputPrimitiveType.String, ElementModelType, false), false), true, false, false), new InputModelProperty("requiredModelListDictionary", "requiredModelListDictionary", "Required dictionary of list of models, illustrating a dictionary of list types.", - new InputDictionaryType("requiredModelListDictionary", InputPrimitiveType.String, new InputListType("requiredModelList", ElementModelType)), true, false, false) + new InputDictionaryType("requiredModelListDictionary", InputPrimitiveType.String, new InputListType("requiredModelList", ElementModelType, false), false), true, false, false) }; // below are test cases diff --git a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/EnumWritingTests.cs b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/EnumWritingTests.cs index dc703919fb0..fe1d4b3aa0b 100644 --- a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/EnumWritingTests.cs +++ b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/EnumWritingTests.cs @@ -31,7 +31,7 @@ public void RoundTripEnumProperties(string expectedModelCodes, string expectedSe new InputModelProperty("Day", "Day", "Required standard enum value.", FixedEnumType, true, false, false), new InputModelProperty("Language", "Language", "Required string enum value.", ExtensibleEnumType, true, false, false) }, - null, new List(), null, null); + null, new List(), null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.EnumPropertiesBasic", null, new List(), new List { FixedEnumType, ExtensibleEnumType }, new List { modelType }, new List(), new InputAuth()), default).Build(true); @@ -47,7 +47,7 @@ public void InputEnumProperties(string expectedModelCodes, string expectedSerial new InputModelProperty("Day", "Day", "Required standard enum value.", FixedEnumType, true, false, false), new InputModelProperty("Language", "Language", "Required string enum value.", ExtensibleEnumType, true, false, false) }, - null, new List(), null, null); + null, new List(), null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.EnumPropertiesBasic", null, new List(), new List { FixedEnumType, ExtensibleEnumType }, new List { modelType }, new List(), new InputAuth()), default).Build(true); @@ -63,7 +63,7 @@ public void OutputEnumProperties(string expectedModelCodes, string expectedSeria new InputModelProperty("Day", "Day", "Required standard enum value.", FixedEnumType, true, false, false), new InputModelProperty("Language", "Language", "Required string enum value.", ExtensibleEnumType, true, false, false) }, - null, new List(), null, null); + null, new List(), null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.EnumPropertiesBasic", null, new List(), new List { FixedEnumType, ExtensibleEnumType }, new List { modelType }, new List(), new InputAuth()), default).Build(true); diff --git a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ModelGenerationTestBase.cs b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ModelGenerationTestBase.cs index 009d33a2dbd..e95a5a4d347 100644 --- a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ModelGenerationTestBase.cs +++ b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ModelGenerationTestBase.cs @@ -20,19 +20,19 @@ public class ModelGenerationTestBase internal static readonly InputModelProperty RequiredIntProperty = new InputModelProperty("requiredInt", "requiredInt", "Required int, illustrating a value type property.", InputPrimitiveType.Int32, true, false, false); - internal static readonly InputModelProperty RequiredStringListProperty = new InputModelProperty("requiredStringList", "requiredStringList", "Required collection of strings, illustrating a collection of reference types.", new InputListType("requiredStringList", InputPrimitiveType.String), true, false, false); + internal static readonly InputModelProperty RequiredStringListProperty = new InputModelProperty("requiredStringList", "requiredStringList", "Required collection of strings, illustrating a collection of reference types.", new InputListType("requiredStringList", InputPrimitiveType.String, false), true, false, false); - internal static readonly InputModelProperty RequiredIntListProperty = new InputModelProperty("requiredIntList", "requiredIntList", "Required collection of ints, illustrating a collection of value types.", new InputListType("requiredIntList", InputPrimitiveType.Int32), true, false, false); + internal static readonly InputModelProperty RequiredIntListProperty = new InputModelProperty("requiredIntList", "requiredIntList", "Required collection of ints, illustrating a collection of value types.", new InputListType("requiredIntList", InputPrimitiveType.Int32, false), true, false, false); internal static TypeFactory CadlTypeFactory => new TypeFactory(null); internal static readonly InputModelType ElementModelType = new InputModelType("SimpleModel", "Cadl.TestServer.ModelCollectionProperties.Models", null, "public", "Simple model that will appear in a collection.", InputModelTypeUsage.RoundTrip, new List { RequiredStringProperty, RequiredIntProperty }, - null, new List(), null, null); + null, new List(), null, null, false); [OneTimeSetUp] - public void init() + public void Initialize() { Configuration.Initialize( outputFolder: "Generated", @@ -51,6 +51,7 @@ public void init() disablePaginationTopRenaming: false, generateModelFactory: true, publicDiscriminatorProperty: false, + deserializeNullCollectionAsNullValue: false, useCoreDataFactoryReplacements: true, modelFactoryForHlc: Array.Empty(), unreferencedTypesHandling: Configuration.UnreferencedTypesHandlingOption.RemoveOrInternalize, diff --git a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ModelWriterTests.cs b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ModelWriterTests.cs index 6b39a5187f4..3d4d0fe1421 100644 --- a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ModelWriterTests.cs +++ b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ModelWriterTests.cs @@ -17,7 +17,7 @@ public void RoundTripBasic(string expectedModelCodes) // refer to the original CADL file: https://github.com/Azure/cadl-ranch/blob/c4f41f483eac812527f7b6dc837bd22d255a18ed/packages/cadl-ranch-specs/http/models/roundtrip-basic/main.cadl#L15-L23 var input = new InputModelType("InputModel", "Cadl.TestServer.InputBasic", null, "public", "Round-trip Model", InputModelTypeUsage.RoundTrip, new List { RequiredStringProperty, RequiredIntProperty }, - null, null, null, null); + null, null, null, null, false); var model = new ModelTypeProvider(input, "test", null); ValidateGeneratedModelCodes(model, expectedModelCodes); @@ -29,7 +29,7 @@ public void InputBasic(string expectedModelCodes, string expectedSerializationCo // refer to the original CADL file: https://github.com/Azure/cadl-ranch/blob/main/packages/cadl-ranch-specs/http/models/input-basic/main.cadl var input = new InputModelType("InputModel", "Cadl.TestServer.InputBasic", null, "public", "Input Model", InputModelTypeUsage.Input, new List { RequiredStringProperty, RequiredIntProperty }, - null, new List(), null, null); + null, new List(), null, null, false); var model = new ModelTypeProvider(input, "test", null); ValidateGeneratedCodes(model, expectedModelCodes, expectedSerializationCodes); @@ -41,7 +41,7 @@ public void OutputBasic(string expectedModelCodes, string expectedSerializationC // refer to the original CADL file: https://github.com/Azure/cadl-ranch/blob/c4f41f483eac812527f7b6dc837bd22d255a18ed/packages/cadl-ranch-specs/http/models/output-basic/main.cadl#L15-L23 var input = new InputModelType("OutputModel", "Cadl.TestServer.OutputBasic", null, "public", "Output Model", InputModelTypeUsage.Output, new List { RequiredStringProperty, RequiredIntProperty }, - null, new List(), null, null); + null, new List(), null, null, false); var model = new ModelTypeProvider(input, "test", null); ValidateGeneratedCodes(model, expectedModelCodes, expectedSerializationCodes); @@ -65,7 +65,7 @@ public void PrimitiveProperties(string expectedModelCodes, string expectedSerial new InputModelProperty("requiredBoolean", "requiredBoolean", "", InputPrimitiveType.Boolean, true, false, false), new InputModelProperty("requiredBytes", "requiredBytes", "", InputPrimitiveType.BinaryData, true, false, false) }, - null, null, null, null); + null, null, null, null, false); var model = new ModelTypeProvider(input, "test", null); ValidateGeneratedCodes(model, expectedModelCodes, expectedSerializationCodes); diff --git a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/NestedModelWritingTests.cs b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/NestedModelWritingTests.cs index d85a069ae7c..fc1ae511e5b 100644 --- a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/NestedModelWritingTests.cs +++ b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/NestedModelWritingTests.cs @@ -20,7 +20,7 @@ public void RoundTripModel(string expectedModelCodes, string expectedSerializati new InputModelProperty("NestedRoundTripModel", "NestedRoundTripModel", "Required nested round-trip model.", NestedRoundTripOnlyModelType, true, false, false), NestedRoundTripSharedModelProperty }, - null, new List(), null, null); + null, new List(), null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("NestedModelsBasic.Models", null, new List(), new List(), new List { model, NestedRoundTripOnlyModelType, NestedRoundTripSharedModelType }, new List(), new InputAuth()), default).Build(true); @@ -38,7 +38,7 @@ public void InputModel(string expectedModelCodes, string expectedSerializationCo new InputModelProperty("NestedInputModel", "NestedInputModel", "Required nested input model.", NestedInputOnlyModelType, true, false, false), NestedRoundTripSharedModelProperty }, - null, new List(), null, null); + null, new List(), null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("NestedModelsBasic.Models", null, new List(), new List(), new List { model, NestedInputOnlyModelType, NestedRoundTripSharedModelType }, new List(), new InputAuth()), default).Build(true); @@ -56,7 +56,7 @@ public void OutpuModel(string expectedModelCodes, string expectedSerializationCo new InputModelProperty("NestedOutputModel", "NestedOutputModel", "Required nested output model.", NestedOutputOnlyModelType, true, false, false), NestedRoundTripSharedModelProperty }, - null, new List(), null, null); + null, new List(), null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("NestedModelsBasic.Models", null, new List(), new List(), new List { model, NestedOutputOnlyModelType, NestedRoundTripSharedModelType }, new List(), new InputAuth()), default).Build(true); @@ -66,19 +66,19 @@ public void OutpuModel(string expectedModelCodes, string expectedSerializationCo private static readonly InputModelType NestedInputOnlyModelType = new InputModelType("NestedInputOnlyModel", "NestedInputOnlyModel", "public", null, "Model to illustrate a nested model that only appears on an input model.", InputModelTypeUsage.Input, new List { RequiredStringProperty, RequiredIntProperty, RequiredStringListProperty, RequiredIntListProperty }, - null, new List(), null, null); + null, new List(), null, null, false); private static readonly InputModelType NestedOutputOnlyModelType = new InputModelType("NestedOutputOnlyModel", "NestedOutputOnlyModel", "public", null, "Model to illustrate a nested model that only appears on an ouput model.", InputModelTypeUsage.Output, new List { RequiredStringProperty, RequiredIntProperty, RequiredStringListProperty, RequiredIntListProperty }, - null, new List(), null, null); + null, new List(), null, null, false); private static readonly InputModelType NestedRoundTripOnlyModelType = new InputModelType("NestedRoundTripOnlyModel", "NestedRoundTripOnlyModel", "public", null, "Model to illustrate a nested model that only appears on a nested model.", InputModelTypeUsage.RoundTrip, new List { RequiredStringProperty, RequiredIntProperty, RequiredStringListProperty, RequiredIntListProperty }, - null, new List(), null, null); + null, new List(), null, null, false); private static readonly InputModelType NestedRoundTripSharedModelType = new InputModelType("NestedRoundTripSharedModel", "NestedRoundTripSharedModel", "public", null, "Model to illustrate a nested model that appears as a nested model on input, output, and round-trip models.", InputModelTypeUsage.RoundTrip, new List { RequiredStringProperty, RequiredIntProperty, RequiredStringListProperty, RequiredIntListProperty }, - null, new List(), null, null); + null, new List(), null, null, false); private static readonly InputModelProperty NestedRoundTripSharedModelProperty = new InputModelProperty("NestedSharedModel", "NestedSharedModel", "Required nested shared model.", NestedRoundTripSharedModelType, true, false, false); diff --git a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/OptionalPropertyWritingTests.cs b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/OptionalPropertyWritingTests.cs index fb3431d9646..befc9eb42ca 100644 --- a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/OptionalPropertyWritingTests.cs +++ b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/OptionalPropertyWritingTests.cs @@ -12,7 +12,7 @@ public void RoundTripModel(string expectedModelCodes, string expectedSerializati { // refer to the original CADL file: https://github.com/Azure/cadl-ranch/blob/bed837a2e29e55569360206afa3393e044dfb070/packages/cadl-ranch-specs/http/models/optional-properties/main.cadl#L35-L38 var model = new InputModelType("RoundTripModel", "Cadl.TestServer.OptionalProperties.Models", "public", null, "Round-trip model with optional properties.", InputModelTypeUsage.RoundTrip, - OptionalProperties, null, null, null, null); + OptionalProperties, null, null, null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.OptionalProperties.Models", null, new List(), new List(), new List { ElementModelType, model }, new List(), new InputAuth()), default).Build(true); @@ -25,7 +25,7 @@ public void InputModel(string expectedModelCodes, string expectedSerializationCo { // refer to the original CADL file: https://github.com/Azure/cadl-ranch/blob/bed837a2e29e55569360206afa3393e044dfb070/packages/cadl-ranch-specs/http/models/optional-properties/main.cadl#L15-L28 var model = new InputModelType("InputModel", "Cadl.TestServer.OptionalProperties.Models", "public", null, "Input model with optional properties.", InputModelTypeUsage.Input, - OptionalProperties, null, null, null, null); + OptionalProperties, null, null, null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.OptionalProperties.Models", null, new List(), new List(), new List { ElementModelType, model }, new List(), new InputAuth()), default).Build(true); @@ -38,7 +38,7 @@ public void OutputModel(string expectedModelCodes, string expectedSerializationC { // refer to the original CADL file: https://github.com/Azure/cadl-ranch/blob/bed837a2e29e55569360206afa3393e044dfb070/packages/cadl-ranch-specs/http/models/optional-properties/main.cadl#L30-L33 var model = new InputModelType("OutputModel", "Cadl.TestServer.OptionalProperties.Models", "public", null, "Output model with optional properties.", InputModelTypeUsage.Output, - OptionalProperties, null, null, null, null); + OptionalProperties, null, null, null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.OptionalProperties.Models", null, new List(), new List(), new List { ElementModelType, model }, new List(), new InputAuth()), default).Build(true); @@ -49,10 +49,10 @@ public void OutputModel(string expectedModelCodes, string expectedSerializationC private static readonly IReadOnlyList OptionalProperties = new List{ new InputModelProperty("optionalString", "optionalString", "Optional string, illustrating an optional reference type property.", InputPrimitiveType.String, false, false, false), new InputModelProperty("optionalInt", "optionalInt", "Optional int, illustrating an optional reference type property.", InputPrimitiveType.Int32, false, false, false), - new InputModelProperty("optionalStringList", "optionalStringList", "Optional string collection.", new InputListType("optionalStringList", InputPrimitiveType.String), false, false, false), - new InputModelProperty("optionalIntList", "optionalIntList", "Optional int collection.", new InputListType("optionalIntList", InputPrimitiveType.Int32), false, false, false), - new InputModelProperty("optionalModelCollection", "optionalModelCollection", "Optional collection of models.", new InputListType("optionalModelCollection", ElementModelType), false, false, false), - new InputModelProperty("optionalModelDictionary", "optionalModelDictionary", "Optional dictionary of models.", new InputDictionaryType("optionalModelDictionary", InputPrimitiveType.String, ElementModelType), false, false, false) + new InputModelProperty("optionalStringList", "optionalStringList", "Optional string collection.", new InputListType("optionalStringList", InputPrimitiveType.String, false), false, false, false), + new InputModelProperty("optionalIntList", "optionalIntList", "Optional int collection.", new InputListType("optionalIntList", InputPrimitiveType.Int32, false), false, false, false), + new InputModelProperty("optionalModelCollection", "optionalModelCollection", "Optional collection of models.", new InputListType("optionalModelCollection", ElementModelType, false), false, false, false), + new InputModelProperty("optionalModelDictionary", "optionalModelDictionary", "Optional dictionary of models.", new InputDictionaryType("optionalModelDictionary", InputPrimitiveType.String, ElementModelType, false), false, false, false) }; // below are test cases diff --git a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ReadonlyPropertyWritingTests.cs b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ReadonlyPropertyWritingTests.cs index 99a0e5d03f2..ca568e5ac0d 100644 --- a/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ReadonlyPropertyWritingTests.cs +++ b/test/AutoRest.TestServerLowLevel.Tests/LowLevel/Generation/ReadonlyPropertyWritingTests.cs @@ -12,7 +12,7 @@ public void RoundTripModel(string expectedModelCodes, string expectedSerializati { // refer to the original CADL file: https://github.com/Azure/cadl-ranch/blob/main/packages/cadl-ranch-specs/http/models/readonly-properties/main.cadl var model = new InputModelType("RoundTripModel", "Cadl.TestServer.ReadonlyProperties.Models", "public", null, "Readonly model", InputModelTypeUsage.RoundTrip, - ReadOnlyProperties, null, null, null, null); + ReadOnlyProperties, null, null, null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.ReadonlyProperties.Models", null, new List(), new List(), new List { ReadonlyModel, model }, new List(), new InputAuth()), default).Build(true); @@ -25,7 +25,7 @@ public void OutputModel(string expectedModelCodes, string expectedSerializationC { // refer to the original CADL file: https://github.com/Azure/cadl-ranch/blob/dc6d00c98983f34b2f723c90fe840678a863438c/packages/cadl-ranch-specs/http/models/readonly-properties/main.cadl#L24-L65 var model = new InputModelType("OutputModel", "Cadl.TestServer.ReadonlyProperties.Models", "public", null, "Readonly model", InputModelTypeUsage.Output, - ReadOnlyProperties, null, null, null, null); + ReadOnlyProperties, null, null, null, null, false); var library = new DpgOutputLibraryBuilder(new InputNamespace("Cadl.TestServer.ReadonlyProperties.Models", null, new List(), new List(), new List { ReadonlyModel, model }, new List(), new InputAuth()), default).Build(true); @@ -35,7 +35,7 @@ public void OutputModel(string expectedModelCodes, string expectedSerializationC // below are test cases private static readonly InputModelType ReadonlyModel = new InputModelType("ReadonlyModel", "Cadl.TestServer.ReadonlyProperties.Models", "public", null, "Readonly model", InputModelTypeUsage.Output, - new List { RequiredStringProperty }, null, null, null, null); + new List { RequiredStringProperty }, null, null, null, null, false); private static readonly IReadOnlyList ReadOnlyProperties = new List{ new InputModelProperty("requiredReadonlyString", "requiredReadonlyString", "Required string, illustrating a readonly reference type property.", InputPrimitiveType.String, true, true, false), @@ -44,14 +44,14 @@ public void OutputModel(string expectedModelCodes, string expectedSerializationC new InputModelProperty("optionalReadonlyInt", "optionalReadonlyInt", "Optional int, illustrating a readonly reference type property.", InputPrimitiveType.Int32, false, true, false), new InputModelProperty("requiredReadonlyModel", "requiredReadonlyModel", "Required readonly model.", ReadonlyModel, true, true, false), new InputModelProperty("optionalReadonlyModel", "optionalReadonlyModel", "Optional readonly model", ReadonlyModel, false, true, false), - new InputModelProperty("requiredReadonlyStringList", "requiredReadonlyStringList", "Required readonly string collection.", new InputListType("requiredReadonlyStringList", InputPrimitiveType.String), true, true, false), - new InputModelProperty("requiredReadonlyIntList", "requiredReadonlyIntList", "Required readonly int collection.", new InputListType("requiredReadonlyIntList", InputPrimitiveType.Int32), true, true, false), - new InputModelProperty("optionalReadonlyStringList", "optionalReadonlyStringList", "Optional readonly string collection.", new InputListType("optionalReadonlyStringList", InputPrimitiveType.String), false, true, false), - new InputModelProperty("optionalReadonlyIntList", "optionalReadonlyIntList", "Optional readonly int collection.", new InputListType("optionalReadonlyIntList", InputPrimitiveType.Int32), false, true, false), - new InputModelProperty("requiredReadonlyStringDictionary", "requiredReadonlyStringDictionary", "Required readonly string collection.", new InputDictionaryType("requiredReadonlyStringDictionary", InputPrimitiveType.String, InputPrimitiveType.String), true, true, false), - new InputModelProperty("requiredReadonlyIntDictionary", "requiredReadonlyIntDictionary", "Required readonly int collection.", new InputDictionaryType("requiredReadonlyIntDictionary", InputPrimitiveType.String, InputPrimitiveType.Int32), true, true, false), - new InputModelProperty("optionalReadonlyStringDictionary", "optionalReadonlyStringDictionary", "Optional readonly string collection.", new InputDictionaryType("optionalReadonlyStringDictionary", InputPrimitiveType.String, InputPrimitiveType.String), false, true, false), - new InputModelProperty("optionalReadonlyIntDictionary", "optionalReadonlyIntDictionary", "Optional readonly int collection.", new InputDictionaryType("optionalReadonlyIntDictionary", InputPrimitiveType.String, InputPrimitiveType.Int32), false, true, false), + new InputModelProperty("requiredReadonlyStringList", "requiredReadonlyStringList", "Required readonly string collection.", new InputListType("requiredReadonlyStringList", InputPrimitiveType.String, false), true, true, false), + new InputModelProperty("requiredReadonlyIntList", "requiredReadonlyIntList", "Required readonly int collection.", new InputListType("requiredReadonlyIntList", InputPrimitiveType.Int32, false), true, true, false), + new InputModelProperty("optionalReadonlyStringList", "optionalReadonlyStringList", "Optional readonly string collection.", new InputListType("optionalReadonlyStringList", InputPrimitiveType.String, false), false, true, false), + new InputModelProperty("optionalReadonlyIntList", "optionalReadonlyIntList", "Optional readonly int collection.", new InputListType("optionalReadonlyIntList", InputPrimitiveType.Int32, false), false, true, false), + new InputModelProperty("requiredReadonlyStringDictionary", "requiredReadonlyStringDictionary", "Required readonly string collection.", new InputDictionaryType("requiredReadonlyStringDictionary", InputPrimitiveType.String, InputPrimitiveType.String, false), true, true, false), + new InputModelProperty("requiredReadonlyIntDictionary", "requiredReadonlyIntDictionary", "Required readonly int collection.", new InputDictionaryType("requiredReadonlyIntDictionary", InputPrimitiveType.String, InputPrimitiveType.Int32, false), true, true, false), + new InputModelProperty("optionalReadonlyStringDictionary", "optionalReadonlyStringDictionary", "Optional readonly string collection.", new InputDictionaryType("optionalReadonlyStringDictionary", InputPrimitiveType.String, InputPrimitiveType.String, false), false, true, false), + new InputModelProperty("optionalReadonlyIntDictionary", "optionalReadonlyIntDictionary", "Optional readonly int collection.", new InputDictionaryType("optionalReadonlyIntDictionary", InputPrimitiveType.String, InputPrimitiveType.Int32, false), false, true, false), }; private static readonly object[] RoundTripModelCase = diff --git a/test/CadlRanchMockApis/src/FirstTest-TypeSpec.ts b/test/CadlRanchMockApis/src/FirstTest-TypeSpec.ts index a8ab7ce4725..d2c88166713 100644 --- a/test/CadlRanchMockApis/src/FirstTest-TypeSpec.ts +++ b/test/CadlRanchMockApis/src/FirstTest-TypeSpec.ts @@ -19,6 +19,7 @@ Scenarios.FirstTest_CreateLiteral = passOnSuccess([ optionalLiteralInt: 456, optionalLiteralFloat: 4.56, optionalLiteralBool: true, + requiredNullableList: [] }); return { status: 200, @@ -35,6 +36,7 @@ Scenarios.FirstTest_CreateLiteral = passOnSuccess([ optionalLiteralInt: 12345, optionalLiteralFloat: 123.45, optionalLiteralBool: false, + requiredNullableList: [] }) }; }), diff --git a/test/CadlRanchMockApis/src/Models-TypeSpec.ts b/test/CadlRanchMockApis/src/Models-TypeSpec.ts index 4fffc5a5b9f..598b6ec9884 100644 --- a/test/CadlRanchMockApis/src/Models-TypeSpec.ts +++ b/test/CadlRanchMockApis/src/Models-TypeSpec.ts @@ -15,13 +15,18 @@ Scenarios.Models_InputToRoundTripPrimitive = passOnSuccess([ req.expect.bodyEquals({ requiredString: "test", requiredInt: 1, + requiredNullableString: null, + requiredNullableInt: null, requiredModel: {}, - requiredIntCollection: [], - requiredStringCollection: [null, "test"], - requiredModelCollection: [null], + requiredIntList: [], + requiredStringList: [null, "test"], + requiredModelList: [null], requiredModelRecord: {}, requiredCollectionWithNullableFloatElement: [null, 12.3], requiredCollectionWithNullableBooleanElement: [null, true, false], + requiredNullableModelList: null, + requiredNullableStringList: null, + requiredNullableIntList: null, }); return { status: 200, @@ -61,13 +66,18 @@ Scenarios.Models_InputToRoundTripReadOnly = passOnSuccess([ req.expect.bodyEquals({ requiredString: "test", requiredInt: 2, - requiredModel: { requiredCollection: [null] }, - requiredIntCollection: [1, 2], - requiredStringCollection: ["a", null], - requiredModelCollection: [{ requiredModelRecord: {} }], + requiredNullableString: null, + requiredNullableInt: null, + requiredModel: { requiredList: [null] }, + requiredIntList: [1, 2], + requiredStringList: ["a", null], + requiredModelList: [{ requiredModelRecord: {} }], requiredModelRecord: {}, requiredCollectionWithNullableFloatElement: [], requiredCollectionWithNullableBooleanElement: [], + requiredNullableModelList: null, + requiredNullableStringList: null, + requiredNullableIntList: null, }); return { status: 200, @@ -75,21 +85,21 @@ Scenarios.Models_InputToRoundTripReadOnly = passOnSuccess([ requiredReadonlyString: "test", requiredReadonlyInt: 12, optionalReadonlyInt: 11, - requiredReadonlyModel: { requiredCollection: [] }, + requiredReadonlyModel: { requiredList: [] }, requiredReadonlyFixedStringEnum: "1", requiredReadonlyExtensibleEnum: "3", optionalReadonlyFixedStringEnum: "2", optionalReadonlyExtensibleEnum: "1", requiredReadonlyStringList: ["abc"], requiredReadonlyIntList: [], - requiredReadOnlyModelCollection: [], + requiredReadOnlyModelList: [], requiredReadOnlyIntRecord: { test: 1 }, requiredStringRecord: { test: "1" }, requiredReadOnlyModelRecord: {}, optionalReadonlyStringList: [null], - optionalReadOnlyModelCollection: [], + optionalReadOnlyModelList: [], optionalReadOnlyStringRecord: {}, - optionalModelRecord: { test: { requiredCollection: [] } }, + optionalModelRecord: { test: { requiredList: [] } }, requiredCollectionWithNullableIntElement: [null, 123], optionalCollectionWithNullableBooleanElement: [ null, diff --git a/test/CadlRanchMockApis/src/Spread-TypeSpec.ts b/test/CadlRanchMockApis/src/Spread-TypeSpec.ts index b7799a59170..9b4d7d38ab8 100644 --- a/test/CadlRanchMockApis/src/Spread-TypeSpec.ts +++ b/test/CadlRanchMockApis/src/Spread-TypeSpec.ts @@ -40,6 +40,11 @@ const spreadAliasWithOptionalPropRequest = { elements: ["a", "b"] }; +const spreadAliasWithRequiredAndOptionalCollections = { + requiredStringList: ["a", "b"], + optionalStringList: ["c", "d"] +}; + Scenarios.Spread_SpreadModel = passOnSuccess( mockapi.post("/spreadModel", (req) => { req.expect.bodyEquals(spreadModelRequest); @@ -107,3 +112,12 @@ Scenarios.Spread_SpreadAliasWithOptionalProps = passOnSuccess( }; }), ); + +Scenarios.Spread_SpreadAliasWithRequiredAndOptionalCollections = passOnSuccess( + mockapi.post("/spreadAliasWithCollections", (req) => { + req.expect.bodyEquals(spreadAliasWithRequiredAndOptionalCollections); + return { + status: 204 + }; + }), +); diff --git a/test/CadlRanchProjects.Tests/FirstTest-TypeSpec.cs b/test/CadlRanchProjects.Tests/FirstTest-TypeSpec.cs index c157fdf969d..c7e8c0318df 100644 --- a/test/CadlRanchProjects.Tests/FirstTest-TypeSpec.cs +++ b/test/CadlRanchProjects.Tests/FirstTest-TypeSpec.cs @@ -1,6 +1,7 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT License. +using System; using System.Threading.Tasks; using AutoRest.TestServer.Tests.Infrastructure; using FirstTestTypeSpec; @@ -17,7 +18,7 @@ public class FirstTestTypeSpecTests : CadlRanchMockApiTestBase [Test] public async Task FirstTest_CreateLiteral() => await Test(async (host) => { - Thing result = await new FirstTestTypeSpecClient(host).CreateLiteralAsync(new Thing("test", "test", "abc") + Thing result = await new FirstTestTypeSpecClient(host).CreateLiteralAsync(new Thing("test", "test", "abc", Array.Empty()) { OptionalLiteralString = ThingOptionalLiteralString.Reject, OptionalLiteralInt = ThingOptionalLiteralInt._456, diff --git a/test/CadlRanchProjects.Tests/Models-TypeSpec.cs b/test/CadlRanchProjects.Tests/Models-TypeSpec.cs index 92cf29c7843..30c8262372d 100644 --- a/test/CadlRanchProjects.Tests/Models-TypeSpec.cs +++ b/test/CadlRanchProjects.Tests/Models-TypeSpec.cs @@ -13,14 +13,17 @@ namespace CadlRanchProjects.Tests { /// - /// End-to-end test cases for `lro-basic-cadl` test project. + /// End-to-end test cases for `Models-TypeSpec` test project. /// public class ModelsTypeSpecTests : CadlRanchMockApiTestBase { [Test] public Task Models_InputToRoundTripPrimitive() => Test(async (host) => { - InputModel input = new("test", 1, new BaseModel(), Enumerable.Empty(), new string[] { null, "test" }, new CollectionItem[] { null }, new Dictionary(), new float?[] { null, 12.3f }, new bool?[] {null, true, false}); + // we should not call the internal ctor. Because this test case is in the same assembly as the source code therefore we can access to the internal ctor now. + // our customer never could. + // when we are calling the internal ctor, we can assign null to collections, which is a case we should avoid. + InputModel input = new("test", 1, null, null, new BaseModel(), Enumerable.Empty(), new string[] { null, "test" }, new CollectionItem[] { null }, new Dictionary(), new float?[] { null, 12.3f }, new bool?[] {null, true, false}, null, null, null); RoundTripPrimitiveModel result = await new ModelsTypeSpecClient(host).InputToRoundTripPrimitiveAsync(input); Assert.AreEqual("test", result.RequiredString); @@ -29,7 +32,7 @@ public Task Models_InputToRoundTripPrimitive() => Test(async (host) => Assert.AreEqual(1234567, result.RequiredSafeInt); Assert.AreEqual(12.3f, result.RequiredFloat); Assert.AreEqual(123.456, result.RequiredDouble); - Assert.True(result.RequiredBoolean); + Assert.IsTrue(result.RequiredBoolean); Assert.AreEqual(DateTimeOffset.Parse("2023-02-14Z02:08:47"), result.RequiredDateTimeOffset); Assert.AreEqual(new TimeSpan(1, 2, 59, 59), result.RequiredTimeSpan); CollectionAssert.AreEqual(new float?[] { null, 12.3f }, result.RequiredCollectionWithNullableFloatElement); @@ -54,13 +57,13 @@ public Task Models_InputToRoundTripOptional() => Test(async (host) => [Test] public Task Models_InputToRoundTripReadOnly() => Test(async (host) => { - InputModel input = new("test", 2, new DerivedModel(new CollectionItem[] { null }), new int[] { 1, 2 }, new string[] { "a", null}, new CollectionItem[] { new CollectionItem(new Dictionary())}, new Dictionary(), Enumerable.Empty(), Enumerable.Empty()); + InputModel input = new("test", 2, null, null, new DerivedModel(new CollectionItem[] { null }), new int[] { 1, 2 }, new string[] { "a", null}, new CollectionItem[] { new CollectionItem(new Dictionary())}, new Dictionary(), Enumerable.Empty(), Enumerable.Empty(), null, null, null); RoundTripReadOnlyModel result = await new ModelsTypeSpecClient(host).InputToRoundTripReadOnlyAsync(input); Assert.AreEqual("test", result.RequiredReadonlyString); Assert.AreEqual(12, result.RequiredReadonlyInt); Assert.AreEqual(11, result.OptionalReadonlyInt); - Assert.IsEmpty(result.RequiredReadonlyModel.RequiredCollection); + Assert.IsEmpty(result.RequiredReadonlyModel.RequiredList); Assert.AreEqual(FixedStringEnum.One, result.RequiredReadonlyFixedStringEnum); Assert.AreEqual("3", result.RequiredReadonlyExtensibleEnum.ToString()); Assert.AreEqual(FixedStringEnum.Two, result.OptionalReadonlyFixedStringEnum); @@ -68,7 +71,7 @@ public Task Models_InputToRoundTripReadOnly() => Test(async (host) => Assert.AreEqual(1, result.RequiredReadonlyStringList.Count); Assert.AreEqual("abc", result.RequiredReadonlyStringList[0]); Assert.IsEmpty(result.RequiredReadonlyIntList); - Assert.IsEmpty(result.RequiredReadOnlyModelCollection); + Assert.IsEmpty(result.RequiredReadOnlyModelList); Assert.AreEqual(1, result.RequiredReadOnlyIntRecord.Count); Assert.AreEqual(1, result.RequiredReadOnlyIntRecord["test"]); Assert.AreEqual(1, result.RequiredStringRecord.Count); @@ -76,10 +79,10 @@ public Task Models_InputToRoundTripReadOnly() => Test(async (host) => Assert.IsEmpty(result.RequiredReadOnlyModelRecord); Assert.AreEqual(1, result.OptionalReadonlyStringList.Count); Assert.IsNull(result.OptionalReadonlyStringList[0]); - Assert.IsEmpty(result.OptionalReadOnlyModelCollection); + Assert.IsEmpty(result.OptionalReadOnlyModelList); Assert.IsEmpty(result.OptionalReadOnlyStringRecord); Assert.AreEqual(1, result.OptionalModelRecord.Count); - Assert.IsEmpty(result.OptionalModelRecord["test"].RequiredCollection); + Assert.IsEmpty(result.OptionalModelRecord["test"].RequiredList); CollectionAssert.AreEqual(new int?[] { null, 123 }, result.RequiredCollectionWithNullableIntElement); CollectionAssert.AreEqual(new bool?[] { null, false, true }, result.OptionalCollectionWithNullableBooleanElement); }); diff --git a/test/CadlRanchProjects.Tests/Spread-TypeSpec.cs b/test/CadlRanchProjects.Tests/Spread-TypeSpec.cs index c2c2d43684c..c4d483a3495 100644 --- a/test/CadlRanchProjects.Tests/Spread-TypeSpec.cs +++ b/test/CadlRanchProjects.Tests/Spread-TypeSpec.cs @@ -62,5 +62,12 @@ public Task Spread_SpreadAliasWithOptionalProps() => Test(async (host) => Response response = await new SpreadTypeSpecClient(host).SpreadAliasWithOptionalPropsAsync("2", 1, "dog", new[] { 1, 2, 3, 4 }, "red", 3, new[] { "a", "b" }); Assert.AreEqual(204, response.Status); }); + + [Test] + public Task Spread_SpreadAliasWithRequiredAndOptionalCollections() => Test(async (host) => + { + Response response = await new SpreadTypeSpecClient(host).SpreadAliasWithCollectionsAsync(new[] { "a", "b" }, new[] { "c", "d" }); + Assert.AreEqual(204, response.Status); + }); } } diff --git a/test/CadlRanchProjects.Tests/type-property-nullable.cs b/test/CadlRanchProjects.Tests/type-property-nullable.cs index 5c882a1f712..40df8b3dd38 100644 --- a/test/CadlRanchProjects.Tests/type-property-nullable.cs +++ b/test/CadlRanchProjects.Tests/type-property-nullable.cs @@ -10,7 +10,7 @@ namespace CadlRanchProjects.Tests { - public class TypePropertyNullableTests : CadlRanchTestBase + public class TypePropertyNullableTests : CadlRanchTestBase { [Test] public Task Type_Property_Nullable_String_getNonNull() => Test(async (host) => @@ -166,12 +166,13 @@ public Task Type_Property_Nullable_CollectionsByte_getNonNull() => Test(async (h }); [Test] - [Ignore("https://github.com/Azure/autorest.csharp/issues/3363")] public Task Type_Property_Nullable_CollectionsByte_getNull() => Test(async (host) => { var response = await new NullableClient(host, null).GetCollectionsByteClient().GetNullAsync(); Assert.AreEqual("foo", response.Value.RequiredProperty); - Assert.AreEqual(null, response.Value.NullableProperty); + // we will never construct a null collection therefore this property is actually undefined here. + Assert.IsNotNull(response.Value.NullableProperty); + Assert.IsFalse(Optional.IsCollectionDefined(response.Value.NullableProperty)); }); [Test] @@ -204,12 +205,13 @@ public Task Type_Property_Nullable_CollectionsModel_getNonNull() => Test(async ( }); [Test] - [Ignore("https://github.com/Azure/autorest.csharp/issues/3363")] public Task Type_Property_Nullable_CollectionsModel_getNull() => Test(async (host) => { var response = await new NullableClient(host, null).GetCollectionsModelClient().GetNullAsync(); Assert.AreEqual("foo", response.Value.RequiredProperty); - Assert.AreEqual(null, response.Value.NullableProperty); + // we will never construct a null collection therefore this property is actually undefined here. + Assert.IsNotNull(response.Value.NullableProperty); + Assert.IsFalse(Optional.IsCollectionDefined(response.Value.NullableProperty)); }); [Test] diff --git a/test/CadlRanchProjects/inheritance/src/Generated/Models/Cat.cs b/test/CadlRanchProjects/inheritance/src/Generated/Models/Cat.cs index bd63c07679c..22295a94314 100644 --- a/test/CadlRanchProjects/inheritance/src/Generated/Models/Cat.cs +++ b/test/CadlRanchProjects/inheritance/src/Generated/Models/Cat.cs @@ -24,7 +24,7 @@ internal Cat(string name, int age) : base(name) Age = age; } - /// Gets or sets the age. - public int Age { get; set; } + /// Gets the age. + public int Age { get; } } } diff --git a/test/CadlRanchProjects/inheritance/src/Generated/Models/Pet.cs b/test/CadlRanchProjects/inheritance/src/Generated/Models/Pet.cs index abce5faa06f..d4a808058a0 100644 --- a/test/CadlRanchProjects/inheritance/src/Generated/Models/Pet.cs +++ b/test/CadlRanchProjects/inheritance/src/Generated/Models/Pet.cs @@ -23,7 +23,7 @@ internal Pet(string name) Name = name; } - /// Gets or sets the name. - public string Name { get; set; } + /// Gets the name. + public string Name { get; } } } diff --git a/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsByteProperty.Serialization.cs b/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsByteProperty.Serialization.cs index b1382bd1310..49f4d7d5ea8 100644 --- a/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsByteProperty.Serialization.cs +++ b/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsByteProperty.Serialization.cs @@ -32,6 +32,11 @@ internal static CollectionsByteProperty DeserializeCollectionsByteProperty(JsonE } if (property.NameEquals("nullableProperty"u8)) { + if (property.Value.ValueKind == JsonValueKind.Null) + { + nullableProperty = new ChangeTrackingList(); + continue; + } List array = new List(); foreach (var item in property.Value.EnumerateArray()) { diff --git a/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsByteProperty.cs b/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsByteProperty.cs index cea939c6bd1..86cf02ff37d 100644 --- a/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsByteProperty.cs +++ b/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsByteProperty.cs @@ -18,14 +18,13 @@ public partial class CollectionsByteProperty /// Initializes a new instance of CollectionsByteProperty. /// Required property. /// Property. - /// or is null. + /// is null. internal CollectionsByteProperty(string requiredProperty, IEnumerable nullableProperty) { Argument.AssertNotNull(requiredProperty, nameof(requiredProperty)); - Argument.AssertNotNull(nullableProperty, nameof(nullableProperty)); RequiredProperty = requiredProperty; - NullableProperty = nullableProperty.ToList(); + NullableProperty = nullableProperty?.ToList(); } /// Initializes a new instance of CollectionsByteProperty. diff --git a/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsModelProperty.Serialization.cs b/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsModelProperty.Serialization.cs index b13885bd20d..8383abdb950 100644 --- a/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsModelProperty.Serialization.cs +++ b/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsModelProperty.Serialization.cs @@ -31,6 +31,11 @@ internal static CollectionsModelProperty DeserializeCollectionsModelProperty(Jso } if (property.NameEquals("nullableProperty"u8)) { + if (property.Value.ValueKind == JsonValueKind.Null) + { + nullableProperty = new ChangeTrackingList(); + continue; + } List array = new List(); foreach (var item in property.Value.EnumerateArray()) { diff --git a/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsModelProperty.cs b/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsModelProperty.cs index 770743cbc44..eac580bd989 100644 --- a/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsModelProperty.cs +++ b/test/CadlRanchProjects/type/property/nullable/src/Generated/Models/CollectionsModelProperty.cs @@ -18,14 +18,13 @@ public partial class CollectionsModelProperty /// Initializes a new instance of CollectionsModelProperty. /// Required property. /// Property. - /// or is null. + /// is null. internal CollectionsModelProperty(string requiredProperty, IEnumerable nullableProperty) { Argument.AssertNotNull(requiredProperty, nameof(requiredProperty)); - Argument.AssertNotNull(nullableProperty, nameof(nullableProperty)); RequiredProperty = requiredProperty; - NullableProperty = nullableProperty.ToList(); + NullableProperty = nullableProperty?.ToList(); } /// Initializes a new instance of CollectionsModelProperty. diff --git a/test/TestProjects/FirstTest-TypeSpec/FirstTest-TypeSpec.tsp b/test/TestProjects/FirstTest-TypeSpec/FirstTest-TypeSpec.tsp index 2636f6eb3e8..ce72816a026 100644 --- a/test/TestProjects/FirstTest-TypeSpec/FirstTest-TypeSpec.tsp +++ b/test/TestProjects/FirstTest-TypeSpec/FirstTest-TypeSpec.tsp @@ -111,6 +111,24 @@ model Thing { @doc("description with xml <|endoftext|>") requiredBadDescription: string; + + @doc("optional nullable collection") + optionalNullableList?: int32[] | null; + + @doc("required nullable collection") + requiredNullableList: int32[] | null; +} + +@doc("A model with a few required nullable properties") +model ModelWithRequiredNullableProperties { + @doc("required nullable primitive type") + requiredNullablePrimitive: int32 | null; + + @doc("required nullable extensible enum type") + requiredExtensibleEnum: StringExtensibleEnum | null; + + @doc("required nullable fixed enum type") + requiredFixedEnum: StringFixedEnum | null; } @doc("this is not a friendly model but with a friendly name") @@ -183,6 +201,9 @@ model RoundTripModel { @doc("optional readonly record of unknown") @visibility("read") readOnlyOptionalRecordUnknown?: Record; + + @doc("this is a model with required nullable properties") + modelWithRequiredNullable: ModelWithRequiredNullableProperties; } enum DaysOfWeekExtensibleEnum { diff --git a/test/TestProjects/FirstTest-TypeSpec/src/Generated/Configuration.json b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Configuration.json index 14f465d4149..435c5495833 100644 --- a/test/TestProjects/FirstTest-TypeSpec/src/Generated/Configuration.json +++ b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Configuration.json @@ -6,5 +6,6 @@ "../../../../../artifacts/bin/AutoRest.CSharp/Debug/net6.0/Generator.Shared", "../../../../../artifacts/bin/AutoRest.CSharp/Debug/net6.0/Azure.Core.Shared" ], - "use-overloads-between-protocol-and-convenience": true + "use-overloads-between-protocol-and-convenience": true, + "deserialize-null-collection-as-null-value": true } diff --git a/test/TestProjects/FirstTest-TypeSpec/src/Generated/Docs/FirstTestTypeSpecClient.xml b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Docs/FirstTestTypeSpecClient.xml index c10f3979fee..1f79a745305 100644 --- a/test/TestProjects/FirstTest-TypeSpec/src/Generated/Docs/FirstTestTypeSpecClient.xml +++ b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Docs/FirstTestTypeSpecClient.xml @@ -44,6 +44,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -68,6 +70,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -92,6 +96,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -116,6 +122,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -134,6 +142,9 @@ var data = new { requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }; Response response = await client.PatchActionAsync(RequestContent.Create(data)); @@ -146,6 +157,7 @@ Console.WriteLine(result.GetProperty("requiredLiteralInt").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> This sample shows how to call PatchActionAsync with all request content, and how to parse the result. ", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }; Response response = await client.PatchActionAsync(RequestContent.Create(data)); @@ -180,6 +198,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -198,6 +218,9 @@ var data = new { requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }; Response response = client.PatchAction(RequestContent.Create(data)); @@ -210,6 +233,7 @@ Console.WriteLine(result.GetProperty("requiredLiteralInt").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> This sample shows how to call PatchAction with all request content, and how to parse the result. ", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }; Response response = client.PatchAction(RequestContent.Create(data)); @@ -244,6 +274,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -254,12 +286,19 @@ This sample shows how to call AnonymousBodyAsync with required parameters. var endpoint = new Uri(""); var client = new FirstTestTypeSpecClient(endpoint); -var thing = new Thing("", "", "") +var thing = new Thing("", "", "", new int[] +{ + 1234 +}) { OptionalLiteralString = ThingOptionalLiteralString.Reject, OptionalLiteralInt = ThingOptionalLiteralInt._456, OptionalLiteralFloat = ThingOptionalLiteralFloat._456, OptionalLiteralBool = true, + OptionalNullableList = +{ + 1234 + }, }; var result = await client.AnonymousBodyAsync(thing); ]]> @@ -272,12 +311,19 @@ This sample shows how to call AnonymousBody with required parameters. var endpoint = new Uri(""); var client = new FirstTestTypeSpecClient(endpoint); -var thing = new Thing("", "", "") +var thing = new Thing("", "", "", new int[] +{ + 1234 +}) { OptionalLiteralString = ThingOptionalLiteralString.Reject, OptionalLiteralInt = ThingOptionalLiteralInt._456, OptionalLiteralFloat = ThingOptionalLiteralFloat._456, OptionalLiteralBool = true, + OptionalNullableList = +{ + 1234 + }, }; var result = client.AnonymousBody(thing); ]]> @@ -298,6 +344,9 @@ var data = new { requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }; Response response = await client.AnonymousBodyAsync(RequestContent.Create(data)); @@ -310,6 +359,7 @@ Console.WriteLine(result.GetProperty("requiredLiteralInt").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> This sample shows how to call AnonymousBodyAsync with all request content, and how to parse the result. ", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }; Response response = await client.AnonymousBodyAsync(RequestContent.Create(data)); @@ -344,6 +400,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -362,6 +420,9 @@ var data = new { requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }; Response response = client.AnonymousBody(RequestContent.Create(data)); @@ -374,6 +435,7 @@ Console.WriteLine(result.GetProperty("requiredLiteralInt").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> This sample shows how to call AnonymousBody with all request content, and how to parse the result. ", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }; Response response = client.AnonymousBody(RequestContent.Create(data)); @@ -408,6 +476,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -574,6 +644,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -598,6 +670,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -608,22 +682,29 @@ This sample shows how to call HelloAgainAsync with required parameters. var endpoint = new Uri(""); var client = new FirstTestTypeSpecClient(endpoint); -var action = new RoundTripModel("", 1234, new StringFixedEnum[] +var action = new RoundTripModel("", 1234, new StringFixedEnum?[] { StringFixedEnum.One -}, new Dictionary +}, new Dictionary { ["key"] = StringExtensibleEnum.One, -}, new Thing("", "", "") +}, new Thing("", "", "", new int[] +{ + 1234 +}) { OptionalLiteralString = ThingOptionalLiteralString.Reject, OptionalLiteralInt = ThingOptionalLiteralInt._456, OptionalLiteralFloat = ThingOptionalLiteralFloat._456, OptionalLiteralBool = true, + OptionalNullableList = +{ + 1234 + }, }, BinaryData.FromString(""), new Dictionary { ["key"] = BinaryData.FromString(""), -}) +}, new ModelWithRequiredNullableProperties(1234, StringExtensibleEnum.One, StringFixedEnum.One)) { IntExtensibleEnum = IntExtensibleEnum.One, IntExtensibleEnumCollection = @@ -663,22 +744,29 @@ This sample shows how to call HelloAgain with required parameters. var endpoint = new Uri(""); var client = new FirstTestTypeSpecClient(endpoint); -var action = new RoundTripModel("", 1234, new StringFixedEnum[] +var action = new RoundTripModel("", 1234, new StringFixedEnum?[] { StringFixedEnum.One -}, new Dictionary +}, new Dictionary { ["key"] = StringExtensibleEnum.One, -}, new Thing("", "", "") +}, new Thing("", "", "", new int[] +{ + 1234 +}) { OptionalLiteralString = ThingOptionalLiteralString.Reject, OptionalLiteralInt = ThingOptionalLiteralInt._456, OptionalLiteralFloat = ThingOptionalLiteralFloat._456, OptionalLiteralBool = true, + OptionalNullableList = +{ + 1234 + }, }, BinaryData.FromString(""), new Dictionary { ["key"] = BinaryData.FromString(""), -}) +}, new ModelWithRequiredNullableProperties(1234, StringExtensibleEnum.One, StringFixedEnum.One)) { IntExtensibleEnum = IntExtensibleEnum.One, IntExtensibleEnumCollection = @@ -735,11 +823,19 @@ var data = new { requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }, requiredUnknown = new {}, requiredRecordUnknown = new { key = new {}, }, + modelWithRequiredNullable = new { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = await client.HelloAgainAsync("", "", RequestContent.Create(data)); @@ -756,9 +852,13 @@ Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiter Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("requiredUnknown").ToString()); Console.WriteLine(result.GetProperty("requiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); ]]> This sample shows how to call HelloAgainAsync with all parameters and request content, and how to parse the result. ", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }, intExtensibleEnum = "1", intExtensibleEnumCollection = new[] { @@ -812,6 +918,11 @@ var data = new { optionalRecordUnknown = new { key = new {}, }, + modelWithRequiredNullable = new { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = await client.HelloAgainAsync("", "", RequestContent.Create(data)); @@ -832,6 +943,8 @@ Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiter Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnum").ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnumCollection")[0].ToString()); Console.WriteLine(result.GetProperty("floatExtensibleEnum").ToString()); @@ -847,6 +960,9 @@ Console.WriteLine(result.GetProperty("requiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyOptionalRecordUnknown").GetProperty("").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); ]]> @@ -874,11 +990,19 @@ var data = new { requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }, requiredUnknown = new {}, requiredRecordUnknown = new { key = new {}, }, + modelWithRequiredNullable = new { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = client.HelloAgain("", "", RequestContent.Create(data)); @@ -895,9 +1019,13 @@ Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiter Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("requiredUnknown").ToString()); Console.WriteLine(result.GetProperty("requiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); ]]> This sample shows how to call HelloAgain with all parameters and request content, and how to parse the result. ", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }, intExtensibleEnum = "1", intExtensibleEnumCollection = new[] { @@ -951,6 +1085,11 @@ var data = new { optionalRecordUnknown = new { key = new {}, }, + modelWithRequiredNullable = new { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = client.HelloAgain("", "", RequestContent.Create(data)); @@ -971,6 +1110,8 @@ Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiter Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnum").ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnumCollection")[0].ToString()); Console.WriteLine(result.GetProperty("floatExtensibleEnum").ToString()); @@ -986,6 +1127,9 @@ Console.WriteLine(result.GetProperty("requiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyOptionalRecordUnknown").GetProperty("").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); ]]> @@ -1013,11 +1157,19 @@ var data = new { requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }, requiredUnknown = new {}, requiredRecordUnknown = new { key = new {}, }, + modelWithRequiredNullable = new { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = await client.NoContentTypeAsync("", "", RequestContent.Create(data)); @@ -1034,9 +1186,13 @@ Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiter Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("requiredUnknown").ToString()); Console.WriteLine(result.GetProperty("requiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); ]]> This sample shows how to call NoContentTypeAsync with all parameters and request content, and how to parse the result. ", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }, intExtensibleEnum = "1", intExtensibleEnumCollection = new[] { @@ -1090,6 +1252,11 @@ var data = new { optionalRecordUnknown = new { key = new {}, }, + modelWithRequiredNullable = new { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = await client.NoContentTypeAsync("", "", RequestContent.Create(data)); @@ -1110,6 +1277,8 @@ Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiter Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnum").ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnumCollection")[0].ToString()); Console.WriteLine(result.GetProperty("floatExtensibleEnum").ToString()); @@ -1125,6 +1294,9 @@ Console.WriteLine(result.GetProperty("requiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyOptionalRecordUnknown").GetProperty("").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); ]]> @@ -1152,11 +1324,19 @@ var data = new { requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }, requiredUnknown = new {}, requiredRecordUnknown = new { key = new {}, }, + modelWithRequiredNullable = new { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = client.NoContentType("", "", RequestContent.Create(data)); @@ -1173,9 +1353,13 @@ Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiter Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("requiredUnknown").ToString()); Console.WriteLine(result.GetProperty("requiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); ]]> This sample shows how to call NoContentType with all parameters and request content, and how to parse the result. ", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }, intExtensibleEnum = "1", intExtensibleEnumCollection = new[] { @@ -1229,6 +1419,11 @@ var data = new { optionalRecordUnknown = new { key = new {}, }, + modelWithRequiredNullable = new { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = client.NoContentType("", "", RequestContent.Create(data)); @@ -1249,6 +1444,8 @@ Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiter Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnum").ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnumCollection")[0].ToString()); Console.WriteLine(result.GetProperty("floatExtensibleEnum").ToString()); @@ -1264,6 +1461,9 @@ Console.WriteLine(result.GetProperty("requiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyOptionalRecordUnknown").GetProperty("").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); +Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); ]]> @@ -1310,6 +1510,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -1334,6 +1536,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -1344,12 +1548,19 @@ This sample shows how to call CreateLiteralAsync with required parameters. var endpoint = new Uri(""); var client = new FirstTestTypeSpecClient(endpoint); -var body = new Thing("", "", "") +var body = new Thing("", "", "", new int[] +{ + 1234 +}) { OptionalLiteralString = ThingOptionalLiteralString.Reject, OptionalLiteralInt = ThingOptionalLiteralInt._456, OptionalLiteralFloat = ThingOptionalLiteralFloat._456, OptionalLiteralBool = true, + OptionalNullableList = +{ + 1234 + }, }; var result = await client.CreateLiteralAsync(body); ]]> @@ -1362,12 +1573,19 @@ This sample shows how to call CreateLiteral with required parameters. var endpoint = new Uri(""); var client = new FirstTestTypeSpecClient(endpoint); -var body = new Thing("", "", "") +var body = new Thing("", "", "", new int[] +{ + 1234 +}) { OptionalLiteralString = ThingOptionalLiteralString.Reject, OptionalLiteralInt = ThingOptionalLiteralInt._456, OptionalLiteralFloat = ThingOptionalLiteralFloat._456, OptionalLiteralBool = true, + OptionalNullableList = +{ + 1234 + }, }; var result = client.CreateLiteral(body); ]]> @@ -1388,6 +1606,9 @@ var data = new { requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }; Response response = await client.CreateLiteralAsync(RequestContent.Create(data)); @@ -1400,6 +1621,7 @@ Console.WriteLine(result.GetProperty("requiredLiteralInt").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> This sample shows how to call CreateLiteralAsync with all request content, and how to parse the result. ", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }; Response response = await client.CreateLiteralAsync(RequestContent.Create(data)); @@ -1434,6 +1662,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -1452,6 +1682,9 @@ var data = new { requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }; Response response = client.CreateLiteral(RequestContent.Create(data)); @@ -1464,6 +1697,7 @@ Console.WriteLine(result.GetProperty("requiredLiteralInt").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> This sample shows how to call CreateLiteral with all request content, and how to parse the result. ", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }; Response response = client.CreateLiteral(RequestContent.Create(data)); @@ -1498,6 +1738,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -1544,6 +1786,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -1568,6 +1812,8 @@ Console.WriteLine(result.GetProperty("optionalLiteralInt").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); +Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); ]]> @@ -1606,12 +1852,19 @@ This sample shows how to call InternalProtocolAsync with required parameters. var endpoint = new Uri(""); var client = new FirstTestTypeSpecClient(endpoint); -var body = new Thing("", "", "") +var body = new Thing("", "", "", new int[] +{ + 1234 +}) { OptionalLiteralString = ThingOptionalLiteralString.Reject, OptionalLiteralInt = ThingOptionalLiteralInt._456, OptionalLiteralFloat = ThingOptionalLiteralFloat._456, OptionalLiteralBool = true, + OptionalNullableList = +{ + 1234 + }, }; var result = await client.InternalProtocolAsync(body); ]]> @@ -1624,12 +1877,19 @@ This sample shows how to call InternalProtocol with required parameters. var endpoint = new Uri(""); var client = new FirstTestTypeSpecClient(endpoint); -var body = new Thing("", "", "") +var body = new Thing("", "", "", new int[] +{ + 1234 +}) { OptionalLiteralString = ThingOptionalLiteralString.Reject, OptionalLiteralInt = ThingOptionalLiteralInt._456, OptionalLiteralFloat = ThingOptionalLiteralFloat._456, OptionalLiteralBool = true, + OptionalNullableList = +{ + 1234 + }, }; var result = client.InternalProtocol(body); ]]> diff --git a/test/TestProjects/FirstTest-TypeSpec/src/Generated/FirstTestTypeSpecModelFactory.cs b/test/TestProjects/FirstTest-TypeSpec/src/Generated/FirstTestTypeSpecModelFactory.cs index 698520108a3..06ef432ae32 100644 --- a/test/TestProjects/FirstTest-TypeSpec/src/Generated/FirstTestTypeSpecModelFactory.cs +++ b/test/TestProjects/FirstTest-TypeSpec/src/Generated/FirstTestTypeSpecModelFactory.cs @@ -26,10 +26,15 @@ public static partial class FirstTestTypeSpecModelFactory /// optional literal float. /// optional literal bool. /// description with xml <|endoftext|>. + /// optional nullable collection. + /// required nullable collection. /// A new instance for mocking. - public static Thing Thing(string name = null, string requiredUnion = null, ThingRequiredLiteralString requiredLiteralString = default, ThingRequiredLiteralInt requiredLiteralInt = default, ThingRequiredLiteralFloat requiredLiteralFloat = default, bool requiredLiteralBool = default, ThingOptionalLiteralString? optionalLiteralString = null, ThingOptionalLiteralInt? optionalLiteralInt = null, ThingOptionalLiteralFloat? optionalLiteralFloat = null, bool? optionalLiteralBool = null, string requiredBadDescription = null) + public static Thing Thing(string name = null, string requiredUnion = null, ThingRequiredLiteralString requiredLiteralString = default, ThingRequiredLiteralInt requiredLiteralInt = default, ThingRequiredLiteralFloat requiredLiteralFloat = default, bool requiredLiteralBool = default, ThingOptionalLiteralString? optionalLiteralString = null, ThingOptionalLiteralInt? optionalLiteralInt = null, ThingOptionalLiteralFloat? optionalLiteralFloat = null, bool? optionalLiteralBool = null, string requiredBadDescription = null, IEnumerable optionalNullableList = null, IEnumerable requiredNullableList = null) { - return new Thing(name, requiredUnion, requiredLiteralString, requiredLiteralInt, requiredLiteralFloat, requiredLiteralBool, optionalLiteralString, optionalLiteralInt, optionalLiteralFloat, optionalLiteralBool, requiredBadDescription); + optionalNullableList ??= new List(); + requiredNullableList ??= new List(); + + return new Thing(name, requiredUnion, requiredLiteralString, requiredLiteralInt, requiredLiteralFloat, requiredLiteralBool, optionalLiteralString, optionalLiteralInt, optionalLiteralFloat, optionalLiteralBool, requiredBadDescription, optionalNullableList?.ToList(), requiredNullableList?.ToList()); } /// Initializes a new instance of RoundTripModel. @@ -53,11 +58,12 @@ public static Thing Thing(string name = null, string requiredUnion = null, Thing /// optional record of unknown. /// required readonly record of unknown. /// optional readonly record of unknown. + /// this is a model with required nullable properties. /// A new instance for mocking. - public static RoundTripModel RoundTripModel(string requiredString = null, int requiredInt = default, IEnumerable requiredCollection = null, IDictionary requiredDictionary = null, Thing requiredModel = null, IntExtensibleEnum? intExtensibleEnum = null, IEnumerable intExtensibleEnumCollection = null, FloatExtensibleEnum? floatExtensibleEnum = null, IEnumerable floatExtensibleEnumCollection = null, FloatFixedEnum? floatFixedEnum = null, IEnumerable floatFixedEnumCollection = null, IntFixedEnum? intFixedEnum = null, IEnumerable intFixedEnumCollection = null, StringFixedEnum? stringFixedEnum = null, BinaryData requiredUnknown = null, BinaryData optionalUnknown = null, IDictionary requiredRecordUnknown = null, IDictionary optionalRecordUnknown = null, IReadOnlyDictionary readOnlyRequiredRecordUnknown = null, IReadOnlyDictionary readOnlyOptionalRecordUnknown = null) + public static RoundTripModel RoundTripModel(string requiredString = null, int requiredInt = default, IEnumerable requiredCollection = null, IDictionary requiredDictionary = null, Thing requiredModel = null, IntExtensibleEnum? intExtensibleEnum = null, IEnumerable intExtensibleEnumCollection = null, FloatExtensibleEnum? floatExtensibleEnum = null, IEnumerable floatExtensibleEnumCollection = null, FloatFixedEnum? floatFixedEnum = null, IEnumerable floatFixedEnumCollection = null, IntFixedEnum? intFixedEnum = null, IEnumerable intFixedEnumCollection = null, StringFixedEnum? stringFixedEnum = null, BinaryData requiredUnknown = null, BinaryData optionalUnknown = null, IDictionary requiredRecordUnknown = null, IDictionary optionalRecordUnknown = null, IReadOnlyDictionary readOnlyRequiredRecordUnknown = null, IReadOnlyDictionary readOnlyOptionalRecordUnknown = null, ModelWithRequiredNullableProperties modelWithRequiredNullable = null) { - requiredCollection ??= new List(); - requiredDictionary ??= new Dictionary(); + requiredCollection ??= new List(); + requiredDictionary ??= new Dictionary(); intExtensibleEnumCollection ??= new List(); floatExtensibleEnumCollection ??= new List(); floatFixedEnumCollection ??= new List(); @@ -67,7 +73,7 @@ public static RoundTripModel RoundTripModel(string requiredString = null, int re readOnlyRequiredRecordUnknown ??= new Dictionary(); readOnlyOptionalRecordUnknown ??= new Dictionary(); - return new RoundTripModel(requiredString, requiredInt, requiredCollection?.ToList(), requiredDictionary, requiredModel, intExtensibleEnum, intExtensibleEnumCollection?.ToList(), floatExtensibleEnum, floatExtensibleEnumCollection?.ToList(), floatFixedEnum, floatFixedEnumCollection?.ToList(), intFixedEnum, intFixedEnumCollection?.ToList(), stringFixedEnum, requiredUnknown, optionalUnknown, requiredRecordUnknown, optionalRecordUnknown, readOnlyRequiredRecordUnknown, readOnlyOptionalRecordUnknown); + return new RoundTripModel(requiredString, requiredInt, requiredCollection?.ToList(), requiredDictionary, requiredModel, intExtensibleEnum, intExtensibleEnumCollection?.ToList(), floatExtensibleEnum, floatExtensibleEnumCollection?.ToList(), floatFixedEnum, floatFixedEnumCollection?.ToList(), intFixedEnum, intFixedEnumCollection?.ToList(), stringFixedEnum, requiredUnknown, optionalUnknown, requiredRecordUnknown, optionalRecordUnknown, readOnlyRequiredRecordUnknown, readOnlyOptionalRecordUnknown, modelWithRequiredNullable); } } } diff --git a/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.Serialization.cs b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.Serialization.cs new file mode 100644 index 00000000000..e7f57235d1e --- /dev/null +++ b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.Serialization.cs @@ -0,0 +1,110 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure; +using Azure.Core; + +namespace FirstTestTypeSpec.Models +{ + public partial class ModelWithRequiredNullableProperties : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + if (RequiredNullablePrimitive != null) + { + writer.WritePropertyName("requiredNullablePrimitive"u8); + writer.WriteNumberValue(RequiredNullablePrimitive.Value); + } + else + { + writer.WriteNull("requiredNullablePrimitive"); + } + if (RequiredExtensibleEnum != null) + { + writer.WritePropertyName("requiredExtensibleEnum"u8); + writer.WriteStringValue(RequiredExtensibleEnum.Value.ToString()); + } + else + { + writer.WriteNull("requiredExtensibleEnum"); + } + if (RequiredFixedEnum != null) + { + writer.WritePropertyName("requiredFixedEnum"u8); + writer.WriteStringValue(RequiredFixedEnum.Value.ToSerialString()); + } + else + { + writer.WriteNull("requiredFixedEnum"); + } + writer.WriteEndObject(); + } + + internal static ModelWithRequiredNullableProperties DeserializeModelWithRequiredNullableProperties(JsonElement element) + { + if (element.ValueKind == JsonValueKind.Null) + { + return null; + } + int? requiredNullablePrimitive = default; + StringExtensibleEnum? requiredExtensibleEnum = default; + StringFixedEnum? requiredFixedEnum = default; + foreach (var property in element.EnumerateObject()) + { + if (property.NameEquals("requiredNullablePrimitive"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + requiredNullablePrimitive = null; + continue; + } + requiredNullablePrimitive = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("requiredExtensibleEnum"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + requiredExtensibleEnum = null; + continue; + } + requiredExtensibleEnum = new StringExtensibleEnum(property.Value.GetString()); + continue; + } + if (property.NameEquals("requiredFixedEnum"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + requiredFixedEnum = null; + continue; + } + requiredFixedEnum = property.Value.GetString().ToStringFixedEnum(); + continue; + } + } + return new ModelWithRequiredNullableProperties(requiredNullablePrimitive, requiredExtensibleEnum, requiredFixedEnum); + } + + /// Deserializes the model from a raw response. + /// The response to deserialize the model from. + internal static ModelWithRequiredNullableProperties FromResponse(Response response) + { + using var document = JsonDocument.Parse(response.Content); + return DeserializeModelWithRequiredNullableProperties(document.RootElement); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.cs b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.cs new file mode 100644 index 00000000000..29ba2aee074 --- /dev/null +++ b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.cs @@ -0,0 +1,31 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +namespace FirstTestTypeSpec.Models +{ + /// A model with a few required nullable properties. + public partial class ModelWithRequiredNullableProperties + { + /// Initializes a new instance of ModelWithRequiredNullableProperties. + /// required nullable primitive type. + /// required nullable extensible enum type. + /// required nullable fixed enum type. + public ModelWithRequiredNullableProperties(int? requiredNullablePrimitive, StringExtensibleEnum? requiredExtensibleEnum, StringFixedEnum? requiredFixedEnum) + { + RequiredNullablePrimitive = requiredNullablePrimitive; + RequiredExtensibleEnum = requiredExtensibleEnum; + RequiredFixedEnum = requiredFixedEnum; + } + + /// required nullable primitive type. + public int? RequiredNullablePrimitive { get; set; } + /// required nullable extensible enum type. + public StringExtensibleEnum? RequiredExtensibleEnum { get; set; } + /// required nullable fixed enum type. + public StringFixedEnum? RequiredFixedEnum { get; set; } + } +} diff --git a/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs index f2bffa9e25b..b6880ea2203 100644 --- a/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs +++ b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs @@ -26,7 +26,12 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStartArray(); foreach (var item in RequiredCollection) { - writer.WriteStringValue(item.ToSerialString()); + if (item == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteStringValue(item.Value.ToSerialString()); } writer.WriteEndArray(); writer.WritePropertyName("requiredDictionary"u8); @@ -34,7 +39,12 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) foreach (var item in RequiredDictionary) { writer.WritePropertyName(item.Key); - writer.WriteStringValue(item.Value.ToString()); + if (item.Value == null) + { + writer.WriteNullValue(); + continue; + } + writer.WriteStringValue(item.Value.Value.ToString()); } writer.WriteEndObject(); writer.WritePropertyName("requiredModel"u8); @@ -101,8 +111,15 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } if (Optional.IsDefined(StringFixedEnum)) { - writer.WritePropertyName("stringFixedEnum"u8); - writer.WriteStringValue(StringFixedEnum.Value.ToSerialString()); + if (StringFixedEnum != null) + { + writer.WritePropertyName("stringFixedEnum"u8); + writer.WriteStringValue(StringFixedEnum.Value.ToSerialString()); + } + else + { + writer.WriteNull("stringFixedEnum"); + } } writer.WritePropertyName("requiredUnknown"u8); #if NET6_0_OR_GREATER @@ -156,6 +173,8 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } writer.WriteEndObject(); } + writer.WritePropertyName("modelWithRequiredNullable"u8); + writer.WriteObjectValue(ModelWithRequiredNullable); writer.WriteEndObject(); } @@ -167,8 +186,8 @@ internal static RoundTripModel DeserializeRoundTripModel(JsonElement element) } string requiredString = default; int requiredInt = default; - IList requiredCollection = default; - IDictionary requiredDictionary = default; + IList requiredCollection = default; + IDictionary requiredDictionary = default; Thing requiredModel = default; Optional intExtensibleEnum = default; Optional> intExtensibleEnumCollection = default; @@ -178,13 +197,14 @@ internal static RoundTripModel DeserializeRoundTripModel(JsonElement element) Optional> floatFixedEnumCollection = default; Optional intFixedEnum = default; Optional> intFixedEnumCollection = default; - Optional stringFixedEnum = default; + Optional stringFixedEnum = default; BinaryData requiredUnknown = default; Optional optionalUnknown = default; IDictionary requiredRecordUnknown = default; Optional> optionalRecordUnknown = default; IReadOnlyDictionary readOnlyRequiredRecordUnknown = default; Optional> readOnlyOptionalRecordUnknown = default; + ModelWithRequiredNullableProperties modelWithRequiredNullable = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("requiredString"u8)) @@ -199,20 +219,34 @@ internal static RoundTripModel DeserializeRoundTripModel(JsonElement element) } if (property.NameEquals("requiredCollection"u8)) { - List array = new List(); + List array = new List(); foreach (var item in property.Value.EnumerateArray()) { - array.Add(item.GetString().ToStringFixedEnum()); + if (item.ValueKind == JsonValueKind.Null) + { + array.Add(null); + } + else + { + array.Add(item.GetString().ToStringFixedEnum()); + } } requiredCollection = array; continue; } if (property.NameEquals("requiredDictionary"u8)) { - Dictionary dictionary = new Dictionary(); + Dictionary dictionary = new Dictionary(); foreach (var property0 in property.Value.EnumerateObject()) { - dictionary.Add(property0.Name, new StringExtensibleEnum(property0.Value.GetString())); + if (property0.Value.ValueKind == JsonValueKind.Null) + { + dictionary.Add(property0.Name, null); + } + else + { + dictionary.Add(property0.Name, new StringExtensibleEnum(property0.Value.GetString())); + } } requiredDictionary = dictionary; continue; @@ -318,6 +352,7 @@ internal static RoundTripModel DeserializeRoundTripModel(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { + stringFixedEnum = null; continue; } stringFixedEnum = property.Value.GetString().ToStringFixedEnum(); @@ -413,8 +448,13 @@ internal static RoundTripModel DeserializeRoundTripModel(JsonElement element) readOnlyOptionalRecordUnknown = dictionary; continue; } + if (property.NameEquals("modelWithRequiredNullable"u8)) + { + modelWithRequiredNullable = ModelWithRequiredNullableProperties.DeserializeModelWithRequiredNullableProperties(property.Value); + continue; + } } - return new RoundTripModel(requiredString, requiredInt, requiredCollection, requiredDictionary, requiredModel, Optional.ToNullable(intExtensibleEnum), Optional.ToList(intExtensibleEnumCollection), Optional.ToNullable(floatExtensibleEnum), Optional.ToList(floatExtensibleEnumCollection), Optional.ToNullable(floatFixedEnum), Optional.ToList(floatFixedEnumCollection), Optional.ToNullable(intFixedEnum), Optional.ToList(intFixedEnumCollection), Optional.ToNullable(stringFixedEnum), requiredUnknown, optionalUnknown.Value, requiredRecordUnknown, Optional.ToDictionary(optionalRecordUnknown), readOnlyRequiredRecordUnknown, Optional.ToDictionary(readOnlyOptionalRecordUnknown)); + return new RoundTripModel(requiredString, requiredInt, requiredCollection, requiredDictionary, requiredModel, Optional.ToNullable(intExtensibleEnum), Optional.ToList(intExtensibleEnumCollection), Optional.ToNullable(floatExtensibleEnum), Optional.ToList(floatExtensibleEnumCollection), Optional.ToNullable(floatFixedEnum), Optional.ToList(floatFixedEnumCollection), Optional.ToNullable(intFixedEnum), Optional.ToList(intFixedEnumCollection), Optional.ToNullable(stringFixedEnum), requiredUnknown, optionalUnknown.Value, requiredRecordUnknown, Optional.ToDictionary(optionalRecordUnknown), readOnlyRequiredRecordUnknown, Optional.ToDictionary(readOnlyOptionalRecordUnknown), modelWithRequiredNullable); } /// Deserializes the model from a raw response. diff --git a/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/RoundTripModel.cs b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/RoundTripModel.cs index 93587978b63..adb3ee32c16 100644 --- a/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/RoundTripModel.cs +++ b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/RoundTripModel.cs @@ -23,8 +23,9 @@ public partial class RoundTripModel /// Required model. /// required unknown. /// required record of unknown. - /// , , , , or is null. - public RoundTripModel(string requiredString, int requiredInt, IEnumerable requiredCollection, IDictionary requiredDictionary, Thing requiredModel, BinaryData requiredUnknown, IDictionary requiredRecordUnknown) + /// this is a model with required nullable properties. + /// , , , , , or is null. + public RoundTripModel(string requiredString, int requiredInt, IEnumerable requiredCollection, IDictionary requiredDictionary, Thing requiredModel, BinaryData requiredUnknown, IDictionary requiredRecordUnknown, ModelWithRequiredNullableProperties modelWithRequiredNullable) { Argument.AssertNotNull(requiredString, nameof(requiredString)); Argument.AssertNotNull(requiredCollection, nameof(requiredCollection)); @@ -32,6 +33,7 @@ public RoundTripModel(string requiredString, int requiredInt, IEnumerable(); ReadOnlyRequiredRecordUnknown = new ChangeTrackingDictionary(); ReadOnlyOptionalRecordUnknown = new ChangeTrackingDictionary(); + ModelWithRequiredNullable = modelWithRequiredNullable; } /// Initializes a new instance of RoundTripModel. @@ -70,7 +73,8 @@ public RoundTripModel(string requiredString, int requiredInt, IEnumerable optional record of unknown. /// required readonly record of unknown. /// optional readonly record of unknown. - internal RoundTripModel(string requiredString, int requiredInt, IList requiredCollection, IDictionary requiredDictionary, Thing requiredModel, IntExtensibleEnum? intExtensibleEnum, IList intExtensibleEnumCollection, FloatExtensibleEnum? floatExtensibleEnum, IList floatExtensibleEnumCollection, FloatFixedEnum? floatFixedEnum, IList floatFixedEnumCollection, IntFixedEnum? intFixedEnum, IList intFixedEnumCollection, StringFixedEnum? stringFixedEnum, BinaryData requiredUnknown, BinaryData optionalUnknown, IDictionary requiredRecordUnknown, IDictionary optionalRecordUnknown, IReadOnlyDictionary readOnlyRequiredRecordUnknown, IReadOnlyDictionary readOnlyOptionalRecordUnknown) + /// this is a model with required nullable properties. + internal RoundTripModel(string requiredString, int requiredInt, IList requiredCollection, IDictionary requiredDictionary, Thing requiredModel, IntExtensibleEnum? intExtensibleEnum, IList intExtensibleEnumCollection, FloatExtensibleEnum? floatExtensibleEnum, IList floatExtensibleEnumCollection, FloatFixedEnum? floatFixedEnum, IList floatFixedEnumCollection, IntFixedEnum? intFixedEnum, IList intFixedEnumCollection, StringFixedEnum? stringFixedEnum, BinaryData requiredUnknown, BinaryData optionalUnknown, IDictionary requiredRecordUnknown, IDictionary optionalRecordUnknown, IReadOnlyDictionary readOnlyRequiredRecordUnknown, IReadOnlyDictionary readOnlyOptionalRecordUnknown, ModelWithRequiredNullableProperties modelWithRequiredNullable) { RequiredString = requiredString; RequiredInt = requiredInt; @@ -92,6 +96,7 @@ internal RoundTripModel(string requiredString, int requiredInt, IList Required string, illustrating a reference type property. @@ -99,9 +104,9 @@ internal RoundTripModel(string requiredString, int requiredInt, IList Required int, illustrating a value type property. public int RequiredInt { get; set; } /// Required collection of enums. - public IList RequiredCollection { get; } + public IList RequiredCollection { get; } /// Required dictionary of enums. - public IDictionary RequiredDictionary { get; } + public IDictionary RequiredDictionary { get; } /// Required model. public Thing RequiredModel { get; set; } /// this is an int based extensible enum. @@ -308,5 +313,7 @@ internal RoundTripModel(string requiredString, int requiredInt, IList /// public IReadOnlyDictionary ReadOnlyOptionalRecordUnknown { get; } + /// this is a model with required nullable properties. + public ModelWithRequiredNullableProperties ModelWithRequiredNullable { get; set; } } } diff --git a/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/Thing.Serialization.cs b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/Thing.Serialization.cs index 9de70932658..b146980684f 100644 --- a/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/Thing.Serialization.cs +++ b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/Thing.Serialization.cs @@ -5,6 +5,7 @@ #nullable disable +using System.Collections.Generic; using System.Text.Json; using Azure; using Azure.Core; @@ -50,6 +51,37 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } writer.WritePropertyName("requiredBadDescription"u8); writer.WriteStringValue(RequiredBadDescription); + if (Optional.IsCollectionDefined(OptionalNullableList)) + { + if (OptionalNullableList != null) + { + writer.WritePropertyName("optionalNullableList"u8); + writer.WriteStartArray(); + foreach (var item in OptionalNullableList) + { + writer.WriteNumberValue(item); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("optionalNullableList"); + } + } + if (RequiredNullableList != null && Optional.IsCollectionDefined(RequiredNullableList)) + { + writer.WritePropertyName("requiredNullableList"u8); + writer.WriteStartArray(); + foreach (var item in RequiredNullableList) + { + writer.WriteNumberValue(item); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("requiredNullableList"); + } writer.WriteEndObject(); } @@ -70,6 +102,8 @@ internal static Thing DeserializeThing(JsonElement element) Optional optionalLiteralFloat = default; Optional optionalLiteralBool = default; string requiredBadDescription = default; + Optional> optionalNullableList = default; + IList requiredNullableList = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("name"u8)) @@ -143,8 +177,38 @@ internal static Thing DeserializeThing(JsonElement element) requiredBadDescription = property.Value.GetString(); continue; } + if (property.NameEquals("optionalNullableList"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + optionalNullableList = null; + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetInt32()); + } + optionalNullableList = array; + continue; + } + if (property.NameEquals("requiredNullableList"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + requiredNullableList = null; + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetInt32()); + } + requiredNullableList = array; + continue; + } } - return new Thing(name, requiredUnion, requiredLiteralString, requiredLiteralInt, requiredLiteralFloat, requiredLiteralBool, Optional.ToNullable(optionalLiteralString), Optional.ToNullable(optionalLiteralInt), Optional.ToNullable(optionalLiteralFloat), Optional.ToNullable(optionalLiteralBool), requiredBadDescription); + return new Thing(name, requiredUnion, requiredLiteralString, requiredLiteralInt, requiredLiteralFloat, requiredLiteralBool, Optional.ToNullable(optionalLiteralString), Optional.ToNullable(optionalLiteralInt), Optional.ToNullable(optionalLiteralFloat), Optional.ToNullable(optionalLiteralBool), requiredBadDescription, Optional.ToList(optionalNullableList), requiredNullableList); } /// Deserializes the model from a raw response. diff --git a/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/Thing.cs b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/Thing.cs index b4b233581fd..31b7b5f392c 100644 --- a/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/Thing.cs +++ b/test/TestProjects/FirstTest-TypeSpec/src/Generated/Models/Thing.cs @@ -6,6 +6,8 @@ #nullable disable using System; +using System.Collections.Generic; +using System.Linq; using Azure.Core; namespace FirstTestTypeSpec.Models @@ -17,8 +19,9 @@ public partial class Thing /// name of the Thing. /// required Union. /// description with xml <|endoftext|>. + /// required nullable collection. /// , or is null. - public Thing(string name, string requiredUnion, string requiredBadDescription) + public Thing(string name, string requiredUnion, string requiredBadDescription, IEnumerable requiredNullableList) { Argument.AssertNotNull(name, nameof(name)); Argument.AssertNotNull(requiredUnion, nameof(requiredUnion)); @@ -27,6 +30,8 @@ public Thing(string name, string requiredUnion, string requiredBadDescription) Name = name; RequiredUnion = requiredUnion; RequiredBadDescription = requiredBadDescription; + OptionalNullableList = new ChangeTrackingList(); + RequiredNullableList = requiredNullableList?.ToList(); } /// Initializes a new instance of Thing. @@ -41,7 +46,9 @@ public Thing(string name, string requiredUnion, string requiredBadDescription) /// optional literal float. /// optional literal bool. /// description with xml <|endoftext|>. - internal Thing(string name, string requiredUnion, ThingRequiredLiteralString requiredLiteralString, ThingRequiredLiteralInt requiredLiteralInt, ThingRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, ThingOptionalLiteralString? optionalLiteralString, ThingOptionalLiteralInt? optionalLiteralInt, ThingOptionalLiteralFloat? optionalLiteralFloat, bool? optionalLiteralBool, string requiredBadDescription) + /// optional nullable collection. + /// required nullable collection. + internal Thing(string name, string requiredUnion, ThingRequiredLiteralString requiredLiteralString, ThingRequiredLiteralInt requiredLiteralInt, ThingRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, ThingOptionalLiteralString? optionalLiteralString, ThingOptionalLiteralInt? optionalLiteralInt, ThingOptionalLiteralFloat? optionalLiteralFloat, bool? optionalLiteralBool, string requiredBadDescription, IList optionalNullableList, IList requiredNullableList) { Name = name; RequiredUnion = requiredUnion; @@ -54,6 +61,8 @@ internal Thing(string name, string requiredUnion, ThingRequiredLiteralString req OptionalLiteralFloat = optionalLiteralFloat; OptionalLiteralBool = optionalLiteralBool; RequiredBadDescription = requiredBadDescription; + OptionalNullableList = optionalNullableList; + RequiredNullableList = requiredNullableList; } /// name of the Thing. @@ -82,5 +91,9 @@ internal Thing(string name, string requiredUnion, ThingRequiredLiteralString req public bool? OptionalLiteralBool { get; set; } /// description with xml <|endoftext|>. public string RequiredBadDescription { get; set; } + /// optional nullable collection. + public IList OptionalNullableList { get; set; } + /// required nullable collection. + public IList RequiredNullableList { get; set; } } } diff --git a/test/TestProjects/FirstTest-TypeSpec/src/Generated/tspCodeModel.json b/test/TestProjects/FirstTest-TypeSpec/src/Generated/tspCodeModel.json index 8c783685e85..e9fc98d7c96 100644 --- a/test/TestProjects/FirstTest-TypeSpec/src/Generated/tspCodeModel.json +++ b/test/TestProjects/FirstTest-TypeSpec/src/Generated/tspCodeModel.json @@ -138,7 +138,7 @@ } ], "IsExtensible": false, - "IsNullable": false, + "IsNullable": true, "Usage": "RoundTrip" }, { @@ -165,7 +165,7 @@ } ], "IsExtensible": true, - "IsNullable": false, + "IsNullable": true, "Usage": "RoundTrip" }, { @@ -540,11 +540,49 @@ }, "IsRequired": true, "IsReadOnly": false + }, + { + "$id": "75", + "Name": "optionalNullableList", + "SerializedName": "optionalNullableList", + "Description": "optional nullable collection", + "Type": { + "$id": "76", + "Name": "Array", + "ElementType": { + "$id": "77", + "Name": "int32", + "Kind": "Int32", + "IsNullable": false + }, + "IsNullable": true + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "78", + "Name": "requiredNullableList", + "SerializedName": "requiredNullableList", + "Description": "required nullable collection", + "Type": { + "$id": "79", + "Name": "Array", + "ElementType": { + "$id": "80", + "Name": "int32", + "Kind": "Int32", + "IsNullable": false + }, + "IsNullable": true + }, + "IsRequired": true, + "IsReadOnly": false } ] }, { - "$id": "75", + "$id": "81", "Name": "Friend", "Namespace": "FirstTestTypeSpec", "Description": "this is not a friendly model but with a friendly name", @@ -552,12 +590,12 @@ "Usage": "RoundTrip", "Properties": [ { - "$id": "76", + "$id": "82", "Name": "name", "SerializedName": "name", "Description": "name of the NotFriend", "Type": { - "$id": "77", + "$id": "83", "Name": "string", "Kind": "String", "IsNullable": false @@ -568,19 +606,19 @@ ] }, { - "$id": "78", + "$id": "84", "Name": "ModelWithFormat", "Namespace": "FirstTestTypeSpec", "IsNullable": false, "Usage": "Input", "Properties": [ { - "$id": "79", + "$id": "85", "Name": "sourceUrl", "SerializedName": "sourceUrl", "Description": "url format", "Type": { - "$id": "80", + "$id": "86", "Name": "string", "Kind": "Uri", "IsNullable": false @@ -589,12 +627,12 @@ "IsReadOnly": false }, { - "$id": "81", + "$id": "87", "Name": "guid", "SerializedName": "guid", "Description": "uuid format", "Type": { - "$id": "82", + "$id": "88", "Name": "string", "Kind": "Guid", "IsNullable": false @@ -605,7 +643,7 @@ ] }, { - "$id": "83", + "$id": "89", "Name": "RoundTripModel", "Namespace": "FirstTestTypeSpec", "Description": "this is a roundtrip model", @@ -613,12 +651,12 @@ "Usage": "RoundTrip", "Properties": [ { - "$id": "84", + "$id": "90", "Name": "requiredString", "SerializedName": "requiredString", "Description": "Required string, illustrating a reference type property.", "Type": { - "$id": "85", + "$id": "91", "Name": "string", "Kind": "String", "IsNullable": false @@ -627,12 +665,12 @@ "IsReadOnly": false }, { - "$id": "86", + "$id": "92", "Name": "requiredInt", "SerializedName": "requiredInt", "Description": "Required int, illustrating a value type property.", "Type": { - "$id": "87", + "$id": "93", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -641,12 +679,12 @@ "IsReadOnly": false }, { - "$id": "88", + "$id": "94", "Name": "requiredCollection", "SerializedName": "requiredCollection", "Description": "Required collection of enums", "Type": { - "$id": "89", + "$id": "95", "Name": "Array", "ElementType": { "$ref": "14" @@ -657,15 +695,15 @@ "IsReadOnly": false }, { - "$id": "90", + "$id": "96", "Name": "requiredDictionary", "SerializedName": "requiredDictionary", "Description": "Required dictionary of enums", "Type": { - "$id": "91", + "$id": "97", "Name": "Dictionary", "KeyType": { - "$id": "92", + "$id": "98", "Name": "string", "Kind": "String", "IsNullable": false @@ -679,7 +717,7 @@ "IsReadOnly": false }, { - "$id": "93", + "$id": "99", "Name": "requiredModel", "SerializedName": "requiredModel", "Description": "Required model", @@ -690,7 +728,7 @@ "IsReadOnly": false }, { - "$id": "94", + "$id": "100", "Name": "intExtensibleEnum", "SerializedName": "intExtensibleEnum", "Description": "this is an int based extensible enum", @@ -701,12 +739,12 @@ "IsReadOnly": false }, { - "$id": "95", + "$id": "101", "Name": "intExtensibleEnumCollection", "SerializedName": "intExtensibleEnumCollection", "Description": "this is a collection of int based extensible enum", "Type": { - "$id": "96", + "$id": "102", "Name": "Array", "ElementType": { "$ref": "22" @@ -717,7 +755,7 @@ "IsReadOnly": false }, { - "$id": "97", + "$id": "103", "Name": "floatExtensibleEnum", "SerializedName": "floatExtensibleEnum", "Description": "this is a float based extensible enum", @@ -728,12 +766,12 @@ "IsReadOnly": false }, { - "$id": "98", + "$id": "104", "Name": "floatExtensibleEnumCollection", "SerializedName": "floatExtensibleEnumCollection", "Description": "this is a collection of float based extensible enum", "Type": { - "$id": "99", + "$id": "105", "Name": "Array", "ElementType": { "$ref": "26" @@ -744,7 +782,7 @@ "IsReadOnly": false }, { - "$id": "100", + "$id": "106", "Name": "floatFixedEnum", "SerializedName": "floatFixedEnum", "Description": "this is a float based fixed enum", @@ -755,12 +793,12 @@ "IsReadOnly": false }, { - "$id": "101", + "$id": "107", "Name": "floatFixedEnumCollection", "SerializedName": "floatFixedEnumCollection", "Description": "this is a collection of float based fixed enum", "Type": { - "$id": "102", + "$id": "108", "Name": "Array", "ElementType": { "$ref": "30" @@ -771,7 +809,7 @@ "IsReadOnly": false }, { - "$id": "103", + "$id": "109", "Name": "intFixedEnum", "SerializedName": "intFixedEnum", "Description": "this is a int based fixed enum", @@ -782,12 +820,12 @@ "IsReadOnly": false }, { - "$id": "104", + "$id": "110", "Name": "intFixedEnumCollection", "SerializedName": "intFixedEnumCollection", "Description": "this is a collection of int based fixed enum", "Type": { - "$id": "105", + "$id": "111", "Name": "Array", "ElementType": { "$ref": "34" @@ -798,7 +836,7 @@ "IsReadOnly": false }, { - "$id": "106", + "$id": "112", "Name": "stringFixedEnum", "SerializedName": "stringFixedEnum", "Description": "this is a string based fixed enum", @@ -809,12 +847,12 @@ "IsReadOnly": false }, { - "$id": "107", + "$id": "113", "Name": "requiredUnknown", "SerializedName": "requiredUnknown", "Description": "required unknown", "Type": { - "$id": "108", + "$id": "114", "Name": "Intrinsic", "Kind": "unknown", "IsNullable": false @@ -823,12 +861,12 @@ "IsReadOnly": false }, { - "$id": "109", + "$id": "115", "Name": "optionalUnknown", "SerializedName": "optionalUnknown", "Description": "optional unknown", "Type": { - "$id": "110", + "$id": "116", "Name": "Intrinsic", "Kind": "unknown", "IsNullable": false @@ -837,21 +875,21 @@ "IsReadOnly": false }, { - "$id": "111", + "$id": "117", "Name": "requiredRecordUnknown", "SerializedName": "requiredRecordUnknown", "Description": "required record of unknown", "Type": { - "$id": "112", + "$id": "118", "Name": "Dictionary", "KeyType": { - "$id": "113", + "$id": "119", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$id": "114", + "$id": "120", "Name": "Intrinsic", "Kind": "unknown", "IsNullable": false @@ -862,21 +900,21 @@ "IsReadOnly": false }, { - "$id": "115", + "$id": "121", "Name": "optionalRecordUnknown", "SerializedName": "optionalRecordUnknown", "Description": "optional record of unknown", "Type": { - "$id": "116", + "$id": "122", "Name": "Dictionary", "KeyType": { - "$id": "117", + "$id": "123", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$id": "118", + "$id": "124", "Name": "Intrinsic", "Kind": "unknown", "IsNullable": false @@ -887,21 +925,21 @@ "IsReadOnly": false }, { - "$id": "119", + "$id": "125", "Name": "readOnlyRequiredRecordUnknown", "SerializedName": "readOnlyRequiredRecordUnknown", "Description": "required readonly record of unknown", "Type": { - "$id": "120", + "$id": "126", "Name": "Dictionary", "KeyType": { - "$id": "121", + "$id": "127", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$id": "122", + "$id": "128", "Name": "Intrinsic", "Kind": "unknown", "IsNullable": false @@ -912,21 +950,21 @@ "IsReadOnly": true }, { - "$id": "123", + "$id": "129", "Name": "readOnlyOptionalRecordUnknown", "SerializedName": "readOnlyOptionalRecordUnknown", "Description": "optional readonly record of unknown", "Type": { - "$id": "124", + "$id": "130", "Name": "Dictionary", "KeyType": { - "$id": "125", + "$id": "131", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$id": "126", + "$id": "132", "Name": "Intrinsic", "Kind": "unknown", "IsNullable": false @@ -935,28 +973,85 @@ }, "IsRequired": false, "IsReadOnly": true + }, + { + "$id": "133", + "Name": "modelWithRequiredNullable", + "SerializedName": "modelWithRequiredNullable", + "Description": "this is a model with required nullable properties", + "Type": { + "$id": "134", + "Name": "ModelWithRequiredNullableProperties", + "Namespace": "FirstTestTypeSpec", + "Description": "A model with a few required nullable properties", + "IsNullable": false, + "Usage": "RoundTrip", + "Properties": [ + { + "$id": "135", + "Name": "requiredNullablePrimitive", + "SerializedName": "requiredNullablePrimitive", + "Description": "required nullable primitive type", + "Type": { + "$id": "136", + "Name": "int32", + "Kind": "Int32", + "IsNullable": true + }, + "IsRequired": true, + "IsReadOnly": false + }, + { + "$id": "137", + "Name": "requiredExtensibleEnum", + "SerializedName": "requiredExtensibleEnum", + "Description": "required nullable extensible enum type", + "Type": { + "$ref": "18" + }, + "IsRequired": true, + "IsReadOnly": false + }, + { + "$id": "138", + "Name": "requiredFixedEnum", + "SerializedName": "requiredFixedEnum", + "Description": "required nullable fixed enum type", + "Type": { + "$ref": "14" + }, + "IsRequired": true, + "IsReadOnly": false + } + ] + }, + "IsRequired": true, + "IsReadOnly": false } ] + }, + { + "$ref": "134" } ], "Clients": [ { - "$id": "127", + "$id": "139", "Name": "FirstTestTypeSpecClient", "Description": "This is a sample typespec project.", "Operations": [ { - "$id": "128", + "$id": "140", "Name": "topAction", "ResourceName": "FirstTestTypeSpec", "Description": "top level method", "Parameters": [ { - "$id": "129", + "$id": "141", "Name": "firstTestTypeSpecUrl", "NameInRequest": "firstTestTypeSpecUrl", "Type": { - "$id": "130", + "$id": "142", "Name": "Uri", "Kind": "Uri", "IsNullable": false @@ -972,11 +1067,11 @@ "Kind": "Client" }, { - "$id": "131", + "$id": "143", "Name": "action", "NameInRequest": "action", "Type": { - "$id": "132", + "$id": "144", "Name": "string", "Kind": "DateTime", "IsNullable": false @@ -992,11 +1087,11 @@ "Kind": "Method" }, { - "$id": "133", + "$id": "145", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "134", + "$id": "146", "Name": "String", "Kind": "String", "IsNullable": false @@ -1011,20 +1106,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "135", + "$id": "147", "Type": { - "$ref": "134" + "$ref": "146" }, "Value": "application/json" } }, { - "$id": "136", + "$id": "148", "Name": "apiVersion", "NameInRequest": "api-version", "Description": "", "Type": { - "$id": "137", + "$id": "149", "Name": "String", "Kind": "String", "IsNullable": false @@ -1039,9 +1134,9 @@ "Explode": false, "Kind": "Client", "DefaultValue": { - "$id": "138", + "$id": "150", "Type": { - "$id": "139", + "$id": "151", "Name": "String", "Kind": "String", "IsNullable": false @@ -1052,7 +1147,7 @@ ], "Responses": [ { - "$id": "140", + "$id": "152", "StatusCodes": [ 200 ], @@ -1073,20 +1168,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "141", + "$id": "153", "Name": "topAction2", "ResourceName": "FirstTestTypeSpec", "Description": "top level method2", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "142", + "$id": "154", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "143", + "$id": "155", "Name": "String", "Kind": "String", "IsNullable": false @@ -1101,20 +1196,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "144", + "$id": "156", "Type": { - "$ref": "143" + "$ref": "155" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "145", + "$id": "157", "StatusCodes": [ 200 ], @@ -1135,16 +1230,16 @@ "GenerateConvenienceMethod": false }, { - "$id": "146", + "$id": "158", "Name": "patchAction", "ResourceName": "FirstTestTypeSpec", "Description": "top level patch", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "147", + "$id": "159", "Name": "body", "NameInRequest": "body", "Type": { @@ -1161,11 +1256,11 @@ "Kind": "Method" }, { - "$id": "148", + "$id": "160", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "149", + "$id": "161", "Name": "String", "Kind": "String", "IsNullable": false @@ -1180,19 +1275,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "150", + "$id": "162", "Type": { - "$ref": "149" + "$ref": "161" }, "Value": "application/json" } }, { - "$id": "151", + "$id": "163", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "152", + "$id": "164", "Name": "String", "Kind": "String", "IsNullable": false @@ -1207,20 +1302,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "153", + "$id": "165", "Type": { - "$ref": "152" + "$ref": "164" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "154", + "$id": "166", "StatusCodes": [ 200 ], @@ -1244,16 +1339,16 @@ "GenerateConvenienceMethod": false }, { - "$id": "155", + "$id": "167", "Name": "anonymousBody", "ResourceName": "FirstTestTypeSpec", "Description": "body parameter without body decorator", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "156", + "$id": "168", "Name": "Thing", "NameInRequest": "Thing", "Description": "A model with a few properties of literal types", @@ -1271,11 +1366,11 @@ "Kind": "Method" }, { - "$id": "157", + "$id": "169", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "158", + "$id": "170", "Name": "String", "Kind": "String", "IsNullable": false @@ -1290,19 +1385,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "159", + "$id": "171", "Type": { - "$ref": "158" + "$ref": "170" }, "Value": "application/json" } }, { - "$id": "160", + "$id": "172", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "161", + "$id": "173", "Name": "String", "Kind": "String", "IsNullable": false @@ -1317,20 +1412,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "162", + "$id": "174", "Type": { - "$ref": "161" + "$ref": "173" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "163", + "$id": "175", "StatusCodes": [ 200 ], @@ -1354,21 +1449,21 @@ "GenerateConvenienceMethod": true }, { - "$id": "164", + "$id": "176", "Name": "friendlyModel", "ResourceName": "FirstTestTypeSpec", "Description": "Model can have its friendly name", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "165", + "$id": "177", "Name": "NotFriend", "NameInRequest": "NotFriend", "Description": "this is not a friendly model but with a friendly name", "Type": { - "$ref": "75" + "$ref": "81" }, "Location": "Body", "IsRequired": true, @@ -1381,11 +1476,11 @@ "Kind": "Method" }, { - "$id": "166", + "$id": "178", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "167", + "$id": "179", "Name": "String", "Kind": "String", "IsNullable": false @@ -1400,19 +1495,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "168", + "$id": "180", "Type": { - "$ref": "167" + "$ref": "179" }, "Value": "application/json" } }, { - "$id": "169", + "$id": "181", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "170", + "$id": "182", "Name": "String", "Kind": "String", "IsNullable": false @@ -1427,25 +1522,25 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "171", + "$id": "183", "Type": { - "$ref": "170" + "$ref": "182" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "172", + "$id": "184", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "75" + "$ref": "81" }, "BodyMediaType": "Json", "Headers": [], @@ -1464,19 +1559,19 @@ "GenerateConvenienceMethod": true }, { - "$id": "173", + "$id": "185", "Name": "addTimeHeader", "ResourceName": "FirstTestTypeSpec", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "174", + "$id": "186", "Name": "repeatabilityFirstSent", "NameInRequest": "Repeatability-First-Sent", "Type": { - "$id": "175", + "$id": "187", "Name": "utcDateTime", "Kind": "DateTime", "IsNullable": false @@ -1492,11 +1587,11 @@ "Kind": "Method" }, { - "$id": "176", + "$id": "188", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "177", + "$id": "189", "Name": "String", "Kind": "String", "IsNullable": false @@ -1511,20 +1606,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "178", + "$id": "190", "Type": { - "$ref": "177" + "$ref": "189" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "179", + "$id": "191", "StatusCodes": [ 204 ], @@ -1542,20 +1637,20 @@ "GenerateConvenienceMethod": false }, { - "$id": "180", + "$id": "192", "Name": "stringFormat", "ResourceName": "FirstTestTypeSpec", "Description": "paramete has string format.", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "181", + "$id": "193", "Name": "subscriptionId", "NameInRequest": "subscriptionId", "Type": { - "$id": "182", + "$id": "194", "Name": "string", "Kind": "Guid", "IsNullable": false @@ -1571,11 +1666,11 @@ "Kind": "Method" }, { - "$id": "183", + "$id": "195", "Name": "body", "NameInRequest": "body", "Type": { - "$ref": "78" + "$ref": "84" }, "Location": "Body", "IsRequired": true, @@ -1588,11 +1683,11 @@ "Kind": "Method" }, { - "$id": "184", + "$id": "196", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "185", + "$id": "197", "Name": "String", "Kind": "String", "IsNullable": false @@ -1607,19 +1702,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "186", + "$id": "198", "Type": { - "$ref": "185" + "$ref": "197" }, "Value": "application/json" } }, { - "$id": "187", + "$id": "199", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "188", + "$id": "200", "Name": "String", "Kind": "String", "IsNullable": false @@ -1634,20 +1729,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "189", + "$id": "201", "Type": { - "$ref": "188" + "$ref": "200" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "190", + "$id": "202", "StatusCodes": [ 204 ], @@ -1668,20 +1763,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "191", + "$id": "203", "Name": "sayHi", "ResourceName": "Demo", "Description": "Return hi", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "192", + "$id": "204", "Name": "headParameter", "NameInRequest": "head-parameter", "Type": { - "$id": "193", + "$id": "205", "Name": "string", "Kind": "String", "IsNullable": false @@ -1697,11 +1792,11 @@ "Kind": "Method" }, { - "$id": "194", + "$id": "206", "Name": "queryParameter", "NameInRequest": "queryParameter", "Type": { - "$id": "195", + "$id": "207", "Name": "string", "Kind": "String", "IsNullable": false @@ -1717,11 +1812,11 @@ "Kind": "Method" }, { - "$id": "196", + "$id": "208", "Name": "optionalQuery", "NameInRequest": "optionalQuery", "Type": { - "$id": "197", + "$id": "209", "Name": "string", "Kind": "String", "IsNullable": false @@ -1737,11 +1832,11 @@ "Kind": "Method" }, { - "$id": "198", + "$id": "210", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "199", + "$id": "211", "Name": "String", "Kind": "String", "IsNullable": false @@ -1756,20 +1851,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "200", + "$id": "212", "Type": { - "$ref": "199" + "$ref": "211" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "201", + "$id": "213", "StatusCodes": [ 200 ], @@ -1790,20 +1885,20 @@ "GenerateConvenienceMethod": false }, { - "$id": "202", + "$id": "214", "Name": "helloAgain", "ResourceName": "Demo2", "Description": "Return hi again", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "203", + "$id": "215", "Name": "p1", "NameInRequest": "p1", "Type": { - "$id": "204", + "$id": "216", "Name": "string", "Kind": "String", "IsNullable": false @@ -1819,14 +1914,14 @@ "Kind": "Method" }, { - "$id": "205", + "$id": "217", "Name": "contentType", "NameInRequest": "content-type", "Type": { - "$id": "206", + "$id": "218", "Name": "Literal", "LiteralValueType": { - "$id": "207", + "$id": "219", "Name": "String", "Kind": "String", "IsNullable": false @@ -1836,9 +1931,9 @@ }, "Location": "Header", "DefaultValue": { - "$id": "208", + "$id": "220", "Type": { - "$ref": "206" + "$ref": "218" }, "Value": "text/plain" }, @@ -1852,11 +1947,11 @@ "Kind": "Constant" }, { - "$id": "209", + "$id": "221", "Name": "p2", "NameInRequest": "p2", "Type": { - "$id": "210", + "$id": "222", "Name": "string", "Kind": "String", "IsNullable": false @@ -1872,11 +1967,11 @@ "Kind": "Method" }, { - "$id": "211", + "$id": "223", "Name": "action", "NameInRequest": "action", "Type": { - "$ref": "83" + "$ref": "89" }, "Location": "Body", "IsRequired": true, @@ -1889,11 +1984,11 @@ "Kind": "Method" }, { - "$id": "212", + "$id": "224", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "213", + "$id": "225", "Name": "String", "Kind": "String", "IsNullable": false @@ -1908,25 +2003,25 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "214", + "$id": "226", "Type": { - "$ref": "213" + "$ref": "225" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "215", + "$id": "227", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "83" + "$ref": "89" }, "BodyMediaType": "Json", "Headers": [], @@ -1945,20 +2040,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "216", + "$id": "228", "Name": "noContentType", "ResourceName": "Demo2", "Description": "Return hi again", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "217", + "$id": "229", "Name": "p1", "NameInRequest": "p1", "Type": { - "$id": "218", + "$id": "230", "Name": "string", "Kind": "String", "IsNullable": false @@ -1974,11 +2069,11 @@ "Kind": "Method" }, { - "$id": "219", + "$id": "231", "Name": "p2", "NameInRequest": "p2", "Type": { - "$id": "220", + "$id": "232", "Name": "string", "Kind": "String", "IsNullable": false @@ -1994,11 +2089,11 @@ "Kind": "Method" }, { - "$id": "221", + "$id": "233", "Name": "action", "NameInRequest": "action", "Type": { - "$ref": "83" + "$ref": "89" }, "Location": "Body", "IsRequired": true, @@ -2011,11 +2106,11 @@ "Kind": "Method" }, { - "$id": "222", + "$id": "234", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "223", + "$id": "235", "Name": "String", "Kind": "String", "IsNullable": false @@ -2030,19 +2125,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "224", + "$id": "236", "Type": { - "$ref": "223" + "$ref": "235" }, "Value": "application/json" } }, { - "$id": "225", + "$id": "237", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "226", + "$id": "238", "Name": "String", "Kind": "String", "IsNullable": false @@ -2057,25 +2152,25 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "227", + "$id": "239", "Type": { - "$ref": "226" + "$ref": "238" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "228", + "$id": "240", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "83" + "$ref": "89" }, "BodyMediaType": "Json", "Headers": [], @@ -2094,20 +2189,20 @@ "GenerateConvenienceMethod": false }, { - "$id": "229", + "$id": "241", "Name": "helloDemo2", "ResourceName": "Demo2", "Description": "Return hi in demo2", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "230", + "$id": "242", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "231", + "$id": "243", "Name": "String", "Kind": "String", "IsNullable": false @@ -2122,20 +2217,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "232", + "$id": "244", "Type": { - "$ref": "231" + "$ref": "243" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "233", + "$id": "245", "StatusCodes": [ 200 ], @@ -2156,16 +2251,16 @@ "GenerateConvenienceMethod": true }, { - "$id": "234", + "$id": "246", "Name": "createLiteral", "ResourceName": "Demo2", "Description": "Create with literal value", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "235", + "$id": "247", "Name": "body", "NameInRequest": "body", "Type": { @@ -2182,11 +2277,11 @@ "Kind": "Method" }, { - "$id": "236", + "$id": "248", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "237", + "$id": "249", "Name": "String", "Kind": "String", "IsNullable": false @@ -2201,19 +2296,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "238", + "$id": "250", "Type": { - "$ref": "237" + "$ref": "249" }, "Value": "application/json" } }, { - "$id": "239", + "$id": "251", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "240", + "$id": "252", "Name": "String", "Kind": "String", "IsNullable": false @@ -2228,20 +2323,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "241", + "$id": "253", "Type": { - "$ref": "240" + "$ref": "252" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "242", + "$id": "254", "StatusCodes": [ 200 ], @@ -2265,23 +2360,23 @@ "GenerateConvenienceMethod": true }, { - "$id": "243", + "$id": "255", "Name": "helloLiteral", "ResourceName": "Demo2", "Description": "Send literal parameters", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "244", + "$id": "256", "Name": "p1", "NameInRequest": "p1", "Type": { - "$id": "245", + "$id": "257", "Name": "Literal", "LiteralValueType": { - "$id": "246", + "$id": "258", "Name": "String", "Kind": "String", "IsNullable": false @@ -2291,9 +2386,9 @@ }, "Location": "Header", "DefaultValue": { - "$id": "247", + "$id": "259", "Type": { - "$ref": "245" + "$ref": "257" }, "Value": "test" }, @@ -2307,14 +2402,14 @@ "Kind": "Constant" }, { - "$id": "248", + "$id": "260", "Name": "p2", "NameInRequest": "p2", "Type": { - "$id": "249", + "$id": "261", "Name": "Literal", "LiteralValueType": { - "$id": "250", + "$id": "262", "Name": "Number", "Kind": "Int32", "IsNullable": false @@ -2324,9 +2419,9 @@ }, "Location": "Path", "DefaultValue": { - "$id": "251", + "$id": "263", "Type": { - "$ref": "249" + "$ref": "261" }, "Value": 123 }, @@ -2340,14 +2435,14 @@ "Kind": "Constant" }, { - "$id": "252", + "$id": "264", "Name": "p3", "NameInRequest": "p3", "Type": { - "$id": "253", + "$id": "265", "Name": "Literal", "LiteralValueType": { - "$id": "254", + "$id": "266", "Name": "Boolean", "Kind": "Boolean", "IsNullable": false @@ -2357,9 +2452,9 @@ }, "Location": "Query", "DefaultValue": { - "$id": "255", + "$id": "267", "Type": { - "$ref": "253" + "$ref": "265" }, "Value": true }, @@ -2373,11 +2468,11 @@ "Kind": "Constant" }, { - "$id": "256", + "$id": "268", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "257", + "$id": "269", "Name": "String", "Kind": "String", "IsNullable": false @@ -2392,20 +2487,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "258", + "$id": "270", "Type": { - "$ref": "257" + "$ref": "269" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "259", + "$id": "271", "StatusCodes": [ 200 ], @@ -2426,20 +2521,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "260", + "$id": "272", "Name": "getUnknownValue", "ResourceName": "EnumTest", "Description": "get extensible enum", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "261", + "$id": "273", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "262", + "$id": "274", "Name": "String", "Kind": "String", "IsNullable": false @@ -2454,20 +2549,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "263", + "$id": "275", "Type": { - "$ref": "262" + "$ref": "274" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "264", + "$id": "276", "StatusCodes": [ 200 ], @@ -2488,16 +2583,16 @@ "GenerateConvenienceMethod": false }, { - "$id": "265", + "$id": "277", "Name": "internalProtocol", "ResourceName": "ProtocolAndConvenient", "Description": "When set protocol false and convenient true, then the protocol method should be internal", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "266", + "$id": "278", "Name": "body", "NameInRequest": "body", "Type": { @@ -2514,11 +2609,11 @@ "Kind": "Method" }, { - "$id": "267", + "$id": "279", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "268", + "$id": "280", "Name": "String", "Kind": "String", "IsNullable": false @@ -2533,19 +2628,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "269", + "$id": "281", "Type": { - "$ref": "268" + "$ref": "280" }, "Value": "application/json" } }, { - "$id": "270", + "$id": "282", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "271", + "$id": "283", "Name": "String", "Kind": "String", "IsNullable": false @@ -2560,20 +2655,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "272", + "$id": "284", "Type": { - "$ref": "271" + "$ref": "283" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "273", + "$id": "285", "StatusCodes": [ 200 ], @@ -2597,20 +2692,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "274", + "$id": "286", "Name": "stillConvenient", "ResourceName": "ProtocolAndConvenient", "Description": "When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one", "Parameters": [ { - "$ref": "129" + "$ref": "141" }, { - "$id": "275", + "$id": "287", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "276", + "$id": "288", "Name": "String", "Kind": "String", "IsNullable": false @@ -2625,20 +2720,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "277", + "$id": "289", "Type": { - "$ref": "276" + "$ref": "288" }, "Value": "application/json" } }, { - "$ref": "136" + "$ref": "148" } ], "Responses": [ { - "$id": "278", + "$id": "290", "StatusCodes": [ 204 ], @@ -2657,19 +2752,19 @@ } ], "Protocol": { - "$id": "279" + "$id": "291" }, "Creatable": true } ], "Auth": { - "$id": "280", + "$id": "292", "ApiKey": { - "$id": "281", + "$id": "293", "Name": "x-ms-api-key" }, "OAuth2": { - "$id": "282", + "$id": "294", "Scopes": [ "https://api.example.com/.default" ] diff --git a/test/TestProjects/FirstTest-TypeSpec/tests/Generated/Samples/Samples_FirstTestTypeSpecClient.cs b/test/TestProjects/FirstTest-TypeSpec/tests/Generated/Samples/Samples_FirstTestTypeSpecClient.cs index 8df4fd75624..d41e3db9793 100644 --- a/test/TestProjects/FirstTest-TypeSpec/tests/Generated/Samples/Samples_FirstTestTypeSpecClient.cs +++ b/test/TestProjects/FirstTest-TypeSpec/tests/Generated/Samples/Samples_FirstTestTypeSpecClient.cs @@ -37,6 +37,7 @@ public void Example_TopAction() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -60,6 +61,8 @@ public void Example_TopAction_AllParameters() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -79,6 +82,7 @@ public async Task Example_TopAction_Async() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -102,6 +106,8 @@ public async Task Example_TopAction_AllParameters_Async() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -131,6 +137,7 @@ public void Example_TopAction2() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -154,6 +161,8 @@ public void Example_TopAction2_AllParameters() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -173,6 +182,7 @@ public async Task Example_TopAction2_Async() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -196,6 +206,8 @@ public async Task Example_TopAction2_AllParameters_Async() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -214,6 +226,9 @@ public void Example_PatchAction() requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }; Response response = client.PatchAction(RequestContent.Create(data)); @@ -226,6 +241,7 @@ public void Example_PatchAction() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -248,6 +264,12 @@ public void Example_PatchAction_AllParameters() optionalLiteralFloat = 4.56, optionalLiteralBool = true, requiredBadDescription = "", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }; Response response = client.PatchAction(RequestContent.Create(data)); @@ -264,6 +286,8 @@ public void Example_PatchAction_AllParameters() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -282,6 +306,9 @@ public async Task Example_PatchAction_Async() requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }; Response response = await client.PatchActionAsync(RequestContent.Create(data)); @@ -294,6 +321,7 @@ public async Task Example_PatchAction_Async() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -316,6 +344,12 @@ public async Task Example_PatchAction_AllParameters_Async() optionalLiteralFloat = 4.56, optionalLiteralBool = true, requiredBadDescription = "", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }; Response response = await client.PatchActionAsync(RequestContent.Create(data)); @@ -332,6 +366,8 @@ public async Task Example_PatchAction_AllParameters_Async() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -350,6 +386,9 @@ public void Example_AnonymousBody() requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }; Response response = client.AnonymousBody(RequestContent.Create(data)); @@ -362,6 +401,7 @@ public void Example_AnonymousBody() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -384,6 +424,12 @@ public void Example_AnonymousBody_AllParameters() optionalLiteralFloat = 4.56, optionalLiteralBool = true, requiredBadDescription = "", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }; Response response = client.AnonymousBody(RequestContent.Create(data)); @@ -400,6 +446,8 @@ public void Example_AnonymousBody_AllParameters() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -418,6 +466,9 @@ public async Task Example_AnonymousBody_Async() requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }; Response response = await client.AnonymousBodyAsync(RequestContent.Create(data)); @@ -430,6 +481,7 @@ public async Task Example_AnonymousBody_Async() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -452,6 +504,12 @@ public async Task Example_AnonymousBody_AllParameters_Async() optionalLiteralFloat = 4.56, optionalLiteralBool = true, requiredBadDescription = "", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }; Response response = await client.AnonymousBodyAsync(RequestContent.Create(data)); @@ -468,6 +526,8 @@ public async Task Example_AnonymousBody_AllParameters_Async() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -477,12 +537,19 @@ public async Task Example_AnonymousBody_Convenience_Async() var endpoint = new Uri(""); var client = new FirstTestTypeSpecClient(endpoint); - var thing = new Thing("", "", "") + var thing = new Thing("", "", "", new int[] + { + 1234 + }) { OptionalLiteralString = ThingOptionalLiteralString.Reject, OptionalLiteralInt = ThingOptionalLiteralInt._456, OptionalLiteralFloat = ThingOptionalLiteralFloat._456, OptionalLiteralBool = true, + OptionalNullableList = +{ + 1234 + }, }; var result = await client.AnonymousBodyAsync(thing); } @@ -710,6 +777,7 @@ public void Example_SayHi() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -733,6 +801,8 @@ public void Example_SayHi_AllParameters() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -752,6 +822,7 @@ public async Task Example_SayHi_Async() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -775,6 +846,8 @@ public async Task Example_SayHi_AllParameters_Async() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -804,12 +877,21 @@ public void Example_HelloAgain() requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }, requiredUnknown = new { }, requiredRecordUnknown = new { key = new { }, }, + modelWithRequiredNullable = new + { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = client.HelloAgain("", "", RequestContent.Create(data)); @@ -826,9 +908,13 @@ public void Example_HelloAgain() Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("requiredUnknown").ToString()); Console.WriteLine(result.GetProperty("requiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); } [Test] @@ -862,6 +948,12 @@ public void Example_HelloAgain_AllParameters() optionalLiteralFloat = 4.56, optionalLiteralBool = true, requiredBadDescription = "", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }, intExtensibleEnum = "1", intExtensibleEnumCollection = new[] { @@ -890,6 +982,12 @@ public void Example_HelloAgain_AllParameters() { key = new { }, }, + modelWithRequiredNullable = new + { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = client.HelloAgain("", "", RequestContent.Create(data)); @@ -910,6 +1008,8 @@ public void Example_HelloAgain_AllParameters() Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnum").ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnumCollection")[0].ToString()); Console.WriteLine(result.GetProperty("floatExtensibleEnum").ToString()); @@ -925,6 +1025,9 @@ public void Example_HelloAgain_AllParameters() Console.WriteLine(result.GetProperty("optionalRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyOptionalRecordUnknown").GetProperty("").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); } [Test] @@ -954,12 +1057,21 @@ public async Task Example_HelloAgain_Async() requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }, requiredUnknown = new { }, requiredRecordUnknown = new { key = new { }, }, + modelWithRequiredNullable = new + { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = await client.HelloAgainAsync("", "", RequestContent.Create(data)); @@ -976,9 +1088,13 @@ public async Task Example_HelloAgain_Async() Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("requiredUnknown").ToString()); Console.WriteLine(result.GetProperty("requiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); } [Test] @@ -1012,6 +1128,12 @@ public async Task Example_HelloAgain_AllParameters_Async() optionalLiteralFloat = 4.56, optionalLiteralBool = true, requiredBadDescription = "", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }, intExtensibleEnum = "1", intExtensibleEnumCollection = new[] { @@ -1040,6 +1162,12 @@ public async Task Example_HelloAgain_AllParameters_Async() { key = new { }, }, + modelWithRequiredNullable = new + { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = await client.HelloAgainAsync("", "", RequestContent.Create(data)); @@ -1060,6 +1188,8 @@ public async Task Example_HelloAgain_AllParameters_Async() Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnum").ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnumCollection")[0].ToString()); Console.WriteLine(result.GetProperty("floatExtensibleEnum").ToString()); @@ -1075,6 +1205,9 @@ public async Task Example_HelloAgain_AllParameters_Async() Console.WriteLine(result.GetProperty("optionalRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyOptionalRecordUnknown").GetProperty("").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); } [Test] @@ -1084,22 +1217,29 @@ public async Task Example_HelloAgain_Convenience_Async() var endpoint = new Uri(""); var client = new FirstTestTypeSpecClient(endpoint); - var action = new RoundTripModel("", 1234, new StringFixedEnum[] + var action = new RoundTripModel("", 1234, new StringFixedEnum?[] { StringFixedEnum.One - }, new Dictionary + }, new Dictionary { ["key"] = StringExtensibleEnum.One, - }, new Thing("", "", "") + }, new Thing("", "", "", new int[] + { + 1234 + }) { OptionalLiteralString = ThingOptionalLiteralString.Reject, OptionalLiteralInt = ThingOptionalLiteralInt._456, OptionalLiteralFloat = ThingOptionalLiteralFloat._456, OptionalLiteralBool = true, + OptionalNullableList = + { + 1234 + }, }, BinaryData.FromString(""), new Dictionary { ["key"] = BinaryData.FromString(""), - }) + }, new ModelWithRequiredNullableProperties(1234, StringExtensibleEnum.One, StringFixedEnum.One)) { IntExtensibleEnum = IntExtensibleEnum.One, IntExtensibleEnumCollection = @@ -1158,12 +1298,21 @@ public void Example_NoContentType() requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }, requiredUnknown = new { }, requiredRecordUnknown = new { key = new { }, }, + modelWithRequiredNullable = new + { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = client.NoContentType("", "", RequestContent.Create(data)); @@ -1180,9 +1329,13 @@ public void Example_NoContentType() Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("requiredUnknown").ToString()); Console.WriteLine(result.GetProperty("requiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); } [Test] @@ -1216,6 +1369,12 @@ public void Example_NoContentType_AllParameters() optionalLiteralFloat = 4.56, optionalLiteralBool = true, requiredBadDescription = "", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }, intExtensibleEnum = "1", intExtensibleEnumCollection = new[] { @@ -1244,6 +1403,12 @@ public void Example_NoContentType_AllParameters() { key = new { }, }, + modelWithRequiredNullable = new + { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = client.NoContentType("", "", RequestContent.Create(data)); @@ -1264,6 +1429,8 @@ public void Example_NoContentType_AllParameters() Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnum").ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnumCollection")[0].ToString()); Console.WriteLine(result.GetProperty("floatExtensibleEnum").ToString()); @@ -1279,6 +1446,9 @@ public void Example_NoContentType_AllParameters() Console.WriteLine(result.GetProperty("optionalRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyOptionalRecordUnknown").GetProperty("").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); } [Test] @@ -1308,12 +1478,21 @@ public async Task Example_NoContentType_Async() requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }, requiredUnknown = new { }, requiredRecordUnknown = new { key = new { }, }, + modelWithRequiredNullable = new + { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = await client.NoContentTypeAsync("", "", RequestContent.Create(data)); @@ -1330,9 +1509,13 @@ public async Task Example_NoContentType_Async() Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("requiredUnknown").ToString()); Console.WriteLine(result.GetProperty("requiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); } [Test] @@ -1366,6 +1549,12 @@ public async Task Example_NoContentType_AllParameters_Async() optionalLiteralFloat = 4.56, optionalLiteralBool = true, requiredBadDescription = "", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }, intExtensibleEnum = "1", intExtensibleEnumCollection = new[] { @@ -1394,6 +1583,12 @@ public async Task Example_NoContentType_AllParameters_Async() { key = new { }, }, + modelWithRequiredNullable = new + { + requiredNullablePrimitive = 1234, + requiredExtensibleEnum = "1", + requiredFixedEnum = "1", + }, }; Response response = await client.NoContentTypeAsync("", "", RequestContent.Create(data)); @@ -1414,6 +1609,8 @@ public async Task Example_NoContentType_AllParameters_Async() Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredNullableList")[0].ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnum").ToString()); Console.WriteLine(result.GetProperty("intExtensibleEnumCollection")[0].ToString()); Console.WriteLine(result.GetProperty("floatExtensibleEnum").ToString()); @@ -1429,6 +1626,9 @@ public async Task Example_NoContentType_AllParameters_Async() Console.WriteLine(result.GetProperty("optionalRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyRequiredRecordUnknown").GetProperty("").ToString()); Console.WriteLine(result.GetProperty("readOnlyOptionalRecordUnknown").GetProperty("").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredNullablePrimitive").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredExtensibleEnum").ToString()); + Console.WriteLine(result.GetProperty("modelWithRequiredNullable").GetProperty("requiredFixedEnum").ToString()); } [Test] @@ -1448,6 +1648,7 @@ public void Example_HelloDemo2() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -1471,6 +1672,8 @@ public void Example_HelloDemo2_AllParameters() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -1490,6 +1693,7 @@ public async Task Example_HelloDemo2_Async() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -1513,6 +1717,8 @@ public async Task Example_HelloDemo2_AllParameters_Async() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -1541,6 +1747,9 @@ public void Example_CreateLiteral() requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }; Response response = client.CreateLiteral(RequestContent.Create(data)); @@ -1553,6 +1762,7 @@ public void Example_CreateLiteral() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -1575,6 +1785,12 @@ public void Example_CreateLiteral_AllParameters() optionalLiteralFloat = 4.56, optionalLiteralBool = true, requiredBadDescription = "", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }; Response response = client.CreateLiteral(RequestContent.Create(data)); @@ -1591,6 +1807,8 @@ public void Example_CreateLiteral_AllParameters() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -1609,6 +1827,9 @@ public async Task Example_CreateLiteral_Async() requiredLiteralFloat = 1.23, requiredLiteralBool = false, requiredBadDescription = "", + requiredNullableList = new[] { + 1234 + }, }; Response response = await client.CreateLiteralAsync(RequestContent.Create(data)); @@ -1621,6 +1842,7 @@ public async Task Example_CreateLiteral_Async() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -1643,6 +1865,12 @@ public async Task Example_CreateLiteral_AllParameters_Async() optionalLiteralFloat = 4.56, optionalLiteralBool = true, requiredBadDescription = "", + optionalNullableList = new[] { + 1234 + }, + requiredNullableList = new[] { + 1234 + }, }; Response response = await client.CreateLiteralAsync(RequestContent.Create(data)); @@ -1659,6 +1887,8 @@ public async Task Example_CreateLiteral_AllParameters_Async() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -1668,12 +1898,19 @@ public async Task Example_CreateLiteral_Convenience_Async() var endpoint = new Uri(""); var client = new FirstTestTypeSpecClient(endpoint); - var body = new Thing("", "", "") + var body = new Thing("", "", "", new int[] + { + 1234 + }) { OptionalLiteralString = ThingOptionalLiteralString.Reject, OptionalLiteralInt = ThingOptionalLiteralInt._456, OptionalLiteralFloat = ThingOptionalLiteralFloat._456, OptionalLiteralBool = true, + OptionalNullableList = +{ + 1234 + }, }; var result = await client.CreateLiteralAsync(body); } @@ -1695,6 +1932,7 @@ public void Example_HelloLiteral() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -1718,6 +1956,8 @@ public void Example_HelloLiteral_AllParameters() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -1737,6 +1977,7 @@ public async Task Example_HelloLiteral_Async() Console.WriteLine(result.GetProperty("requiredLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("requiredLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -1760,6 +2001,8 @@ public async Task Example_HelloLiteral_AllParameters_Async() Console.WriteLine(result.GetProperty("optionalLiteralFloat").ToString()); Console.WriteLine(result.GetProperty("optionalLiteralBool").ToString()); Console.WriteLine(result.GetProperty("requiredBadDescription").ToString()); + Console.WriteLine(result.GetProperty("optionalNullableList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableList")[0].ToString()); } [Test] @@ -1831,12 +2074,19 @@ public async Task Example_InternalProtocol_Convenience_Async() var endpoint = new Uri(""); var client = new FirstTestTypeSpecClient(endpoint); - var body = new Thing("", "", "") + var body = new Thing("", "", "", new int[] + { + 1234 + }) { OptionalLiteralString = ThingOptionalLiteralString.Reject, OptionalLiteralInt = ThingOptionalLiteralInt._456, OptionalLiteralFloat = ThingOptionalLiteralFloat._456, OptionalLiteralBool = true, + OptionalNullableList = +{ + 1234 + }, }; var result = await client.InternalProtocolAsync(body); } diff --git a/test/TestProjects/FirstTest-TypeSpec/tspconfig.yaml b/test/TestProjects/FirstTest-TypeSpec/tspconfig.yaml index b74ff790d83..2cd01170bc8 100644 --- a/test/TestProjects/FirstTest-TypeSpec/tspconfig.yaml +++ b/test/TestProjects/FirstTest-TypeSpec/tspconfig.yaml @@ -1,3 +1,4 @@ options: "@azure-tools/typespec-csharp": generate-convenience-methods: false + deserialize-null-collection-as-null-value: true diff --git a/test/TestProjects/ModelShapes/Generated/Models/InputModel.Serialization.cs b/test/TestProjects/ModelShapes/Generated/Models/InputModel.Serialization.cs index 656e168e66c..55d74d15cf8 100644 --- a/test/TestProjects/ModelShapes/Generated/Models/InputModel.Serialization.cs +++ b/test/TestProjects/ModelShapes/Generated/Models/InputModel.Serialization.cs @@ -81,7 +81,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteNull("RequiredNullableInt"); } - if (RequiredNullableStringList != null) + if (RequiredNullableStringList != null && Optional.IsCollectionDefined(RequiredNullableStringList)) { writer.WritePropertyName("RequiredNullableStringList"u8); writer.WriteStartArray(); @@ -95,7 +95,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteNull("RequiredNullableStringList"); } - if (RequiredNullableIntList != null) + if (RequiredNullableIntList != null && Optional.IsCollectionDefined(RequiredNullableIntList)) { writer.WritePropertyName("RequiredNullableIntList"u8); writer.WriteStartArray(); diff --git a/test/TestProjects/ModelShapes/Generated/Models/MixedModel.Serialization.cs b/test/TestProjects/ModelShapes/Generated/Models/MixedModel.Serialization.cs index bd7cce987e9..97606b1cdaf 100644 --- a/test/TestProjects/ModelShapes/Generated/Models/MixedModel.Serialization.cs +++ b/test/TestProjects/ModelShapes/Generated/Models/MixedModel.Serialization.cs @@ -82,7 +82,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteNull("RequiredNullableInt"); } - if (RequiredNullableStringList != null) + if (RequiredNullableStringList != null && Optional.IsCollectionDefined(RequiredNullableStringList)) { writer.WritePropertyName("RequiredNullableStringList"u8); writer.WriteStartArray(); @@ -96,7 +96,7 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteNull("RequiredNullableStringList"); } - if (RequiredNullableIntList != null) + if (RequiredNullableIntList != null && Optional.IsCollectionDefined(RequiredNullableIntList)) { writer.WritePropertyName("RequiredNullableIntList"u8); writer.WriteStartArray(); @@ -293,7 +293,7 @@ internal static MixedModel DeserializeMixedModel(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { - requiredNullableStringList = null; + requiredNullableStringList = new ChangeTrackingList(); continue; } List array = new List(); @@ -308,7 +308,7 @@ internal static MixedModel DeserializeMixedModel(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { - requiredNullableIntList = null; + requiredNullableIntList = new ChangeTrackingList(); continue; } List array = new List(); @@ -343,7 +343,6 @@ internal static MixedModel DeserializeMixedModel(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { - nonRequiredNullableStringList = null; continue; } List array = new List(); @@ -358,7 +357,6 @@ internal static MixedModel DeserializeMixedModel(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { - nonRequiredNullableIntList = null; continue; } List array = new List(); diff --git a/test/TestProjects/ModelShapes/Generated/Models/OutputModel.Serialization.cs b/test/TestProjects/ModelShapes/Generated/Models/OutputModel.Serialization.cs index 30c34b627c2..1dc14bb9187 100644 --- a/test/TestProjects/ModelShapes/Generated/Models/OutputModel.Serialization.cs +++ b/test/TestProjects/ModelShapes/Generated/Models/OutputModel.Serialization.cs @@ -135,7 +135,7 @@ internal static OutputModel DeserializeOutputModel(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { - requiredNullableStringList = null; + requiredNullableStringList = new ChangeTrackingList(); continue; } List array = new List(); @@ -150,7 +150,7 @@ internal static OutputModel DeserializeOutputModel(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { - requiredNullableIntList = null; + requiredNullableIntList = new ChangeTrackingList(); continue; } List array = new List(); @@ -185,7 +185,6 @@ internal static OutputModel DeserializeOutputModel(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { - nonRequiredNullableStringList = null; continue; } List array = new List(); @@ -200,7 +199,6 @@ internal static OutputModel DeserializeOutputModel(JsonElement element) { if (property.Value.ValueKind == JsonValueKind.Null) { - nonRequiredNullableIntList = null; continue; } List array = new List(); diff --git a/test/TestProjects/Models-TypeSpec/Models-TypeSpec.tsp b/test/TestProjects/Models-TypeSpec/Models-TypeSpec.tsp index d84fab0e8d3..91a857df970 100644 --- a/test/TestProjects/Models-TypeSpec/Models-TypeSpec.tsp +++ b/test/TestProjects/Models-TypeSpec/Models-TypeSpec.tsp @@ -37,13 +37,13 @@ model BaseModelWithProperties { @doc("Derived model") model DerivedModel extends BaseModel { @doc("Required collection") - requiredCollection: CollectionItem[]; + requiredList: CollectionItem[]; } @doc("Derived model with properties") model DerivedModelWithProperties extends BaseModelWithProperties { @doc("Required collection") - requiredCollection: CollectionItem[]; + requiredList: CollectionItem[]; } @discriminator("discriminatorProperty") @@ -124,6 +124,32 @@ model RoundTripModel extends BaseModel { @doc("Required int, illustrating a value type property.") requiredInt: int32; + @doc("Optional string") + nonRequiredString?: string; + + @doc("Optional int") + nonRequiredInt?: int32; + + @doc("Required nullable int") + requiredNullableInt: int32 | null; + + @doc("Required nullable string") + requiredNullableString: string | null; + + @doc("Optional nullable int") + nonRequiredNullableInt?: int32 | null; + + @doc("Optional nullable string") + nonRequiredNullableString?: string | null; + + @doc("Required readonly int") + @visibility("read") + requiredReadonlyInt: int32; + + @doc("Optional readonly int") + @visibility("read") + nonRequiredReadonlyInt?: int32; + @doc("Required model with discriminator") requiredModel: BaseModelWithDiscriminator; @@ -140,7 +166,7 @@ model RoundTripModel extends BaseModel { requiredExtensibleEnum: ExtensibleEnum; @doc("Required collection") - requiredCollection: CollectionItem[]; + requiredList: CollectionItem[]; @doc("Required int record") requiredIntRecord: Record; @@ -174,6 +200,18 @@ model RoundTripModel extends BaseModel { @doc("Optional int8[]") optionalInt8Array?: int8[]; + + @doc("Required nullable int list") + requiredNullableIntList: int32[] | null; + + @doc("Required nullable string list") + requiredNullableStringList: string[] | null; + + @doc("Optional nullable model list") + nonRequiredNullableIntList?: int32[] | null; + + @doc("Optional nullable string list") + nonRequiredNullableStringList?: string[] | null; } @doc("Model used both as input and output with primitive types") @@ -217,17 +255,29 @@ model InputModel { @doc("Required int") requiredInt: int32; + @doc("Required nullable int") + requiredNullableInt: int32 | null; + + @doc("Required nullable string") + requiredNullableString: string | null; + + @doc("Optional nullable int") + nonRequiredNullableInt?: int32 | null; + + @doc("Optional nullable string") + nonRequiredNullableString?: string | null; + @doc("Required model") requiredModel: BaseModel; @doc("Required primitive value type collection") - requiredIntCollection: int32[]; + requiredIntList: int32[]; @doc("Required primitive reference type collection") - requiredStringCollection: string[]; + requiredStringList: string[]; @doc("Required model collection") - requiredModelCollection: CollectionItem[]; + requiredModelList: CollectionItem[]; @doc("Required model record") requiredModelRecord: Record; @@ -237,6 +287,33 @@ model InputModel { @doc("Required collection of which the element is a nullable boolean") requiredCollectionWithNullableBooleanElement: (boolean | null) []; + + @doc("Required model nullable collection") + requiredNullableModelList: CollectionItem[] | null; + + @doc("Required string nullable collection") + requiredNullableStringList: string[] | null; + + @doc("Required int nullable collection") + requiredNullableIntList: int32[] | null; + + @doc("Optional model collection") + nonRequiredModelList?: CollectionItem[]; + + @doc("Optional string collection") + nonRequiredStringList?: string[]; + + @doc("Optional int collection") + nonRequiredIntList?: int32[]; + + @doc("Optional model nullable collection") + nonRequiredNullableModelList?: CollectionItem[] | null; + + @doc("Optional string nullable collection") + nonRequiredNullableStringList?: string[] | null; + + @doc("Optional int nullable collection") + nonRequiredNullableIntList?: int32[] | null; } @doc("Model used only as output") @@ -251,10 +328,22 @@ model OutputModel { requiredModel: DerivedModel; @doc("Required collection") - requiredCollection: CollectionItem[]; + requiredList: CollectionItem[]; @doc("Required model record") requiredModelRecord: Record; + + @doc("Optional model collection") + optionalList?: CollectionItem[]; + + @doc("Optional model nullable collection") + optionalNullableList?: CollectionItem[] | null; + + @doc("Optional model record") + optionalRecord?: Record; + + @doc("Optional model nullable record") + optionalNullableRecord?: Record | null; } @doc("RoundTrip model with optional properties.") @@ -268,12 +357,12 @@ model RoundTripOptionalModel { @doc("Optional string collection.") optionalStringList?: string[]; - + @doc("Optional int collection.") optionalIntList?: int32[]; @doc("Optional model collection") - optionalModelCollection?: CollectionItem[]; + optionalModelList?: CollectionItem[]; @doc("Optional model.") optionalModel?: DerivedModel; @@ -358,7 +447,7 @@ model RoundTripReadOnlyModel { @doc("Required model collection") @visibility("read") - requiredReadOnlyModelCollection: CollectionItem[]; + requiredReadOnlyModelList: CollectionItem[]; @doc("Required int record") @visibility("read") @@ -382,7 +471,7 @@ model RoundTripReadOnlyModel { @doc("Optional model collection") @visibility("read") - optionalReadOnlyModelCollection?: CollectionItem[]; + optionalReadOnlyModelList?: CollectionItem[]; @doc("Optional int record") optionalReadOnlyIntRecord: Record; @@ -511,7 +600,7 @@ model NoUseBase { @doc("Derived model") model RoundTripOnNoUse extends NoUseBase { @doc("Required collection") - requiredCollection: CollectionItem[]; + requiredList: CollectionItem[]; } @doc("Returns RoundTripOnNoUse") diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Docs/ModelsTypeSpecClient.xml b/test/TestProjects/Models-TypeSpec/src/Generated/Docs/ModelsTypeSpecClient.xml index 17b1b35a0b7..a23f2c74e29 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Docs/ModelsTypeSpecClient.xml +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Docs/ModelsTypeSpecClient.xml @@ -58,7 +58,7 @@ This sample shows how to call InputToRoundTripAsync with required parameters. var endpoint = new Uri(""); var client = new ModelsTypeSpecClient(endpoint); -var input = new InputModel("", 1234, new BaseModel(), new int[] +var input = new InputModel("", 1234, 1234, "", new BaseModel(), new int[] { 1234 }, new string[] @@ -76,7 +76,35 @@ var input = new InputModel("", 1234, new BaseModel(), new int[] }, new bool?[] { true -}); +}, Array.Empty(), new string[] +{ + "" +}, new int[] +{ + 1234 +}) +{ + NonRequiredNullableInt = 1234, + NonRequiredNullableString = "", + NonRequiredModelList = {}, + NonRequiredStringList = +{ + "" + }, + NonRequiredIntList = +{ + 1234 + }, + NonRequiredNullableModelList = {}, + NonRequiredNullableStringList = +{ + "" + }, + NonRequiredNullableIntList = +{ + 1234 + }, +}; var result = await client.InputToRoundTripAsync(input); ]]> @@ -88,7 +116,7 @@ This sample shows how to call InputToRoundTrip with required parameters. var endpoint = new Uri(""); var client = new ModelsTypeSpecClient(endpoint); -var input = new InputModel("", 1234, new BaseModel(), new int[] +var input = new InputModel("", 1234, 1234, "", new BaseModel(), new int[] { 1234 }, new string[] @@ -106,14 +134,42 @@ var input = new InputModel("", 1234, new BaseModel(), new int[] }, new bool?[] { true -}); +}, Array.Empty(), new string[] +{ + "" +}, new int[] +{ + 1234 +}) +{ + NonRequiredNullableInt = 1234, + NonRequiredNullableString = "", + NonRequiredModelList = {}, + NonRequiredStringList = +{ + "" + }, + NonRequiredIntList = +{ + 1234 + }, + NonRequiredNullableModelList = {}, + NonRequiredNullableStringList = +{ + "" + }, + NonRequiredNullableIntList = +{ + 1234 + }, +}; var result = client.InputToRoundTrip(input); ]]> -This sample shows how to call InputToRoundTripAsync with required request content and parse the result. +This sample shows how to call InputToRoundTripAsync with required request content, and how to parse the result. "); var client = new ModelsTypeSpecClient(endpoint); @@ -121,14 +177,16 @@ var client = new ModelsTypeSpecClient(endpoint); var data = new { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", requiredModel = new {}, - requiredIntCollection = new[] { + requiredIntList = new[] { 1234 }, - requiredStringCollection = new[] { + requiredStringList = new[] { "" }, - requiredModelCollection = new[] { + requiredModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -144,6 +202,15 @@ var data = new { requiredCollectionWithNullableBooleanElement = new[] { true }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 + }, }; Response response = await client.InputToRoundTripAsync(RequestContent.Create(data)); @@ -151,6 +218,100 @@ Response response = await client.InputToRoundTripAsync(RequestContent.Create(dat JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; Console.WriteLine(result.GetProperty("requiredString").ToString()); Console.WriteLine(result.GetProperty("requiredInt").ToString()); +Console.WriteLine(result.GetProperty("requiredNullableInt").ToString()); +Console.WriteLine(result.GetProperty("requiredNullableString").ToString()); +Console.WriteLine(result.GetProperty("requiredReadonlyInt").ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("discriminatorProperty").ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredPropertyOnBase").ToString()); +Console.WriteLine(result.GetProperty("requiredFixedStringEnum").ToString()); +Console.WriteLine(result.GetProperty("requiredFixedIntEnum").ToString()); +Console.WriteLine(result.GetProperty("requiredExtensibleEnum").ToString()); +Console.WriteLine(result.GetProperty("requiredIntRecord").GetProperty("").ToString()); +Console.WriteLine(result.GetProperty("requiredStringRecord").GetProperty("").ToString()); +Console.WriteLine(result.GetProperty("requiredBytes").ToString()); +Console.WriteLine(result.GetProperty("requiredUint8Array")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredUnknown").ToString()); +Console.WriteLine(result.GetProperty("requiredInt8Array")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableIntList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableStringList")[0].ToString()); +]]> +This sample shows how to call InputToRoundTripAsync with all request content, and how to parse the result. +"); +var client = new ModelsTypeSpecClient(endpoint); + +var data = new { + requiredString = "", + requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", + nonRequiredNullableInt = 1234, + nonRequiredNullableString = "", + requiredModel = new {}, + requiredIntList = new[] { + 1234 + }, + requiredStringList = new[] { + "" + }, + requiredModelList = new[] { + new { + requiredModelRecord = new { + key = new {}, + }, + } + }, + requiredModelRecord = new { + key = new {}, + }, + requiredCollectionWithNullableFloatElement = new[] { + 123.45f + }, + requiredCollectionWithNullableBooleanElement = new[] { + true + }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 + }, + nonRequiredModelList = new[] { + new {} + }, + nonRequiredStringList = new[] { + "" + }, + nonRequiredIntList = new[] { + 1234 + }, + nonRequiredNullableModelList = new[] { + new {} + }, + nonRequiredNullableStringList = new[] { + "" + }, + nonRequiredNullableIntList = new[] { + 1234 + }, +}; + +Response response = await client.InputToRoundTripAsync(RequestContent.Create(data)); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("requiredString").ToString()); +Console.WriteLine(result.GetProperty("requiredInt").ToString()); +Console.WriteLine(result.GetProperty("nonRequiredString").ToString()); +Console.WriteLine(result.GetProperty("nonRequiredInt").ToString()); +Console.WriteLine(result.GetProperty("requiredNullableInt").ToString()); +Console.WriteLine(result.GetProperty("requiredNullableString").ToString()); +Console.WriteLine(result.GetProperty("nonRequiredNullableInt").ToString()); +Console.WriteLine(result.GetProperty("nonRequiredNullableString").ToString()); +Console.WriteLine(result.GetProperty("requiredReadonlyInt").ToString()); +Console.WriteLine(result.GetProperty("nonRequiredReadonlyInt").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("discriminatorProperty").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalPropertyOnBase").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredPropertyOnBase").ToString()); @@ -167,12 +328,16 @@ Console.WriteLine(result.GetProperty("requiredUnknown").ToString()); Console.WriteLine(result.GetProperty("optionalUnknown").ToString()); Console.WriteLine(result.GetProperty("requiredInt8Array")[0].ToString()); Console.WriteLine(result.GetProperty("optionalInt8Array")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableIntList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableStringList")[0].ToString()); +Console.WriteLine(result.GetProperty("nonRequiredNullableIntList")[0].ToString()); +Console.WriteLine(result.GetProperty("nonRequiredNullableStringList")[0].ToString()); ]]> -This sample shows how to call InputToRoundTrip with required request content and parse the result. +This sample shows how to call InputToRoundTrip with required request content, and how to parse the result. "); var client = new ModelsTypeSpecClient(endpoint); @@ -180,14 +345,16 @@ var client = new ModelsTypeSpecClient(endpoint); var data = new { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", requiredModel = new {}, - requiredIntCollection = new[] { + requiredIntList = new[] { 1234 }, - requiredStringCollection = new[] { + requiredStringList = new[] { "" }, - requiredModelCollection = new[] { + requiredModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -203,6 +370,15 @@ var data = new { requiredCollectionWithNullableBooleanElement = new[] { true }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 + }, }; Response response = client.InputToRoundTrip(RequestContent.Create(data)); @@ -210,6 +386,100 @@ Response response = client.InputToRoundTrip(RequestContent.Create(data)); JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; Console.WriteLine(result.GetProperty("requiredString").ToString()); Console.WriteLine(result.GetProperty("requiredInt").ToString()); +Console.WriteLine(result.GetProperty("requiredNullableInt").ToString()); +Console.WriteLine(result.GetProperty("requiredNullableString").ToString()); +Console.WriteLine(result.GetProperty("requiredReadonlyInt").ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("discriminatorProperty").ToString()); +Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredPropertyOnBase").ToString()); +Console.WriteLine(result.GetProperty("requiredFixedStringEnum").ToString()); +Console.WriteLine(result.GetProperty("requiredFixedIntEnum").ToString()); +Console.WriteLine(result.GetProperty("requiredExtensibleEnum").ToString()); +Console.WriteLine(result.GetProperty("requiredIntRecord").GetProperty("").ToString()); +Console.WriteLine(result.GetProperty("requiredStringRecord").GetProperty("").ToString()); +Console.WriteLine(result.GetProperty("requiredBytes").ToString()); +Console.WriteLine(result.GetProperty("requiredUint8Array")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredUnknown").ToString()); +Console.WriteLine(result.GetProperty("requiredInt8Array")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableIntList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableStringList")[0].ToString()); +]]> +This sample shows how to call InputToRoundTrip with all request content, and how to parse the result. +"); +var client = new ModelsTypeSpecClient(endpoint); + +var data = new { + requiredString = "", + requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", + nonRequiredNullableInt = 1234, + nonRequiredNullableString = "", + requiredModel = new {}, + requiredIntList = new[] { + 1234 + }, + requiredStringList = new[] { + "" + }, + requiredModelList = new[] { + new { + requiredModelRecord = new { + key = new {}, + }, + } + }, + requiredModelRecord = new { + key = new {}, + }, + requiredCollectionWithNullableFloatElement = new[] { + 123.45f + }, + requiredCollectionWithNullableBooleanElement = new[] { + true + }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 + }, + nonRequiredModelList = new[] { + new {} + }, + nonRequiredStringList = new[] { + "" + }, + nonRequiredIntList = new[] { + 1234 + }, + nonRequiredNullableModelList = new[] { + new {} + }, + nonRequiredNullableStringList = new[] { + "" + }, + nonRequiredNullableIntList = new[] { + 1234 + }, +}; + +Response response = client.InputToRoundTrip(RequestContent.Create(data)); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("requiredString").ToString()); +Console.WriteLine(result.GetProperty("requiredInt").ToString()); +Console.WriteLine(result.GetProperty("nonRequiredString").ToString()); +Console.WriteLine(result.GetProperty("nonRequiredInt").ToString()); +Console.WriteLine(result.GetProperty("requiredNullableInt").ToString()); +Console.WriteLine(result.GetProperty("requiredNullableString").ToString()); +Console.WriteLine(result.GetProperty("nonRequiredNullableInt").ToString()); +Console.WriteLine(result.GetProperty("nonRequiredNullableString").ToString()); +Console.WriteLine(result.GetProperty("requiredReadonlyInt").ToString()); +Console.WriteLine(result.GetProperty("nonRequiredReadonlyInt").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("discriminatorProperty").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalPropertyOnBase").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredPropertyOnBase").ToString()); @@ -226,6 +496,10 @@ Console.WriteLine(result.GetProperty("requiredUnknown").ToString()); Console.WriteLine(result.GetProperty("optionalUnknown").ToString()); Console.WriteLine(result.GetProperty("requiredInt8Array")[0].ToString()); Console.WriteLine(result.GetProperty("optionalInt8Array")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableIntList")[0].ToString()); +Console.WriteLine(result.GetProperty("requiredNullableStringList")[0].ToString()); +Console.WriteLine(result.GetProperty("nonRequiredNullableIntList")[0].ToString()); +Console.WriteLine(result.GetProperty("nonRequiredNullableStringList")[0].ToString()); ]]> @@ -236,7 +510,7 @@ This sample shows how to call InputToRoundTripPrimitiveAsync with required param var endpoint = new Uri(""); var client = new ModelsTypeSpecClient(endpoint); -var input = new InputModel("", 1234, new BaseModel(), new int[] +var input = new InputModel("", 1234, 1234, "", new BaseModel(), new int[] { 1234 }, new string[] @@ -254,7 +528,35 @@ var input = new InputModel("", 1234, new BaseModel(), new int[] }, new bool?[] { true -}); +}, Array.Empty(), new string[] +{ + "" +}, new int[] +{ + 1234 +}) +{ + NonRequiredNullableInt = 1234, + NonRequiredNullableString = "", + NonRequiredModelList = {}, + NonRequiredStringList = +{ + "" + }, + NonRequiredIntList = +{ + 1234 + }, + NonRequiredNullableModelList = {}, + NonRequiredNullableStringList = +{ + "" + }, + NonRequiredNullableIntList = +{ + 1234 + }, +}; var result = await client.InputToRoundTripPrimitiveAsync(input); ]]> @@ -266,7 +568,7 @@ This sample shows how to call InputToRoundTripPrimitive with required parameters var endpoint = new Uri(""); var client = new ModelsTypeSpecClient(endpoint); -var input = new InputModel("", 1234, new BaseModel(), new int[] +var input = new InputModel("", 1234, 1234, "", new BaseModel(), new int[] { 1234 }, new string[] @@ -284,14 +586,100 @@ var input = new InputModel("", 1234, new BaseModel(), new int[] }, new bool?[] { true -}); +}, Array.Empty(), new string[] +{ + "" +}, new int[] +{ + 1234 +}) +{ + NonRequiredNullableInt = 1234, + NonRequiredNullableString = "", + NonRequiredModelList = {}, + NonRequiredStringList = +{ + "" + }, + NonRequiredIntList = +{ + 1234 + }, + NonRequiredNullableModelList = {}, + NonRequiredNullableStringList = +{ + "" + }, + NonRequiredNullableIntList = +{ + 1234 + }, +}; var result = client.InputToRoundTripPrimitive(input); ]]> -This sample shows how to call InputToRoundTripPrimitiveAsync with required request content and parse the result. +This sample shows how to call InputToRoundTripPrimitiveAsync with required request content, and how to parse the result. +"); +var client = new ModelsTypeSpecClient(endpoint); + +var data = new { + requiredString = "", + requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", + requiredModel = new {}, + requiredIntList = new[] { + 1234 + }, + requiredStringList = new[] { + "" + }, + requiredModelList = new[] { + new { + requiredModelRecord = new { + key = new {}, + }, + } + }, + requiredModelRecord = new { + key = new {}, + }, + requiredCollectionWithNullableFloatElement = new[] { + 123.45f + }, + requiredCollectionWithNullableBooleanElement = new[] { + true + }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 + }, +}; + +Response response = await client.InputToRoundTripPrimitiveAsync(RequestContent.Create(data)); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("requiredString").ToString()); +Console.WriteLine(result.GetProperty("requiredInt").ToString()); +Console.WriteLine(result.GetProperty("requiredInt64").ToString()); +Console.WriteLine(result.GetProperty("requiredSafeInt").ToString()); +Console.WriteLine(result.GetProperty("requiredFloat").ToString()); +Console.WriteLine(result.GetProperty("required_Double").ToString()); +Console.WriteLine(result.GetProperty("requiredBoolean").ToString()); +Console.WriteLine(result.GetProperty("requiredDateTimeOffset").ToString()); +Console.WriteLine(result.GetProperty("requiredTimeSpan").ToString()); +Console.WriteLine(result.GetProperty("requiredCollectionWithNullableFloatElement")[0].ToString()); +]]> +This sample shows how to call InputToRoundTripPrimitiveAsync with all request content, and how to parse the result. "); var client = new ModelsTypeSpecClient(endpoint); @@ -299,14 +687,18 @@ var client = new ModelsTypeSpecClient(endpoint); var data = new { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", + nonRequiredNullableInt = 1234, + nonRequiredNullableString = "", requiredModel = new {}, - requiredIntCollection = new[] { + requiredIntList = new[] { 1234 }, - requiredStringCollection = new[] { + requiredStringList = new[] { "" }, - requiredModelCollection = new[] { + requiredModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -322,6 +714,33 @@ var data = new { requiredCollectionWithNullableBooleanElement = new[] { true }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 + }, + nonRequiredModelList = new[] { + new {} + }, + nonRequiredStringList = new[] { + "" + }, + nonRequiredIntList = new[] { + 1234 + }, + nonRequiredNullableModelList = new[] { + new {} + }, + nonRequiredNullableStringList = new[] { + "" + }, + nonRequiredNullableIntList = new[] { + 1234 + }, }; Response response = await client.InputToRoundTripPrimitiveAsync(RequestContent.Create(data)); @@ -342,7 +761,7 @@ Console.WriteLine(result.GetProperty("requiredCollectionWithNullableFloatElement -This sample shows how to call InputToRoundTripPrimitive with required request content and parse the result. +This sample shows how to call InputToRoundTripPrimitive with required request content, and how to parse the result. "); var client = new ModelsTypeSpecClient(endpoint); @@ -350,14 +769,16 @@ var client = new ModelsTypeSpecClient(endpoint); var data = new { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", requiredModel = new {}, - requiredIntCollection = new[] { + requiredIntList = new[] { 1234 }, - requiredStringCollection = new[] { + requiredStringList = new[] { "" }, - requiredModelCollection = new[] { + requiredModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -373,6 +794,93 @@ var data = new { requiredCollectionWithNullableBooleanElement = new[] { true }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 + }, +}; + +Response response = client.InputToRoundTripPrimitive(RequestContent.Create(data)); + +JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; +Console.WriteLine(result.GetProperty("requiredString").ToString()); +Console.WriteLine(result.GetProperty("requiredInt").ToString()); +Console.WriteLine(result.GetProperty("requiredInt64").ToString()); +Console.WriteLine(result.GetProperty("requiredSafeInt").ToString()); +Console.WriteLine(result.GetProperty("requiredFloat").ToString()); +Console.WriteLine(result.GetProperty("required_Double").ToString()); +Console.WriteLine(result.GetProperty("requiredBoolean").ToString()); +Console.WriteLine(result.GetProperty("requiredDateTimeOffset").ToString()); +Console.WriteLine(result.GetProperty("requiredTimeSpan").ToString()); +Console.WriteLine(result.GetProperty("requiredCollectionWithNullableFloatElement")[0].ToString()); +]]> +This sample shows how to call InputToRoundTripPrimitive with all request content, and how to parse the result. +"); +var client = new ModelsTypeSpecClient(endpoint); + +var data = new { + requiredString = "", + requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", + nonRequiredNullableInt = 1234, + nonRequiredNullableString = "", + requiredModel = new {}, + requiredIntList = new[] { + 1234 + }, + requiredStringList = new[] { + "" + }, + requiredModelList = new[] { + new { + requiredModelRecord = new { + key = new {}, + }, + } + }, + requiredModelRecord = new { + key = new {}, + }, + requiredCollectionWithNullableFloatElement = new[] { + 123.45f + }, + requiredCollectionWithNullableBooleanElement = new[] { + true + }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 + }, + nonRequiredModelList = new[] { + new {} + }, + nonRequiredStringList = new[] { + "" + }, + nonRequiredIntList = new[] { + 1234 + }, + nonRequiredNullableModelList = new[] { + new {} + }, + nonRequiredNullableStringList = new[] { + "" + }, + nonRequiredNullableIntList = new[] { + 1234 + }, }; Response response = client.InputToRoundTripPrimitive(RequestContent.Create(data)); @@ -423,7 +931,7 @@ var data = new { optionalIntList = new[] { 1234 }, - optionalModelCollection = new[] { + optionalModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -498,7 +1006,7 @@ var data = new { optionalIntList = new[] { 1234 }, - optionalModelCollection = new[] { + optionalModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -567,6 +1075,8 @@ var client = new ModelsTypeSpecClient(endpoint); var data = new { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", requiredModel = new { discriminatorProperty = "", requiredPropertyOnBase = 1234, @@ -574,7 +1084,7 @@ var data = new { requiredFixedStringEnum = "1", requiredFixedIntEnum = "1", requiredExtensibleEnum = "1", - requiredCollection = new[] { + requiredList = new[] { new { requiredModelRecord = new { key = new {}, @@ -598,6 +1108,12 @@ var data = new { requiredInt8Array = new[] { 1234 }, + requiredNullableIntList = new[] { + 1234 + }, + requiredNullableStringList = new[] { + "" + }, }; Response response = await client.RoundTripToOutputAsync(RequestContent.Create(data)); @@ -614,6 +1130,12 @@ var client = new ModelsTypeSpecClient(endpoint); var data = new { requiredString = "", requiredInt = 1234, + nonRequiredString = "", + nonRequiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", + nonRequiredNullableInt = 1234, + nonRequiredNullableString = "", requiredModel = new { discriminatorProperty = "", optionalPropertyOnBase = "", @@ -622,7 +1144,7 @@ var data = new { requiredFixedStringEnum = "1", requiredFixedIntEnum = "1", requiredExtensibleEnum = "1", - requiredCollection = new[] { + requiredList = new[] { new { requiredModelRecord = new { key = new {}, @@ -654,6 +1176,18 @@ var data = new { optionalInt8Array = new[] { 1234 }, + requiredNullableIntList = new[] { + 1234 + }, + requiredNullableStringList = new[] { + "" + }, + nonRequiredNullableIntList = new[] { + 1234 + }, + nonRequiredNullableStringList = new[] { + "" + }, }; Response response = await client.RoundTripToOutputAsync(RequestContent.Create(data)); @@ -674,6 +1208,8 @@ var client = new ModelsTypeSpecClient(endpoint); var data = new { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", requiredModel = new { discriminatorProperty = "", requiredPropertyOnBase = 1234, @@ -681,7 +1217,7 @@ var data = new { requiredFixedStringEnum = "1", requiredFixedIntEnum = "1", requiredExtensibleEnum = "1", - requiredCollection = new[] { + requiredList = new[] { new { requiredModelRecord = new { key = new {}, @@ -705,6 +1241,12 @@ var data = new { requiredInt8Array = new[] { 1234 }, + requiredNullableIntList = new[] { + 1234 + }, + requiredNullableStringList = new[] { + "" + }, }; Response response = client.RoundTripToOutput(RequestContent.Create(data)); @@ -721,6 +1263,12 @@ var client = new ModelsTypeSpecClient(endpoint); var data = new { requiredString = "", requiredInt = 1234, + nonRequiredString = "", + nonRequiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", + nonRequiredNullableInt = 1234, + nonRequiredNullableString = "", requiredModel = new { discriminatorProperty = "", optionalPropertyOnBase = "", @@ -729,7 +1277,7 @@ var data = new { requiredFixedStringEnum = "1", requiredFixedIntEnum = "1", requiredExtensibleEnum = "1", - requiredCollection = new[] { + requiredList = new[] { new { requiredModelRecord = new { key = new {}, @@ -761,6 +1309,18 @@ var data = new { optionalInt8Array = new[] { 1234 }, + requiredNullableIntList = new[] { + 1234 + }, + requiredNullableStringList = new[] { + "" + }, + nonRequiredNullableIntList = new[] { + 1234 + }, + nonRequiredNullableStringList = new[] { + "" + }, }; Response response = client.RoundTripToOutput(RequestContent.Create(data)); @@ -1037,7 +1597,7 @@ var endpoint = new Uri(""); var client = new ModelsTypeSpecClient(endpoint); var data = new { - requiredCollection = new[] { + requiredList = new[] { new { requiredModelRecord = new { key = new {}, @@ -1062,7 +1622,7 @@ var endpoint = new Uri(""); var client = new ModelsTypeSpecClient(endpoint); var data = new { - requiredCollection = new[] { + requiredList = new[] { new { requiredModelRecord = new { key = new {}, diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/BaseModelWithProperties.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/BaseModelWithProperties.cs index b5c9c3bebea..97c1a61eeb4 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/BaseModelWithProperties.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/BaseModelWithProperties.cs @@ -23,6 +23,6 @@ internal BaseModelWithProperties(string optionalPropertyOnBase) } /// Optional properties on base. - public string OptionalPropertyOnBase { get; set; } + public string OptionalPropertyOnBase { get; } } } diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModel.Serialization.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModel.Serialization.cs index 59cc20f020c..80900a4569d 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModel.Serialization.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModel.Serialization.cs @@ -17,9 +17,9 @@ public partial class DerivedModel : IUtf8JsonSerializable void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteStartObject(); - writer.WritePropertyName("requiredCollection"u8); + writer.WritePropertyName("requiredList"u8); writer.WriteStartArray(); - foreach (var item in RequiredCollection) + foreach (var item in RequiredList) { writer.WriteObjectValue(item); } @@ -33,21 +33,21 @@ internal static DerivedModel DeserializeDerivedModel(JsonElement element) { return null; } - IList requiredCollection = default; + IList requiredList = default; foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("requiredCollection"u8)) + if (property.NameEquals("requiredList"u8)) { List array = new List(); foreach (var item in property.Value.EnumerateArray()) { array.Add(CollectionItem.DeserializeCollectionItem(item)); } - requiredCollection = array; + requiredList = array; continue; } } - return new DerivedModel(requiredCollection); + return new DerivedModel(requiredList); } /// Deserializes the model from a raw response. diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModel.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModel.cs index 0d19072f577..69a8ec4143f 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModel.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModel.cs @@ -16,23 +16,23 @@ namespace ModelsTypeSpec.Models public partial class DerivedModel : BaseModel { /// Initializes a new instance of DerivedModel. - /// Required collection. - /// is null. - public DerivedModel(IEnumerable requiredCollection) + /// Required collection. + /// is null. + public DerivedModel(IEnumerable requiredList) { - Argument.AssertNotNull(requiredCollection, nameof(requiredCollection)); + Argument.AssertNotNull(requiredList, nameof(requiredList)); - RequiredCollection = requiredCollection.ToList(); + RequiredList = requiredList.ToList(); } /// Initializes a new instance of DerivedModel. - /// Required collection. - internal DerivedModel(IList requiredCollection) + /// Required collection. + internal DerivedModel(IList requiredList) { - RequiredCollection = requiredCollection; + RequiredList = requiredList; } /// Required collection. - public IList RequiredCollection { get; } + public IList RequiredList { get; } } } diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModelWithProperties.Serialization.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModelWithProperties.Serialization.cs index a87d6d21903..ca490ab66c5 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModelWithProperties.Serialization.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModelWithProperties.Serialization.cs @@ -17,9 +17,9 @@ public partial class DerivedModelWithProperties : IUtf8JsonSerializable void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteStartObject(); - writer.WritePropertyName("requiredCollection"u8); + writer.WritePropertyName("requiredList"u8); writer.WriteStartArray(); - foreach (var item in RequiredCollection) + foreach (var item in RequiredList) { writer.WriteObjectValue(item); } @@ -38,18 +38,18 @@ internal static DerivedModelWithProperties DeserializeDerivedModelWithProperties { return null; } - IList requiredCollection = default; + IList requiredList = default; Optional optionalPropertyOnBase = default; foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("requiredCollection"u8)) + if (property.NameEquals("requiredList"u8)) { List array = new List(); foreach (var item in property.Value.EnumerateArray()) { array.Add(CollectionItem.DeserializeCollectionItem(item)); } - requiredCollection = array; + requiredList = array; continue; } if (property.NameEquals("optionalPropertyOnBase"u8)) @@ -58,7 +58,7 @@ internal static DerivedModelWithProperties DeserializeDerivedModelWithProperties continue; } } - return new DerivedModelWithProperties(optionalPropertyOnBase.Value, requiredCollection); + return new DerivedModelWithProperties(optionalPropertyOnBase.Value, requiredList); } /// Deserializes the model from a raw response. diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModelWithProperties.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModelWithProperties.cs index b9bd3b1cc75..7d16a822b00 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModelWithProperties.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/DerivedModelWithProperties.cs @@ -16,24 +16,24 @@ namespace ModelsTypeSpec.Models public partial class DerivedModelWithProperties : BaseModelWithProperties { /// Initializes a new instance of DerivedModelWithProperties. - /// Required collection. - /// is null. - public DerivedModelWithProperties(IEnumerable requiredCollection) + /// Required collection. + /// is null. + public DerivedModelWithProperties(IEnumerable requiredList) { - Argument.AssertNotNull(requiredCollection, nameof(requiredCollection)); + Argument.AssertNotNull(requiredList, nameof(requiredList)); - RequiredCollection = requiredCollection.ToList(); + RequiredList = requiredList.ToList(); } /// Initializes a new instance of DerivedModelWithProperties. /// Optional properties on base. - /// Required collection. - internal DerivedModelWithProperties(string optionalPropertyOnBase, IList requiredCollection) : base(optionalPropertyOnBase) + /// Required collection. + internal DerivedModelWithProperties(string optionalPropertyOnBase, IList requiredList) : base(optionalPropertyOnBase) { - RequiredCollection = requiredCollection; + RequiredList = requiredList; } /// Required collection. - public IList RequiredCollection { get; } + public IList RequiredList { get; } } } diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/InputModel.Serialization.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/InputModel.Serialization.cs index 2d188344e54..db65693a41b 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/InputModel.Serialization.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/InputModel.Serialization.cs @@ -19,25 +19,67 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStringValue(RequiredString); writer.WritePropertyName("requiredInt"u8); writer.WriteNumberValue(RequiredInt); + if (RequiredNullableInt != null) + { + writer.WritePropertyName("requiredNullableInt"u8); + writer.WriteNumberValue(RequiredNullableInt.Value); + } + else + { + writer.WriteNull("requiredNullableInt"); + } + if (RequiredNullableString != null) + { + writer.WritePropertyName("requiredNullableString"u8); + writer.WriteStringValue(RequiredNullableString); + } + else + { + writer.WriteNull("requiredNullableString"); + } + if (Optional.IsDefined(NonRequiredNullableInt)) + { + if (NonRequiredNullableInt != null) + { + writer.WritePropertyName("nonRequiredNullableInt"u8); + writer.WriteNumberValue(NonRequiredNullableInt.Value); + } + else + { + writer.WriteNull("nonRequiredNullableInt"); + } + } + if (Optional.IsDefined(NonRequiredNullableString)) + { + if (NonRequiredNullableString != null) + { + writer.WritePropertyName("nonRequiredNullableString"u8); + writer.WriteStringValue(NonRequiredNullableString); + } + else + { + writer.WriteNull("nonRequiredNullableString"); + } + } writer.WritePropertyName("requiredModel"u8); writer.WriteObjectValue(RequiredModel); - writer.WritePropertyName("requiredIntCollection"u8); + writer.WritePropertyName("requiredIntList"u8); writer.WriteStartArray(); - foreach (var item in RequiredIntCollection) + foreach (var item in RequiredIntList) { writer.WriteNumberValue(item); } writer.WriteEndArray(); - writer.WritePropertyName("requiredStringCollection"u8); + writer.WritePropertyName("requiredStringList"u8); writer.WriteStartArray(); - foreach (var item in RequiredStringCollection) + foreach (var item in RequiredStringList) { writer.WriteStringValue(item); } writer.WriteEndArray(); - writer.WritePropertyName("requiredModelCollection"u8); + writer.WritePropertyName("requiredModelList"u8); writer.WriteStartArray(); - foreach (var item in RequiredModelCollection) + foreach (var item in RequiredModelList) { writer.WriteObjectValue(item); } @@ -74,6 +116,129 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteBooleanValue(item.Value); } writer.WriteEndArray(); + if (RequiredNullableModelList != null && Optional.IsCollectionDefined(RequiredNullableModelList)) + { + writer.WritePropertyName("requiredNullableModelList"u8); + writer.WriteStartArray(); + foreach (var item in RequiredNullableModelList) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("requiredNullableModelList"); + } + if (RequiredNullableStringList != null && Optional.IsCollectionDefined(RequiredNullableStringList)) + { + writer.WritePropertyName("requiredNullableStringList"u8); + writer.WriteStartArray(); + foreach (var item in RequiredNullableStringList) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("requiredNullableStringList"); + } + if (RequiredNullableIntList != null && Optional.IsCollectionDefined(RequiredNullableIntList)) + { + writer.WritePropertyName("requiredNullableIntList"u8); + writer.WriteStartArray(); + foreach (var item in RequiredNullableIntList) + { + writer.WriteNumberValue(item); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("requiredNullableIntList"); + } + if (Optional.IsCollectionDefined(NonRequiredModelList)) + { + writer.WritePropertyName("nonRequiredModelList"u8); + writer.WriteStartArray(); + foreach (var item in NonRequiredModelList) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(NonRequiredStringList)) + { + writer.WritePropertyName("nonRequiredStringList"u8); + writer.WriteStartArray(); + foreach (var item in NonRequiredStringList) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(NonRequiredIntList)) + { + writer.WritePropertyName("nonRequiredIntList"u8); + writer.WriteStartArray(); + foreach (var item in NonRequiredIntList) + { + writer.WriteNumberValue(item); + } + writer.WriteEndArray(); + } + if (Optional.IsCollectionDefined(NonRequiredNullableModelList)) + { + if (NonRequiredNullableModelList != null) + { + writer.WritePropertyName("nonRequiredNullableModelList"u8); + writer.WriteStartArray(); + foreach (var item in NonRequiredNullableModelList) + { + writer.WriteObjectValue(item); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("nonRequiredNullableModelList"); + } + } + if (Optional.IsCollectionDefined(NonRequiredNullableStringList)) + { + if (NonRequiredNullableStringList != null) + { + writer.WritePropertyName("nonRequiredNullableStringList"u8); + writer.WriteStartArray(); + foreach (var item in NonRequiredNullableStringList) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("nonRequiredNullableStringList"); + } + } + if (Optional.IsCollectionDefined(NonRequiredNullableIntList)) + { + if (NonRequiredNullableIntList != null) + { + writer.WritePropertyName("nonRequiredNullableIntList"u8); + writer.WriteStartArray(); + foreach (var item in NonRequiredNullableIntList) + { + writer.WriteNumberValue(item); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("nonRequiredNullableIntList"); + } + } writer.WriteEndObject(); } diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/InputModel.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/InputModel.cs index da2fd237344..cb3a6dae9e7 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/InputModel.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/InputModel.cs @@ -18,76 +18,144 @@ public partial class InputModel /// Initializes a new instance of InputModel. /// Required string. /// Required int. + /// Required nullable int. + /// Required nullable string. /// Required model. - /// Required primitive value type collection. - /// Required primitive reference type collection. - /// Required model collection. + /// Required primitive value type collection. + /// Required primitive reference type collection. + /// Required model collection. /// Required model record. /// Required collection of which the element is a nullable float. /// Required collection of which the element is a nullable boolean. - /// , , , , , , or is null. - public InputModel(string requiredString, int requiredInt, BaseModel requiredModel, IEnumerable requiredIntCollection, IEnumerable requiredStringCollection, IEnumerable requiredModelCollection, IDictionary requiredModelRecord, IEnumerable requiredCollectionWithNullableFloatElement, IEnumerable requiredCollectionWithNullableBooleanElement) + /// Required model nullable collection. + /// Required string nullable collection. + /// Required int nullable collection. + /// , , , , , , or is null. + public InputModel(string requiredString, int requiredInt, int? requiredNullableInt, string requiredNullableString, BaseModel requiredModel, IEnumerable requiredIntList, IEnumerable requiredStringList, IEnumerable requiredModelList, IDictionary requiredModelRecord, IEnumerable requiredCollectionWithNullableFloatElement, IEnumerable requiredCollectionWithNullableBooleanElement, IEnumerable requiredNullableModelList, IEnumerable requiredNullableStringList, IEnumerable requiredNullableIntList) { Argument.AssertNotNull(requiredString, nameof(requiredString)); Argument.AssertNotNull(requiredModel, nameof(requiredModel)); - Argument.AssertNotNull(requiredIntCollection, nameof(requiredIntCollection)); - Argument.AssertNotNull(requiredStringCollection, nameof(requiredStringCollection)); - Argument.AssertNotNull(requiredModelCollection, nameof(requiredModelCollection)); + Argument.AssertNotNull(requiredIntList, nameof(requiredIntList)); + Argument.AssertNotNull(requiredStringList, nameof(requiredStringList)); + Argument.AssertNotNull(requiredModelList, nameof(requiredModelList)); Argument.AssertNotNull(requiredModelRecord, nameof(requiredModelRecord)); Argument.AssertNotNull(requiredCollectionWithNullableFloatElement, nameof(requiredCollectionWithNullableFloatElement)); Argument.AssertNotNull(requiredCollectionWithNullableBooleanElement, nameof(requiredCollectionWithNullableBooleanElement)); RequiredString = requiredString; RequiredInt = requiredInt; + RequiredNullableInt = requiredNullableInt; + RequiredNullableString = requiredNullableString; RequiredModel = requiredModel; - RequiredIntCollection = requiredIntCollection.ToList(); - RequiredStringCollection = requiredStringCollection.ToList(); - RequiredModelCollection = requiredModelCollection.ToList(); + RequiredIntList = requiredIntList.ToList(); + RequiredStringList = requiredStringList.ToList(); + RequiredModelList = requiredModelList.ToList(); RequiredModelRecord = requiredModelRecord; RequiredCollectionWithNullableFloatElement = requiredCollectionWithNullableFloatElement.ToList(); RequiredCollectionWithNullableBooleanElement = requiredCollectionWithNullableBooleanElement.ToList(); + RequiredNullableModelList = requiredNullableModelList?.ToList(); + RequiredNullableStringList = requiredNullableStringList?.ToList(); + RequiredNullableIntList = requiredNullableIntList?.ToList(); + NonRequiredModelList = new ChangeTrackingList(); + NonRequiredStringList = new ChangeTrackingList(); + NonRequiredIntList = new ChangeTrackingList(); + NonRequiredNullableModelList = new ChangeTrackingList(); + NonRequiredNullableStringList = new ChangeTrackingList(); + NonRequiredNullableIntList = new ChangeTrackingList(); } /// Initializes a new instance of InputModel. /// Required string. /// Required int. + /// Required nullable int. + /// Required nullable string. + /// Optional nullable int. + /// Optional nullable string. /// Required model. - /// Required primitive value type collection. - /// Required primitive reference type collection. - /// Required model collection. + /// Required primitive value type collection. + /// Required primitive reference type collection. + /// Required model collection. /// Required model record. /// Required collection of which the element is a nullable float. /// Required collection of which the element is a nullable boolean. - internal InputModel(string requiredString, int requiredInt, BaseModel requiredModel, IList requiredIntCollection, IList requiredStringCollection, IList requiredModelCollection, IDictionary requiredModelRecord, IList requiredCollectionWithNullableFloatElement, IList requiredCollectionWithNullableBooleanElement) + /// Required model nullable collection. + /// Required string nullable collection. + /// Required int nullable collection. + /// Optional model collection. + /// Optional string collection. + /// Optional int collection. + /// Optional model nullable collection. + /// Optional string nullable collection. + /// Optional int nullable collection. + internal InputModel(string requiredString, int requiredInt, int? requiredNullableInt, string requiredNullableString, int? nonRequiredNullableInt, string nonRequiredNullableString, BaseModel requiredModel, IList requiredIntList, IList requiredStringList, IList requiredModelList, IDictionary requiredModelRecord, IList requiredCollectionWithNullableFloatElement, IList requiredCollectionWithNullableBooleanElement, IList requiredNullableModelList, IList requiredNullableStringList, IList requiredNullableIntList, IList nonRequiredModelList, IList nonRequiredStringList, IList nonRequiredIntList, IList nonRequiredNullableModelList, IList nonRequiredNullableStringList, IList nonRequiredNullableIntList) { RequiredString = requiredString; RequiredInt = requiredInt; + RequiredNullableInt = requiredNullableInt; + RequiredNullableString = requiredNullableString; + NonRequiredNullableInt = nonRequiredNullableInt; + NonRequiredNullableString = nonRequiredNullableString; RequiredModel = requiredModel; - RequiredIntCollection = requiredIntCollection; - RequiredStringCollection = requiredStringCollection; - RequiredModelCollection = requiredModelCollection; + RequiredIntList = requiredIntList; + RequiredStringList = requiredStringList; + RequiredModelList = requiredModelList; RequiredModelRecord = requiredModelRecord; RequiredCollectionWithNullableFloatElement = requiredCollectionWithNullableFloatElement; RequiredCollectionWithNullableBooleanElement = requiredCollectionWithNullableBooleanElement; + RequiredNullableModelList = requiredNullableModelList; + RequiredNullableStringList = requiredNullableStringList; + RequiredNullableIntList = requiredNullableIntList; + NonRequiredModelList = nonRequiredModelList; + NonRequiredStringList = nonRequiredStringList; + NonRequiredIntList = nonRequiredIntList; + NonRequiredNullableModelList = nonRequiredNullableModelList; + NonRequiredNullableStringList = nonRequiredNullableStringList; + NonRequiredNullableIntList = nonRequiredNullableIntList; } /// Required string. public string RequiredString { get; } /// Required int. public int RequiredInt { get; } + /// Required nullable int. + public int? RequiredNullableInt { get; } + /// Required nullable string. + public string RequiredNullableString { get; } + /// Optional nullable int. + public int? NonRequiredNullableInt { get; set; } + /// Optional nullable string. + public string NonRequiredNullableString { get; set; } /// Required model. public BaseModel RequiredModel { get; } /// Required primitive value type collection. - public IList RequiredIntCollection { get; } + public IList RequiredIntList { get; } /// Required primitive reference type collection. - public IList RequiredStringCollection { get; } + public IList RequiredStringList { get; } /// Required model collection. - public IList RequiredModelCollection { get; } + public IList RequiredModelList { get; } /// Required model record. public IDictionary RequiredModelRecord { get; } /// Required collection of which the element is a nullable float. public IList RequiredCollectionWithNullableFloatElement { get; } /// Required collection of which the element is a nullable boolean. public IList RequiredCollectionWithNullableBooleanElement { get; } + /// Required model nullable collection. + public IList RequiredNullableModelList { get; set; } + /// Required string nullable collection. + public IList RequiredNullableStringList { get; set; } + /// Required int nullable collection. + public IList RequiredNullableIntList { get; set; } + /// Optional model collection. + public IList NonRequiredModelList { get; } + /// Optional string collection. + public IList NonRequiredStringList { get; } + /// Optional int collection. + public IList NonRequiredIntList { get; } + /// Optional model nullable collection. + public IList NonRequiredNullableModelList { get; set; } + /// Optional string nullable collection. + public IList NonRequiredNullableStringList { get; set; } + /// Optional int nullable collection. + public IList NonRequiredNullableIntList { get; set; } } } diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/NoUseBase.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/NoUseBase.cs index 9f020bc6d9e..f08a0510f3c 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/NoUseBase.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/NoUseBase.cs @@ -24,6 +24,6 @@ internal NoUseBase(string baseModelProp) } /// base model property. - public string BaseModelProp { get; set; } + public string BaseModelProp { get; } } } diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/OutputModel.Serialization.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/OutputModel.Serialization.cs index fc76fa8c5b8..153268bc00e 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/OutputModel.Serialization.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/OutputModel.Serialization.cs @@ -23,8 +23,12 @@ internal static OutputModel DeserializeOutputModel(JsonElement element) string requiredString = default; int requiredInt = default; DerivedModel requiredModel = default; - IReadOnlyList requiredCollection = default; + IReadOnlyList requiredList = default; IReadOnlyDictionary requiredModelRecord = default; + Optional> optionalList = default; + Optional> optionalNullableList = default; + Optional> optionalRecord = default; + Optional> optionalNullableRecord = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("requiredString"u8)) @@ -42,14 +46,14 @@ internal static OutputModel DeserializeOutputModel(JsonElement element) requiredModel = DerivedModel.DeserializeDerivedModel(property.Value); continue; } - if (property.NameEquals("requiredCollection"u8)) + if (property.NameEquals("requiredList"u8)) { List array = new List(); foreach (var item in property.Value.EnumerateArray()) { array.Add(CollectionItem.DeserializeCollectionItem(item)); } - requiredCollection = array; + requiredList = array; continue; } if (property.NameEquals("requiredModelRecord"u8)) @@ -62,8 +66,64 @@ internal static OutputModel DeserializeOutputModel(JsonElement element) requiredModelRecord = dictionary; continue; } + if (property.NameEquals("optionalList"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(CollectionItem.DeserializeCollectionItem(item)); + } + optionalList = array; + continue; + } + if (property.NameEquals("optionalNullableList"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(CollectionItem.DeserializeCollectionItem(item)); + } + optionalNullableList = array; + continue; + } + if (property.NameEquals("optionalRecord"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, RecordItem.DeserializeRecordItem(property0.Value)); + } + optionalRecord = dictionary; + continue; + } + if (property.NameEquals("optionalNullableRecord"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + Dictionary dictionary = new Dictionary(); + foreach (var property0 in property.Value.EnumerateObject()) + { + dictionary.Add(property0.Name, RecordItem.DeserializeRecordItem(property0.Value)); + } + optionalNullableRecord = dictionary; + continue; + } } - return new OutputModel(requiredString, requiredInt, requiredModel, requiredCollection, requiredModelRecord); + return new OutputModel(requiredString, requiredInt, requiredModel, requiredList, requiredModelRecord, Optional.ToList(optionalList), Optional.ToList(optionalNullableList), Optional.ToDictionary(optionalRecord), Optional.ToDictionary(optionalNullableRecord)); } /// Deserializes the model from a raw response. diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/OutputModel.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/OutputModel.cs index 0b750afc302..fc836f5cdc3 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/OutputModel.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/OutputModel.cs @@ -19,36 +19,48 @@ public partial class OutputModel /// Required string. /// Required int. /// Required model. - /// Required collection. + /// Required collection. /// Required model record. - /// , , or is null. - internal OutputModel(string requiredString, int requiredInt, DerivedModel requiredModel, IEnumerable requiredCollection, IReadOnlyDictionary requiredModelRecord) + /// , , or is null. + internal OutputModel(string requiredString, int requiredInt, DerivedModel requiredModel, IEnumerable requiredList, IReadOnlyDictionary requiredModelRecord) { Argument.AssertNotNull(requiredString, nameof(requiredString)); Argument.AssertNotNull(requiredModel, nameof(requiredModel)); - Argument.AssertNotNull(requiredCollection, nameof(requiredCollection)); + Argument.AssertNotNull(requiredList, nameof(requiredList)); Argument.AssertNotNull(requiredModelRecord, nameof(requiredModelRecord)); RequiredString = requiredString; RequiredInt = requiredInt; RequiredModel = requiredModel; - RequiredCollection = requiredCollection.ToList(); + RequiredList = requiredList.ToList(); RequiredModelRecord = requiredModelRecord; + OptionalList = new ChangeTrackingList(); + OptionalNullableList = new ChangeTrackingList(); + OptionalRecord = new ChangeTrackingDictionary(); + OptionalNullableRecord = new ChangeTrackingDictionary(); } /// Initializes a new instance of OutputModel. /// Required string. /// Required int. /// Required model. - /// Required collection. + /// Required collection. /// Required model record. - internal OutputModel(string requiredString, int requiredInt, DerivedModel requiredModel, IReadOnlyList requiredCollection, IReadOnlyDictionary requiredModelRecord) + /// Optional model collection. + /// Optional model nullable collection. + /// Optional model record. + /// Optional model nullable record. + internal OutputModel(string requiredString, int requiredInt, DerivedModel requiredModel, IReadOnlyList requiredList, IReadOnlyDictionary requiredModelRecord, IReadOnlyList optionalList, IReadOnlyList optionalNullableList, IReadOnlyDictionary optionalRecord, IReadOnlyDictionary optionalNullableRecord) { RequiredString = requiredString; RequiredInt = requiredInt; RequiredModel = requiredModel; - RequiredCollection = requiredCollection; + RequiredList = requiredList; RequiredModelRecord = requiredModelRecord; + OptionalList = optionalList; + OptionalNullableList = optionalNullableList; + OptionalRecord = optionalRecord; + OptionalNullableRecord = optionalNullableRecord; } /// Required string. @@ -58,8 +70,16 @@ internal OutputModel(string requiredString, int requiredInt, DerivedModel requir /// Required model. public DerivedModel RequiredModel { get; } /// Required collection. - public IReadOnlyList RequiredCollection { get; } + public IReadOnlyList RequiredList { get; } /// Required model record. public IReadOnlyDictionary RequiredModelRecord { get; } + /// Optional model collection. + public IReadOnlyList OptionalList { get; } + /// Optional model nullable collection. + public IReadOnlyList OptionalNullableList { get; } + /// Optional model record. + public IReadOnlyDictionary OptionalRecord { get; } + /// Optional model nullable record. + public IReadOnlyDictionary OptionalNullableRecord { get; } } } diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RecordItem.Serialization.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RecordItem.Serialization.cs index a4e75ff88b8..06722d0d0b2 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RecordItem.Serialization.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RecordItem.Serialization.cs @@ -17,9 +17,9 @@ public partial class RecordItem : IUtf8JsonSerializable void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteStartObject(); - writer.WritePropertyName("requiredCollection"u8); + writer.WritePropertyName("requiredList"u8); writer.WriteStartArray(); - foreach (var item in RequiredCollection) + foreach (var item in RequiredList) { writer.WriteObjectValue(item); } @@ -33,21 +33,21 @@ internal static RecordItem DeserializeRecordItem(JsonElement element) { return null; } - IList requiredCollection = default; + IList requiredList = default; foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("requiredCollection"u8)) + if (property.NameEquals("requiredList"u8)) { List array = new List(); foreach (var item in property.Value.EnumerateArray()) { array.Add(CollectionItem.DeserializeCollectionItem(item)); } - requiredCollection = array; + requiredList = array; continue; } } - return new RecordItem(requiredCollection); + return new RecordItem(requiredList); } /// Deserializes the model from a raw response. diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RecordItem.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RecordItem.cs index 28539839cbf..49424eef35f 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RecordItem.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RecordItem.cs @@ -15,16 +15,16 @@ namespace ModelsTypeSpec.Models public partial class RecordItem : DerivedModel { /// Initializes a new instance of RecordItem. - /// Required collection. - /// is null. - public RecordItem(IEnumerable requiredCollection) : base(requiredCollection) + /// Required collection. + /// is null. + public RecordItem(IEnumerable requiredList) : base(requiredList) { - Argument.AssertNotNull(requiredCollection, nameof(requiredCollection)); + Argument.AssertNotNull(requiredList, nameof(requiredList)); } /// Initializes a new instance of RecordItem. - /// Required collection. - internal RecordItem(IList requiredCollection) : base(requiredCollection) + /// Required collection. + internal RecordItem(IList requiredList) : base(requiredList) { } } diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs index cffefa31813..dffe43016b8 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripModel.Serialization.cs @@ -22,6 +22,58 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteStringValue(RequiredString); writer.WritePropertyName("requiredInt"u8); writer.WriteNumberValue(RequiredInt); + if (Optional.IsDefined(NonRequiredString)) + { + writer.WritePropertyName("nonRequiredString"u8); + writer.WriteStringValue(NonRequiredString); + } + if (Optional.IsDefined(NonRequiredInt)) + { + writer.WritePropertyName("nonRequiredInt"u8); + writer.WriteNumberValue(NonRequiredInt.Value); + } + if (RequiredNullableInt != null) + { + writer.WritePropertyName("requiredNullableInt"u8); + writer.WriteNumberValue(RequiredNullableInt.Value); + } + else + { + writer.WriteNull("requiredNullableInt"); + } + if (RequiredNullableString != null) + { + writer.WritePropertyName("requiredNullableString"u8); + writer.WriteStringValue(RequiredNullableString); + } + else + { + writer.WriteNull("requiredNullableString"); + } + if (Optional.IsDefined(NonRequiredNullableInt)) + { + if (NonRequiredNullableInt != null) + { + writer.WritePropertyName("nonRequiredNullableInt"u8); + writer.WriteNumberValue(NonRequiredNullableInt.Value); + } + else + { + writer.WriteNull("nonRequiredNullableInt"); + } + } + if (Optional.IsDefined(NonRequiredNullableString)) + { + if (NonRequiredNullableString != null) + { + writer.WritePropertyName("nonRequiredNullableString"u8); + writer.WriteStringValue(NonRequiredNullableString); + } + else + { + writer.WriteNull("nonRequiredNullableString"); + } + } writer.WritePropertyName("requiredModel"u8); writer.WriteObjectValue(RequiredModel); writer.WritePropertyName("requiredFixedStringEnum"u8); @@ -30,9 +82,9 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) writer.WriteNumberValue((int)RequiredFixedIntEnum); writer.WritePropertyName("requiredExtensibleEnum"u8); writer.WriteStringValue(RequiredExtensibleEnum.ToString()); - writer.WritePropertyName("requiredCollection"u8); + writer.WritePropertyName("requiredList"u8); writer.WriteStartArray(); - foreach (var item in RequiredCollection) + foreach (var item in RequiredList) { writer.WriteObjectValue(item); } @@ -117,6 +169,68 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } writer.WriteEndArray(); } + if (RequiredNullableIntList != null && Optional.IsCollectionDefined(RequiredNullableIntList)) + { + writer.WritePropertyName("requiredNullableIntList"u8); + writer.WriteStartArray(); + foreach (var item in RequiredNullableIntList) + { + writer.WriteNumberValue(item); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("requiredNullableIntList"); + } + if (RequiredNullableStringList != null && Optional.IsCollectionDefined(RequiredNullableStringList)) + { + writer.WritePropertyName("requiredNullableStringList"u8); + writer.WriteStartArray(); + foreach (var item in RequiredNullableStringList) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("requiredNullableStringList"); + } + if (Optional.IsCollectionDefined(NonRequiredNullableIntList)) + { + if (NonRequiredNullableIntList != null) + { + writer.WritePropertyName("nonRequiredNullableIntList"u8); + writer.WriteStartArray(); + foreach (var item in NonRequiredNullableIntList) + { + writer.WriteNumberValue(item); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("nonRequiredNullableIntList"); + } + } + if (Optional.IsCollectionDefined(NonRequiredNullableStringList)) + { + if (NonRequiredNullableStringList != null) + { + writer.WritePropertyName("nonRequiredNullableStringList"u8); + writer.WriteStartArray(); + foreach (var item in NonRequiredNullableStringList) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + else + { + writer.WriteNull("nonRequiredNullableStringList"); + } + } writer.WriteEndObject(); } @@ -128,11 +242,19 @@ internal static RoundTripModel DeserializeRoundTripModel(JsonElement element) } string requiredString = default; int requiredInt = default; + Optional nonRequiredString = default; + Optional nonRequiredInt = default; + int? requiredNullableInt = default; + string requiredNullableString = default; + Optional nonRequiredNullableInt = default; + Optional nonRequiredNullableString = default; + int requiredReadonlyInt = default; + Optional nonRequiredReadonlyInt = default; BaseModelWithDiscriminator requiredModel = default; FixedStringEnum requiredFixedStringEnum = default; FixedIntEnum requiredFixedIntEnum = default; ExtensibleEnum requiredExtensibleEnum = default; - IList requiredCollection = default; + IList requiredList = default; IDictionary requiredIntRecord = default; IDictionary requiredStringRecord = default; IDictionary requiredModelRecord = default; @@ -144,6 +266,10 @@ internal static RoundTripModel DeserializeRoundTripModel(JsonElement element) Optional optionalUnknown = default; IList requiredInt8Array = default; Optional> optionalInt8Array = default; + IList requiredNullableIntList = default; + IList requiredNullableStringList = default; + Optional> nonRequiredNullableIntList = default; + Optional> nonRequiredNullableStringList = default; foreach (var property in element.EnumerateObject()) { if (property.NameEquals("requiredString"u8)) @@ -156,6 +282,74 @@ internal static RoundTripModel DeserializeRoundTripModel(JsonElement element) requiredInt = property.Value.GetInt32(); continue; } + if (property.NameEquals("nonRequiredString"u8)) + { + nonRequiredString = property.Value.GetString(); + continue; + } + if (property.NameEquals("nonRequiredInt"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + nonRequiredInt = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("requiredNullableInt"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + requiredNullableInt = null; + continue; + } + requiredNullableInt = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("requiredNullableString"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + requiredNullableString = null; + continue; + } + requiredNullableString = property.Value.GetString(); + continue; + } + if (property.NameEquals("nonRequiredNullableInt"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + nonRequiredNullableInt = null; + continue; + } + nonRequiredNullableInt = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("nonRequiredNullableString"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + nonRequiredNullableString = null; + continue; + } + nonRequiredNullableString = property.Value.GetString(); + continue; + } + if (property.NameEquals("requiredReadonlyInt"u8)) + { + requiredReadonlyInt = property.Value.GetInt32(); + continue; + } + if (property.NameEquals("nonRequiredReadonlyInt"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + nonRequiredReadonlyInt = property.Value.GetInt32(); + continue; + } if (property.NameEquals("requiredModel"u8)) { requiredModel = BaseModelWithDiscriminator.DeserializeBaseModelWithDiscriminator(property.Value); @@ -176,14 +370,14 @@ internal static RoundTripModel DeserializeRoundTripModel(JsonElement element) requiredExtensibleEnum = new ExtensibleEnum(property.Value.GetString()); continue; } - if (property.NameEquals("requiredCollection"u8)) + if (property.NameEquals("requiredList"u8)) { List array = new List(); foreach (var item in property.Value.EnumerateArray()) { array.Add(CollectionItem.DeserializeCollectionItem(item)); } - requiredCollection = array; + requiredList = array; continue; } if (property.NameEquals("requiredIntRecord"u8)) @@ -292,8 +486,66 @@ internal static RoundTripModel DeserializeRoundTripModel(JsonElement element) optionalInt8Array = array; continue; } + if (property.NameEquals("requiredNullableIntList"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + requiredNullableIntList = new ChangeTrackingList(); + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetInt32()); + } + requiredNullableIntList = array; + continue; + } + if (property.NameEquals("requiredNullableStringList"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + requiredNullableStringList = new ChangeTrackingList(); + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + requiredNullableStringList = array; + continue; + } + if (property.NameEquals("nonRequiredNullableIntList"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetInt32()); + } + nonRequiredNullableIntList = array; + continue; + } + if (property.NameEquals("nonRequiredNullableStringList"u8)) + { + if (property.Value.ValueKind == JsonValueKind.Null) + { + continue; + } + List array = new List(); + foreach (var item in property.Value.EnumerateArray()) + { + array.Add(item.GetString()); + } + nonRequiredNullableStringList = array; + continue; + } } - return new RoundTripModel(requiredString, requiredInt, requiredModel, requiredFixedStringEnum, requiredFixedIntEnum, requiredExtensibleEnum, requiredCollection, requiredIntRecord, requiredStringRecord, requiredModelRecord, requiredBytes, optionalBytes.Value, requiredUint8Array, Optional.ToList(optionalUint8Array), requiredUnknown, optionalUnknown.Value, requiredInt8Array, Optional.ToList(optionalInt8Array)); + return new RoundTripModel(requiredString, requiredInt, nonRequiredString.Value, Optional.ToNullable(nonRequiredInt), requiredNullableInt, requiredNullableString, Optional.ToNullable(nonRequiredNullableInt), nonRequiredNullableString.Value, requiredReadonlyInt, Optional.ToNullable(nonRequiredReadonlyInt), requiredModel, requiredFixedStringEnum, requiredFixedIntEnum, requiredExtensibleEnum, requiredList, requiredIntRecord, requiredStringRecord, requiredModelRecord, requiredBytes, optionalBytes.Value, requiredUint8Array, Optional.ToList(optionalUint8Array), requiredUnknown, optionalUnknown.Value, requiredInt8Array, Optional.ToList(optionalInt8Array), requiredNullableIntList, requiredNullableStringList, Optional.ToList(nonRequiredNullableIntList), Optional.ToList(nonRequiredNullableStringList)); } /// Deserializes the model from a raw response. diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripModel.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripModel.cs index b2354e1c1c4..01a60c5766b 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripModel.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripModel.cs @@ -18,11 +18,13 @@ public partial class RoundTripModel : BaseModel /// Initializes a new instance of RoundTripModel. /// Required string, illustrating a reference type property. /// Required int, illustrating a value type property. + /// Required nullable int. + /// Required nullable string. /// Required model with discriminator. /// Required fixed string enum. /// Required fixed int enum. /// Required extensible enum. - /// Required collection. + /// Required collection. /// Required int record. /// Required string record. /// Required Model Record. @@ -30,12 +32,14 @@ public partial class RoundTripModel : BaseModel /// Required uint8[]. /// Required unknown. /// Required int8[]. - /// , , , , , , , , or is null. - public RoundTripModel(string requiredString, int requiredInt, BaseModelWithDiscriminator requiredModel, FixedStringEnum requiredFixedStringEnum, FixedIntEnum requiredFixedIntEnum, ExtensibleEnum requiredExtensibleEnum, IEnumerable requiredCollection, IDictionary requiredIntRecord, IDictionary requiredStringRecord, IDictionary requiredModelRecord, BinaryData requiredBytes, IEnumerable requiredUint8Array, BinaryData requiredUnknown, IEnumerable requiredInt8Array) + /// Required nullable int list. + /// Required nullable string list. + /// , , , , , , , , or is null. + public RoundTripModel(string requiredString, int requiredInt, int? requiredNullableInt, string requiredNullableString, BaseModelWithDiscriminator requiredModel, FixedStringEnum requiredFixedStringEnum, FixedIntEnum requiredFixedIntEnum, ExtensibleEnum requiredExtensibleEnum, IEnumerable requiredList, IDictionary requiredIntRecord, IDictionary requiredStringRecord, IDictionary requiredModelRecord, BinaryData requiredBytes, IEnumerable requiredUint8Array, BinaryData requiredUnknown, IEnumerable requiredInt8Array, IEnumerable requiredNullableIntList, IEnumerable requiredNullableStringList) { Argument.AssertNotNull(requiredString, nameof(requiredString)); Argument.AssertNotNull(requiredModel, nameof(requiredModel)); - Argument.AssertNotNull(requiredCollection, nameof(requiredCollection)); + Argument.AssertNotNull(requiredList, nameof(requiredList)); Argument.AssertNotNull(requiredIntRecord, nameof(requiredIntRecord)); Argument.AssertNotNull(requiredStringRecord, nameof(requiredStringRecord)); Argument.AssertNotNull(requiredModelRecord, nameof(requiredModelRecord)); @@ -46,11 +50,13 @@ public RoundTripModel(string requiredString, int requiredInt, BaseModelWithDiscr RequiredString = requiredString; RequiredInt = requiredInt; + RequiredNullableInt = requiredNullableInt; + RequiredNullableString = requiredNullableString; RequiredModel = requiredModel; RequiredFixedStringEnum = requiredFixedStringEnum; RequiredFixedIntEnum = requiredFixedIntEnum; RequiredExtensibleEnum = requiredExtensibleEnum; - RequiredCollection = requiredCollection.ToList(); + RequiredList = requiredList.ToList(); RequiredIntRecord = requiredIntRecord; RequiredStringRecord = requiredStringRecord; RequiredModelRecord = requiredModelRecord; @@ -60,16 +66,28 @@ public RoundTripModel(string requiredString, int requiredInt, BaseModelWithDiscr RequiredUnknown = requiredUnknown; RequiredInt8Array = requiredInt8Array.ToList(); OptionalInt8Array = new ChangeTrackingList(); + RequiredNullableIntList = requiredNullableIntList?.ToList(); + RequiredNullableStringList = requiredNullableStringList?.ToList(); + NonRequiredNullableIntList = new ChangeTrackingList(); + NonRequiredNullableStringList = new ChangeTrackingList(); } /// Initializes a new instance of RoundTripModel. /// Required string, illustrating a reference type property. /// Required int, illustrating a value type property. + /// Optional string. + /// Optional int. + /// Required nullable int. + /// Required nullable string. + /// Optional nullable int. + /// Optional nullable string. + /// Required readonly int. + /// Optional readonly int. /// Required model with discriminator. /// Required fixed string enum. /// Required fixed int enum. /// Required extensible enum. - /// Required collection. + /// Required collection. /// Required int record. /// Required string record. /// Required Model Record. @@ -81,15 +99,27 @@ public RoundTripModel(string requiredString, int requiredInt, BaseModelWithDiscr /// Optional unknown. /// Required int8[]. /// Optional int8[]. - internal RoundTripModel(string requiredString, int requiredInt, BaseModelWithDiscriminator requiredModel, FixedStringEnum requiredFixedStringEnum, FixedIntEnum requiredFixedIntEnum, ExtensibleEnum requiredExtensibleEnum, IList requiredCollection, IDictionary requiredIntRecord, IDictionary requiredStringRecord, IDictionary requiredModelRecord, BinaryData requiredBytes, BinaryData optionalBytes, IList requiredUint8Array, IList optionalUint8Array, BinaryData requiredUnknown, BinaryData optionalUnknown, IList requiredInt8Array, IList optionalInt8Array) + /// Required nullable int list. + /// Required nullable string list. + /// Optional nullable model list. + /// Optional nullable string list. + internal RoundTripModel(string requiredString, int requiredInt, string nonRequiredString, int? nonRequiredInt, int? requiredNullableInt, string requiredNullableString, int? nonRequiredNullableInt, string nonRequiredNullableString, int requiredReadonlyInt, int? nonRequiredReadonlyInt, BaseModelWithDiscriminator requiredModel, FixedStringEnum requiredFixedStringEnum, FixedIntEnum requiredFixedIntEnum, ExtensibleEnum requiredExtensibleEnum, IList requiredList, IDictionary requiredIntRecord, IDictionary requiredStringRecord, IDictionary requiredModelRecord, BinaryData requiredBytes, BinaryData optionalBytes, IList requiredUint8Array, IList optionalUint8Array, BinaryData requiredUnknown, BinaryData optionalUnknown, IList requiredInt8Array, IList optionalInt8Array, IList requiredNullableIntList, IList requiredNullableStringList, IList nonRequiredNullableIntList, IList nonRequiredNullableStringList) { RequiredString = requiredString; RequiredInt = requiredInt; + NonRequiredString = nonRequiredString; + NonRequiredInt = nonRequiredInt; + RequiredNullableInt = requiredNullableInt; + RequiredNullableString = requiredNullableString; + NonRequiredNullableInt = nonRequiredNullableInt; + NonRequiredNullableString = nonRequiredNullableString; + RequiredReadonlyInt = requiredReadonlyInt; + NonRequiredReadonlyInt = nonRequiredReadonlyInt; RequiredModel = requiredModel; RequiredFixedStringEnum = requiredFixedStringEnum; RequiredFixedIntEnum = requiredFixedIntEnum; RequiredExtensibleEnum = requiredExtensibleEnum; - RequiredCollection = requiredCollection; + RequiredList = requiredList; RequiredIntRecord = requiredIntRecord; RequiredStringRecord = requiredStringRecord; RequiredModelRecord = requiredModelRecord; @@ -101,12 +131,32 @@ internal RoundTripModel(string requiredString, int requiredInt, BaseModelWithDis OptionalUnknown = optionalUnknown; RequiredInt8Array = requiredInt8Array; OptionalInt8Array = optionalInt8Array; + RequiredNullableIntList = requiredNullableIntList; + RequiredNullableStringList = requiredNullableStringList; + NonRequiredNullableIntList = nonRequiredNullableIntList; + NonRequiredNullableStringList = nonRequiredNullableStringList; } /// Required string, illustrating a reference type property. public string RequiredString { get; set; } /// Required int, illustrating a value type property. public int RequiredInt { get; set; } + /// Optional string. + public string NonRequiredString { get; set; } + /// Optional int. + public int? NonRequiredInt { get; set; } + /// Required nullable int. + public int? RequiredNullableInt { get; set; } + /// Required nullable string. + public string RequiredNullableString { get; set; } + /// Optional nullable int. + public int? NonRequiredNullableInt { get; set; } + /// Optional nullable string. + public string NonRequiredNullableString { get; set; } + /// Required readonly int. + public int RequiredReadonlyInt { get; } + /// Optional readonly int. + public int? NonRequiredReadonlyInt { get; } /// /// Required model with discriminator /// Please note is the base class. According to the scenario, a derived class of the base class might need to be assigned here, or this property needs to be casted to one of the possible derived classes. @@ -120,7 +170,7 @@ internal RoundTripModel(string requiredString, int requiredInt, BaseModelWithDis /// Required extensible enum. public ExtensibleEnum RequiredExtensibleEnum { get; set; } /// Required collection. - public IList RequiredCollection { get; } + public IList RequiredList { get; } /// Required int record. public IDictionary RequiredIntRecord { get; } /// Required string record. @@ -231,5 +281,13 @@ internal RoundTripModel(string requiredString, int requiredInt, BaseModelWithDis public IList RequiredInt8Array { get; } /// Optional int8[]. public IList OptionalInt8Array { get; } + /// Required nullable int list. + public IList RequiredNullableIntList { get; set; } + /// Required nullable string list. + public IList RequiredNullableStringList { get; set; } + /// Optional nullable model list. + public IList NonRequiredNullableIntList { get; set; } + /// Optional nullable string list. + public IList NonRequiredNullableStringList { get; set; } } } diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOnNoUse.Serialization.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOnNoUse.Serialization.cs index c52b9e5c7ca..afbb72e3275 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOnNoUse.Serialization.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOnNoUse.Serialization.cs @@ -17,9 +17,9 @@ public partial class RoundTripOnNoUse : IUtf8JsonSerializable void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) { writer.WriteStartObject(); - writer.WritePropertyName("requiredCollection"u8); + writer.WritePropertyName("requiredList"u8); writer.WriteStartArray(); - foreach (var item in RequiredCollection) + foreach (var item in RequiredList) { writer.WriteObjectValue(item); } @@ -35,18 +35,18 @@ internal static RoundTripOnNoUse DeserializeRoundTripOnNoUse(JsonElement element { return null; } - IList requiredCollection = default; + IList requiredList = default; string baseModelProp = default; foreach (var property in element.EnumerateObject()) { - if (property.NameEquals("requiredCollection"u8)) + if (property.NameEquals("requiredList"u8)) { List array = new List(); foreach (var item in property.Value.EnumerateArray()) { array.Add(CollectionItem.DeserializeCollectionItem(item)); } - requiredCollection = array; + requiredList = array; continue; } if (property.NameEquals("baseModelProp"u8)) @@ -55,7 +55,7 @@ internal static RoundTripOnNoUse DeserializeRoundTripOnNoUse(JsonElement element continue; } } - return new RoundTripOnNoUse(baseModelProp, requiredCollection); + return new RoundTripOnNoUse(baseModelProp, requiredList); } /// Deserializes the model from a raw response. diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOnNoUse.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOnNoUse.cs index e0bb4c89618..432823dd08f 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOnNoUse.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOnNoUse.cs @@ -17,28 +17,28 @@ public partial class RoundTripOnNoUse : NoUseBase { /// Initializes a new instance of RoundTripOnNoUse. /// base model property. - /// Required collection. - /// or is null. - public RoundTripOnNoUse(string baseModelProp, IEnumerable requiredCollection) : base(baseModelProp) + /// Required collection. + /// or is null. + public RoundTripOnNoUse(string baseModelProp, IEnumerable requiredList) : base(baseModelProp) { Argument.AssertNotNull(baseModelProp, nameof(baseModelProp)); - Argument.AssertNotNull(requiredCollection, nameof(requiredCollection)); + Argument.AssertNotNull(requiredList, nameof(requiredList)); - RequiredCollection = requiredCollection.ToList(); + RequiredList = requiredList.ToList(); } /// Initializes a new instance of RoundTripOnNoUse. /// base model property. - /// Required collection. + /// Required collection. /// is null. - internal RoundTripOnNoUse(string baseModelProp, IList requiredCollection) : base(baseModelProp) + internal RoundTripOnNoUse(string baseModelProp, IList requiredList) : base(baseModelProp) { Argument.AssertNotNull(baseModelProp, nameof(baseModelProp)); - RequiredCollection = requiredCollection; + RequiredList = requiredList; } /// Required collection. - public IList RequiredCollection { get; } + public IList RequiredList { get; } } } diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOptionalModel.Serialization.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOptionalModel.Serialization.cs index 21aaa594c62..ffba2999aa3 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOptionalModel.Serialization.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOptionalModel.Serialization.cs @@ -48,11 +48,11 @@ void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) } writer.WriteEndArray(); } - if (Optional.IsCollectionDefined(OptionalModelCollection)) + if (Optional.IsCollectionDefined(OptionalModelList)) { - writer.WritePropertyName("optionalModelCollection"u8); + writer.WritePropertyName("optionalModelList"u8); writer.WriteStartArray(); - foreach (var item in OptionalModelCollection) + foreach (var item in OptionalModelList) { writer.WriteObjectValue(item); } @@ -149,7 +149,7 @@ internal static RoundTripOptionalModel DeserializeRoundTripOptionalModel(JsonEle Optional optionalInt = default; Optional> optionalStringList = default; Optional> optionalIntList = default; - Optional> optionalModelCollection = default; + Optional> optionalModelList = default; Optional optionalModel = default; Optional optionalModelWithPropertiesOnBase = default; Optional optionalFixedStringEnum = default; @@ -204,7 +204,7 @@ internal static RoundTripOptionalModel DeserializeRoundTripOptionalModel(JsonEle optionalIntList = array; continue; } - if (property.NameEquals("optionalModelCollection"u8)) + if (property.NameEquals("optionalModelList"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) { @@ -215,7 +215,7 @@ internal static RoundTripOptionalModel DeserializeRoundTripOptionalModel(JsonEle { array.Add(CollectionItem.DeserializeCollectionItem(item)); } - optionalModelCollection = array; + optionalModelList = array; continue; } if (property.NameEquals("optionalModel"u8)) @@ -336,7 +336,7 @@ internal static RoundTripOptionalModel DeserializeRoundTripOptionalModel(JsonEle continue; } } - return new RoundTripOptionalModel(optionalString.Value, Optional.ToNullable(optionalInt), Optional.ToList(optionalStringList), Optional.ToList(optionalIntList), Optional.ToList(optionalModelCollection), optionalModel.Value, optionalModelWithPropertiesOnBase.Value, Optional.ToNullable(optionalFixedStringEnum), Optional.ToNullable(optionalExtensibleEnum), Optional.ToDictionary(optionalIntRecord), Optional.ToDictionary(optionalStringRecord), Optional.ToDictionary(optionalModelRecord), Optional.ToNullable(optionalPlainDate), Optional.ToNullable(optionalPlainTime), Optional.ToList(optionalCollectionWithNullableIntElement)); + return new RoundTripOptionalModel(optionalString.Value, Optional.ToNullable(optionalInt), Optional.ToList(optionalStringList), Optional.ToList(optionalIntList), Optional.ToList(optionalModelList), optionalModel.Value, optionalModelWithPropertiesOnBase.Value, Optional.ToNullable(optionalFixedStringEnum), Optional.ToNullable(optionalExtensibleEnum), Optional.ToDictionary(optionalIntRecord), Optional.ToDictionary(optionalStringRecord), Optional.ToDictionary(optionalModelRecord), Optional.ToNullable(optionalPlainDate), Optional.ToNullable(optionalPlainTime), Optional.ToList(optionalCollectionWithNullableIntElement)); } /// Deserializes the model from a raw response. diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOptionalModel.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOptionalModel.cs index 04ce57095b5..7c96bd5c5bd 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOptionalModel.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripOptionalModel.cs @@ -20,7 +20,7 @@ public RoundTripOptionalModel() { OptionalStringList = new ChangeTrackingList(); OptionalIntList = new ChangeTrackingList(); - OptionalModelCollection = new ChangeTrackingList(); + OptionalModelList = new ChangeTrackingList(); OptionalIntRecord = new ChangeTrackingDictionary(); OptionalStringRecord = new ChangeTrackingDictionary(); OptionalModelRecord = new ChangeTrackingDictionary(); @@ -32,7 +32,7 @@ public RoundTripOptionalModel() /// Optional int, illustrating an optional value type property. /// Optional string collection. /// Optional int collection. - /// Optional model collection. + /// Optional model collection. /// Optional model. /// Optional model with properties on base. /// Optional fixed string enum. @@ -43,13 +43,13 @@ public RoundTripOptionalModel() /// Optional plainDate. /// Optional plainTime. /// Optional collection of which the element is a nullable int. - internal RoundTripOptionalModel(string optionalString, int? optionalInt, IList optionalStringList, IList optionalIntList, IList optionalModelCollection, DerivedModel optionalModel, DerivedModelWithProperties optionalModelWithPropertiesOnBase, FixedStringEnum? optionalFixedStringEnum, ExtensibleEnum? optionalExtensibleEnum, IDictionary optionalIntRecord, IDictionary optionalStringRecord, IDictionary optionalModelRecord, DateTimeOffset? optionalPlainDate, TimeSpan? optionalPlainTime, IList optionalCollectionWithNullableIntElement) + internal RoundTripOptionalModel(string optionalString, int? optionalInt, IList optionalStringList, IList optionalIntList, IList optionalModelList, DerivedModel optionalModel, DerivedModelWithProperties optionalModelWithPropertiesOnBase, FixedStringEnum? optionalFixedStringEnum, ExtensibleEnum? optionalExtensibleEnum, IDictionary optionalIntRecord, IDictionary optionalStringRecord, IDictionary optionalModelRecord, DateTimeOffset? optionalPlainDate, TimeSpan? optionalPlainTime, IList optionalCollectionWithNullableIntElement) { OptionalString = optionalString; OptionalInt = optionalInt; OptionalStringList = optionalStringList; OptionalIntList = optionalIntList; - OptionalModelCollection = optionalModelCollection; + OptionalModelList = optionalModelList; OptionalModel = optionalModel; OptionalModelWithPropertiesOnBase = optionalModelWithPropertiesOnBase; OptionalFixedStringEnum = optionalFixedStringEnum; @@ -71,7 +71,7 @@ internal RoundTripOptionalModel(string optionalString, int? optionalInt, IList Optional int collection. public IList OptionalIntList { get; } /// Optional model collection. - public IList OptionalModelCollection { get; } + public IList OptionalModelList { get; } /// Optional model. public DerivedModel OptionalModel { get; set; } /// Optional model with properties on base. diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripReadOnlyModel.Serialization.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripReadOnlyModel.Serialization.cs index 68f5982b8b0..a519748bbcb 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripReadOnlyModel.Serialization.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripReadOnlyModel.Serialization.cs @@ -32,13 +32,13 @@ internal static RoundTripReadOnlyModel DeserializeRoundTripReadOnlyModel(JsonEle ExtensibleEnum optionalReadonlyExtensibleEnum = default; IReadOnlyList requiredReadonlyStringList = default; IReadOnlyList requiredReadonlyIntList = default; - IReadOnlyList requiredReadOnlyModelCollection = default; + IReadOnlyList requiredReadOnlyModelList = default; IReadOnlyDictionary requiredReadOnlyIntRecord = default; IReadOnlyDictionary requiredStringRecord = default; IReadOnlyDictionary requiredReadOnlyModelRecord = default; Optional> optionalReadonlyStringList = default; Optional> optionalReadonlyIntList = default; - Optional> optionalReadOnlyModelCollection = default; + Optional> optionalReadOnlyModelList = default; IReadOnlyDictionary optionalReadOnlyIntRecord = default; IReadOnlyDictionary optionalReadOnlyStringRecord = default; Optional> optionalModelRecord = default; @@ -124,14 +124,14 @@ internal static RoundTripReadOnlyModel DeserializeRoundTripReadOnlyModel(JsonEle requiredReadonlyIntList = array; continue; } - if (property.NameEquals("requiredReadOnlyModelCollection"u8)) + if (property.NameEquals("requiredReadOnlyModelList"u8)) { List array = new List(); foreach (var item in property.Value.EnumerateArray()) { array.Add(CollectionItem.DeserializeCollectionItem(item)); } - requiredReadOnlyModelCollection = array; + requiredReadOnlyModelList = array; continue; } if (property.NameEquals("requiredReadOnlyIntRecord"u8)) @@ -192,7 +192,7 @@ internal static RoundTripReadOnlyModel DeserializeRoundTripReadOnlyModel(JsonEle optionalReadonlyIntList = array; continue; } - if (property.NameEquals("optionalReadOnlyModelCollection"u8)) + if (property.NameEquals("optionalReadOnlyModelList"u8)) { if (property.Value.ValueKind == JsonValueKind.Null) { @@ -203,7 +203,7 @@ internal static RoundTripReadOnlyModel DeserializeRoundTripReadOnlyModel(JsonEle { array.Add(CollectionItem.DeserializeCollectionItem(item)); } - optionalReadOnlyModelCollection = array; + optionalReadOnlyModelList = array; continue; } if (property.NameEquals("optionalReadOnlyIntRecord"u8)) @@ -279,7 +279,7 @@ internal static RoundTripReadOnlyModel DeserializeRoundTripReadOnlyModel(JsonEle continue; } } - return new RoundTripReadOnlyModel(requiredReadonlyString, requiredReadonlyInt, optionalReadonlyString.Value, Optional.ToNullable(optionalReadonlyInt), requiredReadonlyModel, optionalReadonlyModel.Value, requiredReadonlyFixedStringEnum, requiredReadonlyExtensibleEnum, optionalReadonlyFixedStringEnum, optionalReadonlyExtensibleEnum, requiredReadonlyStringList, requiredReadonlyIntList, requiredReadOnlyModelCollection, requiredReadOnlyIntRecord, requiredStringRecord, requiredReadOnlyModelRecord, Optional.ToList(optionalReadonlyStringList), Optional.ToList(optionalReadonlyIntList), Optional.ToList(optionalReadOnlyModelCollection), optionalReadOnlyIntRecord, optionalReadOnlyStringRecord, Optional.ToDictionary(optionalModelRecord), requiredCollectionWithNullableIntElement, Optional.ToList(optionalCollectionWithNullableBooleanElement)); + return new RoundTripReadOnlyModel(requiredReadonlyString, requiredReadonlyInt, optionalReadonlyString.Value, Optional.ToNullable(optionalReadonlyInt), requiredReadonlyModel, optionalReadonlyModel.Value, requiredReadonlyFixedStringEnum, requiredReadonlyExtensibleEnum, optionalReadonlyFixedStringEnum, optionalReadonlyExtensibleEnum, requiredReadonlyStringList, requiredReadonlyIntList, requiredReadOnlyModelList, requiredReadOnlyIntRecord, requiredStringRecord, requiredReadOnlyModelRecord, Optional.ToList(optionalReadonlyStringList), Optional.ToList(optionalReadonlyIntList), Optional.ToList(optionalReadOnlyModelList), optionalReadOnlyIntRecord, optionalReadOnlyStringRecord, Optional.ToDictionary(optionalModelRecord), requiredCollectionWithNullableIntElement, Optional.ToList(optionalCollectionWithNullableBooleanElement)); } /// Deserializes the model from a raw response. diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripReadOnlyModel.cs b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripReadOnlyModel.cs index 683b655e827..820e54d0543 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripReadOnlyModel.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/Models/RoundTripReadOnlyModel.cs @@ -28,13 +28,13 @@ internal RoundTripReadOnlyModel(IReadOnlyDictionary optionalReadOnl RequiredReadonlyStringList = new ChangeTrackingList(); RequiredReadonlyIntList = new ChangeTrackingList(); - RequiredReadOnlyModelCollection = new ChangeTrackingList(); + RequiredReadOnlyModelList = new ChangeTrackingList(); RequiredReadOnlyIntRecord = new ChangeTrackingDictionary(); RequiredStringRecord = new ChangeTrackingDictionary(); RequiredReadOnlyModelRecord = new ChangeTrackingDictionary(); OptionalReadonlyStringList = new ChangeTrackingList(); OptionalReadonlyIntList = new ChangeTrackingList(); - OptionalReadOnlyModelCollection = new ChangeTrackingList(); + OptionalReadOnlyModelList = new ChangeTrackingList(); OptionalReadOnlyIntRecord = optionalReadOnlyIntRecord; OptionalReadOnlyStringRecord = optionalReadOnlyStringRecord; OptionalModelRecord = new ChangeTrackingDictionary(); @@ -55,19 +55,19 @@ internal RoundTripReadOnlyModel(IReadOnlyDictionary optionalReadOnl /// Optional readonly extensible enum. /// Required readonly string collection. /// Required readonly int collection. - /// Required model collection. + /// Required model collection. /// Required int record. /// Required string record. /// Required model record. /// Optional readonly string collection. /// Optional readonly int collection. - /// Optional model collection. + /// Optional model collection. /// Optional int record. /// Optional string record. /// Optional model record. /// Required collection of which the element is a nullable int. /// Optional collection of which the element is a nullable boolean. - internal RoundTripReadOnlyModel(string requiredReadonlyString, int requiredReadonlyInt, string optionalReadonlyString, int? optionalReadonlyInt, DerivedModel requiredReadonlyModel, DerivedModel optionalReadonlyModel, FixedStringEnum requiredReadonlyFixedStringEnum, ExtensibleEnum requiredReadonlyExtensibleEnum, FixedStringEnum optionalReadonlyFixedStringEnum, ExtensibleEnum optionalReadonlyExtensibleEnum, IReadOnlyList requiredReadonlyStringList, IReadOnlyList requiredReadonlyIntList, IReadOnlyList requiredReadOnlyModelCollection, IReadOnlyDictionary requiredReadOnlyIntRecord, IReadOnlyDictionary requiredStringRecord, IReadOnlyDictionary requiredReadOnlyModelRecord, IReadOnlyList optionalReadonlyStringList, IReadOnlyList optionalReadonlyIntList, IReadOnlyList optionalReadOnlyModelCollection, IReadOnlyDictionary optionalReadOnlyIntRecord, IReadOnlyDictionary optionalReadOnlyStringRecord, IReadOnlyDictionary optionalModelRecord, IReadOnlyList requiredCollectionWithNullableIntElement, IReadOnlyList optionalCollectionWithNullableBooleanElement) + internal RoundTripReadOnlyModel(string requiredReadonlyString, int requiredReadonlyInt, string optionalReadonlyString, int? optionalReadonlyInt, DerivedModel requiredReadonlyModel, DerivedModel optionalReadonlyModel, FixedStringEnum requiredReadonlyFixedStringEnum, ExtensibleEnum requiredReadonlyExtensibleEnum, FixedStringEnum optionalReadonlyFixedStringEnum, ExtensibleEnum optionalReadonlyExtensibleEnum, IReadOnlyList requiredReadonlyStringList, IReadOnlyList requiredReadonlyIntList, IReadOnlyList requiredReadOnlyModelList, IReadOnlyDictionary requiredReadOnlyIntRecord, IReadOnlyDictionary requiredStringRecord, IReadOnlyDictionary requiredReadOnlyModelRecord, IReadOnlyList optionalReadonlyStringList, IReadOnlyList optionalReadonlyIntList, IReadOnlyList optionalReadOnlyModelList, IReadOnlyDictionary optionalReadOnlyIntRecord, IReadOnlyDictionary optionalReadOnlyStringRecord, IReadOnlyDictionary optionalModelRecord, IReadOnlyList requiredCollectionWithNullableIntElement, IReadOnlyList optionalCollectionWithNullableBooleanElement) { RequiredReadonlyString = requiredReadonlyString; RequiredReadonlyInt = requiredReadonlyInt; @@ -81,13 +81,13 @@ internal RoundTripReadOnlyModel(string requiredReadonlyString, int requiredReado OptionalReadonlyExtensibleEnum = optionalReadonlyExtensibleEnum; RequiredReadonlyStringList = requiredReadonlyStringList; RequiredReadonlyIntList = requiredReadonlyIntList; - RequiredReadOnlyModelCollection = requiredReadOnlyModelCollection; + RequiredReadOnlyModelList = requiredReadOnlyModelList; RequiredReadOnlyIntRecord = requiredReadOnlyIntRecord; RequiredStringRecord = requiredStringRecord; RequiredReadOnlyModelRecord = requiredReadOnlyModelRecord; OptionalReadonlyStringList = optionalReadonlyStringList; OptionalReadonlyIntList = optionalReadonlyIntList; - OptionalReadOnlyModelCollection = optionalReadOnlyModelCollection; + OptionalReadOnlyModelList = optionalReadOnlyModelList; OptionalReadOnlyIntRecord = optionalReadOnlyIntRecord; OptionalReadOnlyStringRecord = optionalReadOnlyStringRecord; OptionalModelRecord = optionalModelRecord; @@ -120,7 +120,7 @@ internal RoundTripReadOnlyModel(string requiredReadonlyString, int requiredReado /// Required readonly int collection. public IReadOnlyList RequiredReadonlyIntList { get; } /// Required model collection. - public IReadOnlyList RequiredReadOnlyModelCollection { get; } + public IReadOnlyList RequiredReadOnlyModelList { get; } /// Required int record. public IReadOnlyDictionary RequiredReadOnlyIntRecord { get; } /// Required string record. @@ -132,7 +132,7 @@ internal RoundTripReadOnlyModel(string requiredReadonlyString, int requiredReado /// Optional readonly int collection. public IReadOnlyList OptionalReadonlyIntList { get; } /// Optional model collection. - public IReadOnlyList OptionalReadOnlyModelCollection { get; } + public IReadOnlyList OptionalReadOnlyModelList { get; } /// Optional int record. public IReadOnlyDictionary OptionalReadOnlyIntRecord { get; } /// Optional string record. diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/ModelsTypeSpecModelFactory.cs b/test/TestProjects/Models-TypeSpec/src/Generated/ModelsTypeSpecModelFactory.cs index 2c9a7479380..be0df8294f9 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/ModelsTypeSpecModelFactory.cs +++ b/test/TestProjects/Models-TypeSpec/src/Generated/ModelsTypeSpecModelFactory.cs @@ -5,6 +5,7 @@ #nullable disable +using System; using System.Collections.Generic; using System.Linq; @@ -29,6 +30,67 @@ public static SecondDerivedOutputModel SecondDerivedOutputModel(bool second = de return new SecondDerivedOutputModel("second", second); } + /// Initializes a new instance of RoundTripModel. + /// Required string, illustrating a reference type property. + /// Required int, illustrating a value type property. + /// Optional string. + /// Optional int. + /// Required nullable int. + /// Required nullable string. + /// Optional nullable int. + /// Optional nullable string. + /// Required readonly int. + /// Optional readonly int. + /// Required model with discriminator. + /// Required fixed string enum. + /// Required fixed int enum. + /// Required extensible enum. + /// Required collection. + /// Required int record. + /// Required string record. + /// Required Model Record. + /// Required bytes. + /// Optional bytes. + /// Required uint8[]. + /// Optional uint8[]. + /// Required unknown. + /// Optional unknown. + /// Required int8[]. + /// Optional int8[]. + /// Required nullable int list. + /// Required nullable string list. + /// Optional nullable model list. + /// Optional nullable string list. + /// A new instance for mocking. + public static RoundTripModel RoundTripModel(string requiredString = null, int requiredInt = default, string nonRequiredString = null, int? nonRequiredInt = null, int? requiredNullableInt = null, string requiredNullableString = null, int? nonRequiredNullableInt = null, string nonRequiredNullableString = null, int requiredReadonlyInt = default, int? nonRequiredReadonlyInt = null, BaseModelWithDiscriminator requiredModel = null, FixedStringEnum requiredFixedStringEnum = default, FixedIntEnum requiredFixedIntEnum = default, ExtensibleEnum requiredExtensibleEnum = default, IEnumerable requiredList = null, IDictionary requiredIntRecord = null, IDictionary requiredStringRecord = null, IDictionary requiredModelRecord = null, BinaryData requiredBytes = null, BinaryData optionalBytes = null, IEnumerable requiredUint8Array = null, IEnumerable optionalUint8Array = null, BinaryData requiredUnknown = null, BinaryData optionalUnknown = null, IEnumerable requiredInt8Array = null, IEnumerable optionalInt8Array = null, IEnumerable requiredNullableIntList = null, IEnumerable requiredNullableStringList = null, IEnumerable nonRequiredNullableIntList = null, IEnumerable nonRequiredNullableStringList = null) + { + requiredList ??= new List(); + requiredIntRecord ??= new Dictionary(); + requiredStringRecord ??= new Dictionary(); + requiredModelRecord ??= new Dictionary(); + requiredUint8Array ??= new List(); + optionalUint8Array ??= new List(); + requiredInt8Array ??= new List(); + optionalInt8Array ??= new List(); + requiredNullableIntList ??= new List(); + requiredNullableStringList ??= new List(); + nonRequiredNullableIntList ??= new List(); + nonRequiredNullableStringList ??= new List(); + + return new RoundTripModel(requiredString, requiredInt, nonRequiredString, nonRequiredInt, requiredNullableInt, requiredNullableString, nonRequiredNullableInt, nonRequiredNullableString, requiredReadonlyInt, nonRequiredReadonlyInt, requiredModel, requiredFixedStringEnum, requiredFixedIntEnum, requiredExtensibleEnum, requiredList?.ToList(), requiredIntRecord, requiredStringRecord, requiredModelRecord, requiredBytes, optionalBytes, requiredUint8Array?.ToList(), optionalUint8Array?.ToList(), requiredUnknown, optionalUnknown, requiredInt8Array?.ToList(), optionalInt8Array?.ToList(), requiredNullableIntList?.ToList(), requiredNullableStringList?.ToList(), nonRequiredNullableIntList?.ToList(), nonRequiredNullableStringList?.ToList()); + } + + /// Initializes a new instance of DerivedModelWithProperties. + /// Optional properties on base. + /// Required collection. + /// A new instance for mocking. + public static DerivedModelWithProperties DerivedModelWithProperties(string optionalPropertyOnBase = null, IEnumerable requiredList = null) + { + requiredList ??= new List(); + + return new DerivedModelWithProperties(optionalPropertyOnBase, requiredList?.ToList()); + } + /// Initializes a new instance of RoundTripReadOnlyModel. /// Required string, illustrating a readonly reference type property. /// Required int, illustrating a readonly value type property. @@ -42,52 +104,60 @@ public static SecondDerivedOutputModel SecondDerivedOutputModel(bool second = de /// Optional readonly extensible enum. /// Required readonly string collection. /// Required readonly int collection. - /// Required model collection. + /// Required model collection. /// Required int record. /// Required string record. /// Required model record. /// Optional readonly string collection. /// Optional readonly int collection. - /// Optional model collection. + /// Optional model collection. /// Optional int record. /// Optional string record. /// Optional model record. /// Required collection of which the element is a nullable int. /// Optional collection of which the element is a nullable boolean. /// A new instance for mocking. - public static RoundTripReadOnlyModel RoundTripReadOnlyModel(string requiredReadonlyString = null, int requiredReadonlyInt = default, string optionalReadonlyString = null, int? optionalReadonlyInt = null, DerivedModel requiredReadonlyModel = null, DerivedModel optionalReadonlyModel = null, FixedStringEnum requiredReadonlyFixedStringEnum = default, ExtensibleEnum requiredReadonlyExtensibleEnum = default, FixedStringEnum optionalReadonlyFixedStringEnum = default, ExtensibleEnum optionalReadonlyExtensibleEnum = default, IEnumerable requiredReadonlyStringList = null, IEnumerable requiredReadonlyIntList = null, IEnumerable requiredReadOnlyModelCollection = null, IReadOnlyDictionary requiredReadOnlyIntRecord = null, IReadOnlyDictionary requiredStringRecord = null, IReadOnlyDictionary requiredReadOnlyModelRecord = null, IEnumerable optionalReadonlyStringList = null, IEnumerable optionalReadonlyIntList = null, IEnumerable optionalReadOnlyModelCollection = null, IReadOnlyDictionary optionalReadOnlyIntRecord = null, IReadOnlyDictionary optionalReadOnlyStringRecord = null, IReadOnlyDictionary optionalModelRecord = null, IEnumerable requiredCollectionWithNullableIntElement = null, IEnumerable optionalCollectionWithNullableBooleanElement = null) + public static RoundTripReadOnlyModel RoundTripReadOnlyModel(string requiredReadonlyString = null, int requiredReadonlyInt = default, string optionalReadonlyString = null, int? optionalReadonlyInt = null, DerivedModel requiredReadonlyModel = null, DerivedModel optionalReadonlyModel = null, FixedStringEnum requiredReadonlyFixedStringEnum = default, ExtensibleEnum requiredReadonlyExtensibleEnum = default, FixedStringEnum optionalReadonlyFixedStringEnum = default, ExtensibleEnum optionalReadonlyExtensibleEnum = default, IEnumerable requiredReadonlyStringList = null, IEnumerable requiredReadonlyIntList = null, IEnumerable requiredReadOnlyModelList = null, IReadOnlyDictionary requiredReadOnlyIntRecord = null, IReadOnlyDictionary requiredStringRecord = null, IReadOnlyDictionary requiredReadOnlyModelRecord = null, IEnumerable optionalReadonlyStringList = null, IEnumerable optionalReadonlyIntList = null, IEnumerable optionalReadOnlyModelList = null, IReadOnlyDictionary optionalReadOnlyIntRecord = null, IReadOnlyDictionary optionalReadOnlyStringRecord = null, IReadOnlyDictionary optionalModelRecord = null, IEnumerable requiredCollectionWithNullableIntElement = null, IEnumerable optionalCollectionWithNullableBooleanElement = null) { requiredReadonlyStringList ??= new List(); requiredReadonlyIntList ??= new List(); - requiredReadOnlyModelCollection ??= new List(); + requiredReadOnlyModelList ??= new List(); requiredReadOnlyIntRecord ??= new Dictionary(); requiredStringRecord ??= new Dictionary(); requiredReadOnlyModelRecord ??= new Dictionary(); optionalReadonlyStringList ??= new List(); optionalReadonlyIntList ??= new List(); - optionalReadOnlyModelCollection ??= new List(); + optionalReadOnlyModelList ??= new List(); optionalReadOnlyIntRecord ??= new Dictionary(); optionalReadOnlyStringRecord ??= new Dictionary(); optionalModelRecord ??= new Dictionary(); requiredCollectionWithNullableIntElement ??= new List(); optionalCollectionWithNullableBooleanElement ??= new List(); - return new RoundTripReadOnlyModel(requiredReadonlyString, requiredReadonlyInt, optionalReadonlyString, optionalReadonlyInt, requiredReadonlyModel, optionalReadonlyModel, requiredReadonlyFixedStringEnum, requiredReadonlyExtensibleEnum, optionalReadonlyFixedStringEnum, optionalReadonlyExtensibleEnum, requiredReadonlyStringList?.ToList(), requiredReadonlyIntList?.ToList(), requiredReadOnlyModelCollection?.ToList(), requiredReadOnlyIntRecord, requiredStringRecord, requiredReadOnlyModelRecord, optionalReadonlyStringList?.ToList(), optionalReadonlyIntList?.ToList(), optionalReadOnlyModelCollection?.ToList(), optionalReadOnlyIntRecord, optionalReadOnlyStringRecord, optionalModelRecord, requiredCollectionWithNullableIntElement?.ToList(), optionalCollectionWithNullableBooleanElement?.ToList()); + return new RoundTripReadOnlyModel(requiredReadonlyString, requiredReadonlyInt, optionalReadonlyString, optionalReadonlyInt, requiredReadonlyModel, optionalReadonlyModel, requiredReadonlyFixedStringEnum, requiredReadonlyExtensibleEnum, optionalReadonlyFixedStringEnum, optionalReadonlyExtensibleEnum, requiredReadonlyStringList?.ToList(), requiredReadonlyIntList?.ToList(), requiredReadOnlyModelList?.ToList(), requiredReadOnlyIntRecord, requiredStringRecord, requiredReadOnlyModelRecord, optionalReadonlyStringList?.ToList(), optionalReadonlyIntList?.ToList(), optionalReadOnlyModelList?.ToList(), optionalReadOnlyIntRecord, optionalReadOnlyStringRecord, optionalModelRecord, requiredCollectionWithNullableIntElement?.ToList(), optionalCollectionWithNullableBooleanElement?.ToList()); } /// Initializes a new instance of OutputModel. /// Required string. /// Required int. /// Required model. - /// Required collection. + /// Required collection. /// Required model record. + /// Optional model collection. + /// Optional model nullable collection. + /// Optional model record. + /// Optional model nullable record. /// A new instance for mocking. - public static OutputModel OutputModel(string requiredString = null, int requiredInt = default, DerivedModel requiredModel = null, IEnumerable requiredCollection = null, IReadOnlyDictionary requiredModelRecord = null) + public static OutputModel OutputModel(string requiredString = null, int requiredInt = default, DerivedModel requiredModel = null, IEnumerable requiredList = null, IReadOnlyDictionary requiredModelRecord = null, IEnumerable optionalList = null, IEnumerable optionalNullableList = null, IReadOnlyDictionary optionalRecord = null, IReadOnlyDictionary optionalNullableRecord = null) { - requiredCollection ??= new List(); + requiredList ??= new List(); requiredModelRecord ??= new Dictionary(); + optionalList ??= new List(); + optionalNullableList ??= new List(); + optionalRecord ??= new Dictionary(); + optionalNullableRecord ??= new Dictionary(); - return new OutputModel(requiredString, requiredInt, requiredModel, requiredCollection?.ToList(), requiredModelRecord); + return new OutputModel(requiredString, requiredInt, requiredModel, requiredList?.ToList(), requiredModelRecord, optionalList?.ToList(), optionalNullableList?.ToList(), optionalRecord, optionalNullableRecord); } /// Initializes a new instance of ErrorModel. diff --git a/test/TestProjects/Models-TypeSpec/src/Generated/tspCodeModel.json b/test/TestProjects/Models-TypeSpec/src/Generated/tspCodeModel.json index fa8c0c9701e..b983d3d47de 100644 --- a/test/TestProjects/Models-TypeSpec/src/Generated/tspCodeModel.json +++ b/test/TestProjects/Models-TypeSpec/src/Generated/tspCodeModel.json @@ -212,11 +212,67 @@ }, { "$id": "28", + "Name": "requiredNullableInt", + "SerializedName": "requiredNullableInt", + "Description": "Required nullable int", + "Type": { + "$id": "29", + "Name": "int32", + "Kind": "Int32", + "IsNullable": true + }, + "IsRequired": true, + "IsReadOnly": false + }, + { + "$id": "30", + "Name": "requiredNullableString", + "SerializedName": "requiredNullableString", + "Description": "Required nullable string", + "Type": { + "$id": "31", + "Name": "string", + "Kind": "String", + "IsNullable": true + }, + "IsRequired": true, + "IsReadOnly": false + }, + { + "$id": "32", + "Name": "nonRequiredNullableInt", + "SerializedName": "nonRequiredNullableInt", + "Description": "Optional nullable int", + "Type": { + "$id": "33", + "Name": "int32", + "Kind": "Int32", + "IsNullable": true + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "34", + "Name": "nonRequiredNullableString", + "SerializedName": "nonRequiredNullableString", + "Description": "Optional nullable string", + "Type": { + "$id": "35", + "Name": "string", + "Kind": "String", + "IsNullable": true + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "36", "Name": "requiredModel", "SerializedName": "requiredModel", "Description": "Required model", "Type": { - "$id": "29", + "$id": "37", "Name": "BaseModel", "Namespace": "ModelsTypeSpec", "Description": "Base model", @@ -228,15 +284,15 @@ "IsReadOnly": false }, { - "$id": "30", - "Name": "requiredIntCollection", - "SerializedName": "requiredIntCollection", + "$id": "38", + "Name": "requiredIntList", + "SerializedName": "requiredIntList", "Description": "Required primitive value type collection", "Type": { - "$id": "31", + "$id": "39", "Name": "Array", "ElementType": { - "$id": "32", + "$id": "40", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -247,15 +303,15 @@ "IsReadOnly": false }, { - "$id": "33", - "Name": "requiredStringCollection", - "SerializedName": "requiredStringCollection", + "$id": "41", + "Name": "requiredStringList", + "SerializedName": "requiredStringList", "Description": "Required primitive reference type collection", "Type": { - "$id": "34", + "$id": "42", "Name": "Array", "ElementType": { - "$id": "35", + "$id": "43", "Name": "string", "Kind": "String", "IsNullable": false @@ -266,15 +322,15 @@ "IsReadOnly": false }, { - "$id": "36", - "Name": "requiredModelCollection", - "SerializedName": "requiredModelCollection", + "$id": "44", + "Name": "requiredModelList", + "SerializedName": "requiredModelList", "Description": "Required model collection", "Type": { - "$id": "37", + "$id": "45", "Name": "Array", "ElementType": { - "$id": "38", + "$id": "46", "Name": "CollectionItem", "Namespace": "ModelsTypeSpec", "Description": "Collection item model", @@ -282,46 +338,46 @@ "Usage": "RoundTrip", "Properties": [ { - "$id": "39", + "$id": "47", "Name": "requiredModelRecord", "SerializedName": "requiredModelRecord", "Description": "Required model record", "Type": { - "$id": "40", + "$id": "48", "Name": "Dictionary", "KeyType": { - "$id": "41", + "$id": "49", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$id": "42", + "$id": "50", "Name": "RecordItem", "Namespace": "ModelsTypeSpec", "Description": "Record item model", "IsNullable": false, "BaseModel": { - "$id": "43", + "$id": "51", "Name": "DerivedModel", "Namespace": "ModelsTypeSpec", "Description": "Derived model", "IsNullable": false, "BaseModel": { - "$ref": "29" + "$ref": "37" }, "Usage": "RoundTrip", "Properties": [ { - "$id": "44", - "Name": "requiredCollection", - "SerializedName": "requiredCollection", + "$id": "52", + "Name": "requiredList", + "SerializedName": "requiredList", "Description": "Required collection", "Type": { - "$id": "45", + "$id": "53", "Name": "Array", "ElementType": { - "$ref": "38" + "$ref": "46" }, "IsNullable": false }, @@ -346,21 +402,21 @@ "IsReadOnly": false }, { - "$id": "46", + "$id": "54", "Name": "requiredModelRecord", "SerializedName": "requiredModelRecord", "Description": "Required model record", "Type": { - "$id": "47", + "$id": "55", "Name": "Dictionary", "KeyType": { - "$id": "48", + "$id": "56", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$ref": "42" + "$ref": "50" }, "IsNullable": false }, @@ -368,15 +424,15 @@ "IsReadOnly": false }, { - "$id": "49", + "$id": "57", "Name": "requiredCollectionWithNullableFloatElement", "SerializedName": "requiredCollectionWithNullableFloatElement", "Description": "Required collection of which the element is a nullable float", "Type": { - "$id": "50", + "$id": "58", "Name": "Array", "ElementType": { - "$id": "51", + "$id": "59", "Name": "float32", "Kind": "Float32", "IsNullable": true @@ -387,15 +443,15 @@ "IsReadOnly": false }, { - "$id": "52", + "$id": "60", "Name": "requiredCollectionWithNullableBooleanElement", "SerializedName": "requiredCollectionWithNullableBooleanElement", "Description": "Required collection of which the element is a nullable boolean", "Type": { - "$id": "53", + "$id": "61", "Name": "Array", "ElementType": { - "$id": "54", + "$id": "62", "Name": "boolean", "Kind": "Boolean", "IsNullable": true @@ -404,39 +460,201 @@ }, "IsRequired": true, "IsReadOnly": false + }, + { + "$id": "63", + "Name": "requiredNullableModelList", + "SerializedName": "requiredNullableModelList", + "Description": "Required model nullable collection", + "Type": { + "$id": "64", + "Name": "Array", + "ElementType": { + "$ref": "46" + }, + "IsNullable": true + }, + "IsRequired": true, + "IsReadOnly": false + }, + { + "$id": "65", + "Name": "requiredNullableStringList", + "SerializedName": "requiredNullableStringList", + "Description": "Required string nullable collection", + "Type": { + "$id": "66", + "Name": "Array", + "ElementType": { + "$id": "67", + "Name": "string", + "Kind": "String", + "IsNullable": false + }, + "IsNullable": true + }, + "IsRequired": true, + "IsReadOnly": false + }, + { + "$id": "68", + "Name": "requiredNullableIntList", + "SerializedName": "requiredNullableIntList", + "Description": "Required int nullable collection", + "Type": { + "$id": "69", + "Name": "Array", + "ElementType": { + "$id": "70", + "Name": "int32", + "Kind": "Int32", + "IsNullable": false + }, + "IsNullable": true + }, + "IsRequired": true, + "IsReadOnly": false + }, + { + "$id": "71", + "Name": "nonRequiredModelList", + "SerializedName": "nonRequiredModelList", + "Description": "Optional model collection", + "Type": { + "$id": "72", + "Name": "Array", + "ElementType": { + "$ref": "46" + }, + "IsNullable": false + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "73", + "Name": "nonRequiredStringList", + "SerializedName": "nonRequiredStringList", + "Description": "Optional string collection", + "Type": { + "$id": "74", + "Name": "Array", + "ElementType": { + "$id": "75", + "Name": "string", + "Kind": "String", + "IsNullable": false + }, + "IsNullable": false + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "76", + "Name": "nonRequiredIntList", + "SerializedName": "nonRequiredIntList", + "Description": "Optional int collection", + "Type": { + "$id": "77", + "Name": "Array", + "ElementType": { + "$id": "78", + "Name": "int32", + "Kind": "Int32", + "IsNullable": false + }, + "IsNullable": false + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "79", + "Name": "nonRequiredNullableModelList", + "SerializedName": "nonRequiredNullableModelList", + "Description": "Optional model nullable collection", + "Type": { + "$id": "80", + "Name": "Array", + "ElementType": { + "$ref": "46" + }, + "IsNullable": true + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "81", + "Name": "nonRequiredNullableStringList", + "SerializedName": "nonRequiredNullableStringList", + "Description": "Optional string nullable collection", + "Type": { + "$id": "82", + "Name": "Array", + "ElementType": { + "$id": "83", + "Name": "string", + "Kind": "String", + "IsNullable": false + }, + "IsNullable": true + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "84", + "Name": "nonRequiredNullableIntList", + "SerializedName": "nonRequiredNullableIntList", + "Description": "Optional int nullable collection", + "Type": { + "$id": "85", + "Name": "Array", + "ElementType": { + "$id": "86", + "Name": "int32", + "Kind": "Int32", + "IsNullable": false + }, + "IsNullable": true + }, + "IsRequired": false, + "IsReadOnly": false } ] }, { - "$ref": "29" + "$ref": "37" }, { - "$ref": "38" + "$ref": "46" }, { - "$ref": "43" + "$ref": "51" }, { - "$ref": "42" + "$ref": "50" }, { - "$id": "55", + "$id": "87", "Name": "RoundTripModel", "Namespace": "ModelsTypeSpec", "Description": "Model used both as input and output", "IsNullable": false, "BaseModel": { - "$ref": "29" + "$ref": "37" }, "Usage": "RoundTrip", "Properties": [ { - "$id": "56", + "$id": "88", "Name": "requiredString", "SerializedName": "requiredString", "Description": "Required string, illustrating a reference type property.", "Type": { - "$id": "57", + "$id": "89", "Name": "string", "Kind": "String", "IsNullable": false @@ -445,12 +663,12 @@ "IsReadOnly": false }, { - "$id": "58", + "$id": "90", "Name": "requiredInt", "SerializedName": "requiredInt", "Description": "Required int, illustrating a value type property.", "Type": { - "$id": "59", + "$id": "91", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -459,12 +677,124 @@ "IsReadOnly": false }, { - "$id": "60", + "$id": "92", + "Name": "nonRequiredString", + "SerializedName": "nonRequiredString", + "Description": "Optional string", + "Type": { + "$id": "93", + "Name": "string", + "Kind": "String", + "IsNullable": false + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "94", + "Name": "nonRequiredInt", + "SerializedName": "nonRequiredInt", + "Description": "Optional int", + "Type": { + "$id": "95", + "Name": "int32", + "Kind": "Int32", + "IsNullable": false + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "96", + "Name": "requiredNullableInt", + "SerializedName": "requiredNullableInt", + "Description": "Required nullable int", + "Type": { + "$id": "97", + "Name": "int32", + "Kind": "Int32", + "IsNullable": true + }, + "IsRequired": true, + "IsReadOnly": false + }, + { + "$id": "98", + "Name": "requiredNullableString", + "SerializedName": "requiredNullableString", + "Description": "Required nullable string", + "Type": { + "$id": "99", + "Name": "string", + "Kind": "String", + "IsNullable": true + }, + "IsRequired": true, + "IsReadOnly": false + }, + { + "$id": "100", + "Name": "nonRequiredNullableInt", + "SerializedName": "nonRequiredNullableInt", + "Description": "Optional nullable int", + "Type": { + "$id": "101", + "Name": "int32", + "Kind": "Int32", + "IsNullable": true + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "102", + "Name": "nonRequiredNullableString", + "SerializedName": "nonRequiredNullableString", + "Description": "Optional nullable string", + "Type": { + "$id": "103", + "Name": "string", + "Kind": "String", + "IsNullable": true + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "104", + "Name": "requiredReadonlyInt", + "SerializedName": "requiredReadonlyInt", + "Description": "Required readonly int", + "Type": { + "$id": "105", + "Name": "int32", + "Kind": "Int32", + "IsNullable": false + }, + "IsRequired": true, + "IsReadOnly": true + }, + { + "$id": "106", + "Name": "nonRequiredReadonlyInt", + "SerializedName": "nonRequiredReadonlyInt", + "Description": "Optional readonly int", + "Type": { + "$id": "107", + "Name": "int32", + "Kind": "Int32", + "IsNullable": false + }, + "IsRequired": false, + "IsReadOnly": true + }, + { + "$id": "108", "Name": "requiredModel", "SerializedName": "requiredModel", "Description": "Required model with discriminator", "Type": { - "$id": "61", + "$id": "109", "Name": "BaseModelWithDiscriminator", "Namespace": "ModelsTypeSpec", "Description": "Base model with discriminator property.", @@ -473,7 +803,7 @@ "Usage": "RoundTrip", "Properties": [ { - "$id": "62", + "$id": "110", "Name": "discriminatorProperty", "SerializedName": "discriminatorProperty", "Description": "Discriminator", @@ -481,7 +811,7 @@ "IsReadOnly": false, "IsNullable": false, "Type": { - "$id": "63", + "$id": "111", "Name": "string", "Kind": "String", "IsNullable": false @@ -489,12 +819,12 @@ "IsDiscriminator": true }, { - "$id": "64", + "$id": "112", "Name": "optionalPropertyOnBase", "SerializedName": "optionalPropertyOnBase", "Description": "Optional property on base", "Type": { - "$id": "65", + "$id": "113", "Name": "string", "Kind": "String", "IsNullable": false @@ -503,12 +833,12 @@ "IsReadOnly": false }, { - "$id": "66", + "$id": "114", "Name": "requiredPropertyOnBase", "SerializedName": "requiredPropertyOnBase", "Description": "Required property on base", "Type": { - "$id": "67", + "$id": "115", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -522,7 +852,7 @@ "IsReadOnly": false }, { - "$id": "68", + "$id": "116", "Name": "requiredFixedStringEnum", "SerializedName": "requiredFixedStringEnum", "Description": "Required fixed string enum", @@ -533,7 +863,7 @@ "IsReadOnly": false }, { - "$id": "69", + "$id": "117", "Name": "requiredFixedIntEnum", "SerializedName": "requiredFixedIntEnum", "Description": "Required fixed int enum", @@ -544,7 +874,7 @@ "IsReadOnly": false }, { - "$id": "70", + "$id": "118", "Name": "requiredExtensibleEnum", "SerializedName": "requiredExtensibleEnum", "Description": "Required extensible enum", @@ -555,15 +885,15 @@ "IsReadOnly": false }, { - "$id": "71", - "Name": "requiredCollection", - "SerializedName": "requiredCollection", + "$id": "119", + "Name": "requiredList", + "SerializedName": "requiredList", "Description": "Required collection", "Type": { - "$id": "72", + "$id": "120", "Name": "Array", "ElementType": { - "$ref": "38" + "$ref": "46" }, "IsNullable": false }, @@ -571,21 +901,21 @@ "IsReadOnly": false }, { - "$id": "73", + "$id": "121", "Name": "requiredIntRecord", "SerializedName": "requiredIntRecord", "Description": "Required int record", "Type": { - "$id": "74", + "$id": "122", "Name": "Dictionary", "KeyType": { - "$id": "75", + "$id": "123", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$id": "76", + "$id": "124", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -596,21 +926,21 @@ "IsReadOnly": false }, { - "$id": "77", + "$id": "125", "Name": "requiredStringRecord", "SerializedName": "requiredStringRecord", "Description": "Required string record", "Type": { - "$id": "78", + "$id": "126", "Name": "Dictionary", "KeyType": { - "$id": "79", + "$id": "127", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$id": "80", + "$id": "128", "Name": "string", "Kind": "String", "IsNullable": false @@ -621,21 +951,21 @@ "IsReadOnly": false }, { - "$id": "81", + "$id": "129", "Name": "requiredModelRecord", "SerializedName": "requiredModelRecord", "Description": "Required Model Record", "Type": { - "$id": "82", + "$id": "130", "Name": "Dictionary", "KeyType": { - "$id": "83", + "$id": "131", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$ref": "42" + "$ref": "50" }, "IsNullable": false }, @@ -643,12 +973,12 @@ "IsReadOnly": false }, { - "$id": "84", + "$id": "132", "Name": "requiredBytes", "SerializedName": "requiredBytes", "Description": "Required bytes", "Type": { - "$id": "85", + "$id": "133", "Name": "bytes", "Kind": "Bytes", "IsNullable": false @@ -657,12 +987,12 @@ "IsReadOnly": false }, { - "$id": "86", + "$id": "134", "Name": "optionalBytes", "SerializedName": "optionalBytes", "Description": "Optional bytes", "Type": { - "$id": "87", + "$id": "135", "Name": "bytes", "Kind": "Bytes", "IsNullable": false @@ -671,15 +1001,15 @@ "IsReadOnly": false }, { - "$id": "88", + "$id": "136", "Name": "requiredUint8Array", "SerializedName": "requiredUint8Array", "Description": "Required uint8[]", "Type": { - "$id": "89", + "$id": "137", "Name": "Array", "ElementType": { - "$id": "90", + "$id": "138", "Name": "uint8", "Kind": "Int32", "IsNullable": false @@ -690,15 +1020,15 @@ "IsReadOnly": false }, { - "$id": "91", + "$id": "139", "Name": "optionalUint8Array", "SerializedName": "optionalUint8Array", "Description": "Optional uint8[]", "Type": { - "$id": "92", + "$id": "140", "Name": "Array", "ElementType": { - "$id": "93", + "$id": "141", "Name": "uint8", "Kind": "Int32", "IsNullable": false @@ -709,12 +1039,12 @@ "IsReadOnly": false }, { - "$id": "94", + "$id": "142", "Name": "requiredUnknown", "SerializedName": "requiredUnknown", "Description": "Required unknown", "Type": { - "$id": "95", + "$id": "143", "Name": "Intrinsic", "Kind": "unknown", "IsNullable": false @@ -723,12 +1053,12 @@ "IsReadOnly": false }, { - "$id": "96", + "$id": "144", "Name": "optionalUnknown", "SerializedName": "optionalUnknown", "Description": "Optional unknown", "Type": { - "$id": "97", + "$id": "145", "Name": "Intrinsic", "Kind": "unknown", "IsNullable": false @@ -737,15 +1067,15 @@ "IsReadOnly": false }, { - "$id": "98", + "$id": "146", "Name": "requiredInt8Array", "SerializedName": "requiredInt8Array", "Description": "Required int8[]", "Type": { - "$id": "99", + "$id": "147", "Name": "Array", "ElementType": { - "$id": "100", + "$id": "148", "Name": "int8", "Kind": "Int32", "IsNullable": false @@ -756,15 +1086,15 @@ "IsReadOnly": false }, { - "$id": "101", + "$id": "149", "Name": "optionalInt8Array", "SerializedName": "optionalInt8Array", "Description": "Optional int8[]", "Type": { - "$id": "102", + "$id": "150", "Name": "Array", "ElementType": { - "$id": "103", + "$id": "151", "Name": "int8", "Kind": "Int32", "IsNullable": false @@ -773,31 +1103,107 @@ }, "IsRequired": false, "IsReadOnly": false + }, + { + "$id": "152", + "Name": "requiredNullableIntList", + "SerializedName": "requiredNullableIntList", + "Description": "Required nullable int list", + "Type": { + "$id": "153", + "Name": "Array", + "ElementType": { + "$id": "154", + "Name": "int32", + "Kind": "Int32", + "IsNullable": false + }, + "IsNullable": true + }, + "IsRequired": true, + "IsReadOnly": false + }, + { + "$id": "155", + "Name": "requiredNullableStringList", + "SerializedName": "requiredNullableStringList", + "Description": "Required nullable string list", + "Type": { + "$id": "156", + "Name": "Array", + "ElementType": { + "$id": "157", + "Name": "string", + "Kind": "String", + "IsNullable": false + }, + "IsNullable": true + }, + "IsRequired": true, + "IsReadOnly": false + }, + { + "$id": "158", + "Name": "nonRequiredNullableIntList", + "SerializedName": "nonRequiredNullableIntList", + "Description": "Optional nullable model list", + "Type": { + "$id": "159", + "Name": "Array", + "ElementType": { + "$id": "160", + "Name": "int32", + "Kind": "Int32", + "IsNullable": false + }, + "IsNullable": true + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "161", + "Name": "nonRequiredNullableStringList", + "SerializedName": "nonRequiredNullableStringList", + "Description": "Optional nullable string list", + "Type": { + "$id": "162", + "Name": "Array", + "ElementType": { + "$id": "163", + "Name": "string", + "Kind": "String", + "IsNullable": false + }, + "IsNullable": true + }, + "IsRequired": false, + "IsReadOnly": false } ] }, { - "$ref": "61" + "$ref": "109" }, { - "$id": "104", + "$id": "164", "Name": "DerivedModelWithDiscriminatorA", "Namespace": "ModelsTypeSpec", "Description": "Deriver model with discriminator property.", "IsNullable": false, "DiscriminatorValue": "A", "BaseModel": { - "$ref": "61" + "$ref": "109" }, "Usage": "RoundTrip", "Properties": [ { - "$id": "105", + "$id": "165", "Name": "requiredString", "SerializedName": "requiredString", "Description": "Required string.", "Type": { - "$id": "106", + "$id": "166", "Name": "string", "Kind": "String", "IsNullable": false @@ -808,24 +1214,24 @@ ] }, { - "$id": "107", + "$id": "167", "Name": "DerivedModelWithDiscriminatorB", "Namespace": "ModelsTypeSpec", "Description": "Deriver model with discriminator property.", "IsNullable": false, "DiscriminatorValue": "B", "BaseModel": { - "$ref": "61" + "$ref": "109" }, "Usage": "RoundTrip", "Properties": [ { - "$id": "108", + "$id": "168", "Name": "requiredInt", "SerializedName": "requiredInt", "Description": "Required int.", "Type": { - "$id": "109", + "$id": "169", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -836,23 +1242,23 @@ ] }, { - "$id": "110", + "$id": "170", "Name": "RoundTripPrimitiveModel", "Namespace": "ModelsTypeSpec", "Description": "Model used both as input and output with primitive types", "IsNullable": false, "BaseModel": { - "$ref": "29" + "$ref": "37" }, "Usage": "RoundTrip", "Properties": [ { - "$id": "111", + "$id": "171", "Name": "requiredString", "SerializedName": "requiredString", "Description": "Required string, illustrating a reference type property.", "Type": { - "$id": "112", + "$id": "172", "Name": "string", "Kind": "String", "IsNullable": false @@ -861,12 +1267,12 @@ "IsReadOnly": false }, { - "$id": "113", + "$id": "173", "Name": "requiredInt", "SerializedName": "requiredInt", "Description": "Required int, illustrating a value type property.", "Type": { - "$id": "114", + "$id": "174", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -875,12 +1281,12 @@ "IsReadOnly": false }, { - "$id": "115", + "$id": "175", "Name": "requiredInt64", "SerializedName": "requiredInt64", "Description": "Required int64, illustrating a value type property.", "Type": { - "$id": "116", + "$id": "176", "Name": "int64", "Kind": "Int64", "IsNullable": false @@ -889,12 +1295,12 @@ "IsReadOnly": false }, { - "$id": "117", + "$id": "177", "Name": "requiredSafeInt", "SerializedName": "requiredSafeInt", "Description": "Required safeint, illustrating a value type property.", "Type": { - "$id": "118", + "$id": "178", "Name": "safeint", "Kind": "Int64", "IsNullable": false @@ -903,12 +1309,12 @@ "IsReadOnly": false }, { - "$id": "119", + "$id": "179", "Name": "requiredFloat", "SerializedName": "requiredFloat", "Description": "Required float, illustrating a value type property.", "Type": { - "$id": "120", + "$id": "180", "Name": "float32", "Kind": "Float32", "IsNullable": false @@ -917,12 +1323,12 @@ "IsReadOnly": false }, { - "$id": "121", + "$id": "181", "Name": "required_Double", "SerializedName": "required_Double", "Description": "Required double, illustrating a value type property.", "Type": { - "$id": "122", + "$id": "182", "Name": "float64", "Kind": "Float64", "IsNullable": false @@ -931,12 +1337,12 @@ "IsReadOnly": false }, { - "$id": "123", + "$id": "183", "Name": "requiredBoolean", "SerializedName": "requiredBoolean", "Description": "Required bolean, illustrating a value type property.", "Type": { - "$id": "124", + "$id": "184", "Name": "boolean", "Kind": "Boolean", "IsNullable": false @@ -945,12 +1351,12 @@ "IsReadOnly": false }, { - "$id": "125", + "$id": "185", "Name": "requiredDateTimeOffset", "SerializedName": "requiredDateTimeOffset", "Description": "Required date time offset, illustrating a reference type property.", "Type": { - "$id": "126", + "$id": "186", "Name": "utcDateTime", "Kind": "DateTime", "IsNullable": false @@ -959,12 +1365,12 @@ "IsReadOnly": false }, { - "$id": "127", + "$id": "187", "Name": "requiredTimeSpan", "SerializedName": "requiredTimeSpan", "Description": "Required time span, illustrating a value type property.", "Type": { - "$id": "128", + "$id": "188", "Name": "duration", "Kind": "DurationISO8601", "IsNullable": false @@ -973,15 +1379,15 @@ "IsReadOnly": false }, { - "$id": "129", + "$id": "189", "Name": "requiredCollectionWithNullableFloatElement", "SerializedName": "requiredCollectionWithNullableFloatElement", "Description": "Required collection of which the element is a nullable float", "Type": { - "$id": "130", + "$id": "190", "Name": "Array", "ElementType": { - "$id": "131", + "$id": "191", "Name": "float32", "Kind": "Float32", "IsNullable": true @@ -994,7 +1400,7 @@ ] }, { - "$id": "132", + "$id": "192", "Name": "RoundTripOptionalModel", "Namespace": "ModelsTypeSpec", "Deprecated": "deprecated for test", @@ -1003,12 +1409,12 @@ "Usage": "RoundTrip", "Properties": [ { - "$id": "133", + "$id": "193", "Name": "optionalString", "SerializedName": "optionalString", "Description": "Optional string, illustrating an optional reference type property.", "Type": { - "$id": "134", + "$id": "194", "Name": "string", "Kind": "String", "IsNullable": false @@ -1017,12 +1423,12 @@ "IsReadOnly": false }, { - "$id": "135", + "$id": "195", "Name": "optionalInt", "SerializedName": "optionalInt", "Description": "Optional int, illustrating an optional value type property.", "Type": { - "$id": "136", + "$id": "196", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -1031,15 +1437,15 @@ "IsReadOnly": false }, { - "$id": "137", + "$id": "197", "Name": "optionalStringList", "SerializedName": "optionalStringList", "Description": "Optional string collection.", "Type": { - "$id": "138", + "$id": "198", "Name": "Array", "ElementType": { - "$id": "139", + "$id": "199", "Name": "string", "Kind": "String", "IsNullable": false @@ -1050,15 +1456,15 @@ "IsReadOnly": false }, { - "$id": "140", + "$id": "200", "Name": "optionalIntList", "SerializedName": "optionalIntList", "Description": "Optional int collection.", "Type": { - "$id": "141", + "$id": "201", "Name": "Array", "ElementType": { - "$id": "142", + "$id": "202", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -1069,15 +1475,15 @@ "IsReadOnly": false }, { - "$id": "143", - "Name": "optionalModelCollection", - "SerializedName": "optionalModelCollection", + "$id": "203", + "Name": "optionalModelList", + "SerializedName": "optionalModelList", "Description": "Optional model collection", "Type": { - "$id": "144", + "$id": "204", "Name": "Array", "ElementType": { - "$ref": "38" + "$ref": "46" }, "IsNullable": false }, @@ -1085,29 +1491,29 @@ "IsReadOnly": false }, { - "$id": "145", + "$id": "205", "Name": "optionalModel", "SerializedName": "optionalModel", "Description": "Optional model.", "Type": { - "$ref": "43" + "$ref": "51" }, "IsRequired": false, "IsReadOnly": false }, { - "$id": "146", + "$id": "206", "Name": "optionalModelWithPropertiesOnBase", "SerializedName": "optionalModelWithPropertiesOnBase", "Description": "Optional model with properties on base", "Type": { - "$id": "147", + "$id": "207", "Name": "DerivedModelWithProperties", "Namespace": "ModelsTypeSpec", "Description": "Derived model with properties", "IsNullable": false, "BaseModel": { - "$id": "148", + "$id": "208", "Name": "BaseModelWithProperties", "Namespace": "ModelsTypeSpec", "Description": "Base model with properties", @@ -1115,12 +1521,12 @@ "Usage": "None", "Properties": [ { - "$id": "149", + "$id": "209", "Name": "optionalPropertyOnBase", "SerializedName": "optionalPropertyOnBase", "Description": "Optional properties on base", "Type": { - "$id": "150", + "$id": "210", "Name": "string", "Kind": "String", "IsNullable": false @@ -1133,15 +1539,15 @@ "Usage": "RoundTrip", "Properties": [ { - "$id": "151", - "Name": "requiredCollection", - "SerializedName": "requiredCollection", + "$id": "211", + "Name": "requiredList", + "SerializedName": "requiredList", "Description": "Required collection", "Type": { - "$id": "152", + "$id": "212", "Name": "Array", "ElementType": { - "$ref": "38" + "$ref": "46" }, "IsNullable": false }, @@ -1154,7 +1560,7 @@ "IsReadOnly": false }, { - "$id": "153", + "$id": "213", "Name": "optionalFixedStringEnum", "SerializedName": "optionalFixedStringEnum", "Description": "Optional fixed string enum", @@ -1165,7 +1571,7 @@ "IsReadOnly": false }, { - "$id": "154", + "$id": "214", "Name": "optionalExtensibleEnum", "SerializedName": "optionalExtensibleEnum", "Description": "Optional extensible enum", @@ -1176,21 +1582,21 @@ "IsReadOnly": false }, { - "$id": "155", + "$id": "215", "Name": "optionalIntRecord", "SerializedName": "optionalIntRecord", "Description": "Optional int record", "Type": { - "$id": "156", + "$id": "216", "Name": "Dictionary", "KeyType": { - "$id": "157", + "$id": "217", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$id": "158", + "$id": "218", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -1201,21 +1607,21 @@ "IsReadOnly": false }, { - "$id": "159", + "$id": "219", "Name": "optionalStringRecord", "SerializedName": "optionalStringRecord", "Description": "Optional string record", "Type": { - "$id": "160", + "$id": "220", "Name": "Dictionary", "KeyType": { - "$id": "161", + "$id": "221", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$id": "162", + "$id": "222", "Name": "string", "Kind": "String", "IsNullable": false @@ -1226,21 +1632,21 @@ "IsReadOnly": false }, { - "$id": "163", + "$id": "223", "Name": "optionalModelRecord", "SerializedName": "optionalModelRecord", "Description": "Optional model record", "Type": { - "$id": "164", + "$id": "224", "Name": "Dictionary", "KeyType": { - "$id": "165", + "$id": "225", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$ref": "42" + "$ref": "50" }, "IsNullable": false }, @@ -1248,12 +1654,12 @@ "IsReadOnly": false }, { - "$id": "166", + "$id": "226", "Name": "optionalPlainDate", "SerializedName": "optionalPlainDate", "Description": "Optional plainDate", "Type": { - "$id": "167", + "$id": "227", "Name": "plainDate", "Kind": "Date", "IsNullable": false @@ -1262,12 +1668,12 @@ "IsReadOnly": false }, { - "$id": "168", + "$id": "228", "Name": "optionalPlainTime", "SerializedName": "optionalPlainTime", "Description": "Optional plainTime", "Type": { - "$id": "169", + "$id": "229", "Name": "plainTime", "Kind": "Time", "IsNullable": false @@ -1276,15 +1682,15 @@ "IsReadOnly": false }, { - "$id": "170", + "$id": "230", "Name": "optionalCollectionWithNullableIntElement", "SerializedName": "optionalCollectionWithNullableIntElement", "Description": "Optional collection of which the element is a nullable int", "Type": { - "$id": "171", + "$id": "231", "Name": "Array", "ElementType": { - "$id": "172", + "$id": "232", "Name": "int32", "Kind": "Int32", "IsNullable": true @@ -1297,13 +1703,13 @@ ] }, { - "$ref": "148" + "$ref": "208" }, { - "$ref": "147" + "$ref": "207" }, { - "$id": "173", + "$id": "233", "Name": "RoundTripReadOnlyModel", "Namespace": "ModelsTypeSpec", "Description": "Output model with readonly properties.", @@ -1311,12 +1717,12 @@ "Usage": "Output", "Properties": [ { - "$id": "174", + "$id": "234", "Name": "requiredReadonlyString", "SerializedName": "requiredReadonlyString", "Description": "Required string, illustrating a readonly reference type property.", "Type": { - "$id": "175", + "$id": "235", "Name": "string", "Kind": "String", "IsNullable": false @@ -1325,12 +1731,12 @@ "IsReadOnly": true }, { - "$id": "176", + "$id": "236", "Name": "requiredReadonlyInt", "SerializedName": "requiredReadonlyInt", "Description": "Required int, illustrating a readonly value type property.", "Type": { - "$id": "177", + "$id": "237", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -1339,12 +1745,12 @@ "IsReadOnly": true }, { - "$id": "178", + "$id": "238", "Name": "optionalReadonlyString", "SerializedName": "optionalReadonlyString", "Description": "Optional string, illustrating a readonly reference type property.", "Type": { - "$id": "179", + "$id": "239", "Name": "string", "Kind": "String", "IsNullable": false @@ -1353,12 +1759,12 @@ "IsReadOnly": true }, { - "$id": "180", + "$id": "240", "Name": "optionalReadonlyInt", "SerializedName": "optionalReadonlyInt", "Description": "Optional int, illustrating a readonly value type property.", "Type": { - "$id": "181", + "$id": "241", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -1367,29 +1773,29 @@ "IsReadOnly": true }, { - "$id": "182", + "$id": "242", "Name": "requiredReadonlyModel", "SerializedName": "requiredReadonlyModel", "Description": "Required readonly model.", "Type": { - "$ref": "43" + "$ref": "51" }, "IsRequired": true, "IsReadOnly": true }, { - "$id": "183", + "$id": "243", "Name": "optionalReadonlyModel", "SerializedName": "optionalReadonlyModel", "Description": "Optional readonly model.", "Type": { - "$ref": "43" + "$ref": "51" }, "IsRequired": false, "IsReadOnly": true }, { - "$id": "184", + "$id": "244", "Name": "requiredReadonlyFixedStringEnum", "SerializedName": "requiredReadonlyFixedStringEnum", "Description": "Required readonly fixed string enum", @@ -1400,7 +1806,7 @@ "IsReadOnly": true }, { - "$id": "185", + "$id": "245", "Name": "requiredReadonlyExtensibleEnum", "SerializedName": "requiredReadonlyExtensibleEnum", "Description": "Required readonly extensible enum", @@ -1411,7 +1817,7 @@ "IsReadOnly": true }, { - "$id": "186", + "$id": "246", "Name": "optionalReadonlyFixedStringEnum", "SerializedName": "optionalReadonlyFixedStringEnum", "Description": "Optional readonly fixed string enum", @@ -1422,7 +1828,7 @@ "IsReadOnly": true }, { - "$id": "187", + "$id": "247", "Name": "optionalReadonlyExtensibleEnum", "SerializedName": "optionalReadonlyExtensibleEnum", "Description": "Optional readonly extensible enum", @@ -1433,15 +1839,15 @@ "IsReadOnly": true }, { - "$id": "188", + "$id": "248", "Name": "requiredReadonlyStringList", "SerializedName": "requiredReadonlyStringList", "Description": "Required readonly string collection.", "Type": { - "$id": "189", + "$id": "249", "Name": "Array", "ElementType": { - "$id": "190", + "$id": "250", "Name": "string", "Kind": "String", "IsNullable": false @@ -1452,15 +1858,15 @@ "IsReadOnly": true }, { - "$id": "191", + "$id": "251", "Name": "requiredReadonlyIntList", "SerializedName": "requiredReadonlyIntList", "Description": "Required readonly int collection.", "Type": { - "$id": "192", + "$id": "252", "Name": "Array", "ElementType": { - "$id": "193", + "$id": "253", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -1471,15 +1877,15 @@ "IsReadOnly": true }, { - "$id": "194", - "Name": "requiredReadOnlyModelCollection", - "SerializedName": "requiredReadOnlyModelCollection", + "$id": "254", + "Name": "requiredReadOnlyModelList", + "SerializedName": "requiredReadOnlyModelList", "Description": "Required model collection", "Type": { - "$id": "195", + "$id": "255", "Name": "Array", "ElementType": { - "$ref": "38" + "$ref": "46" }, "IsNullable": false }, @@ -1487,21 +1893,21 @@ "IsReadOnly": true }, { - "$id": "196", + "$id": "256", "Name": "requiredReadOnlyIntRecord", "SerializedName": "requiredReadOnlyIntRecord", "Description": "Required int record", "Type": { - "$id": "197", + "$id": "257", "Name": "Dictionary", "KeyType": { - "$id": "198", + "$id": "258", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$id": "199", + "$id": "259", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -1512,21 +1918,21 @@ "IsReadOnly": true }, { - "$id": "200", + "$id": "260", "Name": "requiredStringRecord", "SerializedName": "requiredStringRecord", "Description": "Required string record", "Type": { - "$id": "201", + "$id": "261", "Name": "Dictionary", "KeyType": { - "$id": "202", + "$id": "262", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$id": "203", + "$id": "263", "Name": "string", "Kind": "String", "IsNullable": false @@ -1537,21 +1943,21 @@ "IsReadOnly": true }, { - "$id": "204", + "$id": "264", "Name": "requiredReadOnlyModelRecord", "SerializedName": "requiredReadOnlyModelRecord", "Description": "Required model record", "Type": { - "$id": "205", + "$id": "265", "Name": "Dictionary", "KeyType": { - "$id": "206", + "$id": "266", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$ref": "42" + "$ref": "50" }, "IsNullable": false }, @@ -1559,15 +1965,15 @@ "IsReadOnly": true }, { - "$id": "207", + "$id": "267", "Name": "optionalReadonlyStringList", "SerializedName": "optionalReadonlyStringList", "Description": "Optional readonly string collection.", "Type": { - "$id": "208", + "$id": "268", "Name": "Array", "ElementType": { - "$id": "209", + "$id": "269", "Name": "string", "Kind": "String", "IsNullable": false @@ -1578,15 +1984,15 @@ "IsReadOnly": true }, { - "$id": "210", + "$id": "270", "Name": "optionalReadonlyIntList", "SerializedName": "optionalReadonlyIntList", "Description": "Optional readonly int collection.", "Type": { - "$id": "211", + "$id": "271", "Name": "Array", "ElementType": { - "$id": "212", + "$id": "272", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -1597,15 +2003,15 @@ "IsReadOnly": true }, { - "$id": "213", - "Name": "optionalReadOnlyModelCollection", - "SerializedName": "optionalReadOnlyModelCollection", + "$id": "273", + "Name": "optionalReadOnlyModelList", + "SerializedName": "optionalReadOnlyModelList", "Description": "Optional model collection", "Type": { - "$id": "214", + "$id": "274", "Name": "Array", "ElementType": { - "$ref": "38" + "$ref": "46" }, "IsNullable": false }, @@ -1613,21 +2019,21 @@ "IsReadOnly": true }, { - "$id": "215", + "$id": "275", "Name": "optionalReadOnlyIntRecord", "SerializedName": "optionalReadOnlyIntRecord", "Description": "Optional int record", "Type": { - "$id": "216", + "$id": "276", "Name": "Dictionary", "KeyType": { - "$id": "217", + "$id": "277", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$id": "218", + "$id": "278", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -1638,21 +2044,21 @@ "IsReadOnly": false }, { - "$id": "219", + "$id": "279", "Name": "optionalReadOnlyStringRecord", "SerializedName": "optionalReadOnlyStringRecord", "Description": "Optional string record", "Type": { - "$id": "220", + "$id": "280", "Name": "Dictionary", "KeyType": { - "$id": "221", + "$id": "281", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$id": "222", + "$id": "282", "Name": "string", "Kind": "String", "IsNullable": false @@ -1663,21 +2069,21 @@ "IsReadOnly": false }, { - "$id": "223", + "$id": "283", "Name": "optionalModelRecord", "SerializedName": "optionalModelRecord", "Description": "Optional model record", "Type": { - "$id": "224", + "$id": "284", "Name": "Dictionary", "KeyType": { - "$id": "225", + "$id": "285", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$ref": "42" + "$ref": "50" }, "IsNullable": false }, @@ -1685,15 +2091,15 @@ "IsReadOnly": true }, { - "$id": "226", + "$id": "286", "Name": "requiredCollectionWithNullableIntElement", "SerializedName": "requiredCollectionWithNullableIntElement", "Description": "Required collection of which the element is a nullable int", "Type": { - "$id": "227", + "$id": "287", "Name": "Array", "ElementType": { - "$id": "228", + "$id": "288", "Name": "int32", "Kind": "Int32", "IsNullable": true @@ -1704,15 +2110,15 @@ "IsReadOnly": false }, { - "$id": "229", + "$id": "289", "Name": "optionalCollectionWithNullableBooleanElement", "SerializedName": "optionalCollectionWithNullableBooleanElement", "Description": "Optional collection of which the element is a nullable boolean", "Type": { - "$id": "230", + "$id": "290", "Name": "Array", "ElementType": { - "$id": "231", + "$id": "291", "Name": "boolean", "Kind": "Boolean", "IsNullable": true @@ -1725,7 +2131,7 @@ ] }, { - "$id": "232", + "$id": "292", "Name": "OutputModel", "Namespace": "ModelsTypeSpec", "Description": "Model used only as output", @@ -1733,12 +2139,12 @@ "Usage": "Output", "Properties": [ { - "$id": "233", + "$id": "293", "Name": "requiredString", "SerializedName": "requiredString", "Description": "Required string", "Type": { - "$id": "234", + "$id": "294", "Name": "string", "Kind": "String", "IsNullable": false @@ -1747,12 +2153,12 @@ "IsReadOnly": false }, { - "$id": "235", + "$id": "295", "Name": "requiredInt", "SerializedName": "requiredInt", "Description": "Required int", "Type": { - "$id": "236", + "$id": "296", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -1761,26 +2167,26 @@ "IsReadOnly": false }, { - "$id": "237", + "$id": "297", "Name": "requiredModel", "SerializedName": "requiredModel", "Description": "Required model", "Type": { - "$ref": "43" + "$ref": "51" }, "IsRequired": true, "IsReadOnly": false }, { - "$id": "238", - "Name": "requiredCollection", - "SerializedName": "requiredCollection", + "$id": "298", + "Name": "requiredList", + "SerializedName": "requiredList", "Description": "Required collection", "Type": { - "$id": "239", + "$id": "299", "Name": "Array", "ElementType": { - "$ref": "38" + "$ref": "46" }, "IsNullable": false }, @@ -1788,31 +2194,107 @@ "IsReadOnly": false }, { - "$id": "240", + "$id": "300", "Name": "requiredModelRecord", "SerializedName": "requiredModelRecord", "Description": "Required model record", "Type": { - "$id": "241", + "$id": "301", "Name": "Dictionary", "KeyType": { - "$id": "242", + "$id": "302", "Name": "string", "Kind": "String", "IsNullable": false }, "ValueType": { - "$ref": "42" + "$ref": "50" }, "IsNullable": false }, "IsRequired": true, "IsReadOnly": false + }, + { + "$id": "303", + "Name": "optionalList", + "SerializedName": "optionalList", + "Description": "Optional model collection", + "Type": { + "$id": "304", + "Name": "Array", + "ElementType": { + "$ref": "46" + }, + "IsNullable": false + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "305", + "Name": "optionalNullableList", + "SerializedName": "optionalNullableList", + "Description": "Optional model nullable collection", + "Type": { + "$id": "306", + "Name": "Array", + "ElementType": { + "$ref": "46" + }, + "IsNullable": true + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "307", + "Name": "optionalRecord", + "SerializedName": "optionalRecord", + "Description": "Optional model record", + "Type": { + "$id": "308", + "Name": "Dictionary", + "KeyType": { + "$id": "309", + "Name": "string", + "Kind": "String", + "IsNullable": false + }, + "ValueType": { + "$ref": "50" + }, + "IsNullable": false + }, + "IsRequired": false, + "IsReadOnly": false + }, + { + "$id": "310", + "Name": "optionalNullableRecord", + "SerializedName": "optionalNullableRecord", + "Description": "Optional model nullable record", + "Type": { + "$id": "311", + "Name": "Dictionary", + "KeyType": { + "$id": "312", + "Name": "string", + "Kind": "String", + "IsNullable": false + }, + "ValueType": { + "$ref": "50" + }, + "IsNullable": true + }, + "IsRequired": false, + "IsReadOnly": false } ] }, { - "$id": "243", + "$id": "313", "Name": "InputRecursiveModel", "Namespace": "ModelsTypeSpec", "Description": "Input model that has property of its own type", @@ -1820,12 +2302,12 @@ "Usage": "Input", "Properties": [ { - "$id": "244", + "$id": "314", "Name": "message", "SerializedName": "message", "Description": "Message", "Type": { - "$id": "245", + "$id": "315", "Name": "string", "Kind": "String", "IsNullable": false @@ -1834,12 +2316,12 @@ "IsReadOnly": false }, { - "$id": "246", + "$id": "316", "Name": "inner", "SerializedName": "inner", "Description": "Required Record", "Type": { - "$ref": "243" + "$ref": "313" }, "IsRequired": false, "IsReadOnly": false @@ -1847,7 +2329,7 @@ ] }, { - "$id": "247", + "$id": "317", "Name": "RoundTripRecursiveModel", "Namespace": "ModelsTypeSpec", "Description": "Roundtrip model that has property of its own type", @@ -1855,12 +2337,12 @@ "Usage": "RoundTrip", "Properties": [ { - "$id": "248", + "$id": "318", "Name": "message", "SerializedName": "message", "Description": "Message", "Type": { - "$id": "249", + "$id": "319", "Name": "string", "Kind": "String", "IsNullable": false @@ -1869,12 +2351,12 @@ "IsReadOnly": false }, { - "$id": "250", + "$id": "320", "Name": "inner", "SerializedName": "inner", "Description": "Required Record", "Type": { - "$ref": "247" + "$ref": "317" }, "IsRequired": false, "IsReadOnly": false @@ -1882,7 +2364,7 @@ ] }, { - "$id": "251", + "$id": "321", "Name": "ErrorModel", "Namespace": "ModelsTypeSpec", "Description": "Output model that has property of its own type", @@ -1890,12 +2372,12 @@ "Usage": "Output", "Properties": [ { - "$id": "252", + "$id": "322", "Name": "message", "SerializedName": "message", "Description": "Error message", "Type": { - "$id": "253", + "$id": "323", "Name": "string", "Kind": "String", "IsNullable": false @@ -1904,12 +2386,12 @@ "IsReadOnly": true }, { - "$id": "254", + "$id": "324", "Name": "innerError", "SerializedName": "innerError", "Description": "Required Record", "Type": { - "$ref": "251" + "$ref": "321" }, "IsRequired": false, "IsReadOnly": true @@ -1917,7 +2399,7 @@ ] }, { - "$id": "255", + "$id": "325", "Name": "NoUseBase", "Namespace": "ModelsTypeSpec", "Description": "Base model", @@ -1925,12 +2407,12 @@ "Usage": "None", "Properties": [ { - "$id": "256", + "$id": "326", "Name": "baseModelProp", "SerializedName": "baseModelProp", "Description": "base model property", "Type": { - "$id": "257", + "$id": "327", "Name": "string", "Kind": "String", "IsNullable": false @@ -1941,26 +2423,26 @@ ] }, { - "$id": "258", + "$id": "328", "Name": "RoundTripOnNoUse", "Namespace": "ModelsTypeSpec", "Description": "Derived model", "IsNullable": false, "BaseModel": { - "$ref": "255" + "$ref": "325" }, "Usage": "RoundTrip", "Properties": [ { - "$id": "259", - "Name": "requiredCollection", - "SerializedName": "requiredCollection", + "$id": "329", + "Name": "requiredList", + "SerializedName": "requiredList", "Description": "Required collection", "Type": { - "$id": "260", + "$id": "330", "Name": "Array", "ElementType": { - "$ref": "38" + "$ref": "46" }, "IsNullable": false }, @@ -1972,21 +2454,21 @@ ], "Clients": [ { - "$id": "261", + "$id": "331", "Name": "ModelsTypeSpecClient", "Description": "CADL project to test various types of models.", "Operations": [ { - "$id": "262", + "$id": "332", "Name": "getOutputDiscriminatorModel", "ResourceName": "ModelsTypeSpec", "Parameters": [ { - "$id": "263", + "$id": "333", "Name": "endpoint", "NameInRequest": "endpoint", "Type": { - "$id": "264", + "$id": "334", "Name": "Uri", "Kind": "Uri", "IsNullable": false @@ -2002,11 +2484,11 @@ "Kind": "Client" }, { - "$id": "265", + "$id": "335", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "266", + "$id": "336", "Name": "String", "Kind": "String", "IsNullable": false @@ -2021,20 +2503,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "267", + "$id": "337", "Type": { - "$ref": "266" + "$ref": "336" }, "Value": "application/json" } }, { - "$id": "268", + "$id": "338", "Name": "apiVersion", "NameInRequest": "api-version", "Description": "", "Type": { - "$id": "269", + "$id": "339", "Name": "String", "Kind": "String", "IsNullable": false @@ -2049,9 +2531,9 @@ "Explode": false, "Kind": "Client", "DefaultValue": { - "$id": "270", + "$id": "340", "Type": { - "$id": "271", + "$id": "341", "Name": "String", "Kind": "String", "IsNullable": false @@ -2062,7 +2544,7 @@ ], "Responses": [ { - "$id": "272", + "$id": "342", "StatusCodes": [ 200 ], @@ -2083,16 +2565,16 @@ "GenerateConvenienceMethod": true }, { - "$id": "273", + "$id": "343", "Name": "inputToRoundTrip", "ResourceName": "ModelsTypeSpec", "Description": "Input model that has property of its own type", "Parameters": [ { - "$ref": "263" + "$ref": "333" }, { - "$id": "274", + "$id": "344", "Name": "input", "NameInRequest": "input", "Type": { @@ -2109,11 +2591,11 @@ "Kind": "Method" }, { - "$id": "275", + "$id": "345", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "276", + "$id": "346", "Name": "String", "Kind": "String", "IsNullable": false @@ -2128,19 +2610,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "277", + "$id": "347", "Type": { - "$ref": "276" + "$ref": "346" }, "Value": "application/json" } }, { - "$id": "278", + "$id": "348", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "279", + "$id": "349", "Name": "String", "Kind": "String", "IsNullable": false @@ -2155,25 +2637,25 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "280", + "$id": "350", "Type": { - "$ref": "279" + "$ref": "349" }, "Value": "application/json" } }, { - "$ref": "268" + "$ref": "338" } ], "Responses": [ { - "$id": "281", + "$id": "351", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "55" + "$ref": "87" }, "BodyMediaType": "Json", "Headers": [], @@ -2192,16 +2674,16 @@ "GenerateConvenienceMethod": true }, { - "$id": "282", + "$id": "352", "Name": "inputToRoundTripPrimitive", "ResourceName": "ModelsTypeSpec", "Description": "Input to RoundTripPrimitive", "Parameters": [ { - "$ref": "263" + "$ref": "333" }, { - "$id": "283", + "$id": "353", "Name": "input", "NameInRequest": "input", "Type": { @@ -2218,11 +2700,11 @@ "Kind": "Method" }, { - "$id": "284", + "$id": "354", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "285", + "$id": "355", "Name": "String", "Kind": "String", "IsNullable": false @@ -2237,19 +2719,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "286", + "$id": "356", "Type": { - "$ref": "285" + "$ref": "355" }, "Value": "application/json" } }, { - "$id": "287", + "$id": "357", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "288", + "$id": "358", "Name": "String", "Kind": "String", "IsNullable": false @@ -2264,25 +2746,25 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "289", + "$id": "359", "Type": { - "$ref": "288" + "$ref": "358" }, "Value": "application/json" } }, { - "$ref": "268" + "$ref": "338" } ], "Responses": [ { - "$id": "290", + "$id": "360", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "110" + "$ref": "170" }, "BodyMediaType": "Json", "Headers": [], @@ -2301,20 +2783,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "291", + "$id": "361", "Name": "inputToRoundTripOptional", "ResourceName": "ModelsTypeSpec", "Description": "Input to RoundTripOptional", "Parameters": [ { - "$ref": "263" + "$ref": "333" }, { - "$id": "292", + "$id": "362", "Name": "input", "NameInRequest": "input", "Type": { - "$ref": "132" + "$ref": "192" }, "Location": "Body", "IsRequired": true, @@ -2327,11 +2809,11 @@ "Kind": "Method" }, { - "$id": "293", + "$id": "363", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "294", + "$id": "364", "Name": "String", "Kind": "String", "IsNullable": false @@ -2346,19 +2828,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "295", + "$id": "365", "Type": { - "$ref": "294" + "$ref": "364" }, "Value": "application/json" } }, { - "$id": "296", + "$id": "366", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "297", + "$id": "367", "Name": "String", "Kind": "String", "IsNullable": false @@ -2373,25 +2855,25 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "298", + "$id": "368", "Type": { - "$ref": "297" + "$ref": "367" }, "Value": "application/json" } }, { - "$ref": "268" + "$ref": "338" } ], "Responses": [ { - "$id": "299", + "$id": "369", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "132" + "$ref": "192" }, "BodyMediaType": "Json", "Headers": [], @@ -2410,17 +2892,17 @@ "GenerateConvenienceMethod": true }, { - "$id": "300", + "$id": "370", "Name": "inputToRoundTripReadOnly", "ResourceName": "ModelsTypeSpec", "Deprecated": "deprecated for test", "Description": "Input to RoundTripReadOnly", "Parameters": [ { - "$ref": "263" + "$ref": "333" }, { - "$id": "301", + "$id": "371", "Name": "input", "NameInRequest": "input", "Type": { @@ -2437,11 +2919,11 @@ "Kind": "Method" }, { - "$id": "302", + "$id": "372", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "303", + "$id": "373", "Name": "String", "Kind": "String", "IsNullable": false @@ -2456,19 +2938,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "304", + "$id": "374", "Type": { - "$ref": "303" + "$ref": "373" }, "Value": "application/json" } }, { - "$id": "305", + "$id": "375", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "306", + "$id": "376", "Name": "String", "Kind": "String", "IsNullable": false @@ -2483,25 +2965,25 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "307", + "$id": "377", "Type": { - "$ref": "306" + "$ref": "376" }, "Value": "application/json" } }, { - "$ref": "268" + "$ref": "338" } ], "Responses": [ { - "$id": "308", + "$id": "378", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "173" + "$ref": "233" }, "BodyMediaType": "Json", "Headers": [], @@ -2520,20 +3002,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "309", + "$id": "379", "Name": "roundTripToOutput", "ResourceName": "ModelsTypeSpec", "Description": "RoundTrip to Output", "Parameters": [ { - "$ref": "263" + "$ref": "333" }, { - "$id": "310", + "$id": "380", "Name": "input", "NameInRequest": "input", "Type": { - "$ref": "55" + "$ref": "87" }, "Location": "Body", "IsRequired": true, @@ -2546,11 +3028,11 @@ "Kind": "Method" }, { - "$id": "311", + "$id": "381", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "312", + "$id": "382", "Name": "String", "Kind": "String", "IsNullable": false @@ -2565,19 +3047,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "313", + "$id": "383", "Type": { - "$ref": "312" + "$ref": "382" }, "Value": "application/json" } }, { - "$id": "314", + "$id": "384", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "315", + "$id": "385", "Name": "String", "Kind": "String", "IsNullable": false @@ -2592,25 +3074,25 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "316", + "$id": "386", "Type": { - "$ref": "315" + "$ref": "385" }, "Value": "application/json" } }, { - "$ref": "268" + "$ref": "338" } ], "Responses": [ { - "$id": "317", + "$id": "387", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "232" + "$ref": "292" }, "BodyMediaType": "Json", "Headers": [], @@ -2629,20 +3111,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "318", + "$id": "388", "Name": "InputRecursive", "ResourceName": "ModelsTypeSpec", "Description": "Input recursive model", "Parameters": [ { - "$ref": "263" + "$ref": "333" }, { - "$id": "319", + "$id": "389", "Name": "input", "NameInRequest": "input", "Type": { - "$ref": "243" + "$ref": "313" }, "Location": "Body", "IsRequired": true, @@ -2655,11 +3137,11 @@ "Kind": "Method" }, { - "$id": "320", + "$id": "390", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "321", + "$id": "391", "Name": "String", "Kind": "String", "IsNullable": false @@ -2674,19 +3156,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "322", + "$id": "392", "Type": { - "$ref": "321" + "$ref": "391" }, "Value": "application/json" } }, { - "$id": "323", + "$id": "393", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "324", + "$id": "394", "Name": "String", "Kind": "String", "IsNullable": false @@ -2701,20 +3183,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "325", + "$id": "395", "Type": { - "$ref": "324" + "$ref": "394" }, "Value": "application/json" } }, { - "$ref": "268" + "$ref": "338" } ], "Responses": [ { - "$id": "326", + "$id": "396", "StatusCodes": [ 200 ], @@ -2735,20 +3217,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "327", + "$id": "397", "Name": "roundTripRecursive", "ResourceName": "ModelsTypeSpec", "Description": "RoundTrip recursive model", "Parameters": [ { - "$ref": "263" + "$ref": "333" }, { - "$id": "328", + "$id": "398", "Name": "input", "NameInRequest": "input", "Type": { - "$ref": "247" + "$ref": "317" }, "Location": "Body", "IsRequired": true, @@ -2761,11 +3243,11 @@ "Kind": "Method" }, { - "$id": "329", + "$id": "399", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "330", + "$id": "400", "Name": "String", "Kind": "String", "IsNullable": false @@ -2780,19 +3262,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "331", + "$id": "401", "Type": { - "$ref": "330" + "$ref": "400" }, "Value": "application/json" } }, { - "$id": "332", + "$id": "402", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "333", + "$id": "403", "Name": "String", "Kind": "String", "IsNullable": false @@ -2807,25 +3289,25 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "334", + "$id": "404", "Type": { - "$ref": "333" + "$ref": "403" }, "Value": "application/json" } }, { - "$ref": "268" + "$ref": "338" } ], "Responses": [ { - "$id": "335", + "$id": "405", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "247" + "$ref": "317" }, "BodyMediaType": "Json", "Headers": [], @@ -2844,20 +3326,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "336", + "$id": "406", "Name": "selfReference", "ResourceName": "ModelsTypeSpec", "Description": "Returns model that has property of its own type", "Parameters": [ { - "$ref": "263" + "$ref": "333" }, { - "$id": "337", + "$id": "407", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "338", + "$id": "408", "Name": "String", "Kind": "String", "IsNullable": false @@ -2872,25 +3354,25 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "339", + "$id": "409", "Type": { - "$ref": "338" + "$ref": "408" }, "Value": "application/json" } }, { - "$ref": "268" + "$ref": "338" } ], "Responses": [ { - "$id": "340", + "$id": "410", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "251" + "$ref": "321" }, "BodyMediaType": "Json", "Headers": [], @@ -2906,20 +3388,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "341", + "$id": "411", "Name": "roundTripToOutputWithNoUseBase", "ResourceName": "ModelsTypeSpec", "Description": "Returns RoundTripOnNoUse", "Parameters": [ { - "$ref": "263" + "$ref": "333" }, { - "$id": "342", + "$id": "412", "Name": "input", "NameInRequest": "input", "Type": { - "$ref": "258" + "$ref": "328" }, "Location": "Body", "IsRequired": true, @@ -2932,11 +3414,11 @@ "Kind": "Method" }, { - "$id": "343", + "$id": "413", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "344", + "$id": "414", "Name": "String", "Kind": "String", "IsNullable": false @@ -2951,19 +3433,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "345", + "$id": "415", "Type": { - "$ref": "344" + "$ref": "414" }, "Value": "application/json" } }, { - "$id": "346", + "$id": "416", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "347", + "$id": "417", "Name": "String", "Kind": "String", "IsNullable": false @@ -2978,25 +3460,25 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "348", + "$id": "418", "Type": { - "$ref": "347" + "$ref": "417" }, "Value": "application/json" } }, { - "$ref": "268" + "$ref": "338" } ], "Responses": [ { - "$id": "349", + "$id": "419", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "258" + "$ref": "328" }, "BodyMediaType": "Json", "Headers": [], @@ -3016,7 +3498,7 @@ } ], "Protocol": { - "$id": "350" + "$id": "420" }, "Creatable": true } diff --git a/test/TestProjects/Models-TypeSpec/tests/Generated/Samples/Samples_ModelsTypeSpecClient.cs b/test/TestProjects/Models-TypeSpec/tests/Generated/Samples/Samples_ModelsTypeSpecClient.cs index 9e543194a45..16a96c74606 100644 --- a/test/TestProjects/Models-TypeSpec/tests/Generated/Samples/Samples_ModelsTypeSpecClient.cs +++ b/test/TestProjects/Models-TypeSpec/tests/Generated/Samples/Samples_ModelsTypeSpecClient.cs @@ -93,14 +93,16 @@ public void Example_InputToRoundTrip() { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", requiredModel = new { }, - requiredIntCollection = new[] { + requiredIntList = new[] { 1234 }, - requiredStringCollection = new[] { + requiredStringList = new[] { "" }, - requiredModelCollection = new[] { + requiredModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -116,6 +118,15 @@ public void Example_InputToRoundTrip() }, requiredCollectionWithNullableBooleanElement = new[] { true + }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 }, }; @@ -124,6 +135,9 @@ public void Example_InputToRoundTrip() JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; Console.WriteLine(result.GetProperty("requiredString").ToString()); Console.WriteLine(result.GetProperty("requiredInt").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableInt").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableString").ToString()); + Console.WriteLine(result.GetProperty("requiredReadonlyInt").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("discriminatorProperty").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredPropertyOnBase").ToString()); Console.WriteLine(result.GetProperty("requiredFixedStringEnum").ToString()); @@ -135,6 +149,8 @@ public void Example_InputToRoundTrip() Console.WriteLine(result.GetProperty("requiredUint8Array")[0].ToString()); Console.WriteLine(result.GetProperty("requiredUnknown").ToString()); Console.WriteLine(result.GetProperty("requiredInt8Array")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableIntList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableStringList")[0].ToString()); } [Test] @@ -148,14 +164,18 @@ public void Example_InputToRoundTrip_AllParameters() { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", + nonRequiredNullableInt = 1234, + nonRequiredNullableString = "", requiredModel = new { }, - requiredIntCollection = new[] { + requiredIntList = new[] { 1234 }, - requiredStringCollection = new[] { + requiredStringList = new[] { "" }, - requiredModelCollection = new[] { + requiredModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -171,6 +191,33 @@ public void Example_InputToRoundTrip_AllParameters() }, requiredCollectionWithNullableBooleanElement = new[] { true + }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 + }, + nonRequiredModelList = new[] { + new {} + }, + nonRequiredStringList = new[] { + "" + }, + nonRequiredIntList = new[] { + 1234 + }, + nonRequiredNullableModelList = new[] { + new {} + }, + nonRequiredNullableStringList = new[] { + "" + }, + nonRequiredNullableIntList = new[] { + 1234 }, }; @@ -179,6 +226,14 @@ public void Example_InputToRoundTrip_AllParameters() JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; Console.WriteLine(result.GetProperty("requiredString").ToString()); Console.WriteLine(result.GetProperty("requiredInt").ToString()); + Console.WriteLine(result.GetProperty("nonRequiredString").ToString()); + Console.WriteLine(result.GetProperty("nonRequiredInt").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableInt").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableString").ToString()); + Console.WriteLine(result.GetProperty("nonRequiredNullableInt").ToString()); + Console.WriteLine(result.GetProperty("nonRequiredNullableString").ToString()); + Console.WriteLine(result.GetProperty("requiredReadonlyInt").ToString()); + Console.WriteLine(result.GetProperty("nonRequiredReadonlyInt").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("discriminatorProperty").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalPropertyOnBase").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredPropertyOnBase").ToString()); @@ -195,6 +250,10 @@ public void Example_InputToRoundTrip_AllParameters() Console.WriteLine(result.GetProperty("optionalUnknown").ToString()); Console.WriteLine(result.GetProperty("requiredInt8Array")[0].ToString()); Console.WriteLine(result.GetProperty("optionalInt8Array")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableIntList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableStringList")[0].ToString()); + Console.WriteLine(result.GetProperty("nonRequiredNullableIntList")[0].ToString()); + Console.WriteLine(result.GetProperty("nonRequiredNullableStringList")[0].ToString()); } [Test] @@ -208,14 +267,16 @@ public async Task Example_InputToRoundTrip_Async() { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", requiredModel = new { }, - requiredIntCollection = new[] { + requiredIntList = new[] { 1234 }, - requiredStringCollection = new[] { + requiredStringList = new[] { "" }, - requiredModelCollection = new[] { + requiredModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -231,6 +292,15 @@ public async Task Example_InputToRoundTrip_Async() }, requiredCollectionWithNullableBooleanElement = new[] { true + }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 }, }; @@ -239,6 +309,9 @@ public async Task Example_InputToRoundTrip_Async() JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; Console.WriteLine(result.GetProperty("requiredString").ToString()); Console.WriteLine(result.GetProperty("requiredInt").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableInt").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableString").ToString()); + Console.WriteLine(result.GetProperty("requiredReadonlyInt").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("discriminatorProperty").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredPropertyOnBase").ToString()); Console.WriteLine(result.GetProperty("requiredFixedStringEnum").ToString()); @@ -250,6 +323,8 @@ public async Task Example_InputToRoundTrip_Async() Console.WriteLine(result.GetProperty("requiredUint8Array")[0].ToString()); Console.WriteLine(result.GetProperty("requiredUnknown").ToString()); Console.WriteLine(result.GetProperty("requiredInt8Array")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableIntList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableStringList")[0].ToString()); } [Test] @@ -263,14 +338,18 @@ public async Task Example_InputToRoundTrip_AllParameters_Async() { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", + nonRequiredNullableInt = 1234, + nonRequiredNullableString = "", requiredModel = new { }, - requiredIntCollection = new[] { + requiredIntList = new[] { 1234 }, - requiredStringCollection = new[] { + requiredStringList = new[] { "" }, - requiredModelCollection = new[] { + requiredModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -286,6 +365,33 @@ public async Task Example_InputToRoundTrip_AllParameters_Async() }, requiredCollectionWithNullableBooleanElement = new[] { true + }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 + }, + nonRequiredModelList = new[] { + new {} + }, + nonRequiredStringList = new[] { + "" + }, + nonRequiredIntList = new[] { + 1234 + }, + nonRequiredNullableModelList = new[] { + new {} + }, + nonRequiredNullableStringList = new[] { + "" + }, + nonRequiredNullableIntList = new[] { + 1234 }, }; @@ -294,6 +400,14 @@ public async Task Example_InputToRoundTrip_AllParameters_Async() JsonElement result = JsonDocument.Parse(response.ContentStream).RootElement; Console.WriteLine(result.GetProperty("requiredString").ToString()); Console.WriteLine(result.GetProperty("requiredInt").ToString()); + Console.WriteLine(result.GetProperty("nonRequiredString").ToString()); + Console.WriteLine(result.GetProperty("nonRequiredInt").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableInt").ToString()); + Console.WriteLine(result.GetProperty("requiredNullableString").ToString()); + Console.WriteLine(result.GetProperty("nonRequiredNullableInt").ToString()); + Console.WriteLine(result.GetProperty("nonRequiredNullableString").ToString()); + Console.WriteLine(result.GetProperty("requiredReadonlyInt").ToString()); + Console.WriteLine(result.GetProperty("nonRequiredReadonlyInt").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("discriminatorProperty").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("optionalPropertyOnBase").ToString()); Console.WriteLine(result.GetProperty("requiredModel").GetProperty("requiredPropertyOnBase").ToString()); @@ -310,6 +424,10 @@ public async Task Example_InputToRoundTrip_AllParameters_Async() Console.WriteLine(result.GetProperty("optionalUnknown").ToString()); Console.WriteLine(result.GetProperty("requiredInt8Array")[0].ToString()); Console.WriteLine(result.GetProperty("optionalInt8Array")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableIntList")[0].ToString()); + Console.WriteLine(result.GetProperty("requiredNullableStringList")[0].ToString()); + Console.WriteLine(result.GetProperty("nonRequiredNullableIntList")[0].ToString()); + Console.WriteLine(result.GetProperty("nonRequiredNullableStringList")[0].ToString()); } [Test] @@ -319,7 +437,7 @@ public async Task Example_InputToRoundTrip_Convenience_Async() var endpoint = new Uri(""); var client = new ModelsTypeSpecClient(endpoint); - var input = new InputModel("", 1234, new BaseModel(), new int[] + var input = new InputModel("", 1234, 1234, "", new BaseModel(), new int[] { 1234 }, new string[] @@ -337,7 +455,35 @@ public async Task Example_InputToRoundTrip_Convenience_Async() }, new bool?[] { true - }); + }, Array.Empty(), new string[] + { + "" + }, new int[] + { + 1234 + }) + { + NonRequiredNullableInt = 1234, + NonRequiredNullableString = "", + NonRequiredModelList = { }, + NonRequiredStringList = +{ + "" + }, + NonRequiredIntList = +{ + 1234 + }, + NonRequiredNullableModelList = { }, + NonRequiredNullableStringList = +{ + "" + }, + NonRequiredNullableIntList = +{ + 1234 + }, + }; var result = await client.InputToRoundTripAsync(input); } @@ -352,14 +498,16 @@ public void Example_InputToRoundTripPrimitive() { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", requiredModel = new { }, - requiredIntCollection = new[] { + requiredIntList = new[] { 1234 }, - requiredStringCollection = new[] { + requiredStringList = new[] { "" }, - requiredModelCollection = new[] { + requiredModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -375,6 +523,15 @@ public void Example_InputToRoundTripPrimitive() }, requiredCollectionWithNullableBooleanElement = new[] { true + }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 }, }; @@ -404,14 +561,18 @@ public void Example_InputToRoundTripPrimitive_AllParameters() { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", + nonRequiredNullableInt = 1234, + nonRequiredNullableString = "", requiredModel = new { }, - requiredIntCollection = new[] { + requiredIntList = new[] { 1234 }, - requiredStringCollection = new[] { + requiredStringList = new[] { "" }, - requiredModelCollection = new[] { + requiredModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -427,6 +588,33 @@ public void Example_InputToRoundTripPrimitive_AllParameters() }, requiredCollectionWithNullableBooleanElement = new[] { true + }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 + }, + nonRequiredModelList = new[] { + new {} + }, + nonRequiredStringList = new[] { + "" + }, + nonRequiredIntList = new[] { + 1234 + }, + nonRequiredNullableModelList = new[] { + new {} + }, + nonRequiredNullableStringList = new[] { + "" + }, + nonRequiredNullableIntList = new[] { + 1234 }, }; @@ -456,14 +644,16 @@ public async Task Example_InputToRoundTripPrimitive_Async() { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", requiredModel = new { }, - requiredIntCollection = new[] { + requiredIntList = new[] { 1234 }, - requiredStringCollection = new[] { + requiredStringList = new[] { "" }, - requiredModelCollection = new[] { + requiredModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -479,6 +669,15 @@ public async Task Example_InputToRoundTripPrimitive_Async() }, requiredCollectionWithNullableBooleanElement = new[] { true + }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 }, }; @@ -508,14 +707,18 @@ public async Task Example_InputToRoundTripPrimitive_AllParameters_Async() { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", + nonRequiredNullableInt = 1234, + nonRequiredNullableString = "", requiredModel = new { }, - requiredIntCollection = new[] { + requiredIntList = new[] { 1234 }, - requiredStringCollection = new[] { + requiredStringList = new[] { "" }, - requiredModelCollection = new[] { + requiredModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -531,6 +734,33 @@ public async Task Example_InputToRoundTripPrimitive_AllParameters_Async() }, requiredCollectionWithNullableBooleanElement = new[] { true + }, + requiredNullableModelList = new[] { + new {} + }, + requiredNullableStringList = new[] { + "" + }, + requiredNullableIntList = new[] { + 1234 + }, + nonRequiredModelList = new[] { + new {} + }, + nonRequiredStringList = new[] { + "" + }, + nonRequiredIntList = new[] { + 1234 + }, + nonRequiredNullableModelList = new[] { + new {} + }, + nonRequiredNullableStringList = new[] { + "" + }, + nonRequiredNullableIntList = new[] { + 1234 }, }; @@ -556,7 +786,7 @@ public async Task Example_InputToRoundTripPrimitive_Convenience_Async() var endpoint = new Uri(""); var client = new ModelsTypeSpecClient(endpoint); - var input = new InputModel("", 1234, new BaseModel(), new int[] + var input = new InputModel("", 1234, 1234, "", new BaseModel(), new int[] { 1234 }, new string[] @@ -574,7 +804,35 @@ public async Task Example_InputToRoundTripPrimitive_Convenience_Async() }, new bool?[] { true - }); + }, Array.Empty(), new string[] + { + "" + }, new int[] + { + 1234 + }) + { + NonRequiredNullableInt = 1234, + NonRequiredNullableString = "", + NonRequiredModelList = { }, + NonRequiredStringList = +{ + "" + }, + NonRequiredIntList = +{ + 1234 + }, + NonRequiredNullableModelList = { }, + NonRequiredNullableStringList = +{ + "" + }, + NonRequiredNullableIntList = +{ + 1234 + }, + }; var result = await client.InputToRoundTripPrimitiveAsync(input); } @@ -610,7 +868,7 @@ public void Example_InputToRoundTripOptional_AllParameters() optionalIntList = new[] { 1234 }, - optionalModelCollection = new[] { + optionalModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -692,7 +950,7 @@ public async Task Example_InputToRoundTripOptional_AllParameters_Async() optionalIntList = new[] { 1234 }, - optionalModelCollection = new[] { + optionalModelList = new[] { new { requiredModelRecord = new { key = new {}, @@ -753,6 +1011,8 @@ public void Example_RoundTripToOutput() { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", requiredModel = new { discriminatorProperty = "", @@ -761,7 +1021,7 @@ public void Example_RoundTripToOutput() requiredFixedStringEnum = "1", requiredFixedIntEnum = "1", requiredExtensibleEnum = "1", - requiredCollection = new[] { + requiredList = new[] { new { requiredModelRecord = new { key = new {}, @@ -787,6 +1047,12 @@ public void Example_RoundTripToOutput() requiredUnknown = new { }, requiredInt8Array = new[] { 1234 + }, + requiredNullableIntList = new[] { + 1234 + }, + requiredNullableStringList = new[] { + "" }, }; @@ -808,6 +1074,12 @@ public void Example_RoundTripToOutput_AllParameters() { requiredString = "", requiredInt = 1234, + nonRequiredString = "", + nonRequiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", + nonRequiredNullableInt = 1234, + nonRequiredNullableString = "", requiredModel = new { discriminatorProperty = "", @@ -817,7 +1089,7 @@ public void Example_RoundTripToOutput_AllParameters() requiredFixedStringEnum = "1", requiredFixedIntEnum = "1", requiredExtensibleEnum = "1", - requiredCollection = new[] { + requiredList = new[] { new { requiredModelRecord = new { key = new {}, @@ -851,6 +1123,18 @@ public void Example_RoundTripToOutput_AllParameters() }, optionalInt8Array = new[] { 1234 + }, + requiredNullableIntList = new[] { + 1234 + }, + requiredNullableStringList = new[] { + "" + }, + nonRequiredNullableIntList = new[] { + 1234 + }, + nonRequiredNullableStringList = new[] { + "" }, }; @@ -872,6 +1156,8 @@ public async Task Example_RoundTripToOutput_Async() { requiredString = "", requiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", requiredModel = new { discriminatorProperty = "", @@ -880,7 +1166,7 @@ public async Task Example_RoundTripToOutput_Async() requiredFixedStringEnum = "1", requiredFixedIntEnum = "1", requiredExtensibleEnum = "1", - requiredCollection = new[] { + requiredList = new[] { new { requiredModelRecord = new { key = new {}, @@ -906,6 +1192,12 @@ public async Task Example_RoundTripToOutput_Async() requiredUnknown = new { }, requiredInt8Array = new[] { 1234 + }, + requiredNullableIntList = new[] { + 1234 + }, + requiredNullableStringList = new[] { + "" }, }; @@ -927,6 +1219,12 @@ public async Task Example_RoundTripToOutput_AllParameters_Async() { requiredString = "", requiredInt = 1234, + nonRequiredString = "", + nonRequiredInt = 1234, + requiredNullableInt = 1234, + requiredNullableString = "", + nonRequiredNullableInt = 1234, + nonRequiredNullableString = "", requiredModel = new { discriminatorProperty = "", @@ -936,7 +1234,7 @@ public async Task Example_RoundTripToOutput_AllParameters_Async() requiredFixedStringEnum = "1", requiredFixedIntEnum = "1", requiredExtensibleEnum = "1", - requiredCollection = new[] { + requiredList = new[] { new { requiredModelRecord = new { key = new {}, @@ -970,6 +1268,18 @@ public async Task Example_RoundTripToOutput_AllParameters_Async() }, optionalInt8Array = new[] { 1234 + }, + requiredNullableIntList = new[] { + 1234 + }, + requiredNullableStringList = new[] { + "" + }, + nonRequiredNullableIntList = new[] { + 1234 + }, + nonRequiredNullableStringList = new[] { + "" }, }; @@ -1213,7 +1523,7 @@ public void Example_RoundTripToOutputWithNoUseBase() var data = new { - requiredCollection = new[] { + requiredList = new[] { new { requiredModelRecord = new { key = new {}, @@ -1238,7 +1548,7 @@ public void Example_RoundTripToOutputWithNoUseBase_AllParameters() var data = new { - requiredCollection = new[] { + requiredList = new[] { new { requiredModelRecord = new { key = new {}, @@ -1263,7 +1573,7 @@ public async Task Example_RoundTripToOutputWithNoUseBase_Async() var data = new { - requiredCollection = new[] { + requiredList = new[] { new { requiredModelRecord = new { key = new {}, @@ -1288,7 +1598,7 @@ public async Task Example_RoundTripToOutputWithNoUseBase_AllParameters_Async() var data = new { - requiredCollection = new[] { + requiredList = new[] { new { requiredModelRecord = new { key = new {}, diff --git a/test/TestProjects/Spread-TypeSpec/Spread-TypeSpec.tsp b/test/TestProjects/Spread-TypeSpec/Spread-TypeSpec.tsp index 8cf49dd1e0e..879ab00b899 100644 --- a/test/TestProjects/Spread-TypeSpec/Spread-TypeSpec.tsp +++ b/test/TestProjects/Spread-TypeSpec/Spread-TypeSpec.tsp @@ -75,6 +75,13 @@ alias ThingAliasWithOptionalProps = { elements?: string[]; }; +alias AliasWithRequiredAndOptionalCollections = { + @doc("required list") + requiredStringList: string[]; + @doc("optional list") + optionalStringList?: string[]; +}; + @route("/spreadModel") @doc("spread a model as body.") @post @@ -110,3 +117,9 @@ op spreadAliasWithSpreadAlias( ...ThingAliasWithSpreadAlias ): void; @post @convenientAPI(true) op spreadAliasWithOptionalProps( ...ThingAliasWithOptionalProps ): void; + +@route("/spreadAliasWithCollections") +@doc("spread an alias with required and optional collections") +@post +@convenientAPI(true) +op spreadAliasWithCollections( ...AliasWithRequiredAndOptionalCollections ): void; diff --git a/test/TestProjects/Spread-TypeSpec/src/Generated/Docs/SpreadTypeSpecClient.xml b/test/TestProjects/Spread-TypeSpec/src/Generated/Docs/SpreadTypeSpecClient.xml index 939978b3deb..9e7659f3591 100644 --- a/test/TestProjects/Spread-TypeSpec/src/Generated/Docs/SpreadTypeSpecClient.xml +++ b/test/TestProjects/Spread-TypeSpec/src/Generated/Docs/SpreadTypeSpecClient.xml @@ -383,6 +383,98 @@ var data = new { Response response = client.SpreadAliasWithOptionalProps("", 1234, RequestContent.Create(data)); Console.WriteLine(response.Status); ]]> + + + + +This sample shows how to call SpreadAliasWithCollectionsAsync with required parameters. +"); +var client = new SpreadTypeSpecClient(endpoint); + +var result = await client.SpreadAliasWithCollectionsAsync(new String[]{""}, new String[]{""}); +]]> + + + + +This sample shows how to call SpreadAliasWithCollections with required parameters. +"); +var client = new SpreadTypeSpecClient(endpoint); + +var result = client.SpreadAliasWithCollections(new String[]{""}, new String[]{""}); +]]> + + + + +This sample shows how to call SpreadAliasWithCollectionsAsync with required request content. +"); +var client = new SpreadTypeSpecClient(endpoint); + +var data = new { + requiredStringList = new[] { + "" + }, +}; + +Response response = await client.SpreadAliasWithCollectionsAsync(RequestContent.Create(data)); +Console.WriteLine(response.Status); +]]> +This sample shows how to call SpreadAliasWithCollectionsAsync with all request content. +"); +var client = new SpreadTypeSpecClient(endpoint); + +var data = new { + requiredStringList = new[] { + "" + }, + optionalStringList = new[] { + "" + }, +}; + +Response response = await client.SpreadAliasWithCollectionsAsync(RequestContent.Create(data)); +Console.WriteLine(response.Status); +]]> + + + + +This sample shows how to call SpreadAliasWithCollections with required request content. +"); +var client = new SpreadTypeSpecClient(endpoint); + +var data = new { + requiredStringList = new[] { + "" + }, +}; + +Response response = client.SpreadAliasWithCollections(RequestContent.Create(data)); +Console.WriteLine(response.Status); +]]> +This sample shows how to call SpreadAliasWithCollections with all request content. +"); +var client = new SpreadTypeSpecClient(endpoint); + +var data = new { + requiredStringList = new[] { + "" + }, + optionalStringList = new[] { + "" + }, +}; + +Response response = client.SpreadAliasWithCollections(RequestContent.Create(data)); +Console.WriteLine(response.Status); +]]> diff --git a/test/TestProjects/Spread-TypeSpec/src/Generated/Models/SpreadAliasWithCollectionsRequest.Serialization.cs b/test/TestProjects/Spread-TypeSpec/src/Generated/Models/SpreadAliasWithCollectionsRequest.Serialization.cs new file mode 100644 index 00000000000..dc788216671 --- /dev/null +++ b/test/TestProjects/Spread-TypeSpec/src/Generated/Models/SpreadAliasWithCollectionsRequest.Serialization.cs @@ -0,0 +1,46 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System.Text.Json; +using Azure.Core; + +namespace SpreadTypeSpec.Models +{ + internal partial class SpreadAliasWithCollectionsRequest : IUtf8JsonSerializable + { + void IUtf8JsonSerializable.Write(Utf8JsonWriter writer) + { + writer.WriteStartObject(); + writer.WritePropertyName("requiredStringList"u8); + writer.WriteStartArray(); + foreach (var item in RequiredStringList) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + if (Optional.IsCollectionDefined(OptionalStringList)) + { + writer.WritePropertyName("optionalStringList"u8); + writer.WriteStartArray(); + foreach (var item in OptionalStringList) + { + writer.WriteStringValue(item); + } + writer.WriteEndArray(); + } + writer.WriteEndObject(); + } + + /// Convert into a Utf8JsonRequestContent. + internal virtual RequestContent ToRequestContent() + { + var content = new Utf8JsonRequestContent(); + content.JsonWriter.WriteObjectValue(this); + return content; + } + } +} diff --git a/test/TestProjects/Spread-TypeSpec/src/Generated/Models/SpreadAliasWithCollectionsRequest.cs b/test/TestProjects/Spread-TypeSpec/src/Generated/Models/SpreadAliasWithCollectionsRequest.cs new file mode 100644 index 00000000000..bef6b260617 --- /dev/null +++ b/test/TestProjects/Spread-TypeSpec/src/Generated/Models/SpreadAliasWithCollectionsRequest.cs @@ -0,0 +1,43 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +// + +#nullable disable + +using System; +using System.Collections.Generic; +using System.Linq; +using Azure.Core; + +namespace SpreadTypeSpec.Models +{ + /// The SpreadAliasWithCollectionsRequest. + internal partial class SpreadAliasWithCollectionsRequest + { + /// Initializes a new instance of SpreadAliasWithCollectionsRequest. + /// required list. + /// is null. + public SpreadAliasWithCollectionsRequest(IEnumerable requiredStringList) + { + Argument.AssertNotNull(requiredStringList, nameof(requiredStringList)); + + RequiredStringList = requiredStringList.ToList(); + OptionalStringList = new ChangeTrackingList(); + } + + /// Initializes a new instance of SpreadAliasWithCollectionsRequest. + /// required list. + /// optional list. + internal SpreadAliasWithCollectionsRequest(IList requiredStringList, IList optionalStringList) + { + RequiredStringList = requiredStringList; + OptionalStringList = optionalStringList; + } + + /// required list. + public IList RequiredStringList { get; } + /// optional list. + public IList OptionalStringList { get; } + } +} diff --git a/test/TestProjects/Spread-TypeSpec/src/Generated/SpreadTypeSpecClient.cs b/test/TestProjects/Spread-TypeSpec/src/Generated/SpreadTypeSpecClient.cs index dffbb8f02fa..43bea5e4fd0 100644 --- a/test/TestProjects/Spread-TypeSpec/src/Generated/SpreadTypeSpecClient.cs +++ b/test/TestProjects/Spread-TypeSpec/src/Generated/SpreadTypeSpecClient.cs @@ -806,6 +806,132 @@ public virtual Response SpreadAliasWithOptionalProps(string id, int top, Request } } + /// spread an alias with required and optional collections. + /// required list. + /// optional list. + /// The cancellation token to use. + /// is null. + /// + public virtual async Task SpreadAliasWithCollectionsAsync(IEnumerable requiredStringList, IEnumerable optionalStringList = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(requiredStringList, nameof(requiredStringList)); + + RequestContext context = FromCancellationToken(cancellationToken); + SpreadAliasWithCollectionsRequest spreadAliasWithCollectionsRequest = new SpreadAliasWithCollectionsRequest(requiredStringList.ToList()); + if (optionalStringList != null) + { + foreach (var value in optionalStringList) + { + spreadAliasWithCollectionsRequest.OptionalStringList.Add(value); + } + } + SpreadAliasWithCollectionsRequest spreadAliasWithCollectionsRequest0 = spreadAliasWithCollectionsRequest; + Response response = await SpreadAliasWithCollectionsAsync(spreadAliasWithCollectionsRequest0.ToRequestContent(), context).ConfigureAwait(false); + return response; + } + + /// spread an alias with required and optional collections. + /// required list. + /// optional list. + /// The cancellation token to use. + /// is null. + /// + public virtual Response SpreadAliasWithCollections(IEnumerable requiredStringList, IEnumerable optionalStringList = null, CancellationToken cancellationToken = default) + { + Argument.AssertNotNull(requiredStringList, nameof(requiredStringList)); + + RequestContext context = FromCancellationToken(cancellationToken); + SpreadAliasWithCollectionsRequest spreadAliasWithCollectionsRequest = new SpreadAliasWithCollectionsRequest(requiredStringList.ToList()); + if (optionalStringList != null) + { + foreach (var value in optionalStringList) + { + spreadAliasWithCollectionsRequest.OptionalStringList.Add(value); + } + } + SpreadAliasWithCollectionsRequest spreadAliasWithCollectionsRequest0 = spreadAliasWithCollectionsRequest; + Response response = SpreadAliasWithCollections(spreadAliasWithCollectionsRequest0.ToRequestContent(), context); + return response; + } + + /// + /// [Protocol Method] spread an alias with required and optional collections + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual async Task SpreadAliasWithCollectionsAsync(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("SpreadTypeSpecClient.SpreadAliasWithCollections"); + scope.Start(); + try + { + using HttpMessage message = CreateSpreadAliasWithCollectionsRequest(content, context); + return await _pipeline.ProcessMessageAsync(message, context).ConfigureAwait(false); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + + /// + /// [Protocol Method] spread an alias with required and optional collections + /// + /// + /// + /// This protocol method allows explicit creation of the request and processing of the response for advanced scenarios. + /// + /// + /// + /// + /// Please try the simpler convenience overload with strongly typed models first. + /// + /// + /// + /// + /// The content to send as the body of the request. + /// The request context, which can override default behaviors of the client pipeline on a per-call basis. + /// is null. + /// Service returned a non-success status code. + /// The response returned from the service. + /// + public virtual Response SpreadAliasWithCollections(RequestContent content, RequestContext context = null) + { + Argument.AssertNotNull(content, nameof(content)); + + using var scope = ClientDiagnostics.CreateScope("SpreadTypeSpecClient.SpreadAliasWithCollections"); + scope.Start(); + try + { + using HttpMessage message = CreateSpreadAliasWithCollectionsRequest(content, context); + return _pipeline.ProcessMessage(message, context); + } + catch (Exception e) + { + scope.Failed(e); + throw; + } + } + internal HttpMessage CreateSpreadModelRequest(RequestContent content, RequestContext context) { var message = _pipeline.CreateMessage(context, ResponseClassifier204); @@ -910,6 +1036,22 @@ internal HttpMessage CreateSpreadAliasWithOptionalPropsRequest(string id, int to return message; } + internal HttpMessage CreateSpreadAliasWithCollectionsRequest(RequestContent content, RequestContext context) + { + var message = _pipeline.CreateMessage(context, ResponseClassifier204); + var request = message.Request; + request.Method = RequestMethod.Post; + var uri = new RawRequestUriBuilder(); + uri.Reset(_endpoint); + uri.AppendPath("/spreadAliasWithCollections", false); + uri.AppendQuery("api-version", _apiVersion, true); + request.Uri = uri; + request.Headers.Add("Accept", "application/json"); + request.Headers.Add("Content-Type", "application/json"); + request.Content = content; + return message; + } + private static RequestContext DefaultRequestContext = new RequestContext(); internal static RequestContext FromCancellationToken(CancellationToken cancellationToken = default) { diff --git a/test/TestProjects/Spread-TypeSpec/src/Generated/tspCodeModel.json b/test/TestProjects/Spread-TypeSpec/src/Generated/tspCodeModel.json index 06b16d09fcf..78abdb8a23c 100644 --- a/test/TestProjects/Spread-TypeSpec/src/Generated/tspCodeModel.json +++ b/test/TestProjects/Spread-TypeSpec/src/Generated/tspCodeModel.json @@ -243,26 +243,73 @@ "IsReadOnly": false } ] + }, + { + "$id": "35", + "Name": "SpreadAliasWithCollectionsRequest", + "Namespace": "SpreadTypeSpec", + "IsNullable": false, + "Usage": "Input", + "Properties": [ + { + "$id": "36", + "Name": "requiredStringList", + "SerializedName": "requiredStringList", + "Description": "required list", + "Type": { + "$id": "37", + "Name": "Array", + "ElementType": { + "$id": "38", + "Name": "string", + "Kind": "String", + "IsNullable": false + }, + "IsNullable": false + }, + "IsRequired": true, + "IsReadOnly": false + }, + { + "$id": "39", + "Name": "optionalStringList", + "SerializedName": "optionalStringList", + "Description": "optional list", + "Type": { + "$id": "40", + "Name": "Array", + "ElementType": { + "$id": "41", + "Name": "string", + "Kind": "String", + "IsNullable": false + }, + "IsNullable": false + }, + "IsRequired": false, + "IsReadOnly": false + } + ] } ], "Clients": [ { - "$id": "35", + "$id": "42", "Name": "SpreadTypeSpecClient", "Description": "This is a spread model or alias service.", "Operations": [ { - "$id": "36", + "$id": "43", "Name": "spreadModel", "ResourceName": "SpreadTypeSpec", "Description": "spread a model as body.", "Parameters": [ { - "$id": "37", + "$id": "44", "Name": "spreadUrl", "NameInRequest": "spreadUrl", "Type": { - "$id": "38", + "$id": "45", "Name": "Uri", "Kind": "Uri", "IsNullable": false @@ -278,7 +325,7 @@ "Kind": "Client" }, { - "$id": "39", + "$id": "46", "Name": "Thing", "NameInRequest": "Thing", "Type": { @@ -295,11 +342,11 @@ "Kind": "Method" }, { - "$id": "40", + "$id": "47", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "41", + "$id": "48", "Name": "String", "Kind": "String", "IsNullable": false @@ -314,19 +361,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "42", + "$id": "49", "Type": { - "$ref": "41" + "$ref": "48" }, "Value": "application/json" } }, { - "$id": "43", + "$id": "50", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "44", + "$id": "51", "Name": "String", "Kind": "String", "IsNullable": false @@ -341,20 +388,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "45", + "$id": "52", "Type": { - "$ref": "44" + "$ref": "51" }, "Value": "application/json" } }, { - "$id": "46", + "$id": "53", "Name": "apiVersion", "NameInRequest": "api-version", "Description": "", "Type": { - "$id": "47", + "$id": "54", "Name": "String", "Kind": "String", "IsNullable": false @@ -369,9 +416,9 @@ "Explode": false, "Kind": "Client", "DefaultValue": { - "$id": "48", + "$id": "55", "Type": { - "$id": "49", + "$id": "56", "Name": "String", "Kind": "String", "IsNullable": false @@ -382,7 +429,7 @@ ], "Responses": [ { - "$id": "50", + "$id": "57", "StatusCodes": [ 204 ], @@ -403,16 +450,16 @@ "GenerateConvenienceMethod": true }, { - "$id": "51", + "$id": "58", "Name": "spreadAlias", "ResourceName": "SpreadTypeSpec", "Description": "spread an alias as body.", "Parameters": [ { - "$ref": "37" + "$ref": "44" }, { - "$id": "52", + "$id": "59", "Name": "SpreadAliasRequest", "NameInRequest": "SpreadAliasRequest", "Type": { @@ -429,11 +476,11 @@ "Kind": "Spread" }, { - "$id": "53", + "$id": "60", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "54", + "$id": "61", "Name": "String", "Kind": "String", "IsNullable": false @@ -448,19 +495,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "55", + "$id": "62", "Type": { - "$ref": "54" + "$ref": "61" }, "Value": "application/json" } }, { - "$id": "56", + "$id": "63", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "57", + "$id": "64", "Name": "String", "Kind": "String", "IsNullable": false @@ -475,20 +522,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "58", + "$id": "65", "Type": { - "$ref": "57" + "$ref": "64" }, "Value": "application/json" } }, { - "$ref": "46" + "$ref": "53" } ], "Responses": [ { - "$id": "59", + "$id": "66", "StatusCodes": [ 204 ], @@ -509,20 +556,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "60", + "$id": "67", "Name": "spreadMultiTargetAlias", "ResourceName": "SpreadTypeSpec", "Description": "spread an alias which has multiple target property as body.", "Parameters": [ { - "$ref": "37" + "$ref": "44" }, { - "$id": "61", + "$id": "68", "Name": "id", "NameInRequest": "id", "Type": { - "$id": "62", + "$id": "69", "Name": "string", "Kind": "String", "IsNullable": false @@ -538,11 +585,11 @@ "Kind": "Method" }, { - "$id": "63", + "$id": "70", "Name": "top", "NameInRequest": "top", "Type": { - "$id": "64", + "$id": "71", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -558,7 +605,7 @@ "Kind": "Method" }, { - "$id": "65", + "$id": "72", "Name": "SpreadMultiTargetAliasRequest", "NameInRequest": "SpreadMultiTargetAliasRequest", "Type": { @@ -575,11 +622,11 @@ "Kind": "Spread" }, { - "$id": "66", + "$id": "73", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "67", + "$id": "74", "Name": "String", "Kind": "String", "IsNullable": false @@ -594,19 +641,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "68", + "$id": "75", "Type": { - "$ref": "67" + "$ref": "74" }, "Value": "application/json" } }, { - "$id": "69", + "$id": "76", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "70", + "$id": "77", "Name": "String", "Kind": "String", "IsNullable": false @@ -621,20 +668,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "71", + "$id": "78", "Type": { - "$ref": "70" + "$ref": "77" }, "Value": "application/json" } }, { - "$ref": "46" + "$ref": "53" } ], "Responses": [ { - "$id": "72", + "$id": "79", "StatusCodes": [ 204 ], @@ -655,20 +702,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "73", + "$id": "80", "Name": "spreadAliasWithModel", "ResourceName": "SpreadTypeSpec", "Description": "spread an alias which contains a complex model property as body.", "Parameters": [ { - "$ref": "37" + "$ref": "44" }, { - "$id": "74", + "$id": "81", "Name": "id", "NameInRequest": "id", "Type": { - "$id": "75", + "$id": "82", "Name": "string", "Kind": "String", "IsNullable": false @@ -684,11 +731,11 @@ "Kind": "Method" }, { - "$id": "76", + "$id": "83", "Name": "top", "NameInRequest": "top", "Type": { - "$id": "77", + "$id": "84", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -704,7 +751,7 @@ "Kind": "Method" }, { - "$id": "78", + "$id": "85", "Name": "Thing", "NameInRequest": "Thing", "Type": { @@ -721,11 +768,11 @@ "Kind": "Method" }, { - "$id": "79", + "$id": "86", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "80", + "$id": "87", "Name": "String", "Kind": "String", "IsNullable": false @@ -740,19 +787,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "81", + "$id": "88", "Type": { - "$ref": "80" + "$ref": "87" }, "Value": "application/json" } }, { - "$id": "82", + "$id": "89", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "83", + "$id": "90", "Name": "String", "Kind": "String", "IsNullable": false @@ -767,20 +814,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "84", + "$id": "91", "Type": { - "$ref": "83" + "$ref": "90" }, "Value": "application/json" } }, { - "$ref": "46" + "$ref": "53" } ], "Responses": [ { - "$id": "85", + "$id": "92", "StatusCodes": [ 204 ], @@ -801,20 +848,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "86", + "$id": "93", "Name": "spreadAliasWithSpreadAlias", "ResourceName": "SpreadTypeSpec", "Description": "spread an alias with contains another alias property as body.", "Parameters": [ { - "$ref": "37" + "$ref": "44" }, { - "$id": "87", + "$id": "94", "Name": "id", "NameInRequest": "id", "Type": { - "$id": "88", + "$id": "95", "Name": "string", "Kind": "String", "IsNullable": false @@ -830,11 +877,11 @@ "Kind": "Method" }, { - "$id": "89", + "$id": "96", "Name": "top", "NameInRequest": "top", "Type": { - "$id": "90", + "$id": "97", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -850,7 +897,7 @@ "Kind": "Method" }, { - "$id": "91", + "$id": "98", "Name": "SpreadAliasWithSpreadAliasRequest", "NameInRequest": "SpreadAliasWithSpreadAliasRequest", "Type": { @@ -867,11 +914,11 @@ "Kind": "Spread" }, { - "$id": "92", + "$id": "99", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "93", + "$id": "100", "Name": "String", "Kind": "String", "IsNullable": false @@ -886,19 +933,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "94", + "$id": "101", "Type": { - "$ref": "93" + "$ref": "100" }, "Value": "application/json" } }, { - "$id": "95", + "$id": "102", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "96", + "$id": "103", "Name": "String", "Kind": "String", "IsNullable": false @@ -913,20 +960,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "97", + "$id": "104", "Type": { - "$ref": "96" + "$ref": "103" }, "Value": "application/json" } }, { - "$ref": "46" + "$ref": "53" } ], "Responses": [ { - "$id": "98", + "$id": "105", "StatusCodes": [ 204 ], @@ -947,20 +994,20 @@ "GenerateConvenienceMethod": true }, { - "$id": "99", + "$id": "106", "Name": "spreadAliasWithOptionalProps", "ResourceName": "SpreadTypeSpec", "Description": "spread an alias with contains optional properties as body.", "Parameters": [ { - "$ref": "37" + "$ref": "44" }, { - "$id": "100", + "$id": "107", "Name": "id", "NameInRequest": "id", "Type": { - "$id": "101", + "$id": "108", "Name": "string", "Kind": "String", "IsNullable": false @@ -976,11 +1023,11 @@ "Kind": "Method" }, { - "$id": "102", + "$id": "109", "Name": "top", "NameInRequest": "top", "Type": { - "$id": "103", + "$id": "110", "Name": "int32", "Kind": "Int32", "IsNullable": false @@ -996,7 +1043,7 @@ "Kind": "Method" }, { - "$id": "104", + "$id": "111", "Name": "SpreadAliasWithOptionalPropsRequest", "NameInRequest": "SpreadAliasWithOptionalPropsRequest", "Type": { @@ -1013,11 +1060,11 @@ "Kind": "Spread" }, { - "$id": "105", + "$id": "112", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "106", + "$id": "113", "Name": "String", "Kind": "String", "IsNullable": false @@ -1032,19 +1079,19 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "107", + "$id": "114", "Type": { - "$ref": "106" + "$ref": "113" }, "Value": "application/json" } }, { - "$id": "108", + "$id": "115", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "109", + "$id": "116", "Name": "String", "Kind": "String", "IsNullable": false @@ -1059,20 +1106,20 @@ "Explode": false, "Kind": "Constant", "DefaultValue": { - "$id": "110", + "$id": "117", "Type": { - "$ref": "109" + "$ref": "116" }, "Value": "application/json" } }, { - "$ref": "46" + "$ref": "53" } ], "Responses": [ { - "$id": "111", + "$id": "118", "StatusCodes": [ 204 ], @@ -1091,10 +1138,116 @@ "BufferResponse": true, "GenerateProtocolMethod": true, "GenerateConvenienceMethod": true + }, + { + "$id": "119", + "Name": "spreadAliasWithCollections", + "ResourceName": "SpreadTypeSpec", + "Description": "spread an alias with required and optional collections", + "Parameters": [ + { + "$ref": "44" + }, + { + "$id": "120", + "Name": "SpreadAliasWithCollectionsRequest", + "NameInRequest": "SpreadAliasWithCollectionsRequest", + "Type": { + "$ref": "35" + }, + "Location": "Body", + "IsRequired": true, + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Spread" + }, + { + "$id": "121", + "Name": "contentType", + "NameInRequest": "Content-Type", + "Type": { + "$id": "122", + "Name": "String", + "Kind": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": true, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "123", + "Type": { + "$ref": "122" + }, + "Value": "application/json" + } + }, + { + "$id": "124", + "Name": "accept", + "NameInRequest": "Accept", + "Type": { + "$id": "125", + "Name": "String", + "Kind": "String", + "IsNullable": false + }, + "Location": "Header", + "IsApiVersion": false, + "IsResourceParameter": false, + "IsContentType": false, + "IsRequired": true, + "IsEndpoint": false, + "SkipUrlEncoding": false, + "Explode": false, + "Kind": "Constant", + "DefaultValue": { + "$id": "126", + "Type": { + "$ref": "125" + }, + "Value": "application/json" + } + }, + { + "$ref": "53" + } + ], + "Responses": [ + { + "$id": "127", + "StatusCodes": [ + 204 + ], + "BodyMediaType": "Json", + "Headers": [], + "IsErrorResponse": false + } + ], + "HttpMethod": "POST", + "RequestBodyMediaType": "Json", + "Uri": "{spreadUrl}", + "Path": "/spreadAliasWithCollections", + "RequestMediaTypes": [ + "application/json" + ], + "BufferResponse": true, + "GenerateProtocolMethod": true, + "GenerateConvenienceMethod": true } ], "Protocol": { - "$id": "112" + "$id": "128" }, "Creatable": true } diff --git a/test/TestProjects/Spread-TypeSpec/tests/Generated/Samples/Samples_SpreadTypeSpecClient.cs b/test/TestProjects/Spread-TypeSpec/tests/Generated/Samples/Samples_SpreadTypeSpecClient.cs index 19917ab23e2..aedf09d43a3 100644 --- a/test/TestProjects/Spread-TypeSpec/tests/Generated/Samples/Samples_SpreadTypeSpecClient.cs +++ b/test/TestProjects/Spread-TypeSpec/tests/Generated/Samples/Samples_SpreadTypeSpecClient.cs @@ -507,5 +507,93 @@ public async Task Example_SpreadAliasWithOptionalProps_Convenience_Async() var result = await client.SpreadAliasWithOptionalPropsAsync("", 1234, "", new int[] { 1234 }, "", 1234, new string[] { "" }); } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SpreadAliasWithCollections() + { + var endpoint = new Uri(""); + var client = new SpreadTypeSpecClient(endpoint); + + var data = new + { + requiredStringList = new[] { + "" + }, + }; + + Response response = client.SpreadAliasWithCollections(RequestContent.Create(data)); + Console.WriteLine(response.Status); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public void Example_SpreadAliasWithCollections_AllParameters() + { + var endpoint = new Uri(""); + var client = new SpreadTypeSpecClient(endpoint); + + var data = new + { + requiredStringList = new[] { + "" + }, + optionalStringList = new[] { + "" + }, + }; + + Response response = client.SpreadAliasWithCollections(RequestContent.Create(data)); + Console.WriteLine(response.Status); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SpreadAliasWithCollections_Async() + { + var endpoint = new Uri(""); + var client = new SpreadTypeSpecClient(endpoint); + + var data = new + { + requiredStringList = new[] { + "" + }, + }; + + Response response = await client.SpreadAliasWithCollectionsAsync(RequestContent.Create(data)); + Console.WriteLine(response.Status); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SpreadAliasWithCollections_AllParameters_Async() + { + var endpoint = new Uri(""); + var client = new SpreadTypeSpecClient(endpoint); + + var data = new + { + requiredStringList = new[] { + "" + }, + optionalStringList = new[] { + "" + }, + }; + + Response response = await client.SpreadAliasWithCollectionsAsync(RequestContent.Create(data)); + Console.WriteLine(response.Status); + } + + [Test] + [Ignore("Only validating compilation of examples")] + public async Task Example_SpreadAliasWithCollections_Convenience_Async() + { + var endpoint = new Uri(""); + var client = new SpreadTypeSpecClient(endpoint); + + var result = await client.SpreadAliasWithCollectionsAsync(new string[] { "" }, new string[] { "" }); + } } } diff --git a/test/TestServerProjects/body-complex/Generated/Models/DictionaryWrapper.Serialization.cs b/test/TestServerProjects/body-complex/Generated/Models/DictionaryWrapper.Serialization.cs index 8970ba5c1f5..88d0d9681c9 100644 --- a/test/TestServerProjects/body-complex/Generated/Models/DictionaryWrapper.Serialization.cs +++ b/test/TestServerProjects/body-complex/Generated/Models/DictionaryWrapper.Serialization.cs @@ -50,7 +50,6 @@ internal static DictionaryWrapper DeserializeDictionaryWrapper(JsonElement eleme { if (property.Value.ValueKind == JsonValueKind.Null) { - defaultProgram = null; continue; } Dictionary dictionary = new Dictionary();