Skip to content

Commit 3137642

Browse files
feat(sidekick): Relax AIP checks for samples of get operations (#3340)
Some reosurces have no singular name configured.
1 parent bd087bc commit 3137642

File tree

2 files changed

+26
-4
lines changed

2 files changed

+26
-4
lines changed

internal/sidekick/api/model.go

Lines changed: 13 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -394,10 +394,19 @@ func (m *Method) AIPStandardGetInfo() *AIPStandardGetInfo {
394394
return nil
395395
}
396396

397-
singular := strings.ToLower(m.OutputType.Resource.Singular)
398-
// The method needs to be called getfoo and the request type needs to be called getfoorequest.
399-
if strings.ToLower(m.Name) != fmt.Sprintf("get%s", singular) ||
400-
strings.ToLower(m.InputType.Name) != fmt.Sprintf("get%srequest", singular) {
397+
// Standard get methods for resource "Foo" should be named "GetFoo".
398+
maybeSingular, found := strings.CutPrefix(strings.ToLower(m.Name), "get")
399+
if !found || maybeSingular == "" {
400+
return nil
401+
}
402+
// The request name should be "GetFooRequest".
403+
if strings.ToLower(m.InputType.Name) != fmt.Sprintf("get%srequest", maybeSingular) {
404+
return nil
405+
}
406+
407+
// If the resource has a singular name, it must match.
408+
if m.OutputType.Resource.Singular != "" &&
409+
strings.ToLower(m.OutputType.Resource.Singular) != maybeSingular {
401410
return nil
402411
}
403412

internal/sidekick/api/model_test.go

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -385,6 +385,19 @@ func TestAIPStandardGetInfo(t *testing.T) {
385385
ResourceNameRequestField: resourceNameField,
386386
},
387387
},
388+
{
389+
name: "valid get operation with missing singular name on resource",
390+
method: &Method{
391+
Name: "GetSecret",
392+
InputType: &Message{Name: "GetSecretRequest", Fields: []*Field{resourceNameField}},
393+
OutputType: &Message{
394+
Resource: &Resource{Type: resourceType, Singular: ""},
395+
},
396+
},
397+
want: &AIPStandardGetInfo{
398+
ResourceNameRequestField: resourceNameField,
399+
},
400+
},
388401
{
389402
name: "method name is incorrect",
390403
method: &Method{

0 commit comments

Comments
 (0)