Skip to content

Latest commit

 

History

History
20 lines (12 loc) · 1.11 KB

README.md

File metadata and controls

20 lines (12 loc) · 1.11 KB

ActionResponseTypeAnalyzer

Build status

Problem

WebApi's HttpResponseMessage is not a generic type. It was at the beginning, but before the release it was decided that it should not be and so we stuck with non-descriptive action method calls like

public HttpResponseMessage Get([FromUri] int someId) { ... }

Creators of WebApi documentation needed to know what the type is, so they invented System.Web.Http.Description.ResponseTypeAttribute. So now there are two sources of truth about what the method returns - method body decides what is being run by computers and attribute decides whay is being read by humans. This leads to mismatches.

Solution

This analyzer is a patch that compares actual types with the declared ones. It contains two diagnostics:

  • ARTA001: Value type declared in ResponseType should match to actual response type.
  • ARTA002: Public controller method specify their response type in the ResponseType attribute.