api-linter icon indicating copy to clipboard operation
api-linter copied to clipboard

We should lint for AIP-213, warning on cross-API references

Open jskeet opened this issue 1 year ago • 0 comments

AIP-213 states:

APIs should not directly depend on protos defined in other APIs. Instead, they should copy and paste the applicable messages into their own API. When doing so, APIs should keep the field names and numbers the same.

We should lint for this, probably by checking imports. Some caveats to this:

  • Various common imports should be allowed, e.g. google/protobuf/*, google/longrunning/*, google/rpc/*
  • Only imports that remain after pruning (e.g. removing internal-only dependencies) should generate warnings
  • This should probably be done at an "API version" boundary - so abc/def/v2/xyz/a.proto should be able to import abc/def/v2/b.proto and vice versa; unversioned APIs are sufficiently rare that we can probably either ignore them or restrict them to the exact same package
  • Very occasionally there are legitimate reasons for an API to use messages from another API; we should be able to configure those "allowed imports" rather than those APIs having to turn the rule off entirely. (They should be able to be confident they're not accidentally importing more than they intended to.)

jskeet avatar Sep 16 '22 14:09 jskeet