Merge pull request #2569 from mfojtik/pluralization_fix
Fix pluralization in RESTMapper when kind ends with 'y'
This commit is contained in:
commit
c5e9f60f9c
@ -101,10 +101,13 @@ func kindToResource(kind string, mixedCase bool) (plural, singular string) {
|
|||||||
} else {
|
} else {
|
||||||
singular = strings.ToLower(kind)
|
singular = strings.ToLower(kind)
|
||||||
}
|
}
|
||||||
if !strings.HasSuffix(singular, "s") {
|
switch string(singular[len(singular)-1]) {
|
||||||
plural = singular + "s"
|
case "s":
|
||||||
} else {
|
|
||||||
plural = singular
|
plural = singular
|
||||||
|
case "y":
|
||||||
|
plural = strings.TrimSuffix(singular, "y") + "ies"
|
||||||
|
default:
|
||||||
|
plural = singular + "s"
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
}
|
}
|
||||||
|
@ -106,6 +106,8 @@ func TestKindToResource(t *testing.T) {
|
|||||||
// API convention changed with regard to capitalization for v1beta3
|
// API convention changed with regard to capitalization for v1beta3
|
||||||
{Kind: "ReplicationController", MixedCase: false, Plural: "replicationcontrollers", Singular: "replicationcontroller"},
|
{Kind: "ReplicationController", MixedCase: false, Plural: "replicationcontrollers", Singular: "replicationcontroller"},
|
||||||
|
|
||||||
|
{Kind: "ImageRepository", MixedCase: true, Plural: "imageRepositories", Singular: "imageRepository"},
|
||||||
|
|
||||||
{Kind: "lowercase", MixedCase: false, Plural: "lowercases", Singular: "lowercase"},
|
{Kind: "lowercase", MixedCase: false, Plural: "lowercases", Singular: "lowercase"},
|
||||||
// Don't add extra s if the original object is already plural
|
// Don't add extra s if the original object is already plural
|
||||||
{Kind: "lowercases", MixedCase: false, Plural: "lowercases", Singular: "lowercases"},
|
{Kind: "lowercases", MixedCase: false, Plural: "lowercases", Singular: "lowercases"},
|
||||||
|
Loading…
Reference in New Issue
Block a user