From a0f16a49fbb6b501cd7cc7c78883290a3375646d Mon Sep 17 00:00:00 2001 From: jolov Date: Wed, 19 Feb 2025 16:08:04 -0800 Subject: [PATCH 1/5] Avoid duplicate null check and fix null serialization property name --- .../MrwSerializationTypeDefinition.cs | 23 +++++++-------- .../MrwSerializationTypeDefinitionTests.cs | 13 +++++++++ .../SerializedNameIsUsed(False).cs | 25 ++++++++++++++++ .../SerializedNameIsUsed(True).cs | 29 +++++++++++++++++++ .../CanCustomizeSerializationMethod.cs | 11 ++----- ...zeSerializationMethodForRenamedProperty.cs | 11 ++----- .../CanReplaceDeserializationMethod.cs | 11 ++----- 7 files changed, 84 insertions(+), 39 deletions(-) create mode 100644 packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/SerializedNameIsUsed(False).cs create mode 100644 packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/SerializedNameIsUsed(True).cs diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs index 62b606d53fd..c543110c2aa 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs @@ -1464,20 +1464,19 @@ private MethodBodyStatement WrapInIsDefined( bool propertyIsNullable, MethodBodyStatement writePropertySerializationStatement) { - // Create the first conditional statement to check if the property is defined - if (propertyIsNullable) - { - writePropertySerializationStatement = CheckPropertyIsInitialized( - propertyType, - wireInfo, - propertyIsRequired, - propertyExpression, - writePropertySerializationStatement); - } - // Directly return the statement if the property is required or a non-nullable value type that is not JsonElement if (IsRequiredOrNonNullableValueType(propertyType, propertyIsRequired)) { + // Create the first conditional statement to check if the property is defined + if (propertyIsNullable) + { + writePropertySerializationStatement = CheckPropertyIsInitialized( + propertyType, + wireInfo, + propertyIsRequired, + propertyExpression, + writePropertySerializationStatement); + } return writePropertySerializationStatement; } @@ -1507,7 +1506,7 @@ private IfElseStatement CheckPropertyIsInitialized( return new IfElseStatement( propertyIsInitialized, writePropertySerializationStatement, - _utf8JsonWriterSnippet.WriteNull(wireInfo.SerializedName.ToVariableName())); + _utf8JsonWriterSnippet.WriteNull(wireInfo.SerializedName)); } /// diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/MrwSerializationTypeDefinitionTests.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/MrwSerializationTypeDefinitionTests.cs index 3bec3492c48..1afbbaa8cb5 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/MrwSerializationTypeDefinitionTests.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/MrwSerializationTypeDefinitionTests.cs @@ -577,6 +577,19 @@ public void TestBuildDeserializationMethod() Assert.IsNotNull(methodBody); } + [TestCase(true)] + [TestCase(false)] + public void SerializedNameIsUsed(bool isRequired) + { + var property = InputFactory.Property("mockProperty", new InputNullableType(InputPrimitiveType.Int32), isRequired: isRequired, wireName: "mock_wire_name"); + var inputModel = InputFactory.Model("mockInputModel", properties: [property]); + var (_, serialization) = CreateModelAndSerialization(inputModel); + + var serializationMethod = serialization.Methods.Single(m => m.Signature.Name == "JsonModelWriteCore"); + var methodBody = serializationMethod.BodyStatements!.ToDisplayString(); + Assert.AreEqual(Helpers.GetExpectedFromFile(isRequired.ToString()), methodBody); + } + [Test] public void TestBuildDeserializationMethodNestedSARD() { diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/SerializedNameIsUsed(False).cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/SerializedNameIsUsed(False).cs new file mode 100644 index 00000000000..24c0cecfb69 --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/SerializedNameIsUsed(False).cs @@ -0,0 +1,25 @@ +string format = (options.Format == "W") ? ((global::System.ClientModel.Primitives.IPersistableModel)this).GetFormatFromOptions(options) : options.Format; +if ((format != "J")) +{ + throw new global::System.FormatException($"The model {nameof(global::Sample.Models.MockInputModel)} does not support writing '{format}' format."); +} +if (global::Sample.Optional.IsDefined(MockProperty)) +{ + writer.WritePropertyName("mock_wire_name"u8); + writer.WriteNumberValue(MockProperty.Value); +} +if (((options.Format != "W") && (_additionalBinaryDataProperties != null))) +{ + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (global::System.Text.Json.JsonDocument document = global::System.Text.Json.JsonDocument.Parse(item.Value)) + { + global::System.Text.Json.JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } +} diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/SerializedNameIsUsed(True).cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/SerializedNameIsUsed(True).cs new file mode 100644 index 00000000000..e23eff479df --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/SerializedNameIsUsed(True).cs @@ -0,0 +1,29 @@ +string format = (options.Format == "W") ? ((global::System.ClientModel.Primitives.IPersistableModel)this).GetFormatFromOptions(options) : options.Format; +if ((format != "J")) +{ + throw new global::System.FormatException($"The model {nameof(global::Sample.Models.MockInputModel)} does not support writing '{format}' format."); +} +if ((MockProperty != null)) +{ + writer.WritePropertyName("mock_wire_name"u8); + writer.WriteNumberValue(MockProperty.Value); +} +else +{ + writer.WriteNull("mock_wire_name"u8); +} +if (((options.Format != "W") && (_additionalBinaryDataProperties != null))) +{ + foreach (var item in _additionalBinaryDataProperties) + { + writer.WritePropertyName(item.Key); +#if NET6_0_OR_GREATER + writer.WriteRawValue(item.Value); +#else + using (global::System.Text.Json.JsonDocument document = global::System.Text.Json.JsonDocument.Parse(item.Value)) + { + global::System.Text.Json.JsonSerializer.Serialize(writer, document.RootElement); + } +#endif + } +} diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/SerializationCustomizationTests/CanCustomizeSerializationMethod.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/SerializationCustomizationTests/CanCustomizeSerializationMethod.cs index 9f844a8e14a..70dcad464df 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/SerializationCustomizationTests/CanCustomizeSerializationMethod.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/SerializationCustomizationTests/CanCustomizeSerializationMethod.cs @@ -37,15 +37,8 @@ protected virtual void JsonModelWriteCore(global::System.Text.Json.Utf8JsonWrite } if (global::Sample.Optional.IsDefined(Prop2)) { - if ((Prop2 != null)) - { - writer.WritePropertyName("prop2"u8); - this.SerializationMethod(writer, options); - } - else - { - writer.WriteNull("prop2"u8); - } + writer.WritePropertyName("prop2"u8); + this.SerializationMethod(writer, options); } if (((options.Format != "W") && (_additionalBinaryDataProperties != null))) { diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/SerializationCustomizationTests/CanCustomizeSerializationMethodForRenamedProperty.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/SerializationCustomizationTests/CanCustomizeSerializationMethodForRenamedProperty.cs index 5655cbd3a5a..95be7b0bcc7 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/SerializationCustomizationTests/CanCustomizeSerializationMethodForRenamedProperty.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/SerializationCustomizationTests/CanCustomizeSerializationMethodForRenamedProperty.cs @@ -37,15 +37,8 @@ protected virtual void JsonModelWriteCore(global::System.Text.Json.Utf8JsonWrite } if (global::Sample.Optional.IsDefined(Prop3)) { - if ((Prop3 != null)) - { - writer.WritePropertyName("prop2"u8); - this.SerializationMethod(writer, options); - } - else - { - writer.WriteNull("prop2"u8); - } + writer.WritePropertyName("prop2"u8); + this.SerializationMethod(writer, options); } if (((options.Format != "W") && (_additionalBinaryDataProperties != null))) { diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/SerializationCustomizationTests/CanReplaceDeserializationMethod.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/SerializationCustomizationTests/CanReplaceDeserializationMethod.cs index e2fb565df0a..ef38135bf08 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/SerializationCustomizationTests/CanReplaceDeserializationMethod.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/SerializationCustomizationTests/CanReplaceDeserializationMethod.cs @@ -36,15 +36,8 @@ protected virtual void JsonModelWriteCore(global::System.Text.Json.Utf8JsonWrite } if (global::Sample.Optional.IsDefined(Prop2)) { - if ((Prop2 != null)) - { - writer.WritePropertyName("prop2"u8); - writer.WriteStringValue(Prop2); - } - else - { - writer.WriteNull("prop2"u8); - } + writer.WritePropertyName("prop2"u8); + writer.WriteStringValue(Prop2); } if (((options.Format != "W") && (_additionalBinaryDataProperties != null))) { From 2a3d28dab8f5b8c81b5688d57c6218f063619d21 Mon Sep 17 00:00:00 2001 From: jolov Date: Wed, 19 Feb 2025 16:11:08 -0800 Subject: [PATCH 2/5] regen --- .../src/Generated/Models/Thing.Serialization.cs | 17 +++++------------ 1 file changed, 5 insertions(+), 12 deletions(-) diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.Serialization.cs index 3bf540d9db0..bd08337d0d9 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.Serialization.cs @@ -76,20 +76,13 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit writer.WriteStringValue(RequiredBadDescription); if (Optional.IsCollectionDefined(OptionalNullableList)) { - if (OptionalNullableList != null) - { - writer.WritePropertyName("optionalNullableList"u8); - writer.WriteStartArray(); - foreach (int item in OptionalNullableList) - { - writer.WriteNumberValue(item); - } - writer.WriteEndArray(); - } - else + writer.WritePropertyName("optionalNullableList"u8); + writer.WriteStartArray(); + foreach (int item in OptionalNullableList) { - writer.WriteNull("optionalNullableList"u8); + writer.WriteNumberValue(item); } + writer.WriteEndArray(); } if (RequiredNullableList != null && Optional.IsCollectionDefined(RequiredNullableList)) { From f6483d608b722f68fc58d5145ed336408fb1cdf5 Mon Sep 17 00:00:00 2001 From: jolov Date: Thu, 20 Feb 2025 13:51:16 -0800 Subject: [PATCH 3/5] Add coverage and fixes --- .../MrwSerializationTypeDefinition.cs | 69 +- ...ypeSpec.Generator.ClientModel.Tests.csproj | 6 + .../RoundTripModel/RoundTripModel.json | 3 +- .../RoundTripModelWireFormat.json | 3 +- .../TestData/Thing/Thing.json | 1 + .../TestData/Thing/ThingWireFormat.json | 3 +- .../TestData/Thing/ThingWithNulls.json | 16 + .../Thing/ThingWithNullsWireFormat.json | 15 + .../Unbranded_TypeSpec/ThingWithNullsTests.cs | 77 ++ .../CanCustomizeNullableStringToFixedEnum.cs | 11 +- .../SerializedNameIsUsed(True).cs | 2 +- .../Unbranded-TypeSpec/Unbranded-TypeSpec.tsp | 6 + .../Unbranded-TypeSpec/src/Custom/Friend.cs | 2 +- ...equiredNullableProperties.Serialization.cs | 6 +- .../Generated/Models/Thing.Serialization.cs | 40 +- .../src/Generated/Models/Thing.cs | 14 +- .../src/Generated/UnbrandedTypeSpecClient.cs | 12 +- .../UnbrandedTypeSpecModelFactory.cs | 6 +- .../Unbranded-TypeSpec/tspCodeModel.json | 736 ++++++++++-------- 19 files changed, 629 insertions(+), 399 deletions(-) create mode 100644 packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNulls.json create mode 100644 packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNullsWireFormat.json create mode 100644 packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/ThingWithNullsTests.cs diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs index c543110c2aa..10a530cd16d 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/src/Providers/MrwSerializationTypeDefinition.cs @@ -1464,49 +1464,27 @@ private MethodBodyStatement WrapInIsDefined( bool propertyIsNullable, MethodBodyStatement writePropertySerializationStatement) { - // Directly return the statement if the property is required or a non-nullable value type that is not JsonElement - if (IsRequiredOrNonNullableValueType(propertyType, propertyIsRequired)) + // Non-nullable value types can be serialized directly + if (IsNonNullableValueType(propertyType)) { - // Create the first conditional statement to check if the property is defined - if (propertyIsNullable) - { - writePropertySerializationStatement = CheckPropertyIsInitialized( - propertyType, - wireInfo, - propertyIsRequired, - propertyExpression, - writePropertySerializationStatement); - } return writePropertySerializationStatement; } - // Conditionally serialize based on whether the property is a collection or a single value - return CreateConditionalSerializationStatement(propertyType, propertyExpression, propertyIsReadOnly, writePropertySerializationStatement); - } - - private IfElseStatement CheckPropertyIsInitialized( - CSharpType propertyType, - PropertyWireInformation wireInfo, - bool isPropRequired, - MemberExpression propertyMemberExpression, - MethodBodyStatement writePropertySerializationStatement) - { - ScopedApi propertyIsInitialized; - - if (propertyType.IsCollection && !propertyType.IsReadOnlyMemory && isPropRequired) - { - propertyIsInitialized = propertyMemberExpression.NotEqual(Null) - .And(OptionalSnippets.IsCollectionDefined(propertyMemberExpression)); - } - else + // Required properties that are not nullable can be serialized directly + if (propertyIsRequired && !propertyIsNullable) { - propertyIsInitialized = propertyMemberExpression.NotEqual(Null); + return writePropertySerializationStatement; } - return new IfElseStatement( - propertyIsInitialized, - writePropertySerializationStatement, - _utf8JsonWriterSnippet.WriteNull(wireInfo.SerializedName)); + // Conditionally serialize based on whether the property is a collection or a single value + return CreateConditionalSerializationStatement( + propertyType, + propertyExpression, + propertyIsReadOnly, + propertyIsNullable, + propertyIsRequired, + wireInfo.SerializedName, + writePropertySerializationStatement); } /// @@ -1763,20 +1741,31 @@ private static ScopedApi GetEnumerableExpression(ValueExpression expression, CSh return expression.As(new CSharpType(typeof(IEnumerable<>), itemType)); } - private static bool IsRequiredOrNonNullableValueType(CSharpType propertyType, bool isRequired) - => isRequired || (!propertyType.IsNullable && propertyType.IsValueType && !propertyType.Equals(typeof(JsonElement))); + private static bool IsNonNullableValueType(CSharpType propertyType) + => propertyType is { IsNullable: false, IsValueType: true } && !propertyType.Equals(typeof(JsonElement)); - private IfStatement CreateConditionalSerializationStatement( + private MethodBodyStatement CreateConditionalSerializationStatement( CSharpType propertyType, MemberExpression propertyMemberExpression, bool isReadOnly, + bool isNullable, + bool isRequired, + string serializedName, MethodBodyStatement writePropertySerializationStatement) { - var isDefinedCondition = propertyType.IsCollection && !propertyType.IsReadOnlyMemory + var isDefinedCondition = propertyType is { IsCollection: true, IsReadOnlyMemory: false } ? OptionalSnippets.IsCollectionDefined(propertyMemberExpression) : OptionalSnippets.IsDefined(propertyMemberExpression); var condition = isReadOnly ? _isNotEqualToWireConditionSnippet.And(isDefinedCondition) : isDefinedCondition; + if (isRequired && isNullable) + { + return new IfElseStatement( + condition, + writePropertySerializationStatement, + _utf8JsonWriterSnippet.WriteNull(serializedName)); + } + return new IfStatement(condition) { writePropertySerializationStatement }; } diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Microsoft.TypeSpec.Generator.ClientModel.Tests.csproj b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Microsoft.TypeSpec.Generator.ClientModel.Tests.csproj index 7792a933537..a3cd5a2acf3 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Microsoft.TypeSpec.Generator.ClientModel.Tests.csproj +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Microsoft.TypeSpec.Generator.ClientModel.Tests.csproj @@ -14,6 +14,12 @@ PreserveNewest + + PreserveNewest + + + PreserveNewest + diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/RoundTripModel/RoundTripModel.json b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/RoundTripModel/RoundTripModel.json index 06d44bdbe79..36d147039c7 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/RoundTripModel/RoundTripModel.json +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/RoundTripModel/RoundTripModel.json @@ -18,7 +18,8 @@ "optionalLiteralInt": 456, "optionalLiteralFloat": 4.56, "optionalLiteralBool": false, - "optionalNullableList": [] + "optionalNullableList": [], + "requiredNullableString": null }, "intExtensibleEnum": 1, "intExtensibleEnumCollection": [1, 3], diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/RoundTripModel/RoundTripModelWireFormat.json b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/RoundTripModel/RoundTripModelWireFormat.json index 89c52b2952c..a74887910ce 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/RoundTripModel/RoundTripModelWireFormat.json +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/RoundTripModel/RoundTripModelWireFormat.json @@ -18,7 +18,8 @@ "optionalLiteralInt": 456, "optionalLiteralFloat": 4.56, "optionalLiteralBool": false, - "optionalNullableList": [] + "optionalNullableList": [], + "requiredNullableString": null }, "intExtensibleEnum": 1, "intExtensibleEnumCollection": [1, 3], diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/Thing.json b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/Thing.json index aa5384517b3..8a32651f66c 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/Thing.json +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/Thing.json @@ -12,5 +12,6 @@ "optionalLiteralFloat": 4.56, "optionalLiteralBool": false, "optionalNullableList": [], + "requiredNullableString": null, "extra": "stuff" } diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWireFormat.json b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWireFormat.json index 77790ca4412..a6ce1e17bee 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWireFormat.json +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWireFormat.json @@ -11,5 +11,6 @@ "optionalLiteralInt": 456, "optionalLiteralFloat": 4.56, "optionalLiteralBool": false, - "optionalNullableList": [] + "optionalNullableList": [], + "requiredNullableString": null } diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNulls.json b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNulls.json new file mode 100644 index 00000000000..c95403c676e --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNulls.json @@ -0,0 +1,16 @@ +{ + "name": "Example Thing", + "requiredUnion": "mockUnion", + "requiredBadDescription": "This is a description with potentially problematic characters like < or >.", + "requiredNullableList": null, + "requiredLiteralString": "accept", + "requiredLiteralInt": 123, + "requiredLiteralFloat": 1.23, + "requiredLiteralBool": false, + "optionalLiteralString": "hi", + "optionalLiteralInt": 456, + "optionalLiteralFloat": 4.56, + "optionalLiteralBool": false, + "requiredNullableString": null, + "extra": "stuff" +} diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNullsWireFormat.json b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNullsWireFormat.json new file mode 100644 index 00000000000..03533756b19 --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNullsWireFormat.json @@ -0,0 +1,15 @@ +{ + "name": "Example Thing", + "requiredUnion": "mockUnion", + "requiredBadDescription": "This is a description with potentially problematic characters like < or >.", + "requiredNullableList": null, + "requiredLiteralString": "accept", + "requiredLiteralInt": 123, + "requiredLiteralFloat": 1.23, + "requiredLiteralBool": false, + "optionalLiteralString": "hi", + "optionalLiteralInt": 456, + "optionalLiteralFloat": 4.56, + "optionalLiteralBool": false, + "requiredNullableString": null +} diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/ThingWithNullsTests.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/ThingWithNullsTests.cs new file mode 100644 index 00000000000..90282ec5ae2 --- /dev/null +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/ThingWithNullsTests.cs @@ -0,0 +1,77 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT License. + +using System.ClientModel; +using System.IO; +using System.Text.Json; +using Microsoft.TypeSpec.Generator.Tests.Common; +using NUnit.Framework; +using UnbrandedTypeSpec; + +namespace Microsoft.TypeSpec.Generator.ClientModel.Tests.ModelReaderWriterValidation.TestProjects.Unbranded_TypeSpec +{ + internal class ThingWithNullsTests : LocalModelJsonTests + { + protected override string JsonPayload => File.ReadAllText(ModelTestHelper.GetLocation("TestData/Thing/ThingWithNulls.json")); + protected override string WirePayload => File.ReadAllText(ModelTestHelper.GetLocation("TestData/Thing/ThingWithNullsWireFormat.json")); + protected override Thing ToModel(ClientResult result) => (Thing)result; + protected override BinaryContent ToBinaryContent(Thing model) => model; + + protected override void CompareModels(Thing model, Thing model2, string format) + { + Assert.AreEqual(model.Name, model2.Name); + Assert.AreEqual(model.RequiredUnion.ToString(), model2.RequiredUnion.ToString()); + Assert.AreEqual(model.RequiredLiteralString, model2.RequiredLiteralString); + Assert.AreEqual(model.RequiredLiteralInt, model2.RequiredLiteralInt); + Assert.AreEqual(model.RequiredLiteralFloat, model2.RequiredLiteralFloat); + Assert.AreEqual(model.RequiredLiteralBool, model2.RequiredLiteralBool); + Assert.AreEqual(model.OptionalLiteralString, model2.OptionalLiteralString); + Assert.AreEqual(model.OptionalLiteralInt, model2.OptionalLiteralInt); + Assert.AreEqual(model.OptionalLiteralFloat, model2.OptionalLiteralFloat); + Assert.AreEqual(model.OptionalLiteralBool, model2.OptionalLiteralBool); + Assert.AreEqual(model.RequiredBadDescription, model2.RequiredBadDescription); + Assert.AreEqual(model.OptionalNullableList, model2.OptionalNullableList); + Assert.AreEqual(model.RequiredNullableList, model2.RequiredNullableList); + + if (format == "J") + { + var rawData = GetRawData(model); + var rawData2 = GetRawData(model2); + Assert.IsNotNull(rawData); + Assert.IsNotNull(rawData2); + Assert.AreEqual(rawData.Count, rawData2.Count); + Assert.AreEqual(rawData["extra"].ToObjectFromJson(), rawData2["extra"].ToObjectFromJson()); + } + } + + protected override void VerifyModel(Thing model, string format) + { + var parsedWireJson = JsonDocument.Parse(WirePayload).RootElement; + Assert.IsNotNull(parsedWireJson); + Assert.AreEqual(parsedWireJson.GetProperty("name").GetString(), model.Name); + Assert.AreEqual("\"mockUnion\"", model.RequiredUnion.ToString()); + Assert.AreEqual(parsedWireJson.GetProperty("requiredBadDescription").GetString(), model.RequiredBadDescription); + Assert.AreEqual(JsonValueKind.Null, parsedWireJson.GetProperty("requiredNullableList").ValueKind); + Assert.IsEmpty(model.RequiredNullableList); + Assert.AreEqual(new ThingRequiredLiteralString(parsedWireJson.GetProperty("requiredLiteralString").GetString()), model.RequiredLiteralString); + Assert.AreEqual(new ThingRequiredLiteralInt(parsedWireJson.GetProperty("requiredLiteralInt").GetInt32()), model.RequiredLiteralInt); + Assert.AreEqual(new ThingRequiredLiteralFloat(parsedWireJson.GetProperty("requiredLiteralFloat").GetSingle()), model.RequiredLiteralFloat); + Assert.AreEqual(parsedWireJson.GetProperty("requiredLiteralBool").GetBoolean(), model.RequiredLiteralBool); + Assert.AreEqual(new ThingOptionalLiteralString(parsedWireJson.GetProperty("optionalLiteralString").GetString()), model.OptionalLiteralString); + Assert.AreEqual(new ThingOptionalLiteralInt(parsedWireJson.GetProperty("optionalLiteralInt").GetInt32()), model.OptionalLiteralInt); + Assert.AreEqual(new ThingOptionalLiteralFloat(parsedWireJson.GetProperty("optionalLiteralFloat").GetSingle()), model.OptionalLiteralFloat); + Assert.AreEqual(parsedWireJson.GetProperty("optionalLiteralBool").GetBoolean(), model.OptionalLiteralBool); + Assert.IsFalse(parsedWireJson.TryGetProperty("optionalNullableList", out _)); + Assert.IsEmpty(model.OptionalNullableList); + + + var rawData = GetRawData(model); + Assert.IsNotNull(rawData); + if (format == "J") + { + var parsedJson = JsonDocument.Parse(JsonPayload).RootElement; + Assert.AreEqual(parsedJson.GetProperty("extra").GetString(), rawData["extra"].ToObjectFromJson()); + } + } + } +} diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizeNullableStringToFixedEnum.cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizeNullableStringToFixedEnum.cs index da5bd7590b8..3313e36b78f 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizeNullableStringToFixedEnum.cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/ModelCustomizationTests/CanCustomizeNullableStringToFixedEnum.cs @@ -30,15 +30,8 @@ protected virtual void JsonModelWriteCore(global::System.Text.Json.Utf8JsonWrite { throw new global::System.FormatException($"The model {nameof(global::Sample.Models.MockInputModel)} does not support writing '{format}' format."); } - if ((Prop1 != null)) - { - writer.WritePropertyName("prop1"u8); - writer.WriteStringValue(Prop1.ToSerialString()); - } - else - { - writer.WriteNull("prop1"u8); - } + writer.WritePropertyName("prop1"u8); + writer.WriteStringValue(Prop1.ToSerialString()); if (((options.Format != "W") && (_additionalBinaryDataProperties != null))) { foreach (var item in _additionalBinaryDataProperties) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/SerializedNameIsUsed(True).cs b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/SerializedNameIsUsed(True).cs index e23eff479df..a3cb6dd8f3c 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/SerializedNameIsUsed(True).cs +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Providers/MrwSerializationTypeDefinitions/TestData/MrwSerializationTypeDefinitionTests/SerializedNameIsUsed(True).cs @@ -3,7 +3,7 @@ { throw new global::System.FormatException($"The model {nameof(global::Sample.Models.MockInputModel)} does not support writing '{format}' format."); } -if ((MockProperty != null)) +if (global::Sample.Optional.IsDefined(MockProperty)) { writer.WritePropertyName("mock_wire_name"u8); writer.WriteNumberValue(MockProperty.Value); diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/Unbranded-TypeSpec.tsp b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/Unbranded-TypeSpec.tsp index a16e47d719f..792ee00863e 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/Unbranded-TypeSpec.tsp +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/Unbranded-TypeSpec.tsp @@ -103,6 +103,12 @@ model Thing { @doc("required literal string") requiredLiteralString: "accept"; + @doc("required nullable string") + requiredNullableString: string | null; + + @doc("required optional string") + optionalNullableString?: string | null; + @doc("required literal int") requiredLiteralInt: 123; diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Custom/Friend.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Custom/Friend.cs index 7f0a8059baa..db4d95fde43 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Custom/Friend.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Custom/Friend.cs @@ -4,7 +4,7 @@ // Demonstrates customizing the namespace of a model namespace UnbrandedTypeSpec.Models.Custom { - [CodeGenTypeAttribute("Friend")] + [CodeGenType("Friend")] public partial class Friend { } diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.Serialization.cs index bfc45ecd97f..60e4c6559b7 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/ModelWithRequiredNullableProperties.Serialization.cs @@ -33,7 +33,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit { throw new FormatException($"The model {nameof(ModelWithRequiredNullableProperties)} does not support writing '{format}' format."); } - if (RequiredNullablePrimitive != null) + if (Optional.IsDefined(RequiredNullablePrimitive)) { writer.WritePropertyName("requiredNullablePrimitive"u8); writer.WriteNumberValue(RequiredNullablePrimitive.Value); @@ -42,7 +42,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit { writer.WriteNull("requiredNullablePrimitive"u8); } - if (RequiredExtensibleEnum != null) + if (Optional.IsDefined(RequiredExtensibleEnum)) { writer.WritePropertyName("requiredExtensibleEnum"u8); writer.WriteStringValue(RequiredExtensibleEnum.Value.ToString()); @@ -51,7 +51,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit { writer.WriteNull("requiredExtensibleEnum"u8); } - if (RequiredFixedEnum != null) + if (Optional.IsDefined(RequiredFixedEnum)) { writer.WritePropertyName("requiredFixedEnum"u8); writer.WriteStringValue(RequiredFixedEnum.Value.ToSerialString()); diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.Serialization.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.Serialization.cs index bd08337d0d9..6854b66f630 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.Serialization.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.Serialization.cs @@ -46,6 +46,20 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit #endif writer.WritePropertyName("requiredLiteralString"u8); writer.WriteStringValue(RequiredLiteralString.ToString()); + if (Optional.IsDefined(RequiredNullableString)) + { + writer.WritePropertyName("requiredNullableString"u8); + writer.WriteStringValue(RequiredNullableString); + } + else + { + writer.WriteNull("requiredNullableString"u8); + } + if (Optional.IsDefined(OptionalNullableString)) + { + writer.WritePropertyName("optionalNullableString"u8); + writer.WriteStringValue(OptionalNullableString); + } writer.WritePropertyName("requiredLiteralInt"u8); writer.WriteNumberValue(RequiredLiteralInt.ToSerialInt32()); writer.WritePropertyName("requiredLiteralFloat"u8); @@ -84,7 +98,7 @@ protected virtual void JsonModelWriteCore(Utf8JsonWriter writer, ModelReaderWrit } writer.WriteEndArray(); } - if (RequiredNullableList != null && Optional.IsCollectionDefined(RequiredNullableList)) + if (Optional.IsCollectionDefined(RequiredNullableList)) { writer.WritePropertyName("requiredNullableList"u8); writer.WriteStartArray(); @@ -139,6 +153,8 @@ internal static Thing DeserializeThing(JsonElement element, ModelReaderWriterOpt string name = default; BinaryData requiredUnion = default; ThingRequiredLiteralString requiredLiteralString = default; + string requiredNullableString = default; + string optionalNullableString = default; ThingRequiredLiteralInt requiredLiteralInt = default; ThingRequiredLiteralFloat requiredLiteralFloat = default; bool requiredLiteralBool = default; @@ -167,6 +183,26 @@ internal static Thing DeserializeThing(JsonElement element, ModelReaderWriterOpt requiredLiteralString = new ThingRequiredLiteralString(prop.Value.GetString()); continue; } + if (prop.NameEquals("requiredNullableString"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + requiredNullableString = null; + continue; + } + requiredNullableString = prop.Value.GetString(); + continue; + } + if (prop.NameEquals("optionalNullableString"u8)) + { + if (prop.Value.ValueKind == JsonValueKind.Null) + { + optionalNullableString = null; + continue; + } + optionalNullableString = prop.Value.GetString(); + continue; + } if (prop.NameEquals("requiredLiteralInt"u8)) { requiredLiteralInt = new ThingRequiredLiteralInt(prop.Value.GetInt32()); @@ -261,6 +297,8 @@ internal static Thing DeserializeThing(JsonElement element, ModelReaderWriterOpt name, requiredUnion, requiredLiteralString, + requiredNullableString, + optionalNullableString, requiredLiteralInt, requiredLiteralFloat, requiredLiteralBool, diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.cs index f2ee96d4c04..924b15fb8ef 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/Models/Thing.cs @@ -18,10 +18,11 @@ public partial class Thing /// Initializes a new instance of . /// name of the Thing. /// required Union. + /// required nullable string. /// description with xml <|endoftext|>. /// required nullable collection. /// , or is null. - public Thing(string name, BinaryData requiredUnion, string requiredBadDescription, IEnumerable requiredNullableList) + public Thing(string name, BinaryData requiredUnion, string requiredNullableString, string requiredBadDescription, IEnumerable requiredNullableList) { Argument.AssertNotNull(name, nameof(name)); Argument.AssertNotNull(requiredUnion, nameof(requiredUnion)); @@ -29,16 +30,19 @@ public Thing(string name, BinaryData requiredUnion, string requiredBadDescriptio Name = name; RequiredUnion = requiredUnion; + RequiredNullableString = requiredNullableString; RequiredBadDescription = requiredBadDescription; OptionalNullableList = new ChangeTrackingList(); RequiredNullableList = requiredNullableList?.ToList(); } - internal Thing(string name, BinaryData requiredUnion, ThingRequiredLiteralString requiredLiteralString, ThingRequiredLiteralInt requiredLiteralInt, ThingRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, ThingOptionalLiteralString? optionalLiteralString, ThingOptionalLiteralInt? optionalLiteralInt, ThingOptionalLiteralFloat? optionalLiteralFloat, bool? optionalLiteralBool, string requiredBadDescription, IList optionalNullableList, IList requiredNullableList, IDictionary additionalBinaryDataProperties) + internal Thing(string name, BinaryData requiredUnion, ThingRequiredLiteralString requiredLiteralString, string requiredNullableString, string optionalNullableString, ThingRequiredLiteralInt requiredLiteralInt, ThingRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, ThingOptionalLiteralString? optionalLiteralString, ThingOptionalLiteralInt? optionalLiteralInt, ThingOptionalLiteralFloat? optionalLiteralFloat, bool? optionalLiteralBool, string requiredBadDescription, IList optionalNullableList, IList requiredNullableList, IDictionary additionalBinaryDataProperties) { Name = name; RequiredUnion = requiredUnion; RequiredLiteralString = requiredLiteralString; + RequiredNullableString = requiredNullableString; + OptionalNullableString = optionalNullableString; RequiredLiteralInt = requiredLiteralInt; RequiredLiteralFloat = requiredLiteralFloat; RequiredLiteralBool = requiredLiteralBool; @@ -102,6 +106,12 @@ internal Thing(string name, BinaryData requiredUnion, ThingRequiredLiteralString /// required literal string. public ThingRequiredLiteralString RequiredLiteralString { get; } = "accept"; + /// required nullable string. + public string RequiredNullableString { get; set; } + + /// required optional string. + public string OptionalNullableString { get; set; } + /// required literal int. public ThingRequiredLiteralInt RequiredLiteralInt { get; } = 123; diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecClient.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecClient.cs index bc3ed0b8eb1..842713308c5 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecClient.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecClient.cs @@ -620,11 +620,13 @@ public virtual async Task AnonymousBodyAsync(BinaryContent content /// name of the Thing. /// required Union. /// required literal string. + /// required nullable string. /// required literal int. /// required literal float. /// required literal bool. /// description with xml <|endoftext|>. /// required nullable collection. + /// required optional string. /// optional literal string. /// optional literal int. /// optional literal float. @@ -633,7 +635,7 @@ public virtual async Task AnonymousBodyAsync(BinaryContent content /// The cancellation token that can be used to cancel the operation. /// , or is null. /// Service returned a non-success status code. - public virtual ClientResult AnonymousBody(string name, BinaryData requiredUnion, ThingRequiredLiteralString requiredLiteralString, ThingRequiredLiteralInt requiredLiteralInt, ThingRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, string requiredBadDescription, IEnumerable requiredNullableList, ThingOptionalLiteralString? optionalLiteralString = default, ThingOptionalLiteralInt? optionalLiteralInt = default, ThingOptionalLiteralFloat? optionalLiteralFloat = default, bool? optionalLiteralBool = default, IEnumerable optionalNullableList = default, CancellationToken cancellationToken = default) + public virtual ClientResult AnonymousBody(string name, BinaryData requiredUnion, ThingRequiredLiteralString requiredLiteralString, string requiredNullableString, ThingRequiredLiteralInt requiredLiteralInt, ThingRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, string requiredBadDescription, IEnumerable requiredNullableList, string optionalNullableString = default, ThingOptionalLiteralString? optionalLiteralString = default, ThingOptionalLiteralInt? optionalLiteralInt = default, ThingOptionalLiteralFloat? optionalLiteralFloat = default, bool? optionalLiteralBool = default, IEnumerable optionalNullableList = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(name, nameof(name)); Argument.AssertNotNull(requiredUnion, nameof(requiredUnion)); @@ -643,6 +645,8 @@ public virtual ClientResult AnonymousBody(string name, BinaryData require name, requiredUnion, requiredLiteralString, + requiredNullableString, + optionalNullableString, requiredLiteralInt, requiredLiteralFloat, requiredLiteralBool, @@ -662,11 +666,13 @@ public virtual ClientResult AnonymousBody(string name, BinaryData require /// name of the Thing. /// required Union. /// required literal string. + /// required nullable string. /// required literal int. /// required literal float. /// required literal bool. /// description with xml <|endoftext|>. /// required nullable collection. + /// required optional string. /// optional literal string. /// optional literal int. /// optional literal float. @@ -675,7 +681,7 @@ public virtual ClientResult AnonymousBody(string name, BinaryData require /// The cancellation token that can be used to cancel the operation. /// , or is null. /// Service returned a non-success status code. - public virtual async Task> AnonymousBodyAsync(string name, BinaryData requiredUnion, ThingRequiredLiteralString requiredLiteralString, ThingRequiredLiteralInt requiredLiteralInt, ThingRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, string requiredBadDescription, IEnumerable requiredNullableList, ThingOptionalLiteralString? optionalLiteralString = default, ThingOptionalLiteralInt? optionalLiteralInt = default, ThingOptionalLiteralFloat? optionalLiteralFloat = default, bool? optionalLiteralBool = default, IEnumerable optionalNullableList = default, CancellationToken cancellationToken = default) + public virtual async Task> AnonymousBodyAsync(string name, BinaryData requiredUnion, ThingRequiredLiteralString requiredLiteralString, string requiredNullableString, ThingRequiredLiteralInt requiredLiteralInt, ThingRequiredLiteralFloat requiredLiteralFloat, bool requiredLiteralBool, string requiredBadDescription, IEnumerable requiredNullableList, string optionalNullableString = default, ThingOptionalLiteralString? optionalLiteralString = default, ThingOptionalLiteralInt? optionalLiteralInt = default, ThingOptionalLiteralFloat? optionalLiteralFloat = default, bool? optionalLiteralBool = default, IEnumerable optionalNullableList = default, CancellationToken cancellationToken = default) { Argument.AssertNotNull(name, nameof(name)); Argument.AssertNotNull(requiredUnion, nameof(requiredUnion)); @@ -685,6 +691,8 @@ public virtual async Task> AnonymousBodyAsync(string name, B name, requiredUnion, requiredLiteralString, + requiredNullableString, + optionalNullableString, requiredLiteralInt, requiredLiteralFloat, requiredLiteralBool, diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecModelFactory.cs b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecModelFactory.cs index 8243f8f4f06..beabe576d85 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecModelFactory.cs +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/src/Generated/UnbrandedTypeSpecModelFactory.cs @@ -16,6 +16,8 @@ public static partial class UnbrandedTypeSpecModelFactory /// name of the Thing. /// required Union. /// required literal string. + /// required nullable string. + /// required optional string. /// required literal int. /// required literal float. /// required literal bool. @@ -27,7 +29,7 @@ public static partial class UnbrandedTypeSpecModelFactory /// optional nullable collection. /// required nullable collection. /// A new instance for mocking. - public static Thing Thing(string name = default, BinaryData requiredUnion = default, ThingRequiredLiteralString requiredLiteralString = default, ThingRequiredLiteralInt requiredLiteralInt = default, ThingRequiredLiteralFloat requiredLiteralFloat = default, bool requiredLiteralBool = default, ThingOptionalLiteralString? optionalLiteralString = default, ThingOptionalLiteralInt? optionalLiteralInt = default, ThingOptionalLiteralFloat? optionalLiteralFloat = default, bool? optionalLiteralBool = default, string requiredBadDescription = default, IEnumerable optionalNullableList = default, IEnumerable requiredNullableList = default) + public static Thing Thing(string name = default, BinaryData requiredUnion = default, ThingRequiredLiteralString requiredLiteralString = default, string requiredNullableString = default, string optionalNullableString = default, ThingRequiredLiteralInt requiredLiteralInt = default, ThingRequiredLiteralFloat requiredLiteralFloat = default, bool requiredLiteralBool = default, ThingOptionalLiteralString? optionalLiteralString = default, ThingOptionalLiteralInt? optionalLiteralInt = default, ThingOptionalLiteralFloat? optionalLiteralFloat = default, bool? optionalLiteralBool = default, string requiredBadDescription = default, IEnumerable optionalNullableList = default, IEnumerable requiredNullableList = default) { optionalNullableList ??= new ChangeTrackingList(); requiredNullableList ??= new ChangeTrackingList(); @@ -36,6 +38,8 @@ public static Thing Thing(string name = default, BinaryData requiredUnion = defa name, requiredUnion, requiredLiteralString, + requiredNullableString, + optionalNullableString, requiredLiteralInt, requiredLiteralFloat, requiredLiteralBool, diff --git a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/tspCodeModel.json b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/tspCodeModel.json index 3b04736bba7..0476180bc8d 100644 --- a/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/tspCodeModel.json +++ b/packages/http-client-csharp/generator/TestProjects/Local/Unbranded-TypeSpec/tspCodeModel.json @@ -968,11 +968,75 @@ { "$id": "107", "kind": "property", + "name": "requiredNullableString", + "serializedName": "requiredNullableString", + "doc": "required nullable string", + "type": { + "$id": "108", + "kind": "nullable", + "type": { + "$id": "109", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "clientNamespace": "" + }, + "optional": false, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "UnbrandedTypeSpec.Thing.requiredNullableString", + "serializationOptions": { + "$id": "110", + "json": { + "$id": "111", + "name": "requiredNullableString" + } + } + }, + { + "$id": "112", + "kind": "property", + "name": "optionalNullableString", + "serializedName": "optionalNullableString", + "doc": "required optional string", + "type": { + "$id": "113", + "kind": "nullable", + "type": { + "$id": "114", + "kind": "string", + "name": "string", + "crossLanguageDefinitionId": "TypeSpec.string", + "decorators": [] + }, + "clientNamespace": "" + }, + "optional": true, + "readOnly": false, + "discriminator": false, + "flatten": false, + "decorators": [], + "crossLanguageDefinitionId": "UnbrandedTypeSpec.Thing.optionalNullableString", + "serializationOptions": { + "$id": "115", + "json": { + "$id": "116", + "name": "optionalNullableString" + } + } + }, + { + "$id": "117", + "kind": "property", "name": "requiredLiteralInt", "serializedName": "requiredLiteralInt", "doc": "required literal int", "type": { - "$id": "108", + "$id": "118", "kind": "constant", "valueType": { "$ref": "5" @@ -987,21 +1051,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.Thing.requiredLiteralInt", "serializationOptions": { - "$id": "109", + "$id": "119", "json": { - "$id": "110", + "$id": "120", "name": "requiredLiteralInt" } } }, { - "$id": "111", + "$id": "121", "kind": "property", "name": "requiredLiteralFloat", "serializedName": "requiredLiteralFloat", "doc": "required literal float", "type": { - "$id": "112", + "$id": "122", "kind": "constant", "valueType": { "$ref": "8" @@ -1016,24 +1080,24 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.Thing.requiredLiteralFloat", "serializationOptions": { - "$id": "113", + "$id": "123", "json": { - "$id": "114", + "$id": "124", "name": "requiredLiteralFloat" } } }, { - "$id": "115", + "$id": "125", "kind": "property", "name": "requiredLiteralBool", "serializedName": "requiredLiteralBool", "doc": "required literal bool", "type": { - "$id": "116", + "$id": "126", "kind": "constant", "valueType": { - "$id": "117", + "$id": "127", "kind": "boolean", "name": "boolean", "crossLanguageDefinitionId": "TypeSpec.boolean", @@ -1049,21 +1113,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.Thing.requiredLiteralBool", "serializationOptions": { - "$id": "118", + "$id": "128", "json": { - "$id": "119", + "$id": "129", "name": "requiredLiteralBool" } } }, { - "$id": "120", + "$id": "130", "kind": "property", "name": "optionalLiteralString", "serializedName": "optionalLiteralString", "doc": "optional literal string", "type": { - "$id": "121", + "$id": "131", "kind": "constant", "valueType": { "$ref": "11" @@ -1078,21 +1142,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.Thing.optionalLiteralString", "serializationOptions": { - "$id": "122", + "$id": "132", "json": { - "$id": "123", + "$id": "133", "name": "optionalLiteralString" } } }, { - "$id": "124", + "$id": "134", "kind": "property", "name": "optionalLiteralInt", "serializedName": "optionalLiteralInt", "doc": "optional literal int", "type": { - "$id": "125", + "$id": "135", "kind": "constant", "valueType": { "$ref": "14" @@ -1107,21 +1171,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.Thing.optionalLiteralInt", "serializationOptions": { - "$id": "126", + "$id": "136", "json": { - "$id": "127", + "$id": "137", "name": "optionalLiteralInt" } } }, { - "$id": "128", + "$id": "138", "kind": "property", "name": "optionalLiteralFloat", "serializedName": "optionalLiteralFloat", "doc": "optional literal float", "type": { - "$id": "129", + "$id": "139", "kind": "constant", "valueType": { "$ref": "17" @@ -1136,24 +1200,24 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.Thing.optionalLiteralFloat", "serializationOptions": { - "$id": "130", + "$id": "140", "json": { - "$id": "131", + "$id": "141", "name": "optionalLiteralFloat" } } }, { - "$id": "132", + "$id": "142", "kind": "property", "name": "optionalLiteralBool", "serializedName": "optionalLiteralBool", "doc": "optional literal bool", "type": { - "$id": "133", + "$id": "143", "kind": "constant", "valueType": { - "$id": "134", + "$id": "144", "kind": "boolean", "name": "boolean", "crossLanguageDefinitionId": "TypeSpec.boolean", @@ -1169,21 +1233,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.Thing.optionalLiteralBool", "serializationOptions": { - "$id": "135", + "$id": "145", "json": { - "$id": "136", + "$id": "146", "name": "optionalLiteralBool" } } }, { - "$id": "137", + "$id": "147", "kind": "property", "name": "requiredBadDescription", "serializedName": "requiredBadDescription", "doc": "description with xml <|endoftext|>", "type": { - "$id": "138", + "$id": "148", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -1196,28 +1260,28 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.Thing.requiredBadDescription", "serializationOptions": { - "$id": "139", + "$id": "149", "json": { - "$id": "140", + "$id": "150", "name": "requiredBadDescription" } } }, { - "$id": "141", + "$id": "151", "kind": "property", "name": "optionalNullableList", "serializedName": "optionalNullableList", "doc": "optional nullable collection", "type": { - "$id": "142", + "$id": "152", "kind": "nullable", "type": { - "$id": "143", + "$id": "153", "kind": "array", "name": "Array", "valueType": { - "$id": "144", + "$id": "154", "kind": "int32", "name": "int32", "crossLanguageDefinitionId": "TypeSpec.int32", @@ -1235,28 +1299,28 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.Thing.optionalNullableList", "serializationOptions": { - "$id": "145", + "$id": "155", "json": { - "$id": "146", + "$id": "156", "name": "optionalNullableList" } } }, { - "$id": "147", + "$id": "157", "kind": "property", "name": "requiredNullableList", "serializedName": "requiredNullableList", "doc": "required nullable collection", "type": { - "$id": "148", + "$id": "158", "kind": "nullable", "type": { - "$id": "149", + "$id": "159", "kind": "array", "name": "Array", "valueType": { - "$id": "150", + "$id": "160", "kind": "int32", "name": "int32", "crossLanguageDefinitionId": "TypeSpec.int32", @@ -1274,9 +1338,9 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.Thing.requiredNullableList", "serializationOptions": { - "$id": "151", + "$id": "161", "json": { - "$id": "152", + "$id": "162", "name": "requiredNullableList" } } @@ -1284,7 +1348,7 @@ ] }, { - "$id": "153", + "$id": "163", "kind": "model", "name": "RoundTripModel", "clientNamespace": "UnbrandedTypeSpec", @@ -1294,13 +1358,13 @@ "decorators": [], "properties": [ { - "$id": "154", + "$id": "164", "kind": "property", "name": "requiredString", "serializedName": "requiredString", "doc": "Required string, illustrating a reference type property.", "type": { - "$id": "155", + "$id": "165", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -1313,21 +1377,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.requiredString", "serializationOptions": { - "$id": "156", + "$id": "166", "json": { - "$id": "157", + "$id": "167", "name": "requiredString" } } }, { - "$id": "158", + "$id": "168", "kind": "property", "name": "requiredInt", "serializedName": "requiredInt", "doc": "Required int, illustrating a value type property.", "type": { - "$id": "159", + "$id": "169", "kind": "int32", "name": "int32", "encode": "string", @@ -1341,21 +1405,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.requiredInt", "serializationOptions": { - "$id": "160", + "$id": "170", "json": { - "$id": "161", + "$id": "171", "name": "requiredInt" } } }, { - "$id": "162", + "$id": "172", "kind": "property", "name": "requiredCollection", "serializedName": "requiredCollection", "doc": "Required collection of enums", "type": { - "$id": "163", + "$id": "173", "kind": "array", "name": "ArrayStringFixedEnum", "valueType": { @@ -1371,24 +1435,24 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.requiredCollection", "serializationOptions": { - "$id": "164", + "$id": "174", "json": { - "$id": "165", + "$id": "175", "name": "requiredCollection" } } }, { - "$id": "166", + "$id": "176", "kind": "property", "name": "requiredDictionary", "serializedName": "requiredDictionary", "doc": "Required dictionary of enums", "type": { - "$id": "167", + "$id": "177", "kind": "dict", "keyType": { - "$id": "168", + "$id": "178", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -1406,15 +1470,15 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.requiredDictionary", "serializationOptions": { - "$id": "169", + "$id": "179", "json": { - "$id": "170", + "$id": "180", "name": "requiredDictionary" } } }, { - "$id": "171", + "$id": "181", "kind": "property", "name": "requiredModel", "serializedName": "requiredModel", @@ -1429,15 +1493,15 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.requiredModel", "serializationOptions": { - "$id": "172", + "$id": "182", "json": { - "$id": "173", + "$id": "183", "name": "requiredModel" } } }, { - "$id": "174", + "$id": "184", "kind": "property", "name": "intExtensibleEnum", "serializedName": "intExtensibleEnum", @@ -1452,21 +1516,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.intExtensibleEnum", "serializationOptions": { - "$id": "175", + "$id": "185", "json": { - "$id": "176", + "$id": "186", "name": "intExtensibleEnum" } } }, { - "$id": "177", + "$id": "187", "kind": "property", "name": "intExtensibleEnumCollection", "serializedName": "intExtensibleEnumCollection", "doc": "this is a collection of int based extensible enum", "type": { - "$id": "178", + "$id": "188", "kind": "array", "name": "ArrayIntExtensibleEnum", "valueType": { @@ -1482,15 +1546,15 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.intExtensibleEnumCollection", "serializationOptions": { - "$id": "179", + "$id": "189", "json": { - "$id": "180", + "$id": "190", "name": "intExtensibleEnumCollection" } } }, { - "$id": "181", + "$id": "191", "kind": "property", "name": "floatExtensibleEnum", "serializedName": "floatExtensibleEnum", @@ -1505,15 +1569,15 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.floatExtensibleEnum", "serializationOptions": { - "$id": "182", + "$id": "192", "json": { - "$id": "183", + "$id": "193", "name": "floatExtensibleEnum" } } }, { - "$id": "184", + "$id": "194", "kind": "property", "name": "floatExtensibleEnumWithIntValue", "serializedName": "floatExtensibleEnumWithIntValue", @@ -1528,21 +1592,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.floatExtensibleEnumWithIntValue", "serializationOptions": { - "$id": "185", + "$id": "195", "json": { - "$id": "186", + "$id": "196", "name": "floatExtensibleEnumWithIntValue" } } }, { - "$id": "187", + "$id": "197", "kind": "property", "name": "floatExtensibleEnumCollection", "serializedName": "floatExtensibleEnumCollection", "doc": "this is a collection of float based extensible enum", "type": { - "$id": "188", + "$id": "198", "kind": "array", "name": "ArrayFloatExtensibleEnum", "valueType": { @@ -1558,15 +1622,15 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.floatExtensibleEnumCollection", "serializationOptions": { - "$id": "189", + "$id": "199", "json": { - "$id": "190", + "$id": "200", "name": "floatExtensibleEnumCollection" } } }, { - "$id": "191", + "$id": "201", "kind": "property", "name": "floatFixedEnum", "serializedName": "floatFixedEnum", @@ -1581,15 +1645,15 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.floatFixedEnum", "serializationOptions": { - "$id": "192", + "$id": "202", "json": { - "$id": "193", + "$id": "203", "name": "floatFixedEnum" } } }, { - "$id": "194", + "$id": "204", "kind": "property", "name": "floatFixedEnumWithIntValue", "serializedName": "floatFixedEnumWithIntValue", @@ -1604,21 +1668,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.floatFixedEnumWithIntValue", "serializationOptions": { - "$id": "195", + "$id": "205", "json": { - "$id": "196", + "$id": "206", "name": "floatFixedEnumWithIntValue" } } }, { - "$id": "197", + "$id": "207", "kind": "property", "name": "floatFixedEnumCollection", "serializedName": "floatFixedEnumCollection", "doc": "this is a collection of float based fixed enum", "type": { - "$id": "198", + "$id": "208", "kind": "array", "name": "ArrayFloatFixedEnum", "valueType": { @@ -1634,15 +1698,15 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.floatFixedEnumCollection", "serializationOptions": { - "$id": "199", + "$id": "209", "json": { - "$id": "200", + "$id": "210", "name": "floatFixedEnumCollection" } } }, { - "$id": "201", + "$id": "211", "kind": "property", "name": "intFixedEnum", "serializedName": "intFixedEnum", @@ -1657,21 +1721,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.intFixedEnum", "serializationOptions": { - "$id": "202", + "$id": "212", "json": { - "$id": "203", + "$id": "213", "name": "intFixedEnum" } } }, { - "$id": "204", + "$id": "214", "kind": "property", "name": "intFixedEnumCollection", "serializedName": "intFixedEnumCollection", "doc": "this is a collection of int based fixed enum", "type": { - "$id": "205", + "$id": "215", "kind": "array", "name": "ArrayIntFixedEnum", "valueType": { @@ -1687,15 +1751,15 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.intFixedEnumCollection", "serializationOptions": { - "$id": "206", + "$id": "216", "json": { - "$id": "207", + "$id": "217", "name": "intFixedEnumCollection" } } }, { - "$id": "208", + "$id": "218", "kind": "property", "name": "stringFixedEnum", "serializedName": "stringFixedEnum", @@ -1710,21 +1774,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.stringFixedEnum", "serializationOptions": { - "$id": "209", + "$id": "219", "json": { - "$id": "210", + "$id": "220", "name": "stringFixedEnum" } } }, { - "$id": "211", + "$id": "221", "kind": "property", "name": "requiredUnknown", "serializedName": "requiredUnknown", "doc": "required unknown", "type": { - "$id": "212", + "$id": "222", "kind": "unknown", "name": "unknown", "crossLanguageDefinitionId": "", @@ -1737,21 +1801,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.requiredUnknown", "serializationOptions": { - "$id": "213", + "$id": "223", "json": { - "$id": "214", + "$id": "224", "name": "requiredUnknown" } } }, { - "$id": "215", + "$id": "225", "kind": "property", "name": "optionalUnknown", "serializedName": "optionalUnknown", "doc": "optional unknown", "type": { - "$id": "216", + "$id": "226", "kind": "unknown", "name": "unknown", "crossLanguageDefinitionId": "", @@ -1764,31 +1828,31 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.optionalUnknown", "serializationOptions": { - "$id": "217", + "$id": "227", "json": { - "$id": "218", + "$id": "228", "name": "optionalUnknown" } } }, { - "$id": "219", + "$id": "229", "kind": "property", "name": "requiredRecordUnknown", "serializedName": "requiredRecordUnknown", "doc": "required record of unknown", "type": { - "$id": "220", + "$id": "230", "kind": "dict", "keyType": { - "$id": "221", + "$id": "231", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", "decorators": [] }, "valueType": { - "$id": "222", + "$id": "232", "kind": "unknown", "name": "unknown", "crossLanguageDefinitionId": "", @@ -1803,31 +1867,31 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.requiredRecordUnknown", "serializationOptions": { - "$id": "223", + "$id": "233", "json": { - "$id": "224", + "$id": "234", "name": "requiredRecordUnknown" } } }, { - "$id": "225", + "$id": "235", "kind": "property", "name": "optionalRecordUnknown", "serializedName": "optionalRecordUnknown", "doc": "optional record of unknown", "type": { - "$id": "226", + "$id": "236", "kind": "dict", "keyType": { - "$id": "227", + "$id": "237", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", "decorators": [] }, "valueType": { - "$id": "228", + "$id": "238", "kind": "unknown", "name": "unknown", "crossLanguageDefinitionId": "", @@ -1842,31 +1906,31 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.optionalRecordUnknown", "serializationOptions": { - "$id": "229", + "$id": "239", "json": { - "$id": "230", + "$id": "240", "name": "optionalRecordUnknown" } } }, { - "$id": "231", + "$id": "241", "kind": "property", "name": "readOnlyRequiredRecordUnknown", "serializedName": "readOnlyRequiredRecordUnknown", "doc": "required readonly record of unknown", "type": { - "$id": "232", + "$id": "242", "kind": "dict", "keyType": { - "$id": "233", + "$id": "243", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", "decorators": [] }, "valueType": { - "$id": "234", + "$id": "244", "kind": "unknown", "name": "unknown", "crossLanguageDefinitionId": "", @@ -1881,31 +1945,31 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.readOnlyRequiredRecordUnknown", "serializationOptions": { - "$id": "235", + "$id": "245", "json": { - "$id": "236", + "$id": "246", "name": "readOnlyRequiredRecordUnknown" } } }, { - "$id": "237", + "$id": "247", "kind": "property", "name": "readOnlyOptionalRecordUnknown", "serializedName": "readOnlyOptionalRecordUnknown", "doc": "optional readonly record of unknown", "type": { - "$id": "238", + "$id": "248", "kind": "dict", "keyType": { - "$id": "239", + "$id": "249", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", "decorators": [] }, "valueType": { - "$id": "240", + "$id": "250", "kind": "unknown", "name": "unknown", "crossLanguageDefinitionId": "", @@ -1920,21 +1984,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.readOnlyOptionalRecordUnknown", "serializationOptions": { - "$id": "241", + "$id": "251", "json": { - "$id": "242", + "$id": "252", "name": "readOnlyOptionalRecordUnknown" } } }, { - "$id": "243", + "$id": "253", "kind": "property", "name": "modelWithRequiredNullable", "serializedName": "modelWithRequiredNullable", "doc": "this is a model with required nullable properties", "type": { - "$id": "244", + "$id": "254", "kind": "model", "name": "ModelWithRequiredNullableProperties", "clientNamespace": "UnbrandedTypeSpec", @@ -1944,16 +2008,16 @@ "decorators": [], "properties": [ { - "$id": "245", + "$id": "255", "kind": "property", "name": "requiredNullablePrimitive", "serializedName": "requiredNullablePrimitive", "doc": "required nullable primitive type", "type": { - "$id": "246", + "$id": "256", "kind": "nullable", "type": { - "$id": "247", + "$id": "257", "kind": "int32", "name": "int32", "crossLanguageDefinitionId": "TypeSpec.int32", @@ -1968,21 +2032,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.ModelWithRequiredNullableProperties.requiredNullablePrimitive", "serializationOptions": { - "$id": "248", + "$id": "258", "json": { - "$id": "249", + "$id": "259", "name": "requiredNullablePrimitive" } } }, { - "$id": "250", + "$id": "260", "kind": "property", "name": "requiredExtensibleEnum", "serializedName": "requiredExtensibleEnum", "doc": "required nullable extensible enum type", "type": { - "$id": "251", + "$id": "261", "kind": "nullable", "type": { "$ref": "28" @@ -1996,21 +2060,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.ModelWithRequiredNullableProperties.requiredExtensibleEnum", "serializationOptions": { - "$id": "252", + "$id": "262", "json": { - "$id": "253", + "$id": "263", "name": "requiredExtensibleEnum" } } }, { - "$id": "254", + "$id": "264", "kind": "property", "name": "requiredFixedEnum", "serializedName": "requiredFixedEnum", "doc": "required nullable fixed enum type", "type": { - "$id": "255", + "$id": "265", "kind": "nullable", "type": { "$ref": "20" @@ -2024,9 +2088,9 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.ModelWithRequiredNullableProperties.requiredFixedEnum", "serializationOptions": { - "$id": "256", + "$id": "266", "json": { - "$id": "257", + "$id": "267", "name": "requiredFixedEnum" } } @@ -2040,21 +2104,21 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.modelWithRequiredNullable", "serializationOptions": { - "$id": "258", + "$id": "268", "json": { - "$id": "259", + "$id": "269", "name": "modelWithRequiredNullable" } } }, { - "$id": "260", + "$id": "270", "kind": "property", "name": "requiredBytes", "serializedName": "requiredBytes", "doc": "Required bytes", "type": { - "$id": "261", + "$id": "271", "kind": "bytes", "name": "bytes", "encode": "base64", @@ -2068,9 +2132,9 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.RoundTripModel.requiredBytes", "serializationOptions": { - "$id": "262", + "$id": "272", "json": { - "$id": "263", + "$id": "273", "name": "requiredBytes" } } @@ -2078,10 +2142,10 @@ ] }, { - "$ref": "244" + "$ref": "254" }, { - "$id": "264", + "$id": "274", "kind": "model", "name": "Friend", "clientNamespace": "UnbrandedTypeSpec", @@ -2091,13 +2155,13 @@ "decorators": [], "properties": [ { - "$id": "265", + "$id": "275", "kind": "property", "name": "name", "serializedName": "name", "doc": "name of the NotFriend", "type": { - "$id": "266", + "$id": "276", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2110,9 +2174,9 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.NotFriend.name", "serializationOptions": { - "$id": "267", + "$id": "277", "json": { - "$id": "268", + "$id": "278", "name": "name" } } @@ -2120,7 +2184,7 @@ ] }, { - "$id": "269", + "$id": "279", "kind": "model", "name": "ProjectedModel", "clientNamespace": "UnbrandedTypeSpec", @@ -2130,13 +2194,13 @@ "decorators": [], "properties": [ { - "$id": "270", + "$id": "280", "kind": "property", "name": "name", "serializedName": "name", "doc": "name of the ModelWithProjectedName", "type": { - "$id": "271", + "$id": "281", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2149,9 +2213,9 @@ "decorators": [], "crossLanguageDefinitionId": "UnbrandedTypeSpec.ModelWithProjectedName.name", "serializationOptions": { - "$id": "272", + "$id": "282", "json": { - "$id": "273", + "$id": "283", "name": "name" } } @@ -2159,7 +2223,7 @@ ] }, { - "$id": "274", + "$id": "284", "kind": "model", "name": "ReturnsAnonymousModelResponse", "clientNamespace": "UnbrandedTypeSpec", @@ -2171,24 +2235,24 @@ ], "Clients": [ { - "$id": "275", + "$id": "285", "Name": "UnbrandedTypeSpecClient", "ClientNamespace": "UnbrandedTypeSpec", "Doc": "This is a sample typespec project.", "Operations": [ { - "$id": "276", + "$id": "286", "Name": "sayHi", "ResourceName": "UnbrandedTypeSpec", "Doc": "Return hi", "Accessibility": "public", "Parameters": [ { - "$id": "277", + "$id": "287", "Name": "headParameter", "NameInRequest": "head-parameter", "Type": { - "$id": "278", + "$id": "288", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2205,11 +2269,11 @@ "SkipUrlEncoding": false }, { - "$id": "279", + "$id": "289", "Name": "queryParameter", "NameInRequest": "queryParameter", "Type": { - "$id": "280", + "$id": "290", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2226,11 +2290,11 @@ "SkipUrlEncoding": false }, { - "$id": "281", + "$id": "291", "Name": "optionalQuery", "NameInRequest": "optionalQuery", "Type": { - "$id": "282", + "$id": "292", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2247,14 +2311,14 @@ "SkipUrlEncoding": false }, { - "$id": "283", + "$id": "293", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "284", + "$id": "294", "kind": "constant", "valueType": { - "$id": "285", + "$id": "295", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2276,7 +2340,7 @@ ], "Responses": [ { - "$id": "286", + "$id": "296", "StatusCodes": [ 200 ], @@ -2302,18 +2366,18 @@ "Decorators": [] }, { - "$id": "287", + "$id": "297", "Name": "helloAgain", "ResourceName": "UnbrandedTypeSpec", "Doc": "Return hi again", "Accessibility": "public", "Parameters": [ { - "$id": "288", + "$id": "298", "Name": "p1", "NameInRequest": "p1", "Type": { - "$id": "289", + "$id": "299", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2330,14 +2394,14 @@ "SkipUrlEncoding": false }, { - "$id": "290", + "$id": "300", "Name": "contentType", "NameInRequest": "Content-Type", "Type": { - "$id": "291", + "$id": "301", "kind": "constant", "valueType": { - "$id": "292", + "$id": "302", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2357,11 +2421,11 @@ "SkipUrlEncoding": false }, { - "$id": "293", + "$id": "303", "Name": "p2", "NameInRequest": "p2", "Type": { - "$id": "294", + "$id": "304", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2378,14 +2442,14 @@ "SkipUrlEncoding": false }, { - "$id": "295", + "$id": "305", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "296", + "$id": "306", "kind": "constant", "valueType": { - "$id": "297", + "$id": "307", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2405,11 +2469,11 @@ "SkipUrlEncoding": false }, { - "$id": "298", + "$id": "308", "Name": "action", "NameInRequest": "action", "Type": { - "$ref": "153" + "$ref": "163" }, "Location": "Body", "IsApiVersion": false, @@ -2424,12 +2488,12 @@ ], "Responses": [ { - "$id": "299", + "$id": "309", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "153" + "$ref": "163" }, "BodyMediaType": "Json", "Headers": [], @@ -2453,18 +2517,18 @@ "Decorators": [] }, { - "$id": "300", + "$id": "310", "Name": "noContentType", "ResourceName": "UnbrandedTypeSpec", "Doc": "Return hi again", "Accessibility": "public", "Parameters": [ { - "$id": "301", + "$id": "311", "Name": "p1", "NameInRequest": "p1", "Type": { - "$id": "302", + "$id": "312", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2481,11 +2545,11 @@ "SkipUrlEncoding": false }, { - "$id": "303", + "$id": "313", "Name": "p2", "NameInRequest": "p2", "Type": { - "$id": "304", + "$id": "314", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2502,15 +2566,15 @@ "SkipUrlEncoding": false }, { - "$id": "305", + "$id": "315", "Name": "contentType", "NameInRequest": "Content-Type", "Doc": "Body parameter's content type. Known values are application/json", "Type": { - "$id": "306", + "$id": "316", "kind": "constant", "valueType": { - "$id": "307", + "$id": "317", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2530,14 +2594,14 @@ "SkipUrlEncoding": false }, { - "$id": "308", + "$id": "318", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "309", + "$id": "319", "kind": "constant", "valueType": { - "$id": "310", + "$id": "320", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2557,11 +2621,11 @@ "SkipUrlEncoding": false }, { - "$id": "311", + "$id": "321", "Name": "action", "NameInRequest": "action", "Type": { - "$ref": "153" + "$ref": "163" }, "Location": "Body", "IsApiVersion": false, @@ -2576,12 +2640,12 @@ ], "Responses": [ { - "$id": "312", + "$id": "322", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "153" + "$ref": "163" }, "BodyMediaType": "Json", "Headers": [], @@ -2605,21 +2669,21 @@ "Decorators": [] }, { - "$id": "313", + "$id": "323", "Name": "helloDemo2", "ResourceName": "UnbrandedTypeSpec", "Doc": "Return hi in demo2", "Accessibility": "public", "Parameters": [ { - "$id": "314", + "$id": "324", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "315", + "$id": "325", "kind": "constant", "valueType": { - "$id": "316", + "$id": "326", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2641,7 +2705,7 @@ ], "Responses": [ { - "$id": "317", + "$id": "327", "StatusCodes": [ 200 ], @@ -2667,22 +2731,22 @@ "Decorators": [] }, { - "$id": "318", + "$id": "328", "Name": "createLiteral", "ResourceName": "UnbrandedTypeSpec", "Doc": "Create with literal value", "Accessibility": "public", "Parameters": [ { - "$id": "319", + "$id": "329", "Name": "contentType", "NameInRequest": "Content-Type", "Doc": "Body parameter's content type. Known values are application/json", "Type": { - "$id": "320", + "$id": "330", "kind": "constant", "valueType": { - "$id": "321", + "$id": "331", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2702,14 +2766,14 @@ "SkipUrlEncoding": false }, { - "$id": "322", + "$id": "332", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "323", + "$id": "333", "kind": "constant", "valueType": { - "$id": "324", + "$id": "334", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2729,7 +2793,7 @@ "SkipUrlEncoding": false }, { - "$id": "325", + "$id": "335", "Name": "body", "NameInRequest": "body", "Type": { @@ -2748,7 +2812,7 @@ ], "Responses": [ { - "$id": "326", + "$id": "336", "StatusCodes": [ 200 ], @@ -2777,21 +2841,21 @@ "Decorators": [] }, { - "$id": "327", + "$id": "337", "Name": "helloLiteral", "ResourceName": "UnbrandedTypeSpec", "Doc": "Send literal parameters", "Accessibility": "public", "Parameters": [ { - "$id": "328", + "$id": "338", "Name": "p1", "NameInRequest": "p1", "Type": { - "$id": "329", + "$id": "339", "kind": "constant", "valueType": { - "$id": "330", + "$id": "340", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2811,14 +2875,14 @@ "SkipUrlEncoding": false }, { - "$id": "331", + "$id": "341", "Name": "p2", "NameInRequest": "p2", "Type": { - "$id": "332", + "$id": "342", "kind": "constant", "valueType": { - "$id": "333", + "$id": "343", "kind": "int32", "name": "int32", "crossLanguageDefinitionId": "TypeSpec.int32", @@ -2838,14 +2902,14 @@ "SkipUrlEncoding": false }, { - "$id": "334", + "$id": "344", "Name": "p3", "NameInRequest": "p3", "Type": { - "$id": "335", + "$id": "345", "kind": "constant", "valueType": { - "$id": "336", + "$id": "346", "kind": "boolean", "name": "boolean", "crossLanguageDefinitionId": "TypeSpec.boolean", @@ -2865,14 +2929,14 @@ "SkipUrlEncoding": false }, { - "$id": "337", + "$id": "347", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "338", + "$id": "348", "kind": "constant", "valueType": { - "$id": "339", + "$id": "349", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2894,7 +2958,7 @@ ], "Responses": [ { - "$id": "340", + "$id": "350", "StatusCodes": [ 200 ], @@ -2920,23 +2984,23 @@ "Decorators": [] }, { - "$id": "341", + "$id": "351", "Name": "topAction", "ResourceName": "UnbrandedTypeSpec", "Doc": "top level method", "Accessibility": "public", "Parameters": [ { - "$id": "342", + "$id": "352", "Name": "action", "NameInRequest": "action", "Type": { - "$id": "343", + "$id": "353", "kind": "utcDateTime", "name": "utcDateTime", "encode": "rfc3339", "wireType": { - "$id": "344", + "$id": "354", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2956,14 +3020,14 @@ "SkipUrlEncoding": false }, { - "$id": "345", + "$id": "355", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "346", + "$id": "356", "kind": "constant", "valueType": { - "$id": "347", + "$id": "357", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -2985,7 +3049,7 @@ ], "Responses": [ { - "$id": "348", + "$id": "358", "StatusCodes": [ 200 ], @@ -3011,21 +3075,21 @@ "Decorators": [] }, { - "$id": "349", + "$id": "359", "Name": "topAction2", "ResourceName": "UnbrandedTypeSpec", "Doc": "top level method2", "Accessibility": "public", "Parameters": [ { - "$id": "350", + "$id": "360", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "351", + "$id": "361", "kind": "constant", "valueType": { - "$id": "352", + "$id": "362", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3047,7 +3111,7 @@ ], "Responses": [ { - "$id": "353", + "$id": "363", "StatusCodes": [ 200 ], @@ -3073,22 +3137,22 @@ "Decorators": [] }, { - "$id": "354", + "$id": "364", "Name": "patchAction", "ResourceName": "UnbrandedTypeSpec", "Doc": "top level patch", "Accessibility": "public", "Parameters": [ { - "$id": "355", + "$id": "365", "Name": "contentType", "NameInRequest": "Content-Type", "Doc": "Body parameter's content type. Known values are application/json", "Type": { - "$id": "356", + "$id": "366", "kind": "constant", "valueType": { - "$id": "357", + "$id": "367", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3108,14 +3172,14 @@ "SkipUrlEncoding": false }, { - "$id": "358", + "$id": "368", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "359", + "$id": "369", "kind": "constant", "valueType": { - "$id": "360", + "$id": "370", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3135,7 +3199,7 @@ "SkipUrlEncoding": false }, { - "$id": "361", + "$id": "371", "Name": "body", "NameInRequest": "body", "Type": { @@ -3154,7 +3218,7 @@ ], "Responses": [ { - "$id": "362", + "$id": "372", "StatusCodes": [ 200 ], @@ -3183,22 +3247,22 @@ "Decorators": [] }, { - "$id": "363", + "$id": "373", "Name": "anonymousBody", "ResourceName": "UnbrandedTypeSpec", "Doc": "body parameter without body decorator", "Accessibility": "public", "Parameters": [ { - "$id": "364", + "$id": "374", "Name": "contentType", "NameInRequest": "Content-Type", "Doc": "Body parameter's content type. Known values are application/json", "Type": { - "$id": "365", + "$id": "375", "kind": "constant", "valueType": { - "$id": "366", + "$id": "376", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3218,14 +3282,14 @@ "SkipUrlEncoding": false }, { - "$id": "367", + "$id": "377", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "368", + "$id": "378", "kind": "constant", "valueType": { - "$id": "369", + "$id": "379", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3245,7 +3309,7 @@ "SkipUrlEncoding": false }, { - "$id": "370", + "$id": "380", "Name": "thing", "NameInRequest": "thing", "Type": { @@ -3264,7 +3328,7 @@ ], "Responses": [ { - "$id": "371", + "$id": "381", "StatusCodes": [ 200 ], @@ -3293,22 +3357,22 @@ "Decorators": [] }, { - "$id": "372", + "$id": "382", "Name": "friendlyModel", "ResourceName": "UnbrandedTypeSpec", "Doc": "Model can have its friendly name", "Accessibility": "public", "Parameters": [ { - "$id": "373", + "$id": "383", "Name": "contentType", "NameInRequest": "Content-Type", "Doc": "Body parameter's content type. Known values are application/json", "Type": { - "$id": "374", + "$id": "384", "kind": "constant", "valueType": { - "$id": "375", + "$id": "385", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3328,14 +3392,14 @@ "SkipUrlEncoding": false }, { - "$id": "376", + "$id": "386", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "377", + "$id": "387", "kind": "constant", "valueType": { - "$id": "378", + "$id": "388", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3355,11 +3419,11 @@ "SkipUrlEncoding": false }, { - "$id": "379", + "$id": "389", "Name": "friend", "NameInRequest": "friend", "Type": { - "$ref": "264" + "$ref": "274" }, "Location": "Body", "IsApiVersion": false, @@ -3374,12 +3438,12 @@ ], "Responses": [ { - "$id": "380", + "$id": "390", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "264" + "$ref": "274" }, "BodyMediaType": "Json", "Headers": [], @@ -3403,22 +3467,22 @@ "Decorators": [] }, { - "$id": "381", + "$id": "391", "Name": "addTimeHeader", "ResourceName": "UnbrandedTypeSpec", "Accessibility": "public", "Parameters": [ { - "$id": "382", + "$id": "392", "Name": "repeatabilityFirstSent", "NameInRequest": "Repeatability-First-Sent", "Type": { - "$id": "383", + "$id": "393", "kind": "utcDateTime", "name": "utcDateTime", "encode": "rfc7231", "wireType": { - "$id": "384", + "$id": "394", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3440,7 +3504,7 @@ ], "Responses": [ { - "$id": "385", + "$id": "395", "StatusCodes": [ 204 ], @@ -3460,22 +3524,22 @@ "Decorators": [] }, { - "$id": "386", + "$id": "396", "Name": "projectedNameModel", "ResourceName": "UnbrandedTypeSpec", "Doc": "Model can have its projected name", "Accessibility": "public", "Parameters": [ { - "$id": "387", + "$id": "397", "Name": "contentType", "NameInRequest": "Content-Type", "Doc": "Body parameter's content type. Known values are application/json", "Type": { - "$id": "388", + "$id": "398", "kind": "constant", "valueType": { - "$id": "389", + "$id": "399", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3495,14 +3559,14 @@ "SkipUrlEncoding": false }, { - "$id": "390", + "$id": "400", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "391", + "$id": "401", "kind": "constant", "valueType": { - "$id": "392", + "$id": "402", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3522,11 +3586,11 @@ "SkipUrlEncoding": false }, { - "$id": "393", + "$id": "403", "Name": "projectedModel", "NameInRequest": "projectedModel", "Type": { - "$ref": "269" + "$ref": "279" }, "Location": "Body", "IsApiVersion": false, @@ -3541,12 +3605,12 @@ ], "Responses": [ { - "$id": "394", + "$id": "404", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "269" + "$ref": "279" }, "BodyMediaType": "Json", "Headers": [], @@ -3570,21 +3634,21 @@ "Decorators": [] }, { - "$id": "395", + "$id": "405", "Name": "returnsAnonymousModel", "ResourceName": "UnbrandedTypeSpec", "Doc": "return anonymous model", "Accessibility": "public", "Parameters": [ { - "$id": "396", + "$id": "406", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "397", + "$id": "407", "kind": "constant", "valueType": { - "$id": "398", + "$id": "408", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3606,12 +3670,12 @@ ], "Responses": [ { - "$id": "399", + "$id": "409", "StatusCodes": [ 200 ], "BodyType": { - "$ref": "274" + "$ref": "284" }, "BodyMediaType": "Json", "Headers": [], @@ -3632,18 +3696,18 @@ "Decorators": [] }, { - "$id": "400", + "$id": "410", "Name": "getUnknownValue", "ResourceName": "UnbrandedTypeSpec", "Doc": "get extensible enum", "Accessibility": "public", "Parameters": [ { - "$id": "401", + "$id": "411", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "402", + "$id": "412", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3662,15 +3726,15 @@ ], "Responses": [ { - "$id": "403", + "$id": "413", "StatusCodes": [ 200 ], "BodyType": { - "$id": "404", + "$id": "414", "kind": "constant", "valueType": { - "$id": "405", + "$id": "415", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3705,22 +3769,22 @@ "Decorators": [] }, { - "$id": "406", + "$id": "416", "Name": "internalProtocol", "ResourceName": "UnbrandedTypeSpec", "Doc": "When set protocol false and convenient true, then the protocol method should be internal", "Accessibility": "public", "Parameters": [ { - "$id": "407", + "$id": "417", "Name": "contentType", "NameInRequest": "Content-Type", "Doc": "Body parameter's content type. Known values are application/json", "Type": { - "$id": "408", + "$id": "418", "kind": "constant", "valueType": { - "$id": "409", + "$id": "419", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3740,14 +3804,14 @@ "SkipUrlEncoding": false }, { - "$id": "410", + "$id": "420", "Name": "accept", "NameInRequest": "Accept", "Type": { - "$id": "411", + "$id": "421", "kind": "constant", "valueType": { - "$id": "412", + "$id": "422", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3767,7 +3831,7 @@ "SkipUrlEncoding": false }, { - "$id": "413", + "$id": "423", "Name": "body", "NameInRequest": "body", "Type": { @@ -3786,7 +3850,7 @@ ], "Responses": [ { - "$id": "414", + "$id": "424", "StatusCodes": [ 200 ], @@ -3815,7 +3879,7 @@ "Decorators": [] }, { - "$id": "415", + "$id": "425", "Name": "stillConvenient", "ResourceName": "UnbrandedTypeSpec", "Doc": "When set protocol false and convenient true, the convenient method should be generated even it has the same signature as protocol one", @@ -3823,7 +3887,7 @@ "Parameters": [], "Responses": [ { - "$id": "416", + "$id": "426", "StatusCodes": [ 204 ], @@ -3843,18 +3907,18 @@ "Decorators": [] }, { - "$id": "417", + "$id": "427", "Name": "headAsBoolean", "ResourceName": "UnbrandedTypeSpec", "Doc": "head as boolean.", "Accessibility": "public", "Parameters": [ { - "$id": "418", + "$id": "428", "Name": "id", "NameInRequest": "id", "Type": { - "$id": "419", + "$id": "429", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3873,7 +3937,7 @@ ], "Responses": [ { - "$id": "420", + "$id": "430", "StatusCodes": [ 204 ], @@ -3893,18 +3957,18 @@ "Decorators": [] }, { - "$id": "421", + "$id": "431", "Name": "WithApiVersion", "ResourceName": "UnbrandedTypeSpec", "Doc": "Return hi again", "Accessibility": "public", "Parameters": [ { - "$id": "422", + "$id": "432", "Name": "p1", "NameInRequest": "p1", "Type": { - "$id": "423", + "$id": "433", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3921,11 +3985,11 @@ "SkipUrlEncoding": false }, { - "$id": "424", + "$id": "434", "Name": "apiVersion", "NameInRequest": "apiVersion", "Type": { - "$id": "425", + "$id": "435", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string", @@ -3939,9 +4003,9 @@ "IsRequired": true, "Kind": "Client", "DefaultValue": { - "$id": "426", + "$id": "436", "Type": { - "$id": "427", + "$id": "437", "kind": "string", "name": "string", "crossLanguageDefinitionId": "TypeSpec.string" @@ -3954,7 +4018,7 @@ ], "Responses": [ { - "$id": "428", + "$id": "438", "StatusCodes": [ 204 ], @@ -3975,15 +4039,15 @@ } ], "Protocol": { - "$id": "429" + "$id": "439" }, "Parameters": [ { - "$id": "430", + "$id": "440", "Name": "unbrandedTypeSpecUrl", "NameInRequest": "unbrandedTypeSpecUrl", "Type": { - "$id": "431", + "$id": "441", "kind": "url", "name": "url", "crossLanguageDefinitionId": "TypeSpec.url" @@ -4003,9 +4067,9 @@ } ], "Auth": { - "$id": "432", + "$id": "442", "ApiKey": { - "$id": "433", + "$id": "443", "Name": "my-api-key", "In": "header" } From 84bd4ce9459d63c566fcd3a03d5e642766e9087c Mon Sep 17 00:00:00 2001 From: jolov Date: Thu, 20 Feb 2025 13:57:41 -0800 Subject: [PATCH 4/5] SPACING --- .../TestData/Thing/ThingWithNulls.json | 28 +++++++++---------- .../Thing/ThingWithNullsWireFormat.json | 26 ++++++++--------- 2 files changed, 27 insertions(+), 27 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNulls.json b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNulls.json index c95403c676e..21c4d4002e0 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNulls.json +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNulls.json @@ -1,16 +1,16 @@ { - "name": "Example Thing", - "requiredUnion": "mockUnion", - "requiredBadDescription": "This is a description with potentially problematic characters like < or >.", - "requiredNullableList": null, - "requiredLiteralString": "accept", - "requiredLiteralInt": 123, - "requiredLiteralFloat": 1.23, - "requiredLiteralBool": false, - "optionalLiteralString": "hi", - "optionalLiteralInt": 456, - "optionalLiteralFloat": 4.56, - "optionalLiteralBool": false, - "requiredNullableString": null, - "extra": "stuff" + "name": "Example Thing", + "requiredUnion": "mockUnion", + "requiredBadDescription": "This is a description with potentially problematic characters like < or >.", + "requiredNullableList": null, + "requiredLiteralString": "accept", + "requiredLiteralInt": 123, + "requiredLiteralFloat": 1.23, + "requiredLiteralBool": false, + "optionalLiteralString": "hi", + "optionalLiteralInt": 456, + "optionalLiteralFloat": 4.56, + "optionalLiteralBool": false, + "requiredNullableString": null, + "extra": "stuff" } diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNullsWireFormat.json b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNullsWireFormat.json index 03533756b19..f41c232480b 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNullsWireFormat.json +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/ModelReaderWriterValidation/TestProjects/Unbranded_TypeSpec/TestData/Thing/ThingWithNullsWireFormat.json @@ -1,15 +1,15 @@ { - "name": "Example Thing", - "requiredUnion": "mockUnion", - "requiredBadDescription": "This is a description with potentially problematic characters like < or >.", - "requiredNullableList": null, - "requiredLiteralString": "accept", - "requiredLiteralInt": 123, - "requiredLiteralFloat": 1.23, - "requiredLiteralBool": false, - "optionalLiteralString": "hi", - "optionalLiteralInt": 456, - "optionalLiteralFloat": 4.56, - "optionalLiteralBool": false, - "requiredNullableString": null + "name": "Example Thing", + "requiredUnion": "mockUnion", + "requiredBadDescription": "This is a description with potentially problematic characters like < or >.", + "requiredNullableList": null, + "requiredLiteralString": "accept", + "requiredLiteralInt": 123, + "requiredLiteralFloat": 1.23, + "requiredLiteralBool": false, + "optionalLiteralString": "hi", + "optionalLiteralInt": 456, + "optionalLiteralFloat": 4.56, + "optionalLiteralBool": false, + "requiredNullableString": null } From 9afc5285ca1d480c504a635a1c551962288dbccf Mon Sep 17 00:00:00 2001 From: jolov Date: Thu, 20 Feb 2025 14:15:56 -0800 Subject: [PATCH 5/5] update csproj --- .../Microsoft.TypeSpec.Generator.ClientModel.Tests.csproj | 6 ------ 1 file changed, 6 deletions(-) diff --git a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Microsoft.TypeSpec.Generator.ClientModel.Tests.csproj b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Microsoft.TypeSpec.Generator.ClientModel.Tests.csproj index a3cd5a2acf3..7792a933537 100644 --- a/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Microsoft.TypeSpec.Generator.ClientModel.Tests.csproj +++ b/packages/http-client-csharp/generator/Microsoft.TypeSpec.Generator.ClientModel/test/Microsoft.TypeSpec.Generator.ClientModel.Tests.csproj @@ -14,12 +14,6 @@ PreserveNewest - - PreserveNewest - - - PreserveNewest -