Swashbuckle.AspNetCore icon indicating copy to clipboard operation
Swashbuckle.AspNetCore copied to clipboard

[Bug]: Inconsistent examples/schemas generated for types

Open danlyons-home opened this issue 6 months ago • 3 comments

Describe the bug

Body and response example and schema can be different despite an endpoint using the same type for both body and response.

Expected behavior

I would expect that for any type T that the example and schema representing said type should be identical in the body and response section of the generated swagger documentation.

Actual behavior

The schemas and examples for the type differ.

For example, when System.Drawing.Size is sent/received either directly or as a child of the type actually being sent/received, the generated example body is as follows:

{
  "width": 0,
  "height": 0
}

with schema image

while the generated example response is as follows:

{
  "isEmpty": true,
  "width": 0,
  "height": 0
}

with schema image

Steps to reproduce

Run dotnet new webapi -controllers.

Add the following to WeatherForecastController:

    public sealed record FooItem(int Id, Size size, string Name);

    [HttpPost("/size")]
    public Size ChangeSize([FromBody] Size newSize) => newSize;

    [HttpPost("/item")]
    public FooItem ChangeItem([FromBody] FooItem item) => item;

Start the project. The generated swagger doc page that comes up in the debug session will include the different body/response examples/schemas.

Exception(s) (if any)

No response

Swashbuckle.AspNetCore version

6.4.0, 6.6.2, 6.7.0

.NET Version

8.0.205

Anything else?

No response

danlyons-home avatar Aug 01 '24 16:08 danlyons-home