-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Open
Labels
Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.This issue needs the attention of a contributor, typically because the OP has provided an update.area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
Microsoft.Extensions.ApiDescription.Server
can generate type with no members in generated OpenAPI definition under certain circumstances.
Here is an example generated by Microsoft.Extensions.ApiDescription.Server
, user
shall have members or a component reference, but it's empty (see https://github.com/pchalamet/openapi-any-repro):
"RefProfile2": {
"required": [
"user",
"id"
],
"type": "object",
"properties": {
"user": { },
"id": {
"type": "string"
}
},
"nullable": true
},
Expected Behavior
user
is expected to have a members, like this:
"RefProfile": {
"required": [
"user",
"id"
],
"type": "object",
"properties": {
"user": {
"$ref": "#/components/schemas/RefUser"
},
"id": {
"type": "string"
}
}
}
Steps To Reproduce
Everything is here: https://github.com/pchalamet/openapi-any-repro
with steps to reproduce the problem.
but here is the code:
var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
var app = builder.Build();
app.MapGet("/get", () =>
new Subscription {
Advisor = null,
Profile = new RefProfile { User = new RefUser { Name = "Toto " } },
});
app.MapOpenApi("/");
app.Run();
public record Subscription {
public required RefProfile Profile { get; init; }
public required RefProfile? Advisor { get; init; } // <-- NRT is the problem here
}
public record RefProfile {
public required RefUser User { get; init; }
}
public record RefUser {
public required string Name { get; init; }
}
Exceptions (if any)
No response
.NET Version
9.0.304
Anything else?
SDK: 9.0.304
Microsoft.Extensions.ApiDescription.Server: 9.0.8 (not tried on latest 10 preview)
Metadata
Metadata
Assignees
Labels
Needs: Attention 👋This issue needs the attention of a contributor, typically because the OP has provided an update.This issue needs the attention of a contributor, typically because the OP has provided an update.area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi