-
Notifications
You must be signed in to change notification settings - Fork 8
protogen(Protobuf-Editions): support Protobuf Edition 2023 and 2024 #369
Copy link
Copy link
Closed
Description
Goal
Give users the ability to customize the generated proto file edition and file options, and make use of the protobuf new features.
Solution
Extend ProtoOutputOption fields:
Lines 174 to 178 in bc70718
| type ProtoOutputOption struct { | |
| // Specify subdir (relative to output dir) for generated proto files. | |
| // | |
| // Default: "". | |
| Subdir string `yaml:"subdir"` |
- Protobuf Editions: add new option
edition. - Feature Settings for Editions, add extend
fileOptionsability at file-level. Note that if the give keys has prefix "features", then output the string value without quote? or just use the raw yaml value (breaking change).
For example
// Output options for generating proto files.
type ProtoOutputOption struct {
// Specify the generated protobuf file's edition.
// See https://protobuf.dev/editions/overview/.
//
// Default: "".
Edition string `yaml:"edition"`
// Specify options (including features) at file level.
// Examples: "go_package", "csharp_namespace", "features.(pb.go).strip_enum_prefix" etc.
//
// References
// - https://protobuf.dev/programming-guides/proto3/#options
// - https://protobuf.dev/editions/features/
//
// Default: nil.
FileOptions map[string]string `yaml:"fileOptions"`
// ...
}Examples
You can set the strip_enum_prefix feature in edition 2024 (or newer) .proto files:
edition = "2024";
import "google/protobuf/go_features.proto";
option features.(pb.go).strip_enum_prefix = STRIP_ENUM_PREFIX_STRIP;
enum Strip {
STRIP_ZERO = 0;
STRIP_ONE = 1;
}References
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels