Skip to content

Commit

Permalink
feat(runtime): add new Go-specific API level feature
Browse files Browse the repository at this point in the history
- Introduce new GoFeatures API level setting for protobuf
- Add renamed_services map to GoSettings for service name customization
- Update enum deprecation warnings and improve documentation links
- Refactor error_details.proto to enhance field-level error handling
  • Loading branch information
godcong committed Dec 20, 2024
1 parent 7630008 commit 2656d17
Show file tree
Hide file tree
Showing 8 changed files with 119 additions and 16 deletions.
10 changes: 10 additions & 0 deletions third_party/google/api/client.proto
Original file line number Diff line number Diff line change
Expand Up @@ -342,6 +342,16 @@ message RubySettings {
message GoSettings {
// Some settings.
CommonLanguageSettings common = 1;

// Map of service names to renamed services. Keys are the package relative
// service names and values are the name to be used for the service client
// and call options.
//
// publishing:
// go_settings:
// renamed_services:
// Publisher: TopicAdmin
map<string, string> renamed_services = 2;
}

// Describes the generator configuration for a method.
Expand Down
2 changes: 1 addition & 1 deletion third_party/google/protobuf/api.proto
Original file line number Diff line number Diff line change
Expand Up @@ -166,7 +166,7 @@ message Method {
// The mixin construct implies that all methods in `AccessControl` are
// also declared with same name and request/response types in
// `Storage`. A documentation generator or annotation processor will
// see the effective `Storage.GetAcl` method after inherting
// see the effective `Storage.GetAcl` method after inheriting
// documentation and annotations as follows:
//
// service Storage {
Expand Down
17 changes: 14 additions & 3 deletions third_party/google/protobuf/cpp_features.proto
Original file line number Diff line number Diff line change
Expand Up @@ -27,10 +27,10 @@ message CppFeatures {
feature_support = {
edition_introduced: EDITION_2023,
edition_deprecated: EDITION_2023,
deprecation_warning: "The legacy closed enum treatment in C++ is "
deprecation_warning: "The legacy closed enum behavior in C++ is "
"deprecated and is scheduled to be removed in "
"edition 2025. Mark enum type on the enum "
"definitions themselves rather than on fields.",
"edition 2025. See http://protobuf.dev/programming-guides/enum/#cpp for "
"more information",
},
edition_defaults = { edition: EDITION_LEGACY, value: "true" },
edition_defaults = { edition: EDITION_PROTO3, value: "false" }
Expand All @@ -53,4 +53,15 @@ message CppFeatures {
edition_defaults = { edition: EDITION_LEGACY, value: "STRING" },
edition_defaults = { edition: EDITION_2024, value: "VIEW" }
];

optional bool enum_name_uses_string_view = 3 [
retention = RETENTION_SOURCE,
targets = TARGET_TYPE_ENUM,
targets = TARGET_TYPE_FILE,
feature_support = {
edition_introduced: EDITION_2024,
},
edition_defaults = { edition: EDITION_LEGACY, value: "false" },
edition_defaults = { edition: EDITION_2024, value: "true" }
];
}
21 changes: 16 additions & 5 deletions third_party/google/protobuf/descriptor.proto
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,13 @@ option optimize_for = SPEED;
// files it parses.
message FileDescriptorSet {
repeated FileDescriptorProto file = 1;

// Extensions for tooling.
extensions 536000000 [declaration = {
number: 536000000
type: ".buf.descriptor.v1.FileDescriptorSetExtension"
full_name: ".buf.descriptor.v1.buf_file_descriptor_set_extension"
}];
}

// The full set of known editions.
Expand All @@ -80,7 +87,7 @@ enum Edition {
EDITION_2024 = 1001;

// Placeholder editions for testing feature resolution. These should not be
// used or relyed on outside of tests.
// used or relied on outside of tests.
EDITION_1_TEST_ONLY = 1;
EDITION_2_TEST_ONLY = 2;
EDITION_99997_TEST_ONLY = 99997;
Expand Down Expand Up @@ -732,8 +739,6 @@ message FieldOptions {
optional bool debug_redact = 16 [default = false];

// If set to RETENTION_SOURCE, the option will be omitted from the binary.
// Note: as of January 2023, support for this is in progress and does not yet
// have an effect (b/264593489).
enum OptionRetention {
RETENTION_UNKNOWN = 0;
RETENTION_RUNTIME = 1;
Expand All @@ -744,8 +749,7 @@ message FieldOptions {

// This indicates the types of entities that the field may apply to when used
// as an option. If it is unset, then the field may be freely used as an
// option on any kind of entity. Note: as of January 2023, support for this is
// in progress and does not yet have an effect (b/264593489).
// option on any kind of entity.
enum OptionTargetType {
TARGET_TYPE_UNKNOWN = 0;
TARGET_TYPE_FILE = 1;
Expand Down Expand Up @@ -1255,6 +1259,13 @@ message SourceCodeInfo {
optional string trailing_comments = 4;
repeated string leading_detached_comments = 6;
}

// Extensions for tooling.
extensions 536000000 [declaration = {
number: 536000000
type: ".buf.descriptor.v1.SourceCodeInfoExtension"
full_name: ".buf.descriptor.v1.buf_source_code_info_extension"
}];
}

// Describes the relationship between generated code and its original source
Expand Down
57 changes: 57 additions & 0 deletions third_party/google/protobuf/go_features.proto
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
// Protocol Buffers - Google's data interchange format
// Copyright 2023 Google Inc. All rights reserved.
//
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file or at
// https://developers.google.com/open-source/licenses/bsd

syntax = "proto2";

package pb;

import "google/protobuf/descriptor.proto";

option go_package = "google.golang.org/protobuf/types/gofeaturespb";

extend google.protobuf.FeatureSet {
optional GoFeatures go = 1002;
}

message GoFeatures {
// Whether or not to generate the deprecated UnmarshalJSON method for enums.
optional bool legacy_unmarshal_json_enum = 1 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_ENUM,
targets = TARGET_TYPE_FILE,
feature_support = {
edition_introduced: EDITION_2023,
edition_deprecated: EDITION_2023,
deprecation_warning: "The legacy UnmarshalJSON API is deprecated and "
"will be removed in a future edition.",
},
edition_defaults = { edition: EDITION_LEGACY, value: "true" },
edition_defaults = { edition: EDITION_PROTO3, value: "false" }
];

enum APILevel {
// API_LEVEL_UNSPECIFIED results in selecting the OPEN API,
// but needs to be a separate value to distinguish between
// an explicitly set api level or a missing api level.
API_LEVEL_UNSPECIFIED = 0;
API_OPEN = 1;
API_HYBRID = 2;
API_OPAQUE = 3;
}

// One of OPEN, HYBRID or OPAQUE.
optional APILevel api_level = 2 [
retention = RETENTION_RUNTIME,
targets = TARGET_TYPE_MESSAGE,
targets = TARGET_TYPE_FILE,
feature_support = {
edition_introduced: EDITION_2023,
},
edition_defaults = { edition: EDITION_LEGACY, value: "API_LEVEL_UNSPECIFIED" },
edition_defaults = { edition: EDITION_2024, value: "API_OPAQUE" }
];
}
6 changes: 3 additions & 3 deletions third_party/google/protobuf/java_features.proto
Original file line number Diff line number Diff line change
Expand Up @@ -30,10 +30,10 @@ message JavaFeatures {
feature_support = {
edition_introduced: EDITION_2023,
edition_deprecated: EDITION_2023,
deprecation_warning: "The legacy closed enum treatment in Java is "
deprecation_warning: "The legacy closed enum behavior in Java is "
"deprecated and is scheduled to be removed in "
"edition 2025. Mark enum type on the enum "
"definitions themselves rather than on fields.",
"edition 2025. See http://protobuf.dev/programming-guides/enum/#java for "
"more information.",
},
edition_defaults = { edition: EDITION_LEGACY, value: "true" },
edition_defaults = { edition: EDITION_PROTO3, value: "false" }
Expand Down
3 changes: 2 additions & 1 deletion third_party/google/rpc/context/attribute_context.proto
Original file line number Diff line number Diff line change
Expand Up @@ -275,7 +275,8 @@ message AttributeContext {
// may be set by external tools to store and retrieve arbitrary metadata.
// They are not queryable and should be preserved when modifying objects.
//
// More info: https://kubernetes.io/docs/user-guide/annotations
// More info:
// https://kubernetes.io/docs/concepts/overview/working-with-objects/annotations/
map<string, string> annotations = 6;

// Mutable. The display name set by clients. Must be <= 63 characters.
Expand Down
19 changes: 16 additions & 3 deletions third_party/google/rpc/error_details.proto
Original file line number Diff line number Diff line change
Expand Up @@ -66,11 +66,12 @@ message ErrorInfo {

// Additional structured details about this error.
//
// Keys should match /[a-zA-Z0-9-_]/ and be limited to 64 characters in
// Keys must match a regular expression of `[a-z][a-zA-Z0-9-_]+` but should
// ideally be lowerCamelCase. Also, they must be limited to 64 characters in
// length. When identifying the current value of an exceeded limit, the units
// should be contained in the key, not the value. For example, rather than
// {"instanceLimit": "100/request"}, should be returned as,
// {"instanceLimitPerRequest": "100"}, if the client exceeds the number of
// `{"instanceLimit": "100/request"}`, should be returned as,
// `{"instanceLimitPerRequest": "100"}`, if the client exceeds the number of
// instances that can be created in a single (batch) request.
map<string, string> metadata = 3;
}
Expand Down Expand Up @@ -211,6 +212,18 @@ message BadRequest {

// A description of why the request element is bad.
string description = 2;

// The reason of the field-level error. This is a constant value that
// identifies the proximate cause of the field-level error. It should
// uniquely identify the type of the FieldViolation within the scope of the
// google.rpc.ErrorInfo.domain. This should be at most 63
// characters and match a regular expression of `[A-Z][A-Z0-9_]+[A-Z0-9]`,
// which represents UPPER_SNAKE_CASE.
string reason = 3;

// Provides a localized error message for field-level errors that is safe to
// return to the API consumer.
LocalizedMessage localized_message = 4;
}

// Describes all violations in a client request.
Expand Down

0 comments on commit 2656d17

Please sign in to comment.