You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I notice a change in the generation of the open API in this situation:
public abstract class A {
public string? PropA { get; set; }
}
public class B: A
{
public string? PropB { get; set; }
}
public class C: B
{
public string? PropC { get; set; }
}
public class TestController : ControllerBase
{
[HttpPost]
public ActionResult Post(A model)
{
return Ok();
}
}
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
c.UseOneOfForPolymorphism();
c.SelectSubTypesUsing(t => typeof(A) == t ? [typeof(C)] : []);
});
Expected behavior
With version 7.0.0, the behavior is correct.
Actual behavior
With version 7.2.0, the properties of class B are missing.
Steps to reproduce
I am attaching the test solution, which currently references version 7.0.0 to test the correct case. To test the incorrect case with the new version, just update the references in the csproj to 7.2.0
fenzad
changed the title
[Bug]: Behavior change with UseOneOfForPolymorphism and abstract classes from version 7.0.0 and version 7.0.2
[Bug]: Behavior change with UseOneOfForPolymorphism and abstract classes from version 7.0.0 and version 7.2.0
Dec 16, 2024
The issue is resolved by specifying in SelectSubTypesUsing: c.SelectSubTypesUsing(t => typeof(A) == t ? [typeof(C)] : typeof(B) == t ? [typeof(C)] : []);
However, this is a different behavior compared to the previous version…
The correct behavior (which at this point I don’t know if it was more correct before or now) is up to and including version 7.0.0. From version 7.1.0, there has been a change.
Describe the bug
I notice a change in the generation of the open API in this situation:
public abstract class A {
public string? PropA { get; set; }
}
public class B: A
{
public string? PropB { get; set; }
}
public class C: B
{
public string? PropC { get; set; }
}
public class TestController : ControllerBase
{
[HttpPost]
public ActionResult Post(A model)
{
return Ok();
}
}
builder.Services.AddSwaggerGen(c =>
{
c.SwaggerDoc("v1", new OpenApiInfo { Title = "My API", Version = "v1" });
c.UseOneOfForPolymorphism();
c.SelectSubTypesUsing(t => typeof(A) == t ? [typeof(C)] : []);
});
Expected behavior
With version 7.0.0, the behavior is correct.
Actual behavior
With version 7.2.0, the properties of class B are missing.
Steps to reproduce
I am attaching the test solution, which currently references version 7.0.0 to test the correct case. To test the incorrect case with the new version, just update the references in the csproj to 7.2.0
TestSwagger.zip
Exception(s) (if any)
No response
Swashbuckle.AspNetCore version
7.0.0 and 7.2.0
.NET Version
net9.0
Anything else?
No response
The text was updated successfully, but these errors were encountered: