Skip to content

[v5] OpenApiSchemaService throws InvalidOperationException on nested array references #538

@DeagleGross

Description

@DeagleGross

Description

When generating OpenAPI documents for endpoints whose request bodies have nested types referencing arrays of other types, OpenApiSchemaService throws InvalidOperationException instead of producing the schema.

Reproduction

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

app.MapPost("/items", (ItemRequest req) => Results.Ok());
app.Run();

public class ItemRequest
{
    public required List<ItemReference> References { get; init; }
}

public class ItemReference
{
    public required string Id { get; init; }
}

Hitting /openapi/v1.json throws:

System.InvalidOperationException: The schema for type 'ItemReference' could not be resolved.
   at Microsoft.AspNetCore.OpenApi.Services.OpenApiSchemaService.GetSchemaForType(Type, ...)

Expected

OpenAPI document should generate with ItemRequest.References as an array of ItemReference references.

Version

.NET 11.0

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions