Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Jan 31, 2026

Problem

RequiredPropertySchemaTransformer was marking all non-nullable reference types as required in OpenAPI schemas, including properties with default initializers. This caused OAuthAccount.ExtraData to appear as required when it shouldn't be:

public record OAuthAccount
{
    public required string Provider { get; init; }      // ✓ Should be required
    public required string ProviderUserId { get; init; } // ✓ Should be required  
    public required string Username { get; init; }       // ✓ Should be required
    
    public SettingsDictionary ExtraData { get; init; } = new(); // ✗ Was marked required, should be optional
}

Solution

Check for C# 11+ RequiredMemberAttribute instead of relying on nullability context:

// Before: Used nullability context (unreliable for properties with initializers)
var nullabilityInfo = nullabilityContext.Create(property);
return nullabilityInfo.WriteState == NullabilityState.NotNull;

// After: Check for explicit 'required' modifier
var requiredMemberAttribute = property.GetCustomAttribute<RequiredMemberAttribute>();
if (requiredMemberAttribute is not null)
    return true;

Reference types are now only marked as required if they have the explicit required modifier. Non-nullable value types remain required as before.

Original prompt

Reference: https://github.com/exceptionless/Exceptionless/actions/runs/21518290999/job/62002232212 find rca and apply fix


💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.

@CLAassistant
Copy link

CLA assistant check
Thank you for your submission! We really appreciate it. Like many open source projects, we ask that you sign our Contributor License Agreement before we can accept your contribution.
You have signed the CLA already but the status is still pending? Let us recheck it.

Copilot AI and others added 2 commits January 31, 2026 23:22
…nAPI schema

Properties with default initializers (like ExtraData = new()) are now correctly treated as optional unless they have the explicit 'required' modifier.

Co-authored-by: niemyjski <1020579+niemyjski@users.noreply.github.com>
Co-authored-by: niemyjski <1020579+niemyjski@users.noreply.github.com>
Copilot AI changed the title [WIP] Find root cause analysis and apply fix fix: OpenAPI schema incorrectly marks properties with default initializers as required Jan 31, 2026
Copilot AI requested a review from niemyjski January 31, 2026 23:28
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

3 participants