Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Hide swagger bad response example model in net core 2.2

I upgrade my netcore 2.1 project to 2.2 and i have a problem with my swagger page.

Previously in swagger bad response it only show "Bad Request" without the model.

But after i upgraded to net core 2.2 there is a model shown in the bad request example.The image is below.

How do i hide it so that it just show the "Bad request".

I already tested using CustomApiConvention but no success so far.

    [HttpGet("{id}")]
    [ProducesResponseType(StatusCodes.Status204NoContent)]
    [ProducesResponseType(StatusCodes.Status400BadRequest)]
    [ProducesResponseType(StatusCodes.Status404NotFound)]
    [ProducesDefaultResponseType]
    public async Task<ActionResult<Employee>> GetEmployee(int id)
    {
        var employee = await _context.Employee.FindAsync(id);

        if (employee == null)
        {
            return NotFound();
        }

        return employee;
    }

How do i hide it so that it just show the "Bad request"?

enter image description here

like image 774
capudang Avatar asked May 28 '19 11:05

capudang


1 Answers

To anyone who got the same problem. Just add this to your code.

services.AddMvc()
.SetCompatibilityVersion(CompatibilityVersion.Version_2_2)
.ConfigureApiBehaviorOptions(options =>
{
    options.SuppressMapClientErrors = true;
});

This will disable ProblemDetails response.

https://docs.microsoft.com/en-us/aspnet/core/web-api/?view=aspnetcore-2.2#problem-details-for-error-status-codes

like image 128
capudang Avatar answered Sep 28 '22 10:09

capudang