Repository navigation
Labels
Regressionarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.
Milestone
Description
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:
CreateTicketRequestmapped first: the default leaks to every property that usesPriority.CreateTicketRequestmapped 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.
- Caused by Upgrade to Microsoft.OpenApi 2.x and support OpenAPI v3.1 #59480 (10.0-preview1): components became keyed by name only, so the second
Priorityoverwrites the first instead of becomingPriority2. - [release/10.0] Fix circular reference resolution for schemas containing arrays #64720 (10.0.2) changed this to "first registration wins". It also fixed the same leak for
[DefaultValue]viax-ref-default, but not for constructor defaults, whichJsonSchemaExporterwrites onto the property's node itself.
Related: #65017 (same order dependence, with null in an enum).
Metadata
Metadata
Assignees
Labels
Regressionarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcbugThis issue describes a behavior which is not expected - a bug.
Activity
github-actions commentedon Oct 15, 2026
Triage Summary
Area:
area-minimal(Microsoft.AspNetCore.OpenApi schema generation)Type:
Bug(generated schema depends on endpoint mapping order)Regression Info
Priority/Priority2components, each property referencing the correct one; later versions emit a single sharedPrioritycomponent.Potential Duplicates
Notes
nullin an enum), OpenAPI: [Obsolete] on a property leaksdeprecated: trueinto the shared component schema #69729 ([Obsolete]leakingdeprecated: trueinto the shared component).