Created
September 10, 2016 03:15
-
-
Save smaglio81/e57a8bdf0541933d7004665a85a7b198 to your computer and use it in GitHub Desktop.
This file contains hidden or 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); | |
} | |
} | |
} | |
} |
One more case.
For instance, if we have an endpoint with parameter such as /api/v1/orders/{orderId}
it changing to /api/v1/orders/{orderid}
.
And when we try to make request instead of
curl -X GET "http://127.0.0.1:9001/api/v1/orders/1" -H "accept: application/json"
we receive
curl -X GET "http://127.0.0.1:9001/api/v1/orders/{orderid}" -H "accept: application/json"
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
You should check your dictionary for repeated key before adding to avoid runtime issues. Other that that, the extension is great!