Skip to content

OpenAPI schema generation fails for second IList<T> property in ASP.NET Core 9 #64251

@kvanover

Description

@kvanover

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When using ASP.NET Core 9’s built-in OpenAPI support (Microsoft.AspNetCore.OpenApi), the schema generator incorrectly handles multiple properties of the same generic type (IList). The first property is generated correctly with a $ref to the component schema, but the second property produces an empty items object.

It will generate:


"weatherPoints1": {
  "type": "array",
  "items": {
    "$ref": "#/components/schemas/WeatherPoints"
  }
},
"weatherPoints2": {
  "type": "array",
  "items": { }
}

Expected Behavior


"weatherPoints2": {
  "type": "array",
  "items": {
    "$ref": "#/components/schemas/WeatherPoints"
  }
}

Steps To Reproduce

  1. Create a minimal API project in .NET 9.
  2. Add the following classes:
public class WeatherForecast
{
    public DateOnly Date { get; set; }
    public int TemperatureC { get; set; }
    public int TemperatureF => 32 + (int)(TemperatureC / 0.5556);
    public IList<WeatherPoints> WeatherPoints1 { get; set; } = new List<WeatherPoints>();
    public IList<WeatherPoints> WeatherPoints2 { get; set; } = new List<WeatherPoints>();
    public string? Summary { get; set; }
}

public class WeatherPoints
{
    public int Point { get; set; }
}
  1. Map an endpoint returning WeatherForecast:
app.MapGet("/weatherforecast", () => new WeatherForecast())
.WithName("GetWeatherForecast")
.WithOpenApi();
  1. Run the app and inspect /openapi/v1.json.

Exceptions (if any)

No response

.NET Version

9.0.306

Anything else?

  • .NET SDK: 9.0.x
  • ASP.NET Core: 9.0
  • Package: Microsoft.AspNetCore.OpenApi

Metadata

Metadata

Assignees

No one assigned

    Labels

    area-minimalIncludes minimal APIs, endpoint filters, parameter binding, request delegate generator etcfeature-openapi

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions