Skip to content

fix: use package:protobuf imports for wellknown types#36

Open
xander1421 wants to merge 1 commit into
connectrpc:mainfrom
xander1421:fix/wellknown-types-package-imports
Open

fix: use package:protobuf imports for wellknown types#36
xander1421 wants to merge 1 commit into
connectrpc:mainfrom
xander1421:fix/wellknown-types-package-imports

Conversation

@xander1421
Copy link
Copy Markdown

@xander1421 xander1421 commented Jan 11, 2026

Fixes #33

Problem

When using connect-dart with protocolbuffers/dart plugin, wellknown types (google.protobuf.*) are provided by package:protobuf/well_known_types/ rather than being generated locally.

Previously, connect-dart always generated relative imports for these types, causing type mismatches at runtime.

Solution

Add a new plugin option wellknown_from_package (default: true) that controls how wellknown types are imported:

  • wellknown_from_package=true (default): imports from package:protobuf/well_known_types/
  • wellknown_from_package=false: generates relative imports (for custom setups)

Also updates protobuf constraint to >=4.0.0 <7.0.0 for protobuf 6.x support.

Usage

# buf.gen.yaml - default behavior (package imports)
- local: path/to/protoc-gen-connect-dart
  out: lib/gen

# Or explicitly disable for custom setups
- local: path/to/protoc-gen-connect-dart
  out: lib/gen
  opt: wellknown_from_package=false

Supported wellknown types

Any, Duration, Empty, FieldMask, Struct, Value, ListValue, NullValue, Timestamp, and all wrapper types.

Add plugin option to control how wellknown types (google.protobuf.*)
are imported. When enabled (default: true), imports from
package:protobuf/well_known_types/ instead of relative paths.

This matches the default behavior of protocolbuffers/dart plugin
and prevents type mismatches when using both plugins together.

Options:
- wellknown_from_package=true (default): use package:protobuf imports
- wellknown_from_package=false: use relative imports (for custom setups)

Also updates protobuf constraint to >=4.0.0 <7.0.0 for protobuf 6.x.

Fixes connectrpc#33
@xander1421 xander1421 force-pushed the fix/wellknown-types-package-imports branch from 10b6d16 to 3ec5734 Compare January 11, 2026 04:47
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add support for protobuf v5

1 participant