Skip to content

Empty OpenApi schema is generated for type referenced multiple times as generic argument #61194

Open
@sbomer

Description

@sbomer

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

For T referenced from multiple List<T> properties, the generated schema for T is empty.

class Config
{
    public List<Item> Items1 { get; set; }
    public List<Item> Items2 { get; set; }
}
class Item
{
    public string Value { get; set; }
}

Item gets an empty schema.

Expected Behavior

The schema should look like this:

      "Config": {
        "type": "object",
        "properties": {
          "items1": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Item"
            }
          }
        }
      },
      "Item": {
        "type": "object",
        "properties": {
          "value": {
            "type": "string"
          }
        }

Steps To Reproduce

<Project Sdk="Microsoft.NET.Sdk.Web">

  <PropertyGroup>
    <TargetFramework>net10.0</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.AspNetCore.OpenApi" Version="10.0.0-preview.4.25176.5" />
  </ItemGroup>

</Project>
using System.Collections.Generic;
using Microsoft.AspNetCore.OpenApi;

var builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
var app = builder.Build();

app.MapGet("/get", () => new Config
{
    Items1 = new()
});

app.MapOpenApi("/");
app.Run();

class Config
{
    public List<Item> Items1 { get; set; }
    public List<Item> Items2 { get; set; }
}
class Item
{
    public string Value { get; set; }
}

The generated schema has:

      "Config": {
        "type": "object",
        "properties": {
          "items1": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Item"
            }
          },
          "items2": {
            "type": "array",
            "items": {
              "$ref": "#/components/schemas/Item"
            }
          }
        }
      },
      "Item": { }

Removing one of the List<Item> properties fixes it.

Exceptions (if any)

No response

.NET Version

No response

Anything else?

No response

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