diff --git a/rules/aip0123/resource_pattern.go b/rules/aip0123/resource_pattern.go index f0c7bc5d0..8a378160a 100644 --- a/rules/aip0123/resource_pattern.go +++ b/rules/aip0123/resource_pattern.go @@ -46,9 +46,11 @@ func lintResourcePattern(resource *annotations.ResourceDescriptor, desc desc.Des } // Ensure that the constant segments of the pattern uses camel case, - // not snake case. + // not snake case, and there are no spaces. for _, pattern := range resource.GetPattern() { - if strings.Contains(getPlainPattern(pattern), "_") { + plainPattern := getPlainPattern(pattern) + + if strings.Contains(plainPattern, "_") { return []lint.Problem{{ Message: fmt.Sprintf( "Resource patterns should use camel case (apart from the variable names), such as %q.", @@ -58,6 +60,13 @@ func lintResourcePattern(resource *annotations.ResourceDescriptor, desc desc.Des Location: loc, }} } + if strings.Contains(plainPattern, " ") { + return []lint.Problem{{ + Message: "Resource patterns should not have spaces", + Descriptor: desc, + Location: loc, + }} + } } return nil } diff --git a/rules/aip0123/resource_pattern_test.go b/rules/aip0123/resource_pattern_test.go index 65956557d..276de85ee 100644 --- a/rules/aip0123/resource_pattern_test.go +++ b/rules/aip0123/resource_pattern_test.go @@ -32,6 +32,9 @@ func TestResourcePattern(t *testing.T) { {"SnakeCase", `pattern: "book_publishers/{book_publisher}/books/{book}"`, testutils.Problems{{ Message: "bookPublishers/{book_publisher}/books/{book}", }}}, + {"HasSpaces", `pattern: "publishers/{publisher}/ books /{book}"`, testutils.Problems{{ + Message: "Resource patterns should not have spaces", + }}}, } { t.Run(test.name, func(t *testing.T) { f := testutils.ParseProto3Tmpl(t, `