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

fix(AIP-133): lint http collection ID for lookalikes #1286

Merged
merged 1 commit into from
Nov 13, 2023
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
6 changes: 6 additions & 0 deletions rules/aip0133/http_uri_resource.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@ var httpURIResource = &lint.MethodRule{
// Extract the suffix of the URI path as the collection identifier.
uriParts := strings.Split(utils.GetHTTPRules(m)[0].URI, "/")
collectionName := uriParts[len(uriParts)-1]
// Custom Method Standard Create lookalikes can still be linted, but
// don't include the custom method http suffix
// e.g. .../books:createAndCheckout --> books.
if strings.Contains(collectionName, ":") {
collectionName = strings.Split(collectionName, ":")[0]
}

// Ensure that a collection identifier is provided.
if collectionName == "" {
Expand Down
2 changes: 2 additions & 0 deletions rules/aip0133/http_uri_resource_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -30,9 +30,11 @@ func TestHTTPURIResource(t *testing.T) {
problems testutils.Problems
}{
{"Valid", "/v1/{parent=publishers/*}/books", "publishers/{publisher}/books/{book}", nil},
{"ValidCustomLookalike", "/v1/{parent=publishers/*}/books:createAndCheckout", "publishers/{publisher}/books/{book}", nil},
{"MethodMissingURIPath", "", "publishers/{publisher}/books/{book}", nil},
{"MethodMissingCollectionURISuffix", "/v1/", "publishers/{publisher}/books/{book}", testutils.Problems{{Message: "The URI path does not end in a collection identifier."}}},
{"ResourceMissingCollectionInPattern", "/v1/{parent=publishers/*}/books", "publishers/{publisher}", testutils.Problems{{Message: "Resource pattern should contain the collection identifier \"books/\"."}}},
{"ResourceMissingCollectionCustomLookalike", "/v1/{parent=publishers/*}/books:createAndCheckout", "publishers/{publisher}", testutils.Problems{{Message: "Resource pattern should contain the collection identifier \"books/\"."}}},
}

for _, test := range tests {
Expand Down