Stubs

Reference

stubs.yaml

stubs.yaml configures a workspace: the modules in it, what they depend on, and how they're linted and checked for breaking changes. stubs init writes one, and stubs init --from-buf writes one from a buf project's files (see Already using buf?).

version: 1
name: stubs.dev/acme/payments
deps:
  - stubs.dev/acme/common
lint:
  use: [standard]
breaking:
  use: [file]

stubs reads the file strictly: an unknown key is an error, rather than a misspelt one quietly doing nothing. Paths use forward slashes, are relative to the file, and stay inside its directory.

version

The format: 1. Required.

name

The workspace's module's name on a registry, when the workspace is one module: every .proto file under the directory stubs.yaml is in. A name is the registry's host, an owner and the module's name, as in stubs.dev/acme/payments. A module needs one to be pushed, or to be depended on by name. It can't be used together with modules.

modules

A workspace of several modules, each a directory of .proto files. Without modules, the workspace is one module of every .proto file under the file's directory.

version: 1
modules:
  - path: proto/payments
    name: stubs.dev/acme/payments
  - path: proto/common
    name: stubs.dev/acme/common
    exclude: [proto/common/internal]

path

The module's directory, relative to stubs.yaml. Its files import each other relative to it. Required.

name

The module's name on a registry, as for name.

exclude

Directories left out of the module, relative to stubs.yaml.

deps

The modules the workspace's modules import, by name. stubs deps update resolves each at its default label and pins the exact commits, with every commit those depend on, in stubs.lock. A module of the workspace itself is never pinned: it's built from its files.

deps:
  - stubs.dev/acme/common
  - stubs.dev/googleapis/googleapis

policies

Registry policies whose rules stubs lint and stubs breaking check with, as well as the workspace's own lint and breaking: each by name, at its main label, or at a label or commit after a colon. stubs deps update pins each one's commit in stubs.lock, so everyone checks with the same rules until it's run again. The workspace's ignore, ignore_only and disallow_comment_ignores apply to a policy's rules too.

policies:
  - stubs.dev/acme/style:v1

lint

Which lint rules stubs lint checks, and their settings. Without it, the standard category.

lint:
  use: [standard, comments]
  except: [comment-field]
  ignore: [proto/vendor]
  ignore_only:
    package-version-suffix: [proto/legacy]
  enum_zero_value_suffix: _UNSPECIFIED

use

Categories and rules to check. Without it, standard. Rules and categories are named as the rule pages name them, in lower case with hyphens; Buf's spelling (FIELD_LOWER_SNAKE_CASE) works too.

except

Categories and rules left out of those use chose.

ignore

Files and directories no rule checks, relative to stubs.yaml.

ignore_only

For a rule or a category, the files and directories it doesn't check.

disallow_comment_ignores

true stops comments from excusing an element. Without it, a line // stubs:lint:ignore <rule> (or Buf's // buf:lint:ignore <RULE>) in the comment before an element excuses that element from that rule.

disable_builtin

true turns every rule off.

enum_zero_value_suffix

The suffix enum-zero-value-suffix asks of each enum's zero value. Defaults to _UNSPECIFIED.

service_suffix

The suffix service-suffix asks of each service's name. Defaults to Service.

rpc_allow_same_request_response

true lets an RPC use one message as both its request and its response.

rpc_allow_google_protobuf_empty_requests

true lets an RPC take google.protobuf.Empty.

rpc_allow_google_protobuf_empty_responses

true lets an RPC return google.protobuf.Empty.

breaking

Which breaking-change rules stubs breaking checks. Without it, the file category.

breaking:
  use: [file]
  except: [field-same-json-name]
  ignore: [proto/internal]
  ignore_unstable_packages: true

use, except, ignore and ignore_only

As in lint, for the breaking-change rules and categories.

disable_builtin

true turns every rule off.

ignore_unstable_packages

true leaves files in unstable packages, whose last part is a version like v1alpha1, v1beta1 or v1test, out of the comparison.