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

[Bug]: Response model schema is missing when Content-Type is specified

Open sergiojrdotnet opened this issue 9 months ago • 0 comments

Describe the bug

I'm trying to change the response type for bad request responses. However, when ProducesResponseType attribute has a specific Content-Type value, the model schema is suppressed from swagger.json

Expected behavior

swagger,json

"responses": {
    "200": {
        "description": "Success",
        "content": {
            "application/json": {
                "schema": {
                    "type": "array",
                    "items": {
                        "$ref": "#/components/schemas/GnreDto"
                    }
                }
            }
        }
    },
    "400": {
        "description": "Bad Request",
        "content": {
            "application/json": {
                "schema": {
                    "$ref": "#/components/schemas/ValidationProblemDetails"
                }
            }
        }
    }
}

Actual behavior

swagger,json

"responses": {
    "200": {
        "description": "Success",
        "content": {
            "application/json": {
                "schema": {
                    "type": "array",
                    "items": {
                        "$ref": "#/components/schemas/GnreDto"
                    }
                }
            }
        }
    },
    "400": {
        "description": "Bad Request"
    }
}

Steps to reproduce

[HttpGet]
[Produces(MediaTypeNames.Application.Json)]
[ProducesResponseType(StatusCodes.Status200OK)]
[ProducesResponseType(typeof(ValidationProblemDetails), StatusCodes.Status400BadRequest, MediaTypeNames.Application.ProblemJson)]

Exception(s) (if any)

No response

Swashbuckle.AspNetCore version

6.5.0

.NET Version

net8.0

Anything else?

No response

sergiojrdotnet avatar May 20 '24 05:05 sergiojrdotnet