Skip to content

API Analyzer doesn't recognize ControllerBase.ValidationProblem. #6061

@ghost

Description

Describe the bug

The Web API Analyzer doesn't recognize ControllerBase.ValidationProblem() and does not prompt a codefix to add a [ProducesResponseType] attribute like it does for ControllerBase.BadRequest().

To Reproduce

Steps to reproduce the behavior:

  1. Using ASP.NET Core 2.2
  2. Install Microsoft.AspNetCore.Mvc.Api.Analyzers 2.2.0
  3. Add return ValidationProblem(); to a controller marked with [ApiController].

Expected behavior

Analyzer catches the issue and underlines return ValidationProblem();
Codefix prompt to add appropriate attributes to action.

Additional context

Using ASP.NET Core 2.2 and Microsoft.AspNetCore.Mvc.Api.Analyzers 2.2.0. Since the default ModelStateInvalidFilter uses ValidationProblemDetails to build a 400 response object, it makes sense that people may want to do the same for validation problems within actions so that the response format is consistent in both cases. Alternatively or additionally, there should be a way to opt into ControllerBase.BadRequest(ModelState) using ValidationProblemDetails to build its response object for consistency with ModelStateInvalidFilter.

Metadata

Metadata

Assignees

Labels

affected-fewThis issue impacts only small number of customersanalyzerIndicates an issue which is related to analyzer experiencebugThis issue describes a behavior which is not expected - a bug.feature-openapiinvestigateold-area-web-frameworks-do-not-use*DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labelsseverity-minorThis label is used by an internal tool

Type

No type

Projects

No projects

Milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions