From 7235a9b1f01b8c45e4da93868bf0248ac775a808 Mon Sep 17 00:00:00 2001 From: Michal Fojtik Date: Mon, 24 Nov 2014 20:32:18 +0100 Subject: [PATCH] Fix pluralization in RESTMapper when kind ends with 'y' --- pkg/api/meta/restmapper.go | 9 ++++++--- pkg/api/meta/restmapper_test.go | 2 ++ 2 files changed, 8 insertions(+), 3 deletions(-) diff --git a/pkg/api/meta/restmapper.go b/pkg/api/meta/restmapper.go index 5e3db787cc..df83f6cc63 100644 --- a/pkg/api/meta/restmapper.go +++ b/pkg/api/meta/restmapper.go @@ -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 } diff --git a/pkg/api/meta/restmapper_test.go b/pkg/api/meta/restmapper_test.go index 75d95f9085..7941332ab3 100644 --- a/pkg/api/meta/restmapper_test.go +++ b/pkg/api/meta/restmapper_test.go @@ -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"},