Skip to content

Commit dd8d917

Browse files
committed
controller naming to lower
1 parent 211f0f8 commit dd8d917

File tree

2 files changed

+57
-4
lines changed

2 files changed

+57
-4
lines changed
Lines changed: 55 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,72 @@
11
using System.Reflection;
2+
using System.Text.RegularExpressions;
23
using Microsoft.AspNetCore.Builder;
4+
using Microsoft.AspNetCore.Mvc.ApplicationModels;
35
using Microsoft.Extensions.DependencyInjection;
6+
using Microsoft.OpenApi.Models;
47

58
namespace SharedKernel.Extensions;
69

710
public static class ControllerExtensions
811
{
912
public static WebApplicationBuilder AddControllers(this WebApplicationBuilder builder, Assembly[] assemblies)
1013
{
11-
var mvcBuilder = builder.Services.AddControllers();
14+
var mvcBuilder = builder.Services.AddControllers(options => options.Conventions.Add(new ToLowerNamingConvention()));
1215
foreach (var assembly in assemblies)
1316
{
1417
mvcBuilder.AddApplicationPart(assembly);
1518
}
1619

1720
return builder;
1821
}
19-
}
22+
}
23+
24+
public class ToLowerNamingConvention : IControllerModelConvention
25+
{
26+
public void Apply(ControllerModel controller)
27+
{
28+
controller.ControllerName = controller.ControllerName.ToLower();
29+
30+
foreach (var action in controller.Actions)
31+
{
32+
action.ActionName = action.ActionName.ToLower();
33+
}
34+
}
35+
}
36+
37+
// public class KebabCaseTagNamingDocumentFilter : IDocumentFilter
38+
// {
39+
// public void Apply(OpenApiDocument swaggerDoc, DocumentFilterContext context)
40+
// {
41+
// // Modify the OpenAPI document here if needed
42+
// foreach (var pathItem in swaggerDoc.Paths)
43+
// {
44+
// // Modify the OpenAPI operation tags to kebab case
45+
// foreach (var operation in pathItem.Value.Operations)
46+
// {
47+
// operation.Value.Tags = operation.Value
48+
// .Tags
49+
// .Select(tag => KebabCase(tag))
50+
// .ToList();
51+
// }
52+
// }
53+
// }
54+
//
55+
// private OpenApiTag KebabCase(OpenApiTag tag)
56+
// {
57+
// // Simple kebab case conversion logic
58+
// const string pattern = "[^a-zA-Z-]";
59+
//
60+
// var name = Regex.Replace(tag.Name, pattern, "");
61+
//
62+
// var newName = string
63+
// .Concat(name.Select((x, i) => i > 0 && char.IsUpper(x)
64+
// ? "-" + x.ToString()
65+
// .ToLower()
66+
// : x.ToString()))
67+
// .ToLower();
68+
//
69+
// tag.Name = newName;
70+
// return tag;
71+
// }
72+
// }

src/SharedKernel/SharedKernel.csproj

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,13 +8,13 @@
88
<PackageReadmeFile>Readme.md</PackageReadmeFile>
99
<Authors>Pandatech</Authors>
1010
<Copyright>MIT</Copyright>
11-
<Version>1.0.11</Version>
11+
<Version>1.0.12</Version>
1212
<PackageId>Pandatech.SharedKernel</PackageId>
1313
<Title>Pandatech Shared Kernel Library</Title>
1414
<PackageTags>Pandatech, shared kernel, library, OpenAPI, Swagger, utilities, scalar</PackageTags>
1515
<Description>Pandatech.SharedKernel provides centralized configurations, utilities, and extensions for ASP.NET Core projects. For more information refere to readme.md document.</Description>
1616
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-sharedkernel</RepositoryUrl>
17-
<PackageReleaseNotes>OpenApi update</PackageReleaseNotes>
17+
<PackageReleaseNotes>Controller naming to lower</PackageReleaseNotes>
1818
</PropertyGroup>
1919

2020
<ItemGroup>

0 commit comments

Comments
 (0)