Skip to content

Instantly share code, notes, and snippets.

@VladoMS
Forked from smaglio81/LowercaseDocumentFilter.cs
Created January 21, 2017 08:19
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 VladoMS/e720c40c3b528008ea61f7daeea700fb to your computer and use it in GitHub Desktop.
Save VladoMS/e720c40c3b528008ea61f7daeea700fb to your computer and use it in GitHub Desktop.
using System.Collections.Generic;
using System.Web.Http.Description;
using Swashbuckle.Swagger;
namespace BoundedContext.Web.Swagger
{
public class LowercaseDocumentFilter : IDocumentFilter
{
public void Apply(SwaggerDocument swaggerDoc, SchemaRegistry schemaRegistry, IApiExplorer apiExplorer)
{
//////// PATHS
var paths = swaggerDoc.paths;
// generate the new keys
var newPaths = new Dictionary<string, PathItem>();
var removeKeys = new List<string>();
foreach (var path in paths)
{
var newKey = path.Key.ToLower();
if (newKey != path.Key)
{
removeKeys.Add(path.Key);
newPaths.Add(newKey, path.Value);
}
}
// add the new keys
foreach (var path in newPaths)
{
swaggerDoc.paths.Add(path.Key, path.Value);
}
// remove the old keys
foreach (var key in removeKeys)
{
swaggerDoc.paths.Remove(key);
}
}
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment