Skip to content

[Bug]: A nullable struct property results in an invalid generated schema. #3013

@igor-korolyov

Description

@igor-korolyov

Describe the bug

Invalid schema has been generated in cases where a type has a nullable property of a custom struct.

Version 6.2.2 behaves in the expected way.

Expected behavior

A valid schema should be generated.

Actual behavior

An invalid (and recursive) schema has been generated.
image

Steps to reproduce

public class Program
{
    public static void Main(string[] args)
    {
        var builder = WebApplication.CreateBuilder(args);

        // Add services to the container.

        builder.Services.AddControllers();
        // Learn more about configuring Swagger/OpenAPI at https://aka.ms/aspnetcore/swashbuckle
        builder.Services.AddEndpointsApiExplorer();
        builder.Services.AddSwaggerGen();

        var app = builder.Build();

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

        app.UseAuthorization();


        app.MapControllers();

        app.Run();
    }
}

[ApiController]
[Route("[controller]/[action]")]
public class TestController : ControllerBase
{
    [HttpGet]
    public TestResponse Get()
    {
        return new()
        {
            Foo = new(1, 2),
        };
    }
}

public record TestResponse
{
    public TestStruct? Foo { get; init; }
}

public record struct TestStruct(int A, int B);

Exception(s) (if any)

No response

Swashbuckle.AspNetCore version

6.7.0

.NET Version

net8.0

Anything else?

No response

Metadata

Metadata

Labels

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions