Skip to content

Instantly share code, notes, and snippets.

@gavilanch
Created June 4, 2020 16:53
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 gavilanch/680f859091d5c57b977d52e9595afc8b to your computer and use it in GitHub Desktop.
Save gavilanch/680f859091d5c57b977d52e9595afc8b to your computer and use it in GitHub Desktop.
public class GroupingByNamespaceConvention : IControllerModelConvention
{
public void Apply(ControllerModel controller)
{
var controllerNamespace = controller.ControllerType.Namespace;
var apiVersion = controllerNamespace.Split(".").Last().ToLower();
if (!apiVersion.StartsWith("v")) { apiVersion = "v1"; }
controller.ApiExplorer.GroupName = apiVersion;
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment