Merge pull request #2569 from mfojtik/pluralization_fix

Fix pluralization in RESTMapper when kind ends with 'y'
pull/6/head
Clayton Coleman 2014-11-25 09:53:46 -06:00
commit c5e9f60f9c
2 changed files with 8 additions and 3 deletions

View File

@ -101,10 +101,13 @@ func kindToResource(kind string, mixedCase bool) (plural, singular string) {
} else {
singular = strings.ToLower(kind)
}
if !strings.HasSuffix(singular, "s") {
plural = singular + "s"
} else {
switch string(singular[len(singular)-1]) {
case "s":
plural = singular
case "y":
plural = strings.TrimSuffix(singular, "y") + "ies"
default:
plural = singular + "s"
}
return
}

View File

@ -106,6 +106,8 @@ func TestKindToResource(t *testing.T) {
// API convention changed with regard to capitalization for v1beta3
{Kind: "ReplicationController", MixedCase: false, Plural: "replicationcontrollers", Singular: "replicationcontroller"},
{Kind: "ImageRepository", MixedCase: true, Plural: "imageRepositories", Singular: "imageRepository"},
{Kind: "lowercase", MixedCase: false, Plural: "lowercases", Singular: "lowercase"},
// Don't add extra s if the original object is already plural
{Kind: "lowercases", MixedCase: false, Plural: "lowercases", Singular: "lowercases"},