Skip to content

.NET 9 OpenAPI incorrect schema for array of nullable strings #60803

Open
@Markz878

Description

@Markz878

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

When a class has a property of type string?[], the generated OpenApi schema does not allow nulls.

Expected Behavior

The schema object should allow nulls in the array.

Steps To Reproduce

Minimal repro:

WebApplicationBuilder builder = WebApplication.CreateBuilder(args);
builder.Services.AddOpenApi();
WebApplication app = builder.Build();
app.MapOpenApi();
app.MapGet("/weatherforecast", () =>
{
    return Enumerable.Range(1, 5).Select(index => new WeatherForecast(["10", null, "30"])).ToArray();
});
app.Run();
internal record WeatherForecast(string?[] Temperature);

Exceptions (if any)

No response

.NET Version

9.0.2 and 10.0.100-preview.1.25120.13

Anything else?

Any ideas how to fix this with for example a schema transformer?

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