From 2656d17b6fe50b872631e41dd49974b980ac3b8d Mon Sep 17 00:00:00 2001 From: godcong Date: Fri, 20 Dec 2024 21:50:08 +0800 Subject: [PATCH] feat(runtime): add new Go-specific API level feature - 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 --- third_party/google/api/client.proto | 10 ++++ third_party/google/protobuf/api.proto | 2 +- .../google/protobuf/cpp_features.proto | 17 +++++- third_party/google/protobuf/descriptor.proto | 21 +++++-- third_party/google/protobuf/go_features.proto | 57 +++++++++++++++++++ .../google/protobuf/java_features.proto | 6 +- .../rpc/context/attribute_context.proto | 3 +- third_party/google/rpc/error_details.proto | 19 ++++++- 8 files changed, 119 insertions(+), 16 deletions(-) create mode 100644 third_party/google/protobuf/go_features.proto diff --git a/third_party/google/api/client.proto b/third_party/google/api/client.proto index 6003be5..7e3e66e 100644 --- a/third_party/google/api/client.proto +++ b/third_party/google/api/client.proto @@ -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 renamed_services = 2; } // Describes the generator configuration for a method. diff --git a/third_party/google/protobuf/api.proto b/third_party/google/protobuf/api.proto index 4222351..afc9cc1 100644 --- a/third_party/google/protobuf/api.proto +++ b/third_party/google/protobuf/api.proto @@ -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 { diff --git a/third_party/google/protobuf/cpp_features.proto b/third_party/google/protobuf/cpp_features.proto index f3d6704..a0d1929 100644 --- a/third_party/google/protobuf/cpp_features.proto +++ b/third_party/google/protobuf/cpp_features.proto @@ -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" } @@ -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" } + ]; } diff --git a/third_party/google/protobuf/descriptor.proto b/third_party/google/protobuf/descriptor.proto index dfabac4..6011f72 100644 --- a/third_party/google/protobuf/descriptor.proto +++ b/third_party/google/protobuf/descriptor.proto @@ -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. @@ -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; @@ -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; @@ -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; @@ -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 diff --git a/third_party/google/protobuf/go_features.proto b/third_party/google/protobuf/go_features.proto new file mode 100644 index 0000000..ceb3a13 --- /dev/null +++ b/third_party/google/protobuf/go_features.proto @@ -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" } + ]; +} diff --git a/third_party/google/protobuf/java_features.proto b/third_party/google/protobuf/java_features.proto index bbf441c..1c6dbdb 100644 --- a/third_party/google/protobuf/java_features.proto +++ b/third_party/google/protobuf/java_features.proto @@ -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" } diff --git a/third_party/google/rpc/context/attribute_context.proto b/third_party/google/rpc/context/attribute_context.proto index d6871eb..353b28a 100644 --- a/third_party/google/rpc/context/attribute_context.proto +++ b/third_party/google/rpc/context/attribute_context.proto @@ -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 annotations = 6; // Mutable. The display name set by clients. Must be <= 63 characters. diff --git a/third_party/google/rpc/error_details.proto b/third_party/google/rpc/error_details.proto index c06afd4..776a9d3 100644 --- a/third_party/google/rpc/error_details.proto +++ b/third_party/google/rpc/error_details.proto @@ -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 metadata = 3; } @@ -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.