Stubs

Reference

stubs.gen.yaml and buf.gen.yaml

stubs generate reads stubs.gen.yaml: the plugins to run, the inputs to run them on, and options to set for each language. buf.gen.yaml has the same format; stubs reads it when you name it, as in stubs generate --template buf.gen.yaml.

version: v2
clean: true
managed:
  enabled: true
  override:
    - file_option: go_package_prefix
      value: github.com/acme/payments/gen/go
plugins:
  - remote: stubs.dev/stubs/protobuf-go:v1.36.12
    out: gen/go
    opt: paths=source_relative
  - local: protoc-gen-es
    out: gen/es
    include_imports: true
inputs:
  - directory: proto

version

The format: v2. stubs also reads v1 and v1beta1 files; stubs config migrate rewrites them as v2. Required.

clean

true deletes each plugin's out (a directory, zip or jar) before generating, so files from types you've removed don't linger. Defaults to false.

plugins

The plugins to run, in order. Each entry names exactly one of remote, local or protoc_builtin, and an out.

KeyWhat it doesDefault
remoteA plugin Stubs runs for you: stubs.dev/owner/name, with :version to pin one (see Remote plugins).—
revisionWith remote, a revision of that version. Usually left out, for the latest.latest
localA plugin program: its name on your PATH, its path, or a list of the program and its arguments.—
protoc_builtinOne of protoc's own generators, without protoc-gen-: java, python, cpp …—
protoc_pathWith protoc_builtin, the protoc to run, or a list of it and its arguments.protoc on your PATH
outWhere the files go: a directory, or a .zip or .jar. Created if it's missing. Required.—
optOptions for the plugin: one string, or a list.none
include_importstrue also generates the files your inputs import, except the well-known types.false
include_wktWith include_imports, true generates the well-known types too.false
strategyFor local and protoc_builtin: directory runs the plugin once per directory, all once for everything.directory
typesGenerates only these types (fully qualified, as acme.payments.v1.Payment) and what they need.all
exclude_typesLeaves these types out.none

opt

Options are the plugin's own: paths=source_relative for the Go plugin, target=ts for protobuf-es and so on.

out

Relative to the directory stubs generate runs in, unless you pass -o.

include_imports

Generates every file the inputs import, so the output stands on its own. A dependency's files come from the version stubs.lock pins.

include_wkt

The well-known types (google/protobuf/*.proto) usually come with each language's Protobuf runtime, so they're left out unless you ask.

strategy

Most plugins work either way. all is for plugins that need to see every file at once.

types

Narrows generation to what you use from a large module.

Exclude types

exclude_types takes types out of generation, on a plugin or an input: fully-qualified names of messages, enums or services, and everything inside them.

inputs:
  - module: stubs.dev/acme/payments
    exclude_types:
      - acme.payments.v1.InternalService

managed

Managed mode sets file and field options for you, so .proto files don't need a go_package, java_package and the like for every language. It changes the options as they're generated, never your files.

managed:
  enabled: true
  disable:
    - module: stubs.dev/acme/common
  override:
    - file_option: java_package_prefix
      value: com.acme
    - field_option: jstype
      value: JS_STRING
      field: acme.payments.v1.Payment.amount_minor

enabled

true turns managed mode on. The other keys only apply when it's on. Defaults to false.

disable

Rules for what managed mode leaves alone. Each can name a file_option or field_option, and narrow it to a module, a path within it, or a field (fully qualified, for field options). A rule with only module leaves that module's files alone entirely.

override

Rules that set an option's value. Each names exactly one file_option or field_option and its value, and can be narrowed by module, path or field as in disable. Later rules win over earlier ones.

The file options are java_package, java_package_prefix, java_package_suffix, java_outer_classname, java_multiple_files, optimize_for, go_package, go_package_prefix, cc_enable_arenas, objc_class_prefix, csharp_namespace, csharp_namespace_prefix, php_namespace, php_metadata_namespace, php_metadata_namespace_suffix, ruby_package, ruby_package_suffix and swift_prefix. The field option is jstype.

module

A module's name, as in stubs.dev/acme/common, for rules that apply to it alone.

inputs

What to generate from. Without inputs, stubs generate uses the workspace in the current directory, or the input you pass it. Each entry names one source:

KeyThe input
directoryA local directory: a workspace or module.
moduleA module on a registry, as stubs.dev/acme/payments or stubs.dev/acme/payments:v1.
proto_fileOne .proto file, with its workspace. include_package_files: true adds the other files of its package.
git_repoA Git repository's URL or path, at a branch, tag, commit or ref (depth and recurse_submodules too).
tarballA .tar or .tar.gz archive's path or URL.
zip_archiveA .zip archive's path or URL.
binary_image, json_image, text_image, yaml_imageAn image stubs build wrote.

Any input can be narrowed with types, exclude_types, paths and exclude_paths.

directory

Relative to where stubs generate runs.

proto_file

Generates for that file alone, built with the rest of its workspace.

git_repo

stubs clones it as git would, with your Git credentials.

tarball

A .tar, .tar.gz or .tgz archive, from a path or an https:// URL.

zip_archive

A .zip archive, from a path or an https:// URL.

subdir

For a repository or an archive: the directory inside it to use as the input.

strip_components

For an archive: how many leading directories to drop from its paths, as tar --strip-components does.

compression

For a tarball: none, gzip or zstd, when the file's name doesn't say.