Skip to content

Commit

Permalink
feat(AIP-133): ignore create methods with invalid LRO response types (#…
Browse files Browse the repository at this point in the history
…1366)

* feat(AIP-133): ignore create methods with invalid LRO response types

* chore: clean up return type resolution logic
  • Loading branch information
andrei-scripniciuc authored Apr 12, 2024
1 parent ca10a56 commit 22d015a
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 1 deletion.
2 changes: 1 addition & 1 deletion rules/aip0133/request_required_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ import (
// The create request message should not have unrecognized fields.
var requestRequiredFields = &lint.MethodRule{
Name: lint.NewRuleName(133, "request-required-fields"),
OnlyIf: utils.IsCreateMethod,
OnlyIf: utils.IsCreateMethodWithResolvedReturnType,
LintMethod: func(m *desc.MethodDescriptor) []lint.Problem {
ot := utils.GetResponseType(m)
r := utils.GetResource(ot)
Expand Down
12 changes: 12 additions & 0 deletions rules/internal/utils/method.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,18 @@ func IsCreateMethod(m *desc.MethodDescriptor) bool {
return createMethodRegexp.MatchString(m.GetName())
}

// IsCreateMethod returns true if this is a AIP-133 Create method with
// a non-nil response type. This method should be used for filtering in linter
// rules which access the response type of the method, to avoid crashing due
// to dereferencing a nil pointer to the response.
func IsCreateMethodWithResolvedReturnType(m *desc.MethodDescriptor) bool {
if !IsCreateMethod(m) {
return false
}

return GetResponseType(m) != nil
}

// IsGetMethod returns true if this is a AIP-131 Get method.
func IsGetMethod(m *desc.MethodDescriptor) bool {
methodName := m.GetName()
Expand Down

0 comments on commit 22d015a

Please sign in to comment.