Skip to content

Reference external proto enum types#1286

Open
jwils wants to merge 2 commits into
joshuaw/protobuf-schema-generationfrom
joshuaw/protobuf-external-types
Open

Reference external proto enum types#1286
jwils wants to merge 2 commits into
joshuaw/protobuf-schema-generationfrom
joshuaw/protobuf-external-types

Conversation

@jwils

@jwils jwils commented Jul 1, 2026

Copy link
Copy Markdown
Collaborator

Why

Some schemas already have canonical protobuf enum definitions, and generating duplicate enums in schema.proto makes Java consumers deal with parallel types.

What

  • Add proto_external_types to import and reference existing proto enum types
  • Validate external enum references against exactly one option-free proto_enum_mappings source
  • Preserve generated local definitions for transformed, curated, multi-source, or non-enum types
  • Document the enum-only API and add focused generator/error coverage

Risk Assessment

Low — this only affects the unreleased elasticgraph-protobuf extension from #1080, and external references are opt-in with validation.

References

jwils added 2 commits July 1, 2026 15:36
Adds `elasticgraph-protobuf`, a self-contained schema-definition extension
that generates Protocol Buffers schema artifacts from an ElasticGraph schema.

Running `schema_artifacts:dump` emits:

- `schema.proto` — the generated Protobuf schema for the indexed types
- `proto_field_numbers.yaml` — a sidecar that reserves field numbers so they
  stay stable as the schema evolves (including across field renames)

Capabilities:

- Maps built-in ElasticGraph scalars to proto types, with `proto_field` to
  configure custom scalars.
- Generates messages for object/interface/union types and enums (with a
  zero-valued `*_UNSPECIFIED` entry), escaping proto reserved words and
  wrapping nested lists so the output stays valid.
- `proto_enum_mappings` reuses enum values already maintained elsewhere.

The generator emits `proto3` by default and can emit `proto2` via
`syntax: :proto2` (which labels every field `optional`/`repeated`). Arbitrary
file-level headers (e.g. `option` declarations) can be injected verbatim via
`headers:`, so language-specific options can be set without baking any
particular convention into the gem.
Some schemas already have canonical protobuf enum definitions, and generating
duplicate enums in `schema.proto` makes consumers deal with parallel types.

- Add `proto_external_types` to import and reference existing proto enum types
- Validate external enum references against exactly one option-free
  `proto_enum_mappings` source
- Render `import` statements for referenced proto files
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.

1 participant