Skip to content
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions src/Refitter.Core/CSharpClientGeneratorFactory.cs
Original file line number Diff line number Diff line change
Expand Up @@ -62,6 +62,12 @@ public CustomCSharpClientGenerator Create()
settings.CodeGeneratorSettings,
generator.Settings.CSharpGeneratorSettings);

// Auto-enable optional properties as nullable when nullable reference types enabled
if (generator.Settings.CSharpGeneratorSettings.GenerateNullableReferenceTypes)
{
generator.Settings.CSharpGeneratorSettings.GenerateOptionalPropertiesAsNullable = true;
}
Comment on lines +65 to +69

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change alters nullability generation behavior but there’s no regression test asserting that an OpenAPI schema with type: string + nullable: true (and/or an optional string property) generates string? when nullable reference types are enabled. Please add/extend a unit test that checks the generated DTO/contract property type (not just build success) to prevent this from regressing again.

Copilot generated this review using guidance from repository custom instructions.

Comment on lines +65 to +70

Copilot AI Mar 3, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This forces GenerateOptionalPropertiesAsNullable = true whenever GenerateNullableReferenceTypes is enabled, which effectively ignores any explicit configuration that tries to keep generateOptionalPropertiesAsNullable disabled (it’s documented as an independent setting). Consider only auto-enabling when the user has not explicitly set GenerateOptionalPropertiesAsNullable, or introduce a dedicated setting to control this coupling (and document the behavior).

Suggested change
// Auto-enable optional properties as nullable when nullable reference types enabled
if (generator.Settings.CSharpGeneratorSettings.GenerateNullableReferenceTypes)
{
generator.Settings.CSharpGeneratorSettings.GenerateOptionalPropertiesAsNullable = true;
}

Copilot uses AI. Check for mistakes.
return generator;
}

Expand Down
Loading