Aller au contenu

Missing produces response type (ARCH801)

Ce contenu n’est pas encore disponible dans votre langue.

Key dotnet.api.missing-produces-response-type · Severity info · Category api

Actions without ProducesResponseType attributes produce missing or incorrect response schemas in OpenAPI/Swagger documentation. Possible status codes should be declared explicitly.

[HttpGet("{id}")]
public async Task<IActionResult> GetById(int id)
{
var user = await _service.FindAsync(id);
return user is null ? NotFound() : Ok(user);
}
[HttpGet("{id}")]
[ProducesResponseType(typeof(UserResponse), StatusCodes.Status200OK)]
[ProducesResponseType(StatusCodes.Status404NotFound)]
public async Task<IActionResult> GetById(int id)
{
var user = await _service.FindAsync(id);
return user is null ? NotFound() : Ok(user);
}

Add [ProducesResponseType] attributes for every status code and body type an action can return.