Skip to content

Commit c7dd792

Browse files
committed
pluralizing model name in minimalapi scenarios using humanizer (#2401)
1 parent 759f2f4 commit c7dd792

7 files changed

Lines changed: 10 additions & 8 deletions

File tree

eng/Versions.props

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -83,6 +83,7 @@
8383
<MicrosoftExtensionsFileProvidersPhysicalPackageVersion>7.0.0</MicrosoftExtensionsFileProvidersPhysicalPackageVersion>
8484
<NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
8585
<NuGetPackagingVersion>6.3.1</NuGetPackagingVersion>
86+
<HumanizerPackageVersion>2.14.1</HumanizerPackageVersion>
8687
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
8788
<!-- Everything below here are Packages only used by test projects -->
8889
<!-- Microsoft.AspNetCore.Server.Kestrel -->

src/Scaffolding/VS.Web.CG.Mvc/Templates/MinimalApi/MinimalApi.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
string routePrefix = "/api/" + modelName;
77
string endPointsClassName = Model.EndpointsName;
88
string methodName = $"Map{@modelName}Endpoints";
9-
string pluralModel = $"{@modelName}s";
9+
string pluralModel = Model.ModelType.PluralName;
1010
string getAllModels = $"GetAll{@pluralModel}";
1111
string getModelById = $"Get{@modelName}ById";
1212
string deleteModel = $"Delete{@modelName}";

src/Scaffolding/VS.Web.CG.Mvc/Templates/MinimalApi/MinimalApiEf.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
string routePrefix = "/api/" + modelName;
66
string endPointsClassName = Model.EndpointsName;
77
string methodName = $"Map{@modelName}Endpoints";
8-
string pluralModel = $"{@modelName}s";
8+
string pluralModel = Model.ModelType.PluralName;
99
string getAllModels = $"GetAll{@pluralModel}";
1010
string getModelById = $"Get{@modelName}ById";
1111
string deleteModel = $"Delete{@modelName}";

src/Scaffolding/VS.Web.CG.Mvc/Templates/MinimalApi/MinimalApiEfNoClass.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
string routePrefix = "/api/" + modelName;
55
string endPointsClassName = Model.EndpointsName;
66
string methodName = $"Map{@modelName}Endpoints";
7-
string pluralModel = $"{@modelName}s";
7+
string pluralModel = Model.ModelType.PluralName;
88
string getAllModels = $"GetAll{@pluralModel}";
99
string getModelById = $"Get{@modelName}ById";
1010
string deleteModel = $"Delete{@modelName}";

src/Scaffolding/VS.Web.CG.Mvc/Templates/MinimalApi/MinimalApiNoClass.cshtml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
string routePrefix = "/api/" + modelName;
77
string endPointsClassName = Model.EndpointsName;
88
string methodName = $"Map{@modelName}Endpoints";
9-
string pluralModel = $"{@modelName}s";
9+
string pluralModel = Model.ModelType.PluralName;
1010
string getAllModels = $"GetAll{@pluralModel}";
1111
string getModelById = $"Get{@modelName}ById";
1212
string deleteModel = $"Delete{@modelName}";

src/Shared/Microsoft.DotNet.Scaffolding.Shared/Microsoft.DotNet.Scaffolding.Shared.csproj

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,11 +22,10 @@
2222
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Features" Version="$(CodeAnalysisVersion)" />
2323
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="$(CodeAnalysisVersion)" />
2424
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="$(CodeAnalysisVersion)" />
25-
26-
25+
<PackageReference Include="Humanizer" Version="$(HumanizerPackageVersion)"/>
2726
<PackageReference Include="NuGet.ProjectModel" Version="$(NuGetProjectModelVersion)" />
2827
</ItemGroup>
29-
28+
3029
<ItemGroup>
3130
<Compile Update="MessageStrings.Designer.cs">
3231
<DesignTime>True</DesignTime>
@@ -41,5 +40,5 @@
4140
<LastGenOutput>MessageStrings.Designer.cs</LastGenOutput>
4241
</EmbeddedResource>
4342
</ItemGroup>
44-
43+
4544
</Project>

src/Shared/Microsoft.DotNet.Scaffolding.Shared/Project/ModelType.cs

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
// The .NET Foundation licenses this file to you under the MIT license.
33

44
using System;
5+
using Humanizer;
56
using Microsoft.CodeAnalysis;
67

78
namespace Microsoft.DotNet.Scaffolding.Shared.Project
@@ -14,6 +15,7 @@ public class ModelType
1415

1516
public string FullName { get; set; }
1617

18+
public string PluralName => Name?.Pluralize(inputIsKnownToBeSingular: false);
1719
// Violating the principle that ModelType should be decoupled from Roslyn's API.
1820
// I had to do this for editing DbContext scenarios but I need to figure out if there
1921
// is a better way.

0 commit comments

Comments
 (0)