AEP-0004 Linter Rules
Resource annotation presence
Resource annotation presence
This rule enforces that the same resource type doesn’t appear in more than one
google.api.resource
annotation, as described in AEP-004.
Details
This rule complains about messages that have the same type
for the
google.api.resource
annotation, which frequently occur due to copy-paste
errors and messages spread across multiple files and/or packages. Duplicate
resource definitions can cause compilation problems in generated client code.
Examples
Incorrect code for this rule:
Correct code for this rule:
Disabling
If you need to violate this rule, use a comment at the top of the file. Remember to also include an aep.dev/not-precedent comment explaining why.
Resource path field never optional
Resource path field never optional
This rule enforces that the path field of a resource message is not labeled with proto3_optional.
Details
This rule scans for messages with a google.api.resource
annotation and ensures
that the configured path field (either path
or whichever field specified via
path_field
) is not labeled as optional
.
Examples
Incorrect code for this rule:
Correct code for this rule:
Disabling
If you need to violate this rule, use a leading comment above the message.
If you need to violate this rule for an entire file, place the comment at the top of the file.
Resource annotation presence
Resource annotation presence
This rule enforces that top-level messages that appear to represent resources
have a google.api.resource
annotation, as described in AEP-4.
Details
This rule scans all top-level messages, and assumes that messages with a
string path
field are resources unless the message name ends with Request
.
For messages that are resources, it complains if the google.api.resource
annotation is missing.
Examples
Incorrect code for this rule:
Correct code for this rule:
Disabling
If you need to violate this rule, use a leading comment above the message.
If you need to violate this rule for an entire file, place the comment at the top of the file.
Resource patterns
Resource patterns
This rule enforces that files that define a resource with the
google.api.resource_definition
annotation have a pattern
defined, as
described in AEP-123.
Details
This rule scans all google.api.resource_definition
annotations in all files,
and complains if pattern
is not provided at least once. It also complains if
the segments outside of variable names contain underscores.
Examples
Incorrect code for this rule:
Correct code for this rule:
Disabling
If you need to violate this rule, use a comment on the annotation.
If you need to violate this rule for an entire file, place the comment at the top of the file.
Resource type name
Resource type name
This rule enforces that files that define a resource with the
google.api.resource_definition
annotation have a properly formatted type
, as
described in AEP-123.
Details
This rule scans files with google.api.resource_definition
annotations, and
validates the format of the type
field conforms to {Service Name}/{Type}
.
Examples
Incorrect code for this rule:
Correct code for this rule:
Disabling
If you need to violate this rule, use a leading comment above the annotation.
If you need to violate this rule for an entire file, place the comment at the top of the file.
Resource pattern variables
Resource pattern variables
This rule enforces that resource patterns use consistent variable naming conventions, as described in AEP-4.
Details
This rule scans all files with google.api.resource_definition
annotations, and
complains if variables in a pattern
use camel case, or end in _id
.
Examples
Incorrect code for this rule:
Correct code for this rule:
Disabling
If you need to violate this rule, use a leading comment above the annotation.
If you need to violate this rule for an entire file, place the comment at the top of the file.
Resource name components alternate
Resource name components alternate
This rule enforces that messages that have a google.api.resource
annotation
have pattern
annotations that alternate between collection and identifier, as
described in AEP-4.
Details
This rule scans messages with a google.api.resource
annotation, and validates
that each pattern
alternated between collection and identifiers.
Examples
Incorrect code for this rule:
Correct code for this rule:
Disabling
If you need to violate this rule, use a leading comment above the message.
If you need to violate this rule for an entire file, place the comment at the top of the file.
Resource path field
Resource path
field
This rule enforces that messages that appear to represent resources have a
string path
field, as described in AEP-4.
Details
This rule scans all messages that have a google.api.resource
annotation, and
complains if the path
field is missing or if it is any type other than
singular string
.
Examples
Incorrect code for this rule:
Correct code for this rule:
Disabling
If you need to violate this rule, use a leading comment above the message, or above the field if it is the wrong type.
If you need to violate this rule for an entire file, place the comment at the top of the file.
Resource patterns
Resource patterns
This rule enforces that messages that appear to represent resources have a
pattern
defined on their google.api.resource
annotation, as described in
AEP-4.
Details
This rule scans all messages with google.api.resource
annotations, and
complains if pattern
is not provided at least once. It also complains if the
segments outside of variable names contain underscores.
Examples
Incorrect code for this rule:
Correct code for this rule:
Disabling
If you need to violate this rule, use a leading comment above the message.
If you need to violate this rule for an entire file, place the comment at the top of the file.
Resource type name
Resource type name
This rule enforces that messages that have a google.api.resource
annotation,
have a properly formatted plural
, as described in AEP-4.
Details
This rule scans messages with a google.api.resource
annotation, and
verifies the plural
field exists.
Examples
Incorrect code for this rule:
Correct code for this rule:
Disabling
If you need to violate this rule, use a leading comment above the message.
If you need to violate this rule for an entire file, place the comment at the top of the file.
Resource annotation presence
Resource annotation presence
This rule enforces that any field with a google.api.resource_reference
annotation has a string
type, as described in AEP-4.
Details
This rule scans all fields with a google.api.resource_reference
annotation.
If one is found, the type is checked, and the rule complains if the type is
anything other than string
.
It suggests the removal of the annotation rather than fixing the type, because what we have observed in real life is that the annotation is usually what is in error rather than the selected type.
Examples
Incorrect code for this rule:
Correct code for this rule:
Disabling
Do not violate this rule; it will break several tools.
Resource type name
Resource type name
This rule enforces that messages that have a google.api.resource
annotation,
have a properly formatted singular
, as described in AEP-4.
Details
This rule scans messages with a google.api.resource
annotation, and validates
the format of the singular
field is the lower camel case of type.
Examples
Incorrect code for this rule:
Correct code for this rule:
Disabling
If you need to violate this rule, use a leading comment above the message.
If you need to violate this rule for an entire file, place the comment at the top of the file.
Resource type name
Resource type name
This rule enforces that messages that have a google.api.resource
annotation,
have a properly formatted type
, as described in AEP-4.
Details
This rule scans messages with a google.api.resource
annotation, and validates
the format of the type
field conforms to {Service Name}/{Type}
.
Examples
Incorrect code for this rule:
Correct code for this rule:
Disabling
If you need to violate this rule, use a leading comment above the message.
If you need to violate this rule for an entire file, place the comment at the top of the file.
Resource pattern variables
Resource pattern variables
This rule enforces that resource patterns use consistent variable naming conventions, as described in AEP-4.
Details
This rule scans all messages with google.api.resource
annotations, and
complains if variables in a pattern
use camel case, or end in _id
.
Examples
Incorrect code for this rule:
Correct code for this rule:
Disabling
If you need to violate this rule, use a leading comment above the message.
If you need to violate this rule for an entire file, place the comment at the top of the file.