Skip to content

MS OpenAPI does not generate a valid schema for nullable complex properties #59976

@luisabreu

Description

@luisabreu

Is there an existing issue for this?

  • I have searched the existing issues

Describe the bug

The new OpenAPI support for ASP.NET Core projects generates semantic errors for some types, specifically for $ref entries. The sample below reproduces the issue: one of the properties gets the following ref: "$ref" "#/components/schemas/#/properties/locaisRemover/items/properties/locais" which produces invalid description.

Expected Behavior

No response

Steps To Reproduce

Here's a sample that reproduces the issue by using and :

using Microsoft.AspNetCore.Http.HttpResults;

var builder = WebApplication.CreateBuilder(args);

// Add services to the container.
// Learn more about configuring OpenAPI at https://aka.ms/aspnet/openapi
builder.Services.AddOpenApi( );
var app = builder.Build( );

// Configure the HTTP request pipeline.
if( app.Environment.IsDevelopment( ) ) {
    app.MapOpenApi( );
}
app.UseHttpsRedirection( );

app.MapPut("/test",
           (MsgMovimentacaoLocaisTrabalho msg) => Results.Ok( ))
   .WithName("GetWeatherForecast");

app.Run( );


public class MsgMovimentacaoLocaisTrabalho {    
    public IList<InfoGeral>? LocaisRemover { get; set; }
    public InfoGeral? LocaisAssociar { get; set; }
}

public class InfoGeral {    
    public Guid GuidDirecao { get; set; }
    public IEnumerable<int> Locais { get; set; } = Enumerable.Empty<int>();
}

Exceptions (if any)

No response

.NET Version

9.0.101

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

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions