Skip to content

Instantly share code, notes, and snippets.

@justinyoo
Last active August 17, 2017 13:33
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save justinyoo/7d353f345a2e875b7c47679d650f83a1 to your computer and use it in GitHub Desktop.
Save justinyoo/7d353f345a2e875b7c47679d650f83a1 to your computer and use it in GitHub Desktop.
Swashbuckle Pro Tips for ASP.NET Web API #3
public static class WebApiConfig
{
public static void Register(IAppBuilder app, IContainer container)
{
var settings = new JsonSerializerSettings()
{
// Add JSON serialiser settings to support camelCasing.
ContractResolver = new CamelCasePropertyNamesContractResolver(),
...
};
var config = new HttpConfiguration();
var jsonFormatter = config.Formatters.JsonFormatter;
jsonFormatter.SerializerSettings = settings;
jsonFormatter.SupportedMediaTypes.Clear();
jsonFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/json"));
var xmlFormatter = config.Formatters.XmlFormatter;
xmlFormatter.SupportedMediaTypes.Clear();
xmlFormatter.SupportedMediaTypes.Add(new MediaTypeHeaderValue("application/xml"));
config.Formatters.Clear();
config.Formatters.AddRange(new List<MediaTypeFormatter>() { jsonFormatter, xmlFormatter });
...
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment