Search code examples
c#asp.net-mvcgetasp.net-web-api2

How to create correct HELP page for GET request with Dictionary parameters?


I have a Search method in my API controller. It is a GET request with input parameter of Dictionary keyValuePairs.

Code is something like this.

[Route("Search")] 
[HttpGet]
public IHttpActionResult Search( Dictionary<string, string> keyValuePairs)
 {

  IDictionary<string, object> resultDict = new Dictionary<string, object>();  
  var keyValueParameters = this.Url.Request.GetQueryNameValuePairs();           

//Do bunch of things with keyValueParameters and fill up resultDict 

   return Ok(resultDict);

  }

Help page is as follow. Request

Response Where you can see Body Parameters in Request Information but not for Response Information. Shouldn't it be other way around for GET. I am sure I need to handle this little differently given dictionaries involved but not able to figure it out.


Solution

  • It seems like the Helper pages are using pretty common ApiExplorer package. I did not try it myself but you can add something like this to your code to make it understand what is the correct response there:

    [ProducesResponseType(type: typeof(IDictionary<string, object>), statusCode: StatusCodes.Status200OK)]
    public IHttpActionResult Search( Dictionary<string, string> keyValuePairs)