Skip to content

Commit 4e4d6b9

Browse files
authored
feat(gapic-generator): Add clarifying notes to oneof members in proto_docs (#1142)
1 parent 8b45c4a commit 4e4d6b9

File tree

28 files changed

+298
-1
lines changed

28 files changed

+298
-1
lines changed

gapic-generator/lib/gapic/schema/loader.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -190,6 +190,7 @@ def load_message registry, descriptor, address, docs, path
190190
fields = (descriptor.field || []).each_with_index.map do |f, i|
191191
load_field registry, f, address, docs, path + [2, i]
192192
end
193+
fields.each { |field| field.populate_oneof_siblings! fields }
193194
extensions = (descriptor.extension || []).each_with_index.map do |e, i|
194195
load_field registry, e, address, docs, path + [6, i]
195196
end

gapic-generator/lib/gapic/schema/wrappers.rb

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -761,6 +761,7 @@ def initialize descriptor, address, docs, message, enum
761761
super descriptor, address, docs
762762
@message = message
763763
@enum = enum
764+
@oneof_siblings = nil
764765
end
765766

766767
OPTION_EXTENSION_NAMES = {
@@ -968,6 +969,30 @@ def is_deprecated?
968969
option_named "deprecated"
969970
end
970971

972+
# @private
973+
# Populate the oneof_siblings array. This is nil if this field is not part
974+
# of a oneof, otherwise it's an array of fields that are members of the
975+
# oneof, with the first element being the current field.
976+
def populate_oneof_siblings! all_fields
977+
return unless oneof?
978+
@oneof_siblings = [self]
979+
all_fields.each do |field|
980+
@oneof_siblings << field if field != self && field.oneof? && field.oneof_index == oneof_index
981+
end
982+
end
983+
984+
# @private
985+
# Override this to add a note related to oneofs being mutually exclusive.
986+
def docs_leading_comments disable_xrefs: false, transport: nil
987+
str = super
988+
return str unless @oneof_siblings && @oneof_siblings.size > 1
989+
siblings = @oneof_siblings.map { |field| "`#{field.name}`" }.join ", "
990+
note = "Note: The following fields are mutually exclusive: " \
991+
"#{siblings}. If a field in that set is populated, all other " \
992+
"fields in the set will automatically be cleared."
993+
str ? "#{str.strip}\n\n#{note}" : note
994+
end
995+
971996
# @!method name
972997
# @return [String] the unqualified name of the field.
973998
# @!method number

gapic-generator/test/gapic/presenters/field_presenter_test.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -136,7 +136,11 @@ def test_typical_garbage_oneof_enum_field
136136
assert_equal "oneof_multiple_enum", fp.name
137137
assert_equal "@!attribute [rw] oneof_multiple_enum", fp.doc_attribute_type
138138
assert_equal "::So::Much::Trash::GarbageEnum", fp.output_doc_types
139-
assert_equal fp.doc_description, "This is a multiple-field oneof's enum field.\n"
139+
expected_description = "This is a multiple-field oneof's enum field.\n\n" \
140+
"Note: The following fields are mutually exclusive: `oneof_multiple_enum`, `oneof_multiple_message`, " \
141+
"`oneof_multiple_bytes`, `oneof_multiple_double`. If a field in that set is populated, all other fields in " \
142+
"the set will automatically be cleared."
143+
assert_equal expected_description, fp.doc_description
140144
assert_equal ":DEFAULT_GARBAGE", fp.default_value
141145
assert_equal ".endless.trash.forever.GarbageEnum", fp.type_name
142146
assert_equal "::So::Much::Trash::GarbageEnum", fp.type_name_full

shared/output/ads/googleads/proto_docs/google/ads/googleads/v15/resources/campaign.rb

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -267,60 +267,88 @@ module Resources
267267
# @!attribute [rw] bidding_strategy
268268
# @return [::String]
269269
# Portfolio bidding strategy used by campaign.
270+
#
271+
# Note: The following fields are mutually exclusive: `bidding_strategy`, `commission`, `manual_cpa`, `manual_cpc`, `manual_cpm`, `manual_cpv`, `maximize_conversions`, `maximize_conversion_value`, `target_cpa`, `target_impression_share`, `target_roas`, `target_spend`, `percent_cpc`, `target_cpm`. If a field in that set is populated, all other fields in the set will automatically be cleared.
270272
# @!attribute [rw] commission
271273
# @return [::Google::Ads::GoogleAds::V15::Common::Commission]
272274
# Commission is an automatic bidding strategy in which the advertiser pays
273275
# a certain portion of the conversion value.
276+
#
277+
# Note: The following fields are mutually exclusive: `commission`, `bidding_strategy`, `manual_cpa`, `manual_cpc`, `manual_cpm`, `manual_cpv`, `maximize_conversions`, `maximize_conversion_value`, `target_cpa`, `target_impression_share`, `target_roas`, `target_spend`, `percent_cpc`, `target_cpm`. If a field in that set is populated, all other fields in the set will automatically be cleared.
274278
# @!attribute [rw] manual_cpa
275279
# @return [::Google::Ads::GoogleAds::V15::Common::ManualCpa]
276280
# Standard Manual CPA bidding strategy.
277281
# Manual bidding strategy that allows advertiser to set the bid per
278282
# advertiser-specified action. Supported only for Local Services campaigns.
283+
#
284+
# Note: The following fields are mutually exclusive: `manual_cpa`, `bidding_strategy`, `commission`, `manual_cpc`, `manual_cpm`, `manual_cpv`, `maximize_conversions`, `maximize_conversion_value`, `target_cpa`, `target_impression_share`, `target_roas`, `target_spend`, `percent_cpc`, `target_cpm`. If a field in that set is populated, all other fields in the set will automatically be cleared.
279285
# @!attribute [rw] manual_cpc
280286
# @return [::Google::Ads::GoogleAds::V15::Common::ManualCpc]
281287
# Standard Manual CPC bidding strategy.
282288
# Manual click-based bidding where user pays per click.
289+
#
290+
# Note: The following fields are mutually exclusive: `manual_cpc`, `bidding_strategy`, `commission`, `manual_cpa`, `manual_cpm`, `manual_cpv`, `maximize_conversions`, `maximize_conversion_value`, `target_cpa`, `target_impression_share`, `target_roas`, `target_spend`, `percent_cpc`, `target_cpm`. If a field in that set is populated, all other fields in the set will automatically be cleared.
283291
# @!attribute [rw] manual_cpm
284292
# @return [::Google::Ads::GoogleAds::V15::Common::ManualCpm]
285293
# Standard Manual CPM bidding strategy.
286294
# Manual impression-based bidding where user pays per thousand
287295
# impressions.
296+
#
297+
# Note: The following fields are mutually exclusive: `manual_cpm`, `bidding_strategy`, `commission`, `manual_cpa`, `manual_cpc`, `manual_cpv`, `maximize_conversions`, `maximize_conversion_value`, `target_cpa`, `target_impression_share`, `target_roas`, `target_spend`, `percent_cpc`, `target_cpm`. If a field in that set is populated, all other fields in the set will automatically be cleared.
288298
# @!attribute [rw] manual_cpv
289299
# @return [::Google::Ads::GoogleAds::V15::Common::ManualCpv]
290300
# A bidding strategy that pays a configurable amount per video view.
301+
#
302+
# Note: The following fields are mutually exclusive: `manual_cpv`, `bidding_strategy`, `commission`, `manual_cpa`, `manual_cpc`, `manual_cpm`, `maximize_conversions`, `maximize_conversion_value`, `target_cpa`, `target_impression_share`, `target_roas`, `target_spend`, `percent_cpc`, `target_cpm`. If a field in that set is populated, all other fields in the set will automatically be cleared.
291303
# @!attribute [rw] maximize_conversions
292304
# @return [::Google::Ads::GoogleAds::V15::Common::MaximizeConversions]
293305
# Standard Maximize Conversions bidding strategy that automatically
294306
# maximizes number of conversions while spending your budget.
307+
#
308+
# Note: The following fields are mutually exclusive: `maximize_conversions`, `bidding_strategy`, `commission`, `manual_cpa`, `manual_cpc`, `manual_cpm`, `manual_cpv`, `maximize_conversion_value`, `target_cpa`, `target_impression_share`, `target_roas`, `target_spend`, `percent_cpc`, `target_cpm`. If a field in that set is populated, all other fields in the set will automatically be cleared.
295309
# @!attribute [rw] maximize_conversion_value
296310
# @return [::Google::Ads::GoogleAds::V15::Common::MaximizeConversionValue]
297311
# Standard Maximize Conversion Value bidding strategy that automatically
298312
# sets bids to maximize revenue while spending your budget.
313+
#
314+
# Note: The following fields are mutually exclusive: `maximize_conversion_value`, `bidding_strategy`, `commission`, `manual_cpa`, `manual_cpc`, `manual_cpm`, `manual_cpv`, `maximize_conversions`, `target_cpa`, `target_impression_share`, `target_roas`, `target_spend`, `percent_cpc`, `target_cpm`. If a field in that set is populated, all other fields in the set will automatically be cleared.
299315
# @!attribute [rw] target_cpa
300316
# @return [::Google::Ads::GoogleAds::V15::Common::TargetCpa]
301317
# Standard Target CPA bidding strategy that automatically sets bids to
302318
# help get as many conversions as possible at the target
303319
# cost-per-acquisition (CPA) you set.
320+
#
321+
# Note: The following fields are mutually exclusive: `target_cpa`, `bidding_strategy`, `commission`, `manual_cpa`, `manual_cpc`, `manual_cpm`, `manual_cpv`, `maximize_conversions`, `maximize_conversion_value`, `target_impression_share`, `target_roas`, `target_spend`, `percent_cpc`, `target_cpm`. If a field in that set is populated, all other fields in the set will automatically be cleared.
304322
# @!attribute [rw] target_impression_share
305323
# @return [::Google::Ads::GoogleAds::V15::Common::TargetImpressionShare]
306324
# Target Impression Share bidding strategy. An automated bidding strategy
307325
# that sets bids to achieve a chosen percentage of impressions.
326+
#
327+
# Note: The following fields are mutually exclusive: `target_impression_share`, `bidding_strategy`, `commission`, `manual_cpa`, `manual_cpc`, `manual_cpm`, `manual_cpv`, `maximize_conversions`, `maximize_conversion_value`, `target_cpa`, `target_roas`, `target_spend`, `percent_cpc`, `target_cpm`. If a field in that set is populated, all other fields in the set will automatically be cleared.
308328
# @!attribute [rw] target_roas
309329
# @return [::Google::Ads::GoogleAds::V15::Common::TargetRoas]
310330
# Standard Target ROAS bidding strategy that automatically maximizes
311331
# revenue while averaging a specific target return on ad spend (ROAS).
332+
#
333+
# Note: The following fields are mutually exclusive: `target_roas`, `bidding_strategy`, `commission`, `manual_cpa`, `manual_cpc`, `manual_cpm`, `manual_cpv`, `maximize_conversions`, `maximize_conversion_value`, `target_cpa`, `target_impression_share`, `target_spend`, `percent_cpc`, `target_cpm`. If a field in that set is populated, all other fields in the set will automatically be cleared.
312334
# @!attribute [rw] target_spend
313335
# @return [::Google::Ads::GoogleAds::V15::Common::TargetSpend]
314336
# Standard Target Spend bidding strategy that automatically sets your bids
315337
# to help get as many clicks as possible within your budget.
338+
#
339+
# Note: The following fields are mutually exclusive: `target_spend`, `bidding_strategy`, `commission`, `manual_cpa`, `manual_cpc`, `manual_cpm`, `manual_cpv`, `maximize_conversions`, `maximize_conversion_value`, `target_cpa`, `target_impression_share`, `target_roas`, `percent_cpc`, `target_cpm`. If a field in that set is populated, all other fields in the set will automatically be cleared.
316340
# @!attribute [rw] percent_cpc
317341
# @return [::Google::Ads::GoogleAds::V15::Common::PercentCpc]
318342
# Standard Percent Cpc bidding strategy where bids are a fraction of the
319343
# advertised price for some good or service.
344+
#
345+
# Note: The following fields are mutually exclusive: `percent_cpc`, `bidding_strategy`, `commission`, `manual_cpa`, `manual_cpc`, `manual_cpm`, `manual_cpv`, `maximize_conversions`, `maximize_conversion_value`, `target_cpa`, `target_impression_share`, `target_roas`, `target_spend`, `target_cpm`. If a field in that set is populated, all other fields in the set will automatically be cleared.
320346
# @!attribute [rw] target_cpm
321347
# @return [::Google::Ads::GoogleAds::V15::Common::TargetCpm]
322348
# A bidding strategy that automatically optimizes cost per thousand
323349
# impressions.
350+
#
351+
# Note: The following fields are mutually exclusive: `target_cpm`, `bidding_strategy`, `commission`, `manual_cpa`, `manual_cpc`, `manual_cpm`, `manual_cpv`, `maximize_conversions`, `maximize_conversion_value`, `target_cpa`, `target_impression_share`, `target_roas`, `target_spend`, `percent_cpc`. If a field in that set is populated, all other fields in the set will automatically be cleared.
324352
class Campaign
325353
include ::Google::Protobuf::MessageExts
326354
extend ::Google::Protobuf::MessageExts::ClassMethods

shared/output/ads/googleads/proto_docs/google/ads/googleads/v15/services/campaign_service.rb

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -56,16 +56,22 @@ class MutateCampaignsRequest
5656
# @!attribute [rw] create
5757
# @return [::Google::Ads::GoogleAds::V15::Resources::Campaign]
5858
# Create operation: No resource name is expected for the new campaign.
59+
#
60+
# Note: The following fields are mutually exclusive: `create`, `update`, `remove`. If a field in that set is populated, all other fields in the set will automatically be cleared.
5961
# @!attribute [rw] update
6062
# @return [::Google::Ads::GoogleAds::V15::Resources::Campaign]
6163
# Update operation: The campaign is expected to have a valid
6264
# resource name.
65+
#
66+
# Note: The following fields are mutually exclusive: `update`, `create`, `remove`. If a field in that set is populated, all other fields in the set will automatically be cleared.
6367
# @!attribute [rw] remove
6468
# @return [::String]
6569
# Remove operation: A resource name for the removed campaign is
6670
# expected, in this format:
6771
#
6872
# `customers/{customer_id}/campaigns/{campaign_id}`
73+
#
74+
# Note: The following fields are mutually exclusive: `remove`, `create`, `update`. If a field in that set is populated, all other fields in the set will automatically be cleared.
6975
class CampaignOperation
7076
include ::Google::Protobuf::MessageExts
7177
extend ::Google::Protobuf::MessageExts::ClassMethods

shared/output/cloud/grafeas_v1/proto_docs/google/protobuf/struct.rb

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -53,21 +53,33 @@ class FieldsEntry
5353
# @!attribute [rw] null_value
5454
# @return [::Google::Protobuf::NullValue]
5555
# Represents a null value.
56+
#
57+
# Note: The following fields are mutually exclusive: `null_value`, `number_value`, `string_value`, `bool_value`, `struct_value`, `list_value`. If a field in that set is populated, all other fields in the set will automatically be cleared.
5658
# @!attribute [rw] number_value
5759
# @return [::Float]
5860
# Represents a double value.
61+
#
62+
# Note: The following fields are mutually exclusive: `number_value`, `null_value`, `string_value`, `bool_value`, `struct_value`, `list_value`. If a field in that set is populated, all other fields in the set will automatically be cleared.
5963
# @!attribute [rw] string_value
6064
# @return [::String]
6165
# Represents a string value.
66+
#
67+
# Note: The following fields are mutually exclusive: `string_value`, `null_value`, `number_value`, `bool_value`, `struct_value`, `list_value`. If a field in that set is populated, all other fields in the set will automatically be cleared.
6268
# @!attribute [rw] bool_value
6369
# @return [::Boolean]
6470
# Represents a boolean value.
71+
#
72+
# Note: The following fields are mutually exclusive: `bool_value`, `null_value`, `number_value`, `string_value`, `struct_value`, `list_value`. If a field in that set is populated, all other fields in the set will automatically be cleared.
6573
# @!attribute [rw] struct_value
6674
# @return [::Google::Protobuf::Struct]
6775
# Represents a structured value.
76+
#
77+
# Note: The following fields are mutually exclusive: `struct_value`, `null_value`, `number_value`, `string_value`, `bool_value`, `list_value`. If a field in that set is populated, all other fields in the set will automatically be cleared.
6878
# @!attribute [rw] list_value
6979
# @return [::Google::Protobuf::ListValue]
7080
# Represents a repeated `Value`.
81+
#
82+
# Note: The following fields are mutually exclusive: `list_value`, `null_value`, `number_value`, `string_value`, `bool_value`, `struct_value`. If a field in that set is populated, all other fields in the set will automatically be cleared.
7183
class Value
7284
include ::Google::Protobuf::MessageExts
7385
extend ::Google::Protobuf::MessageExts::ClassMethods

0 commit comments

Comments
 (0)