You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit aa783ed
Browse filesBrowse the repository at this point in the historyBrowse files
* fix: [csharp] conditionalSerialization must not flag value-typed properties the caller never set
With conditionalSerialization=true, an all-optional model's public constructor
took every value-typed property as a plain value type and then guarded the
serialization flag with `if (this.AutoRenew != null)` — always true for a
non-nullable bool/int/enum, so every value-typed property was marked as set the
moment the model was constructed. A partial-update command built as
`new UpdateThingCommand(note: "renamed")` went on the wire as
{"autoRenew":false,"note":"renamed"}: an invented false on the exact
operation where it does the most damage. (The C# compiler flags the old guard
itself: CS0472 'the result of the expression is always true'.)
Optional value-typed constructor parameters without a default value are now
nullable, and the flag is only raised when the argument was actually provided:
if (autoRenew != null)
{
this._AutoRenew = autoRenew.Value;
this._flagAutoRenew = true;
}
Required properties, properties with a spec default, reference types, and the
public property surface (plain value-typed properties with flag-raising
setters) are all generated byte-for-byte as before; only the optional
value-type constructor path changes.
Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01CxDNCjqJycKTfzVWg2SeTJ
* test: [csharp] cover optional enums and nullable value types in the conditionalSerialization constructor
Extends the conditional-serialization-value-types fixture with an optional
inline enum, a nullable enum and a nullable integer. The test now asserts
that enums take the guarded `.Value` path, that `nullable: true` value types
keep their existing null check, and that no parameter type is emitted as `T??`.
Co-Authored-By: Claude Opus 5 (1M context) <noreply@anthropic.com>
* test: [csharp] drop conditionalSerialization assertions the remaining ones already imply
Co-Authored-By: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
---------
Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
Copy file name to clipboardExpand all lines: modules/openapi-generator/src/test/java/org/openapitools/codegen/csharpnetcore/CSharpClientCodegenTest.java
+72Lines changed: 72 additions & 0 deletions
Original file line number
Diff line number
Diff line change
@@ -605,6 +605,78 @@ public void testMapResponse() throws Exception {
605
605
Assert.assertTrue(cr1.isMap);
606
606
}
607
607
608
+
@Test(description = "conditionalSerialization: an all-optional model's public constructor must not raise the serialization flag for value-typed properties the caller never passed")
Copy file name to clipboardExpand all lines: samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/ApiResponse.cs
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -38,11 +38,11 @@ public partial class ApiResponse : IEquatable<ApiResponse>, IValidatableObject
Copy file name to clipboardExpand all lines: samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/AppleReq.cs
Copy file name to clipboardExpand all lines: samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/Banana.cs
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -36,11 +36,11 @@ public partial class Banana : IEquatable<Banana>, IValidatableObject
36
36
/// Initializes a new instance of the <see cref="Banana" /> class.
Copy file name to clipboardExpand all lines: samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/BananaReq.cs
Copy file name to clipboardExpand all lines: samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/Cat.cs
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -47,11 +47,11 @@ protected Cat()
47
47
/// <param name="declawed">declawed.</param>
48
48
/// <param name="className">className (required) (default to "Cat").</param>
49
49
/// <param name="color">color (default to "red").</param>
Copy file name to clipboardExpand all lines: samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/Category.cs
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -45,17 +45,17 @@ protected Category()
45
45
/// </summary>
46
46
/// <param name="id">id.</param>
47
47
/// <param name="name">name (required) (default to "default-name").</param>
Copy file name to clipboardExpand all lines: samples/client/petstore/csharp/restsharp/standard2.0/ConditionalSerialization/src/Org.OpenAPITools/Model/DateOnlyClass.cs
+3-3Lines changed: 3 additions & 3 deletions
Original file line number
Diff line number
Diff line change
@@ -36,11 +36,11 @@ public partial class DateOnlyClass : IEquatable<DateOnlyClass>, IValidatableObje
36
36
/// Initializes a new instance of the <see cref="DateOnlyClass" /> class.
0 commit comments