-
Notifications
You must be signed in to change notification settings - Fork 10.4k
Description
Is there an existing issue for this?
- I have searched the existing issues
Describe the bug
When properties of two unrelated types share the same type, OpenAPI document generation does not assign types to one of them. This applies if both unrelated types are returned from the same minimal api endpoint. For example: If there was a record MapNode, and record MapLink, and two different records had Collections of each, regardless of what the property name is, one of the two different records will not generate correctly.
This does not happen if MapNode and MapLink are not in Collections. I have tested with Lists and Arrays.
To show:
public record MapNode
{
public required string Name { get; init; }
}
public record MapLink
{
public required int Source { get; init; }
public required int Target { get; init; }
public required decimal Value { get; init; }
}
public record OverallDataContainer
{
public DataContainer1? Container1 { get; init; }
public DataContainer2? Container2 { get; init; }
}
public record DataContainer1
{
public required List<MapNode> Container1MapNodes { get; init; }
public required List<MapLink> Container1MapLinks { get; init; }
}
public record DataContainer2
{
public required List<MapNode> Container2MapNodes { get; init; }
public required List<MapLink> Container2MapLinks { get; init; }
}
If OverallDataContainer was returned by an endpoint, DataContainer1 generates an openApi schema correctly, while DataContainer2 does not:
"DataContainer1": {
"required": [
"container1MapNodes",
"container1MapLinks"
],
"type": "object",
"properties": {
"container1MapNodes": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MapNode"
}
},
"container1MapLinks": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MapLink"
}
}
},
"nullable": true
},
"DataContainer2": {
"required": [
"container2MapNodes",
"container2MapLinks"
],
"type": "object",
"properties": {
"container2MapNodes": {
"type": "array",
"items": { }
},
"container2MapLinks": {
"type": "array",
"items": { }
}
},
"nullable": true
},
Current workaround: Split MapNode and MapLink into different types per record (Container1MapNode, Container1MapLink, Container2MapNode, and Container2MapLink)
Expected Behavior
Expected behaviour would be that container2MapNodes and container2MapLinks share the same properties as container1MapNodes and containter1MapLinks:
"DataContainer1": {
"required": [
"container1MapNodes",
"container1MapLinks"
],
"type": "object",
"properties": {
"container1MapNodes": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MapNode"
}
},
"container1MapLinks": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MapLink"
}
}
},
"nullable": true
},
"DataContainer2": {
"required": [
"container2MapNodes",
"container2MapLinks"
],
"type": "object",
"properties": {
"container2MapNodes": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MapNode"
}
},
"container2MapLinks": {
"type": "array",
"items": {
"$ref": "#/components/schemas/MapLink"
}
}
},
"nullable": true
},
Steps To Reproduce
Github repo which reproduces the issue
Exceptions (if any)
No response
.NET Version
9.0.203
Anything else?
Microsoft.AspNetCore.OpenApi version 9.0.4 - This is also an issue when downgraded to version 9.0
Scalar.AspNetCore version 2.1.16
Running on Visual Studio Community 2022 v17.13.6