Skip to content

OpenAPI analyzers for Problem Details #39750

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

Closed
1 task done
sliekens opened this issue Jan 25, 2022 · 2 comments
Closed
1 task done

OpenAPI analyzers for Problem Details #39750

sliekens opened this issue Jan 25, 2022 · 2 comments
Labels
✔️ Resolution: Duplicate Resolved as a duplicate of another issue old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels Status: Resolved

Comments

@sliekens
Copy link

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

@pranavkm
Copy link
Contributor

@captainsafia is this a dupe of #6061?

@pranavkm pranavkm added the old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels label Jan 25, 2022
@captainsafia
Copy link
Member

Yep! @StevenLiekens We resolved this issue in 7.0-preview1. You can try the nightly release via https://github.com/dotnet/installer or wait until the official release drops.

@captainsafia captainsafia added the ✔️ Resolution: Duplicate Resolved as a duplicate of another issue label Jan 25, 2022
@ghost ghost added the Status: Resolved label Jan 25, 2022
@ghost ghost locked as resolved and limited conversation to collaborators Feb 25, 2022
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
✔️ Resolution: Duplicate Resolved as a duplicate of another issue old-area-web-frameworks-do-not-use *DEPRECATED* This label is deprecated in favor of the area-mvc and area-minimal labels Status: Resolved
Projects
None yet
Development

No branches or pull requests

3 participants