googleapis / googleapis/api-linter
core::0203::field-behavior-required looking outside of the current file
- Dominant language
- Go
- Stars
- 765
- Forks
- 181
- Avg merge
- 2d 12h
- Merged PRs (30d)
- 3
Description
Using api-linter 1.51.0 (slowly upgrading, I'm getting a panic with anything more recent than 1.51.0 at the moment, I'll investigate that one later...), I have an issue with the new-ish `core::0203::field-behavior-required` rule. I have a proto file importing `google/protobuf/field_mask.proto`, and using it in a service:
```
// Request message to update a foo.
message UpdateFooRequest {
// Fields to update. The name must be the name of an existing resource.
Foo foo = 1 [(google.api.field_behavior) = REQUIRED];
// Fields to update.
google.protobuf.FieldMask update_mask = 2 [(google.api.field_behavior) = OPTIONAL];
}
```
Invoking `api-linter` with this command line (generated through Bazel but it shouldn't matter really?):
`'../com_github_googleapis_api_linter_linux_amd64/api-linter' 'bar/foo/v1/foo_service.proto' --set-exit-status --proto-path bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/descriptor_proto --proto-path bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/duration_proto --proto-path bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/timestamp_proto --proto-path external/com_envoyproxy_protoc_gen_validate --proto-path external/com_google_googleapis --proto-path . --proto-path bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/empty_proto --proto-path bazel-out/k8-fastbuild/bin/external/com_google_protobuf/src/google/protobuf/_virtual_imports/field_mask_proto`
The rule ends up reporting a violation in a file outside of my control, namely `field_mask.proto`:
```
- file_path: bar/foo/v1/foo_service.proto
problems:
- message: google.api.field_behavior annotation must be set on "paths" and contain
one of, "{"IMMUTABLE", "OPTIONAL", "OUTPUT_ONLY", "REQUIRED"}"
location:
start_position:
line_number: 1
column_number: 1
end_position:
line_number: 1
column_number: 1
path: google/protobuf/field_mask.proto
rule_id: core::0203::field-behavior-required
rule_doc_uri: https://linter.aip.dev/203/field-behavior-required
2023/07/19 01:23:41 found problems during linting
```
`field_mask.proto` is added to the path by the last `--proto-path` argument, but is not passed directly to `api-linter` for linting, so I would expect failures not to be reported. Is this expected? How can I disable the rule for an imported file (as I obviously can't edit this file, and being in the `protobuf` repo, I assume these annotations can't reasonably be added at all) otherwise?
Contributor guide
Assessment
This issue has not been assessed yet.