Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Adopt AEP 132 #60

Merged
merged 2 commits into from
Jul 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions rules/aep0132/http_body.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
// List methods should not have an HTTP body.
var httpBody = &lint.MethodRule{
Name: lint.NewRuleName(132, "http-body"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: utils.IsListMethod,
LintMethod: utils.LintNoHTTPBody,
}
1 change: 1 addition & 0 deletions rules/aep0132/http_method.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
// List methods should use the HTTP GET verb.
var httpMethod = &lint.MethodRule{
Name: lint.NewRuleName(132, "http-method"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: utils.IsListMethod,
LintMethod: utils.LintHTTPMethod("GET"),
}
3 changes: 2 additions & 1 deletion rules/aep0132/http_uri_parent.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@ import (

// List methods should have a parent variable if the request has a parent field.
var httpURIParent = &lint.MethodRule{
Name: lint.NewRuleName(132, "http-uri-parent"),
Name: lint.NewRuleName(132, "http-uri-parent"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: func(m *desc.MethodDescriptor) bool {
return utils.IsListMethod(m) && m.GetInputType().FindFieldByName("parent") != nil
},
Expand Down
3 changes: 2 additions & 1 deletion rules/aep0132/method_signature.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (
)

var methodSignature = &lint.MethodRule{
Name: lint.NewRuleName(132, "method-signature"),
Name: lint.NewRuleName(132, "method-signature"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: func(m *desc.MethodDescriptor) bool {
return utils.IsListMethod(m) && m.GetInputType().FindFieldByName("parent") != nil
},
Expand Down
3 changes: 2 additions & 1 deletion rules/aep0132/request_field_types.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,8 @@ var knownFields = map[string]func(*desc.FieldDescriptor) []lint.Problem{

// List fields should have the correct type.
var requestFieldTypes = &lint.FieldRule{
Name: lint.NewRuleName(132, "request-field-types"),
Name: lint.NewRuleName(132, "request-field-types"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: func(f *desc.FieldDescriptor) bool {
return utils.IsListRequestMessage(f.GetOwner()) && knownFields[f.GetName()] != nil
},
Expand Down
1 change: 1 addition & 0 deletions rules/aep0132/request_message_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
// List messages should have a properly named Request message.
var requestMessageName = &lint.MethodRule{
Name: lint.NewRuleName(132, "request-message-name"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: utils.IsListMethod,
LintMethod: utils.LintMethodHasMatchingRequestName,
}
3 changes: 2 additions & 1 deletion rules/aep0132/request_parent_behavior.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
)

var requestParentBehavior = &lint.FieldRule{
Name: lint.NewRuleName(132, "request-parent-behavior"),
Name: lint.NewRuleName(132, "request-parent-behavior"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: func(f *desc.FieldDescriptor) bool {
return utils.IsListRequestMessage(f.GetOwner()) && f.GetName() == "parent"
},
Expand Down
3 changes: 2 additions & 1 deletion rules/aep0132/request_parent_field.go
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,8 @@ import (
// The type of the parent field in the List request message should
// be string.
var requestParentField = &lint.FieldRule{
Name: lint.NewRuleName(132, "request-parent-field"),
Name: lint.NewRuleName(132, "request-parent-field"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: func(f *desc.FieldDescriptor) bool {
return utils.IsListRequestMessage(f.GetOwner()) && f.GetName() == "parent"
},
Expand Down
3 changes: 2 additions & 1 deletion rules/aep0132/request_parent_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,8 @@ import (
)

var requestParentReference = &lint.FieldRule{
Name: lint.NewRuleName(132, "request-parent-reference"),
Name: lint.NewRuleName(132, "request-parent-reference"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: func(f *desc.FieldDescriptor) bool {
return utils.IsListRequestMessage(f.GetOwner()) && f.GetName() == "parent"
},
Expand Down
5 changes: 3 additions & 2 deletions rules/aep0132/request_parent_required.go
Original file line number Diff line number Diff line change
Expand Up @@ -12,8 +12,9 @@ import (

// The List standard method should contain a parent field.
var requestParentRequired = &lint.MessageRule{
Name: lint.NewRuleName(132, "request-parent-required"),
OnlyIf: utils.IsListRequestMessage,
Name: lint.NewRuleName(132, "request-parent-required"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: utils.IsListRequestMessage,
LintMessage: func(m *desc.MessageDescriptor) []lint.Problem {
// Rule check: Establish that a `parent` field is present.
if m.FindFieldByName("parent") == nil {
Expand Down
2 changes: 1 addition & 1 deletion rules/aep0132/request_parent_required_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -54,7 +54,7 @@ func TestRequestParentRequired(t *testing.T) {
option (google.api.resource) = {
pattern: "books/{book}"
};
string name = 1;
string path = 1;
}
`, test)
problems := requestParentRequired.Lint(f)
Expand Down
3 changes: 2 additions & 1 deletion rules/aep0132/request_parent_valid_reference.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (
)

var requestParentValidReference = &lint.FieldRule{
Name: lint.NewRuleName(132, "request-parent-valid-reference"),
Name: lint.NewRuleName(132, "request-parent-valid-reference"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: func(f *desc.FieldDescriptor) bool {
ref := utils.GetResourceReference(f)
return utils.IsListRequestMessage(f.GetOwner()) && f.GetName() == "parent" && ref != nil && ref.GetType() != ""
Expand Down
2 changes: 1 addition & 1 deletion rules/aep0132/request_parent_valid_reference_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ func TestRequestParentValidReference(t *testing.T) {
pattern: "publishers/{publisher}/books/{book}"
};

string name = 1;
string path = 1;
}
`, test)
field := f.GetMessageTypes()[0].GetFields()[0]
Expand Down
5 changes: 3 additions & 2 deletions rules/aep0132/request_required_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,9 @@ import (

// The list request message should not have unrecognized fields.
var requestRequiredFields = &lint.MessageRule{
Name: lint.NewRuleName(132, "request-required-fields"),
OnlyIf: utils.IsListRequestMessage,
Name: lint.NewRuleName(132, "request-required-fields"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: utils.IsListRequestMessage,
LintMessage: func(m *desc.MessageDescriptor) (problems []lint.Problem) {
// Rule check: Establish that there are no unexpected fields.
allowedRequiredFields := stringset.New("parent")
Expand Down
2 changes: 1 addition & 1 deletion rules/aep0132/request_required_fields_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -93,7 +93,7 @@ func TestRequiredFieldTests(t *testing.T) {
type: "library.googleapis.com/Book"
pattern: "publishers/{publisher}/books/{book}"
};
string name = 1;
string path = 1;
}
`, test)
var dbr desc.Descriptor = f.FindMessage("ListBooksRequest")
Expand Down
3 changes: 2 additions & 1 deletion rules/aep0132/request_show_deleted_required.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,8 @@ import (
// List requests should contain a show_deleted field if the resource supports
// soft delete.
var requestShowDeletedRequired = &lint.MessageRule{
Name: lint.NewRuleName(132, "request-show-deleted-required"),
Name: lint.NewRuleName(132, "request-show-deleted-required"),
RuleType: lint.NewRuleType(lint.ShouldRule),
OnlyIf: func(m *desc.MessageDescriptor) bool {
if !utils.IsListRequestMessage(m) {
return false
Expand Down
3 changes: 2 additions & 1 deletion rules/aep0132/request_unknown_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,8 @@ var allowedFields = stringset.New(

// List methods should not have unrecognized fields.
var unknownFields = &lint.FieldRule{
Name: lint.NewRuleName(132, "request-unknown-fields"),
Name: lint.NewRuleName(132, "request-unknown-fields"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: func(f *desc.FieldDescriptor) bool {
return utils.IsListRequestMessage(f.GetOwner())
},
Expand Down
3 changes: 2 additions & 1 deletion rules/aep0132/resource_reference_type.go
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,8 @@ import (
// List methods should reference the target resource via `child_type` or the
// parent directly via `type`.
var resourceReferenceType = &lint.MethodRule{
Name: lint.NewRuleName(132, "resource-reference-type"),
Name: lint.NewRuleName(132, "resource-reference-type"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: func(m *desc.MethodDescriptor) bool {
p := m.GetInputType().FindFieldByName("parent")

Expand Down
2 changes: 1 addition & 1 deletion rules/aep0132/resource_reference_type_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ option (google.api.resource) = {
}
message Book {
{{ .ResourceAnnotation }}
string name = 1;
string path = 1;
}
`, test)
field := file.GetServices()[0].GetMethods()[0].GetInputType().FindFieldByName("parent")
Expand Down
1 change: 1 addition & 0 deletions rules/aep0132/response_message_name.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ import (
// List messages should use a `ListFoosResponse` response message.
var responseMessageName = &lint.MethodRule{
Name: lint.NewRuleName(132, "response-message-name"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: utils.IsListMethod,
LintMethod: utils.LintMethodHasMatchingResponseName,
}
3 changes: 2 additions & 1 deletion rules/aep0132/response_unknown_fields.go
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,8 @@ var respAllowedFields = stringset.New(
)

var responseUnknownFields = &lint.FieldRule{
Name: lint.NewRuleName(132, "response-unknown-fields"),
Name: lint.NewRuleName(132, "response-unknown-fields"),
RuleType: lint.NewRuleType(lint.MustRule),
OnlyIf: func(f *desc.FieldDescriptor) bool {
return utils.IsListResponseMessage(f.GetOwner())
},
Expand Down
Loading