Do not return plural type in GetObjectIdAndTypeFromUrlPath

This commit is contained in:
Christian Schaible 2024-10-10 15:18:14 +02:00
parent 965fa4e617
commit 66773aad3d
2 changed files with 6 additions and 10 deletions

View file

@ -912,7 +912,6 @@ func OperationNameFromGrpcMethod(path string) string {
func GetObjectIdAndTypeFromUrlPath(path string) ( func GetObjectIdAndTypeFromUrlPath(path string) (
string, string,
*SingularType, *SingularType,
*PluralType,
error, error,
) { ) {
@ -922,15 +921,15 @@ func GetObjectIdAndTypeFromUrlPath(path string) (
objectTypePlural := AsPluralType(objectTypeIdMatches[1]) objectTypePlural := AsPluralType(objectTypeIdMatches[1])
objectTypeSingular, err := objectTypePlural.AsSingularType() objectTypeSingular, err := objectTypePlural.AsSingularType()
if err != nil { if err != nil {
return "", nil, nil, err return "", nil, err
} }
objectType := &objectTypeSingular objectType := &objectTypeSingular
objectId := objectTypeIdMatches[2] objectId := objectTypeIdMatches[2]
return objectId, objectType, &objectTypePlural, nil return objectId, objectType, nil
} }
return "", nil, nil, nil return "", nil, nil
} }
func ToArrayMap(input map[string]string) map[string][]string { func ToArrayMap(input map[string]string) map[string][]string {

View file

@ -978,27 +978,24 @@ func Test_OperationNameFromGrpcMethod(t *testing.T) {
func Test_GetObjectIdAndTypeFromUrlPath(t *testing.T) { func Test_GetObjectIdAndTypeFromUrlPath(t *testing.T) {
t.Run("object id and type not in url", func(t *testing.T) { t.Run("object id and type not in url", func(t *testing.T) {
objectId, singularType, pluralType, err := GetObjectIdAndTypeFromUrlPath("/v2/projects/audit") objectId, singularType, err := GetObjectIdAndTypeFromUrlPath("/v2/projects/audit")
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "", objectId) assert.Equal(t, "", objectId)
assert.Nil(t, singularType) assert.Nil(t, singularType)
assert.Nil(t, pluralType)
}) })
t.Run("object id and type in url", func(t *testing.T) { t.Run("object id and type in url", func(t *testing.T) {
objectId, singularType, pluralType, err := GetObjectIdAndTypeFromUrlPath("/v2/projects/f17d4064-9b65-4334-b6a7-8fed96340124") objectId, singularType, err := GetObjectIdAndTypeFromUrlPath("/v2/projects/f17d4064-9b65-4334-b6a7-8fed96340124")
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "f17d4064-9b65-4334-b6a7-8fed96340124", objectId) assert.Equal(t, "f17d4064-9b65-4334-b6a7-8fed96340124", objectId)
assert.Equal(t, SingularTypeProject, *singularType) assert.Equal(t, SingularTypeProject, *singularType)
assert.Equal(t, PluralTypeProject, *pluralType)
}) })
t.Run("multiple object ids and types in url", func(t *testing.T) { t.Run("multiple object ids and types in url", func(t *testing.T) {
objectId, singularType, pluralType, err := GetObjectIdAndTypeFromUrlPath("/v2/organization/8ee58bec-d496-4bb9-af8d-72fda4d78b6b/projects/f17d4064-9b65-4334-b6a7-8fed96340124") objectId, singularType, err := GetObjectIdAndTypeFromUrlPath("/v2/organization/8ee58bec-d496-4bb9-af8d-72fda4d78b6b/projects/f17d4064-9b65-4334-b6a7-8fed96340124")
assert.NoError(t, err) assert.NoError(t, err)
assert.Equal(t, "f17d4064-9b65-4334-b6a7-8fed96340124", objectId) assert.Equal(t, "f17d4064-9b65-4334-b6a7-8fed96340124", objectId)
assert.Equal(t, SingularTypeProject, *singularType) assert.Equal(t, SingularTypeProject, *singularType)
assert.Equal(t, PluralTypeProject, *pluralType)
}) })
} }