Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Failed to generate the sample for media type 'application/x-www-form-urlencoded'

I recently started creating a ASP.net Web API

For some reason I keep receiving this error when viewing the auto generated help documentation:

enter image description here

This is for a POST method

Samples show up fine for application/json and application/xml

I'm not quite sure but the application/-x-www-form-urlencoded keeps showing up

I've googled the error quite a bit but can't quite find what might be causing this

I truly appreciate any help that can be provided, also please let me know if you have any questions.

like image 727
99823 Avatar asked Apr 02 '13 17:04

99823


1 Answers

This is an expected behavior. HelpPage sample generation uses the actual formatters present on the HttpConfiguration to 'write' the sample objects. FormUrlEncodedMediaTypeFormatter cannot 'write' any type, hence HelpPage cannot generate samples for it. As a workaround you could explicitly supply a sample for a particular type (as shown in the Areas\HelpPage\App_Start\HelpPageConfig.cs's commented code).

config.SetSampleForType("[0]=foo&[1]=bar", new MediaTypeHeaderValue("application/x-www-form-urlencoded"), typeof(IEnumerable<string>)); 
like image 66
Kiran Avatar answered Oct 11 '22 21:10

Kiran