Zum Inhalt springen

Missing produces response type (ARCH801)

Dieser Inhalt ist noch nicht in deiner Sprache verfügbar.

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.