googleapis / googleapis/api-linter

Include the proto "stdlib" in the api-linter distribution

Open
#1,024 0 comments 1 reaction 0 assignees View on GitHub
Dominant language
Go
Stars
765
Forks
181
Avg merge
2d 12h
Merged PRs (30d)
3

Description

One of the tricker things I've discovered a couple of times when setting up this API linter is that you need to have a local copy of the source of the proto stdlib to handle imports like

```proto
import "google/api/annotations.proto";
import "google/api/field_behavior.proto";
import "google/api/resource.proto";
import "google/protobuf/duration.proto";
```

I've been working in Go for a long while now, but I presume the same is true in other languages. When I compile my `.pb.go` files, it refers to the precompiled form of all these imports like [`durationpb`](https://pkg.go.dev/google.golang.org/protobuf/types/known/durationpb) or [`fieldmaskpb`](https://pkg.go.dev/google.golang.org/protobuf/types/known/fieldmaskpb). `protoc` by way of `protoc-gen-go` explicitly imports these requirements from the "normal distribution channels" and do not compile my local copy of `duration.proto` in favor of fetching it from this [precompiled github repo](https://github.com/protocolbuffers/protobuf-go). This leads to an interesting situation where I am vendoring `.proto` files which might be out of sync with what I'm importing exclusively to get linting.

Concrete proposal:

Include a fall-back definition (maybe gated behind a flag) of the ~30 protos that make up the "stdlib". Especially protos that are required to be imported by AIP so that you can just run the linter without having to vendor in the protos. Here are the paths I would vendor:

```
google/api/
annotations.proto
client.proto
field_behavior.proto
http.proto
httpbody.proto
resource.proto
visibility.proto

google/longrunning/
operations.proto

google/rpc/
code.proto
error_details.proto
status.proto

google/type/
calendar_period.proto
color.proto
date.proto
datetime.proto
dayofweek.proto
decimal.proto
expr.proto
fraction.proto
interval.proto
latlng.proto
localized_text.proto
money.proto
month.proto
phone_number.proto
postal_address.proto
quaternion.proto
timeofday.proto
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.