Skip to content

Commit

Permalink
Merge pull request #12 from PandaTechAM/development
Browse files Browse the repository at this point in the history
To kebab controllers
  • Loading branch information
HaikAsatryan authored Dec 3, 2024
2 parents 27a0df2 + 5038eef commit 8a2e598
Show file tree
Hide file tree
Showing 2 changed files with 20 additions and 3 deletions.
19 changes: 18 additions & 1 deletion src/SharedKernel/Extensions/ControllerExtensions.cs
Original file line number Diff line number Diff line change
@@ -1,19 +1,36 @@
using System.Reflection;
using System.Text.RegularExpressions;
using Humanizer;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Mvc.ApplicationModels;
using Microsoft.Extensions.DependencyInjection;
using Microsoft.OpenApi.Models;

namespace SharedKernel.Extensions;

public static class ControllerExtensions
{
public static WebApplicationBuilder AddControllers(this WebApplicationBuilder builder, Assembly[] assemblies)
{
var mvcBuilder = builder.Services.AddControllers();
var mvcBuilder = builder.Services.AddControllers(options => options.Conventions.Add(new ToLowerNamingConvention()));
foreach (var assembly in assemblies)
{
mvcBuilder.AddApplicationPart(assembly);
}

return builder;
}
}

public class ToLowerNamingConvention : IControllerModelConvention
{
public void Apply(ControllerModel controller)
{
controller.ControllerName = controller.ControllerName.Kebaberize();

foreach (var action in controller.Actions)
{
action.ActionName = action.ActionName.Kebaberize();
}
}
}
4 changes: 2 additions & 2 deletions src/SharedKernel/SharedKernel.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@
<PackageReadmeFile>Readme.md</PackageReadmeFile>
<Authors>Pandatech</Authors>
<Copyright>MIT</Copyright>
<Version>1.0.11</Version>
<Version>1.0.12</Version>
<PackageId>Pandatech.SharedKernel</PackageId>
<Title>Pandatech Shared Kernel Library</Title>
<PackageTags>Pandatech, shared kernel, library, OpenAPI, Swagger, utilities, scalar</PackageTags>
<Description>Pandatech.SharedKernel provides centralized configurations, utilities, and extensions for ASP.NET Core projects. For more information refere to readme.md document.</Description>
<RepositoryUrl>https://github.com/PandaTechAM/be-lib-sharedkernel</RepositoryUrl>
<PackageReleaseNotes>OpenApi update</PackageReleaseNotes>
<PackageReleaseNotes>Controller naming to kebab</PackageReleaseNotes>
</PropertyGroup>

<ItemGroup>
Expand Down

0 comments on commit 8a2e598

Please sign in to comment.