Is there a Roslyn analyzer for validating OpenAPI response type, function signature return value and response content type?

Viewed 101

In a .Net 5.0 web API project, I have enabled OpenAPI analyzers in my csproj file with this element

<PropertyGroup>
  <IncludeOpenAPIAnalyzers>true</IncludeOpenAPIAnalyzers>
</PropertyGroup>

In my controller, if I have this code

[HttpGet]
[ProducesResponseType(typeof(bool), StatusCodes.Status200OK)]
public ActionResult<int> MyFunction()
{
    return Ok("abc");
}

then, I don't get any warnings that the ProducesResponseTypeAttribute's return type bool doesn't match the function signature's ActionResult generic type int.

I also don't get any compilation errors even though OK(...) contains a string type instead of an int type.

Is there a Roslyn analyzer that can detect this type of coding error?

0 Answers
Related