Skip to content

Commit

Permalink
pluralizing model name in minimalapi scenarios using humanizer (#2401)
Browse files Browse the repository at this point in the history
  • Loading branch information
deepchoudhery authored May 8, 2023
1 parent e7eb78e commit 1f49f72
Show file tree
Hide file tree
Showing 7 changed files with 10 additions and 8 deletions.
1 change: 1 addition & 0 deletions eng/Versions.props
Original file line number Diff line number Diff line change
Expand Up @@ -80,6 +80,7 @@
<MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>6.0.0-preview.3.21166.3</MicrosoftExtensionsCommandLineUtilsSourcesPackageVersion>
<NewtonsoftJsonPackageVersion>13.0.1</NewtonsoftJsonPackageVersion>
<NuGetPackagingVersion>6.3.1</NuGetPackagingVersion>
<HumanizerPackageVersion>2.14.1</HumanizerPackageVersion>
<!--~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ -->
<!-- Everything below here are Packages only used by test projects -->
<!-- Microsoft.AspNetCore.Server.Kestrel -->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
string routePrefix = "/api/" + modelName;
string endPointsClassName = Model.EndpointsName;
string methodName = $"Map{@modelName}Endpoints";
string pluralModel = $"{@modelName}s";
string pluralModel = Model.ModelType.PluralName;
string getAllModels = $"GetAll{@pluralModel}";
string getModelById = $"Get{@modelName}ById";
string deleteModel = $"Delete{@modelName}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
string routePrefix = "/api/" + modelName;
string endPointsClassName = Model.EndpointsName;
string methodName = $"Map{@modelName}Endpoints";
string pluralModel = $"{@modelName}s";
string pluralModel = Model.ModelType.PluralName;
string getAllModels = $"GetAll{@pluralModel}";
string getModelById = $"Get{@modelName}ById";
string deleteModel = $"Delete{@modelName}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
string routePrefix = "/api/" + modelName;
string endPointsClassName = Model.EndpointsName;
string methodName = $"Map{@modelName}Endpoints";
string pluralModel = $"{@modelName}s";
string pluralModel = Model.ModelType.PluralName;
string getAllModels = $"GetAll{@pluralModel}";
string getModelById = $"Get{@modelName}ById";
string deleteModel = $"Delete{@modelName}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,7 @@
string routePrefix = "/api/" + modelName;
string endPointsClassName = Model.EndpointsName;
string methodName = $"Map{@modelName}Endpoints";
string pluralModel = $"{@modelName}s";
string pluralModel = Model.ModelType.PluralName;
string getAllModels = $"GetAll{@pluralModel}";
string getModelById = $"Get{@modelName}ById";
string deleteModel = $"Delete{@modelName}";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,10 @@
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Features" Version="$(CodeAnalysisVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.VisualBasic.Workspaces" Version="$(CodeAnalysisVersion)" />
<PackageReference Include="Microsoft.CodeAnalysis.Workspaces.MSBuild" Version="$(CodeAnalysisVersion)" />


<PackageReference Include="Humanizer" Version="$(HumanizerPackageVersion)"/>
<PackageReference Include="NuGet.ProjectModel" Version="$(NuGetProjectModelVersion)" />
</ItemGroup>

<ItemGroup>
<Compile Update="MessageStrings.Designer.cs">
<DesignTime>True</DesignTime>
Expand All @@ -41,5 +40,5 @@
<LastGenOutput>MessageStrings.Designer.cs</LastGenOutput>
</EmbeddedResource>
</ItemGroup>

</Project>
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
// The .NET Foundation licenses this file to you under the MIT license.

using System;
using Humanizer;
using Microsoft.CodeAnalysis;

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

public string FullName { get; set; }

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

0 comments on commit 1f49f72

Please sign in to comment.