Skip to content

protogen(Protobuf-Editions): support Protobuf Edition 2023 and 2024 #369

@wenchy

Description

@wenchy

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:

tableau/options/options.go

Lines 174 to 178 in bc70718

type ProtoOutputOption struct {
// Specify subdir (relative to output dir) for generated proto files.
//
// Default: "".
Subdir string `yaml:"subdir"`

  1. Protobuf Editions: add new option edition.
  2. Feature Settings for Editions, add extend fileOptions ability 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

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions