Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
igor-korolyov opened this issue Aug 7, 2024 · 5 comments · Fixed by #3015
Closed

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

igor-korolyov opened this issue Aug 7, 2024 · 5 comments · Fixed by #3015
Assignees
Labels
Milestone

Comments

@igor-korolyov
Copy link

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

@martincostello martincostello added the help-wanted A change up for grabs for contributions from the community label Aug 7, 2024
@shihabmridha
Copy link

We are having the same issue.
+1

@martincostello martincostello removed the help-wanted A change up for grabs for contributions from the community label Aug 8, 2024
@martincostello martincostello self-assigned this Aug 8, 2024
martincostello added a commit to martincostello/Swashbuckle.AspNetCore that referenced this issue Aug 8, 2024
Add example controller code from domaindrivendev#3013.
@martincostello martincostello added this to the v6.7.1 milestone Aug 8, 2024
@martincostello
Copy link
Collaborator

Looks like this was broken by #2941.

martincostello added a commit to martincostello/Swashbuckle.AspNetCore that referenced this issue Aug 8, 2024
Fix incorrect handling of schemas for nullable properties.
Resolves domaindrivendev#3013.
@jgarciadelanoceda
Copy link
Contributor

Sorry for the inconvenience!

@ahoke-cr
Copy link

This is doubly bad because object types as references that are properties of an object or request are not allowed to have descriptions. This makes 6.7.0 unusable for us as it results in most of our API docs being unusable with unhelpful descriptions of object properties/request parameters being the description of the schema itself (empty in the case of these "NullableInt32" etc. types).

martincostello added a commit that referenced this issue Aug 17, 2024
Add example controller code from #3013.
@martincostello
Copy link
Collaborator

Version 6.7.1 is now available from NuGet.org which resolves this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants