Missing produces response type (ARCH801)
Esta página aún no está disponible en tu idioma.
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.
Incorrect
Section titled “Incorrect”[HttpGet("{id}")]public async Task<IActionResult> GetById(int id){ var user = await _service.FindAsync(id); return user is null ? NotFound() : Ok(user);}Correct
Section titled “Correct”[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.