WEB API generated API help area does not display response body formats / samples

I have created reference documentation for my api 2 projects (based on owin / katana). I turned on all the settings in the configuration and installed Microsoft.AspNet.WebApi.OData. I currently have the following settings:

config.SetSampleObjects(new Dictionary<Type, object>
{
    {typeof(string), "sample string"},
    {typeof(IEnumerable<string>), new string[]{"sample 1", "sample 2"}}
});

config.SetSampleForMediaType(
    new TextSample("Binary JSON content. See http://bsonspec.org for details."),
    new MediaTypeHeaderValue("application/bson"));

config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>));

config.SetSampleRequest("1234", new MediaTypeHeaderValue("text/plain"), "Values", "Put");

config.SetSampleResponse(new ImageSample("../images/aspNetHome.png"), new MediaTypeHeaderValue("image/png"), "Values", "Get", "id");

config.SetActualRequestType(typeof(string), "Values", "Get");

config.SetActualResponseType(typeof(string), "Values", "Post");

However, I am not creating any sample response. My page should look like I saw on the Internet

how it should look

but it is so. How can I display sample responses, such as JSON, as shown in the first snapshot?

enter image description here

+4
source share
2 answers

- . , - :

config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>))

, JSON.

: http://blogs.msdn.com/b/yaohuang1/archive/2012/10/13/asp-net-web-api-help-page-part-2-providing-custom-samples-on-the-help-page.aspx

+1

ResponseType, :

    [HttpGet]
    [Route("enterprise/")]
    [ResponseType(typeof(EnterpriseViewModel))]
    public IHttpActionResult Get()
    {
        ...
    }

, ViewModel.

0

Source: https://habr.com/ru/post/1616964/


All Articles