The Wayback Machine - https://web.archive.org/web/20220125172620/https://github.com/dotnet/aspnetcore/issues/39750
Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

OpenAPI analyzers for Problem Details #39750

Open
1 task done
StevenLiekens opened this issue Jan 25, 2022 · 0 comments
Open
1 task done

OpenAPI analyzers for Problem Details #39750

StevenLiekens opened this issue Jan 25, 2022 · 0 comments

Comments

@StevenLiekens
Copy link

@StevenLiekens StevenLiekens commented Jan 25, 2022

Is there an existing issue for this?

  • I have searched the existing issues

Is your feature request related to a problem? Please describe the problem.

Hello, I enabled the OpenAPI analyzers for my web API and it reports undocumented status codes when I use BadRequest().

using System.ComponentModel.DataAnnotations;
using Microsoft.AspNetCore.Mvc;

[ApiController]
[Route("things")]
public class ThingsController : ControllerBase
{
    [HttpPost("number-guess")]
    [ProducesResponseType(200)]
    public ActionResult<string> GuessNumber([Required] int number)
    {
        if (number != 4)
        {
            return BadRequest("that was not my number");
//          ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ Action method returns undeclared status code '400'.
        }

        return Ok("you guessed my number");
    }
}

Now I want to use standardized Problem Details responses in my API. However, the analyzers don't show a warning for the same action if I use ValidationProblem() or Problem().

Describe the solution you'd like

Add OpenAPI analyzers for Problem Details shorthand methods.

return ValidationProblem(title: "that was not my number";
return Problem(title: "that was not my number", statusCode: 400);

Additional context

No response

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Linked pull requests

Successfully merging a pull request may close this issue.

None yet
1 participant