-
-
Save VladoMS/e720c40c3b528008ea61f7daeea700fb to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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