-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Closed as duplicate of#60381
Closed as duplicate of#60381
Copy link
Labels
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.AspNetCore.OpenApi v9.0.2
When response type references same type indirectly as collection elements more than once, all $refs but first gets messed up. It tries pointing to array element of first encountered one. See example bellow
builder.Services.AddOpenApi();
// ...
app.MapOpenApi();
app.MapGet("/test", () =>
{
return new Both();
});
public class Nested { }
public class First
{
public Nested[] Things { get; set; }
}
public class Second
{
public Nested[] Things { get; set; }
}
public class Both
{
public First First { get; set; }
public Second Second { get; set; }
}
Opening open API json would show spec like so:
{
// ....
"components": {
"schemas": {
"Both": {
"type": "object",
"properties": {
"first": {
"$ref": "#/components/schemas/First"
},
"second": {
"$ref": "#/components/schemas/Second"
}
}
},
"First": {
"type": "object",
"properties": {
"things": {
"type": "array",
"items": {
// correct reference at first encounter
"$ref": "#/components/schemas/Nested"
}
}
}
},
"Nested": {
"type": "object"
},
"Second": {
"type": "object",
"properties": {
"things": {
"type": "array",
"items": {
// invalid at any other
"$ref": "#/components/schemas/#/properties/first/properties/things/items"
}
}
}
}
}
}
}
Expected Behavior
No response
Steps To Reproduce
Simple repo with code mentioned above: https://github.com/Madajevas/OpenApiComponentReuseIssue/blob/master/OpenApiComponentReuseIssue/Program.cs
Exceptions (if any)
No response
.NET Version
9.0.200
Anything else?
No response
Metadata
Metadata
Assignees
Labels
area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi