Skip to content

OpenApi 9.0.9 - Incorrect reference types for classes with more than one collection properties of the same reference type #63790

@vukispasic

Description

@vukispasic

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

Hello, based on this issue microsoft/OpenAPI.NET#2496, I was instructed to open issue in this repository.
For response models that contain multiple collection properties referring to the same collection type, the generated document contains invalid schema references for all but one of those properties.

OpenApi File To Reproduce
SampleOpenApi_v1.0.json

Expected Behavior

All the properties should point to the correct schema reference type

Steps To Reproduce

/* Response Models */
public class Account
{
public int Id { get; init; }
public required string Name { get; init; }
}

public class LegalEntity
{
public required ICollection Balances { get; init; }
public required ICollection Assets { get; init; }
public required ICollection Equities { get; init; }
public required ICollection DeletedAccounts { get; init; }
}

/* Api */
[Route("api/v{version:apiVersion}/accounts")]
public class LegalEntitiesController : ApiControllerBase
{
///


/// Get legal entities
///

/// The
[ApiVersion("1.0")]
[ApiVersion("2.0")]
[HttpGet(Name = nameof(GetLegalEntityAccounts))]
[ProducesResponseType(typeof(IEnumerable), StatusCodes.Status200OK)]
[ProducesDefaultResponseType]
public IEnumerable GetLegalEntityAccounts()
{
return Enumerable.Range(1, 5).Select(index => new LegalEntity
{
Balances =
[
new Account { Id = index + 1, Name = "Balance 1" },
new Account { Id = index + 2, Name = "Balance 2" }
],
Assets =
[
new Account { Id = index + 3, Name = "Asset 1" },
new Account { Id = index + 4, Name = "Asset 2" }
],
Equities =
[
new Account { Id = index + 5, Name = "Equity 1" },
new Account { Id = index + 6, Name = "Equity 2" }
],
DeletedAccounts = [index + 7, index + 8]
});
}
}

Invalid schema reference types in the generated open api document

{
...
"components": {
"schemas": {
...
"LegalEntity": {
"required": [
"balances",
"assets",
"equities",
"deletedAccounts"
],
"type": "object",
"properties": {
"balances": {
"type": "array",
"items": {
"$ref": "#/components/schemas/Account"
}
},
"assets": {
"type": "array",
"items": {
"$ref": "#/components/schemas/#/items/properties/balances/items"
}
},
"equities": {
"type": "array",
"items": {
"$ref": "#/components/schemas/#/items/properties/balances/items"
}
},
"deletedAccounts": {
"type": "array",
"items": {
"type": "integer",
"format": "int32"
}
}
}
},
}
}
}

Sample repo is created by @asankaf: https://github.com/asankaf/aspnetcore-sampleopenapi

Exceptions (if any)

No response

.NET Version

.NET 9

Anything else?

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    Needs: Author FeedbackThe author of this issue needs to respond in order for us to continue investigating this issue.Status: No Recent Activityarea-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etc

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions