Skip to content

Commit

Permalink
fix(AIP-133): lint http collection ID for lookalikes (#1286)
Browse files Browse the repository at this point in the history
  • Loading branch information
noahdietz authored Nov 13, 2023
1 parent a3f3066 commit 3397db6
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 0 deletions.
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

0 comments on commit 3397db6

Please sign in to comment.