Skip to content

Compact single-message option syntax in proto#1

Merged
tomlinford merged 1 commit into
mainfrom
claude/compact-single-option-messages-011CUuBK7rpacDMVrdoGqydS
Nov 8, 2025
Merged

Compact single-message option syntax in proto#1
tomlinford merged 1 commit into
mainfrom
claude/compact-single-option-messages-011CUuBK7rpacDMVrdoGqydS

Conversation

@tomlinford
Copy link
Copy Markdown
Owner

Add support for compact dot notation syntax for field options with single-field nested messages. This makes option declarations more readable and concise.

Examples:

  • Before: [(buf.validate.field) = {int32: {gte: 2020}}]

  • After: [(buf.validate.field).int32.gte = 2020]

  • Before: [(validate.rules) = {string: {uuid: true}}]

  • After: [(validate.rules).string.uuid = true]

Implementation:

  • Add flattenSingleFieldPath() to recursively detect and flatten single-field nested maps into dot-separated paths
  • Update addShortOptions() to apply flattening to field options
  • Long options (option declarations) continue to use message literals
  • Add comprehensive regression tests

Changes:

  • proto_ast/ast.go: Add flattening logic in addShortOptions()
  • proto_ast/ast_test.go: Add tests for nested single-field cases
  • sroto_ir/example_test.go: Update expected output
  • README.md: Update examples to show new compact format
  • example/options_example.proto: Regenerate with compact format
  • Vendor google/protobuf protos needed for protoc validation

The compact format only applies to field options (inside []), not to long options which properly use message literal syntax:
option (google.api.http) = {get: "/users/{id}"};

Add support for compact dot notation syntax for field options with
single-field nested messages. This makes option declarations more
readable and concise.

Examples:
- Before: [(buf.validate.field) = {int32: {gte: 2020}}]
- After: [(buf.validate.field).int32.gte = 2020]

- Before: [(validate.rules) = {string: {uuid: true}}]
- After: [(validate.rules).string.uuid = true]

Implementation:
- Add flattenSingleFieldPath() to recursively detect and flatten
  single-field nested maps into dot-separated paths
- Update addShortOptions() to apply flattening to field options
- Long options (option declarations) continue to use message literals
- Add comprehensive regression tests

The compact format only applies to field options (inside []), not to
long options which properly use message literal syntax:
  option (google.api.http) = {get: "/users/{id}"};

Changes:
- proto_ast/ast.go: Add flattening logic in addShortOptions()
- proto_ast/ast_test.go: Add tests for nested single-field cases
- sroto_ir/example_test.go: Update expected output
- README.md: Update examples to show new compact format
- example/options_example.proto: Regenerate with compact format
- Vendor minimal set of google/protobuf protos for protoc validation
- Fix golangci-lint errcheck warnings
- Update CI: Go 1.22, protoc 3.20.0, golangci-lint latest
@tomlinford tomlinford force-pushed the claude/compact-single-option-messages-011CUuBK7rpacDMVrdoGqydS branch from 207f1bc to 7969cd8 Compare November 8, 2025 01:39
@tomlinford tomlinford merged commit 44652cb into main Nov 8, 2025
2 checks passed
@tomlinford tomlinford deleted the claude/compact-single-option-messages-011CUuBK7rpacDMVrdoGqydS branch November 10, 2025 16:17
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.

2 participants