Skip to content

OpenAPI: record constructor default is written to the shared enum component instead of the $ref #69862

Description

@sander1095

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

A record constructor default (Priority Priority = Priority.Normal) is written onto the shared Priority enum component instead of next to the $ref. The result depends on endpoint mapping order:

  • CreateTicketRequest mapped first: the default leaks to every property that uses Priority.
  • CreateTicketRequest mapped second: the default is dropped.

Expected Behavior

"Priority": { "enum": ["Low", "Normal", "High"] },
"CreateTicketRequest": { "properties": { "priority": { "$ref": "#/components/schemas/Priority", "default": "Normal" } } },
"UpdateTicketRequest": { "properties": { "priority": { "$ref": "#/components/schemas/Priority" } } }

This is what [DefaultValue(Priority.Normal)] on a class property already produces.

Steps To Reproduce

Save as defaults.cs, run dotnet run defaults.cs:

#:sdk Microsoft.NET.Sdk.Web
#:package Microsoft.AspNetCore.OpenApi@11.0.0-rc.1.26425.128
// File-based apps disable reflection-based JSON serialization by default
#:property JsonSerializerIsReflectionEnabledByDefault=true

using System.Text.Json.Serialization;
using Microsoft.AspNetCore.OpenApi;
using Microsoft.OpenApi;

var builder = WebApplication.CreateBuilder(args);
builder.Logging.ClearProviders();
builder.Services.AddOpenApi();
var app = builder.Build();

app.MapPost("/tickets", (CreateTicketRequest r) => { });
app.MapPut("/tickets/{id}", (int id, UpdateTicketRequest r) => { });

await app.StartAsync();
var document = await app.Services.GetRequiredKeyedService<IOpenApiDocumentProvider>("v1").GetOpenApiDocumentAsync();
Console.WriteLine(await document.SerializeAsJsonAsync(OpenApiSpecVersion.OpenApi3_1));
await app.StopAsync();

[JsonConverter(typeof(JsonStringEnumConverter<Priority>))]
public enum Priority { Low, Normal, High }

public record CreateTicketRequest(string Title, Priority Priority = Priority.Normal);
public record UpdateTicketRequest(string Title, Priority Priority);

Actual:

"Priority": { "enum": ["Low", "Normal", "High"], "default": "Normal" },        // ❌ applies to UpdateTicketRequest too
"CreateTicketRequest": { "properties": { "priority": { "$ref": "#/components/schemas/Priority" } } },
"UpdateTicketRequest": { "properties": { "priority": { "$ref": "#/components/schemas/Priority" } } }

Swap the two Map* calls and Priority has no default anywhere.

Exceptions (if any)

None.

.NET Version

11.0.100-rc.1.26425.128

Anything else?

Regression from 9.0. 9.0.0 and 9.0.21 emitted two components (Priority with the default, Priority2 without), so each property pointed at the right one. Broken in 10.0.0-preview.1 through 10.0.13, and 11.0.0-rc.1.

Related: #65017 (same order dependence, with null in an enum).

Activity

  1. added
    area-minimal
    on Oct 15, 2026
  2. github-actions commented on Oct 15, 2026

    @github-actions
    Contributor

    Triage Summary

    Area: area-minimal (Microsoft.AspNetCore.OpenApi schema generation)
    Type: Bug (generated schema depends on endpoint mapping order)

    Regression Info

    • Previously working version: ASP.NET Core 9.0.0 and 9.0.21 (per reporter)
    • Failing version: 10.0.0-preview.1 through 10.0.13, and 11.0.0-rc.1 (per reporter)
    • Reporter states 9.0 emitted separate Priority / Priority2 components, each property referencing the correct one; later versions emit a single shared Priority component.

    Potential Duplicates

    • None found

    Notes

    Generated by Issue Triage Agent for dotnet/aspnetcore for #69862 · copilot · auto · 27 AIC · ⌖ 1.01 AIC · ⊞ 30.4K · ◷

  3. added
    bug
    on Oct 23, 2026
  4. added this to the .NET 12 Planning milestone on Nov 11, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Regressionarea-minimalbug

    Type

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions