Skip to content

Commit 8546394

Browse files
fix: docs for oneof parameters (#1207)
* fix: docs for oneof parameters
1 parent c3db374 commit 8546394

File tree

10 files changed

+47
-36
lines changed

10 files changed

+47
-36
lines changed

gapic-generator/lib/gapic/presenters/field_presenter.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -72,8 +72,8 @@ def output_doc_types
7272
# gRPC client classes. Uses the default transport if not provided.
7373
# @return [String]
7474
#
75-
def doc_description transport: nil
76-
@field.docs_leading_comments transport: transport
75+
def doc_description transport: nil, is_rpc_param: false
76+
@field.docs_leading_comments transport: transport, is_rpc_param: is_rpc_param
7777
end
7878

7979
def default_value

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

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -983,16 +983,22 @@ def populate_oneof_siblings! all_fields
983983

984984
# @private
985985
# 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
986+
def docs_leading_comments disable_xrefs: false, transport: nil, is_rpc_param: false
987+
str = super(disable_xrefs: disable_xrefs, transport: transport)
988988
return str unless @oneof_siblings && @oneof_siblings.size > 1
989989
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."
990+
note =
991+
if is_rpc_param
992+
"Note: The following parameters are mutually exclusive: #{siblings}. " \
993+
"At most one of these parameters can be set. If more than one is set, " \
994+
"only one will be used, and it is not defined which one."
995+
else
996+
"Note: The following fields are mutually exclusive: #{siblings}. " \
997+
"If a field in that set is populated, all other fields in the set " \
998+
"will automatically be cleared."
999+
end
9931000
str ? "#{str.strip}\n\n#{note}" : note
9941001
end
995-
9961002
# @!method name
9971003
# @return [String] the unqualified name of the field.
9981004
# @!method number

gapic-generator/templates/default/service/client/method/docs/_request_normal.text.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<%- method.arguments.each do |arg| -%>
2020
# @param <%= arg.name %> [<%= arg.doc_types %>]
2121
<%- if arg.doc_description -%>
22-
<%= indent arg.doc_description(transport: :grpc), "# " %>
22+
<%= indent arg.doc_description(transport: :grpc, is_rpc_param: true), "# " %>
2323
<%- end -%>
2424
<%- end -%>
2525
<%- end -%>

gapic-generator/templates/default/service/rest/client/method/docs/_request.text.erb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
<%- method.arguments.each do |arg| -%>
2020
# @param <%= arg.name %> [<%= arg.doc_types %>]
2121
<%- if arg.doc_description -%>
22-
<%= indent arg.doc_description(transport: :rest), "# " %>
22+
<%= indent arg.doc_description(transport: :rest, is_rpc_param: true), "# " %>
2323
<%- end -%>
2424
<%- end -%>
2525
<%- end -%>

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,11 @@ def test_typical_garbage_oneof_enum_field
141141
"`oneof_multiple_bytes`, `oneof_multiple_double`. If a field in that set is populated, all other fields in " \
142142
"the set will automatically be cleared."
143143
assert_equal expected_description, fp.doc_description
144+
expected_description_rpc_params = "This is a multiple-field oneof's enum field.\n\n" \
145+
"Note: The following parameters are mutually exclusive: `oneof_multiple_enum`, `oneof_multiple_message`, " \
146+
"`oneof_multiple_bytes`, `oneof_multiple_double`. At most one of these parameters can be set. If more than one is set, " \
147+
"only one will be used, and it is not defined which one."
148+
assert_equal expected_description_rpc_params, fp.doc_description(is_rpc_param: true)
144149
assert_equal ":DEFAULT_GARBAGE", fp.default_value
145150
assert_equal ".endless.trash.forever.GarbageEnum", fp.type_name
146151
assert_equal "::So::Much::Trash::GarbageEnum", fp.type_name_full

shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2061,12 +2061,12 @@ def import_product_sets request, options = nil
20612061
# @param product_set_purge_config [::Google::Cloud::Vision::V1::ProductSetPurgeConfig, ::Hash]
20622062
# Specify which ProductSet contains the Products to be deleted.
20632063
#
2064-
# Note: The following fields are mutually exclusive: `product_set_purge_config`, `delete_orphan_products`. If a field in that set is populated, all other fields in the set will automatically be cleared.
2064+
# Note: The following parameters are mutually exclusive: `product_set_purge_config`, `delete_orphan_products`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
20652065
# @param delete_orphan_products [::Boolean]
20662066
# If delete_orphan_products is true, all Products that are not in any
20672067
# ProductSet will be deleted.
20682068
#
2069-
# Note: The following fields are mutually exclusive: `delete_orphan_products`, `product_set_purge_config`. If a field in that set is populated, all other fields in the set will automatically be cleared.
2069+
# Note: The following parameters are mutually exclusive: `delete_orphan_products`, `product_set_purge_config`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
20702070
# @param parent [::String]
20712071
# Required. The project and location in which the Products should be deleted.
20722072
#

shared/output/cloud/vision_v1/lib/google/cloud/vision/v1/product_search/rest/client.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1929,12 +1929,12 @@ def import_product_sets request, options = nil
19291929
# @param product_set_purge_config [::Google::Cloud::Vision::V1::ProductSetPurgeConfig, ::Hash]
19301930
# Specify which ProductSet contains the Products to be deleted.
19311931
#
1932-
# Note: The following fields are mutually exclusive: `product_set_purge_config`, `delete_orphan_products`. If a field in that set is populated, all other fields in the set will automatically be cleared.
1932+
# Note: The following parameters are mutually exclusive: `product_set_purge_config`, `delete_orphan_products`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
19331933
# @param delete_orphan_products [::Boolean]
19341934
# If delete_orphan_products is true, all Products that are not in any
19351935
# ProductSet will be deleted.
19361936
#
1937-
# Note: The following fields are mutually exclusive: `delete_orphan_products`, `product_set_purge_config`. If a field in that set is populated, all other fields in the set will automatically be cleared.
1937+
# Note: The following parameters are mutually exclusive: `delete_orphan_products`, `product_set_purge_config`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
19381938
# @param parent [::String]
19391939
# Required. The project and location in which the Products should be deleted.
19401940
#

shared/output/gapic/templates/garbage/lib/so/much/trash/garbage_service/client.rb

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -717,27 +717,27 @@ def get_repeated_garbage request, options = nil
717717
# @param oneof_pair_int32 [::Integer]
718718
# This is a pair oneof's int32 field.
719719
#
720-
# Note: The following fields are mutually exclusive: `oneof_pair_int32`, `oneof_pair_float`. If a field in that set is populated, all other fields in the set will automatically be cleared.
720+
# Note: The following parameters are mutually exclusive: `oneof_pair_int32`, `oneof_pair_float`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
721721
# @param oneof_pair_float [::Float]
722722
# This is a pair oneof's float field.
723723
#
724-
# Note: The following fields are mutually exclusive: `oneof_pair_float`, `oneof_pair_int32`. If a field in that set is populated, all other fields in the set will automatically be cleared.
724+
# Note: The following parameters are mutually exclusive: `oneof_pair_float`, `oneof_pair_int32`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
725725
# @param oneof_multiple_message [::So::Much::Trash::SimpleGarbageItem, ::Hash]
726726
# This is a multiple-field oneof's message field.
727727
#
728-
# Note: The following fields are mutually exclusive: `oneof_multiple_message`, `oneof_multiple_bytes`, `oneof_multiple_enum`, `oneof_multiple_double`. If a field in that set is populated, all other fields in the set will automatically be cleared.
728+
# Note: The following parameters are mutually exclusive: `oneof_multiple_message`, `oneof_multiple_bytes`, `oneof_multiple_enum`, `oneof_multiple_double`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
729729
# @param oneof_multiple_bytes [::String]
730730
# This is a multiple-field oneof's bytes field.
731731
#
732-
# Note: The following fields are mutually exclusive: `oneof_multiple_bytes`, `oneof_multiple_message`, `oneof_multiple_enum`, `oneof_multiple_double`. If a field in that set is populated, all other fields in the set will automatically be cleared.
732+
# Note: The following parameters are mutually exclusive: `oneof_multiple_bytes`, `oneof_multiple_message`, `oneof_multiple_enum`, `oneof_multiple_double`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
733733
# @param oneof_multiple_enum [::So::Much::Trash::GarbageEnum]
734734
# This is a multiple-field oneof's enum field.
735735
#
736-
# Note: The following fields are mutually exclusive: `oneof_multiple_enum`, `oneof_multiple_message`, `oneof_multiple_bytes`, `oneof_multiple_double`. If a field in that set is populated, all other fields in the set will automatically be cleared.
736+
# Note: The following parameters are mutually exclusive: `oneof_multiple_enum`, `oneof_multiple_message`, `oneof_multiple_bytes`, `oneof_multiple_double`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
737737
# @param oneof_multiple_double [::Float]
738738
# This is a multiple-field oneof's double field.
739739
#
740-
# Note: The following fields are mutually exclusive: `oneof_multiple_double`, `oneof_multiple_message`, `oneof_multiple_bytes`, `oneof_multiple_enum`. If a field in that set is populated, all other fields in the set will automatically be cleared.
740+
# Note: The following parameters are mutually exclusive: `oneof_multiple_double`, `oneof_multiple_message`, `oneof_multiple_bytes`, `oneof_multiple_enum`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
741741
# @param optional_int32 [::Integer]
742742
# @param case [::String]
743743
# This field tests for collisions against Ruby reserved keywords.

shared/output/gapic/templates/showcase/lib/google/showcase/v1beta1/echo/client.rb

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -254,11 +254,11 @@ def logger
254254
# @param content [::String]
255255
# The content to be echoed by the server.
256256
#
257-
# Note: The following fields are mutually exclusive: `content`, `error`. If a field in that set is populated, all other fields in the set will automatically be cleared.
257+
# Note: The following parameters are mutually exclusive: `content`, `error`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
258258
# @param error [::Google::Rpc::Status, ::Hash]
259259
# The error to be thrown by the server.
260260
#
261-
# Note: The following fields are mutually exclusive: `error`, `content`. If a field in that set is populated, all other fields in the set will automatically be cleared.
261+
# Note: The following parameters are mutually exclusive: `error`, `content`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
262262
# @param severity [::Google::Showcase::V1beta1::Severity]
263263
# The severity to be echoed by the server.
264264
# @param header [::String]
@@ -982,20 +982,20 @@ def paged_expand_legacy_mapped request, options = nil
982982
# @param end_time [::Google::Protobuf::Timestamp, ::Hash]
983983
# The time that this operation will complete.
984984
#
985-
# Note: The following fields are mutually exclusive: `end_time`, `ttl`. If a field in that set is populated, all other fields in the set will automatically be cleared.
985+
# Note: The following parameters are mutually exclusive: `end_time`, `ttl`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
986986
# @param ttl [::Google::Protobuf::Duration, ::Hash]
987987
# The duration of this operation.
988988
#
989-
# Note: The following fields are mutually exclusive: `ttl`, `end_time`. If a field in that set is populated, all other fields in the set will automatically be cleared.
989+
# Note: The following parameters are mutually exclusive: `ttl`, `end_time`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
990990
# @param error [::Google::Rpc::Status, ::Hash]
991991
# The error that will be returned by the server. If this code is specified
992992
# to be the OK rpc code, an empty response will be returned.
993993
#
994-
# Note: The following fields are mutually exclusive: `error`, `success`. If a field in that set is populated, all other fields in the set will automatically be cleared.
994+
# Note: The following parameters are mutually exclusive: `error`, `success`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
995995
# @param success [::Google::Showcase::V1beta1::WaitResponse, ::Hash]
996996
# The response to be returned on operation completion.
997997
#
998-
# Note: The following fields are mutually exclusive: `success`, `error`. If a field in that set is populated, all other fields in the set will automatically be cleared.
998+
# Note: The following parameters are mutually exclusive: `success`, `error`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
999999
#
10001000
# @yield [response, operation] Access the result along with the RPC operation
10011001
# @yieldparam response [::Gapic::Operation]
@@ -1086,11 +1086,11 @@ def wait request, options = nil
10861086
# The error that will be returned by the server. If this code is specified
10871087
# to be the OK rpc code, an empty response will be returned.
10881088
#
1089-
# Note: The following fields are mutually exclusive: `error`, `success`. If a field in that set is populated, all other fields in the set will automatically be cleared.
1089+
# Note: The following parameters are mutually exclusive: `error`, `success`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
10901090
# @param success [::Google::Showcase::V1beta1::BlockResponse, ::Hash]
10911091
# The response to be returned that will signify successful method call.
10921092
#
1093-
# Note: The following fields are mutually exclusive: `success`, `error`. If a field in that set is populated, all other fields in the set will automatically be cleared.
1093+
# Note: The following parameters are mutually exclusive: `success`, `error`. At most one of these parameters can be set. If more than one is set, only one will be used, and it is not defined which one.
10941094
#
10951095
# @yield [response, operation] Access the result along with the RPC operation
10961096
# @yieldparam response [::Google::Showcase::V1beta1::BlockResponse]

0 commit comments

Comments
 (0)