Skip to content

Commit c9cb6c7

Browse files
authored
fix: list oneofs in docstring (#1030)
* fix: list oneofs in docstring * chore: copy to ads templates * docs: remove separate list in docstring * chore: also update ads
1 parent 99ee3e7 commit c9cb6c7

File tree

7 files changed

+105
-0
lines changed

7 files changed

+105
-0
lines changed

packages/gapic-generator/gapic/ads-templates/%namespace/%name/%version/%sub/types/_message.py.j2

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,25 @@ class {{ message.name }}({{ p }}.Message):
22
r"""{{ message.meta.doc|rst(indent=4) }}
33
{% if message.fields|length %}
44

5+
{# Only include note if a oneof has more than one member field. #}
6+
{% if message.oneof_fields() %}
7+
{% if message.oneof_fields().values() | map('length') | max > 1 %}
8+
This message has `oneof`_ fields (mutually exclusive fields).
9+
For each oneof, at most one member field can be set at the same time.
10+
Setting any member of the oneof automatically clears all other
11+
members.
12+
13+
{% endif %}
14+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
15+
16+
{% endif %}
517
Attributes:
618
{% for field in message.fields.values() %}
719
{{ field.name }} ({{ field.ident.sphinx }}):
820
{{ field.meta.doc|rst(indent=12, nl=False) }}
21+
{% if field.oneof %}
22+
This field is a member of `oneof`_ ``{{ field.oneof }}``.
23+
{% endif %}
924
{% endfor %}
1025
{% endif %}
1126
"""

packages/gapic-generator/gapic/templates/%namespace/%name_%version/%sub/types/_message.py.j2

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,10 +2,25 @@ class {{ message.name }}({{ p }}.Message):
22
r"""{{ message.meta.doc|rst(indent=4) }}
33
{% if message.fields|length %}
44

5+
{# Only include note if a oneof has more than one member field. #}
6+
{% if message.oneof_fields() %}
7+
{% if message.oneof_fields().values() | map('length') | max > 1 %}
8+
This message has `oneof`_ fields (mutually exclusive fields).
9+
For each oneof, at most one member field can be set at the same time.
10+
Setting any member of the oneof automatically clears all other
11+
members.
12+
13+
{% endif %}
14+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
15+
16+
{% endif %}
517
Attributes:
618
{% for field in message.fields.values() %}
719
{{ field.name }} ({{ field.ident.sphinx }}):
820
{{ field.meta.doc|rst(indent=12, nl=False) }}
21+
{% if field.oneof %}
22+
This field is a member of `oneof`_ ``{{ field.oneof }}``.
23+
{% endif %}
924
{% endfor %}
1025
{% endif %}
1126
"""

packages/gapic-generator/tests/integration/goldens/asset/google/cloud/asset_v1/types/asset_service.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -512,13 +512,22 @@ class DeleteFeedRequest(proto.Message):
512512
class OutputConfig(proto.Message):
513513
r"""Output configuration for export assets destination.
514514
515+
This message has `oneof`_ fields (mutually exclusive fields).
516+
For each oneof, at most one member field can be set at the same time.
517+
Setting any member of the oneof automatically clears all other
518+
members.
519+
520+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
521+
515522
Attributes:
516523
gcs_destination (google.cloud.asset_v1.types.GcsDestination):
517524
Destination on Cloud Storage.
525+
This field is a member of `oneof`_ ``destination``.
518526
bigquery_destination (google.cloud.asset_v1.types.BigQueryDestination):
519527
Destination on BigQuery. The output table
520528
stores the fields in asset proto as columns in
521529
BigQuery.
530+
This field is a member of `oneof`_ ``destination``.
522531
"""
523532

524533
gcs_destination = proto.Field(
@@ -538,9 +547,12 @@ class OutputConfig(proto.Message):
538547
class OutputResult(proto.Message):
539548
r"""Output result of export assets.
540549
550+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
551+
541552
Attributes:
542553
gcs_result (google.cloud.asset_v1.types.GcsOutputResult):
543554
Export result on Cloud Storage.
555+
This field is a member of `oneof`_ ``result``.
544556
"""
545557

546558
gcs_result = proto.Field(
@@ -569,6 +581,13 @@ class GcsOutputResult(proto.Message):
569581
class GcsDestination(proto.Message):
570582
r"""A Cloud Storage location.
571583
584+
This message has `oneof`_ fields (mutually exclusive fields).
585+
For each oneof, at most one member field can be set at the same time.
586+
Setting any member of the oneof automatically clears all other
587+
members.
588+
589+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
590+
572591
Attributes:
573592
uri (str):
574593
The uri of the Cloud Storage object. It's the same uri that
@@ -581,6 +600,7 @@ class GcsDestination(proto.Message):
581600
there is no
582601
`hold <https://cloud.google.com/storage/docs/object-holds>`__,
583602
it will be overwritten with the exported result.
603+
This field is a member of `oneof`_ ``object_uri``.
584604
uri_prefix (str):
585605
The uri prefix of all generated Cloud Storage objects.
586606
Example: "gs://bucket_name/object_name_prefix". Each object
@@ -591,6 +611,7 @@ class GcsDestination(proto.Message):
591611
compute.googleapis.com/Disk assets. An INVALID_ARGUMENT
592612
error will be returned if file with the same name
593613
"gs://bucket_name/object_name_prefix" already exists.
614+
This field is a member of `oneof`_ ``object_uri``.
594615
"""
595616

596617
uri = proto.Field(
@@ -751,9 +772,12 @@ class PubsubDestination(proto.Message):
751772
class FeedOutputConfig(proto.Message):
752773
r"""Output configuration for asset feed destination.
753774
775+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
776+
754777
Attributes:
755778
pubsub_destination (google.cloud.asset_v1.types.PubsubDestination):
756779
Destination on Pub/Sub.
780+
This field is a member of `oneof`_ ``destination``.
757781
"""
758782

759783
pubsub_destination = proto.Field(
@@ -1420,12 +1444,15 @@ class Options(proto.Message):
14201444
class ConditionContext(proto.Message):
14211445
r"""The IAM conditions context.
14221446
1447+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
1448+
14231449
Attributes:
14241450
access_time (google.protobuf.timestamp_pb2.Timestamp):
14251451
The hypothetical access timestamp to evaluate IAM
14261452
conditions. Note that this value must not be earlier than
14271453
the current time; otherwise, an INVALID_ARGUMENT error will
14281454
be returned.
1455+
This field is a member of `oneof`_ ``TimeContext``.
14291456
"""
14301457

14311458
access_time = proto.Field(
@@ -1580,11 +1607,20 @@ class IamPolicyAnalysisOutputConfig(proto.Message):
15801607
r"""Output configuration for export IAM policy analysis
15811608
destination.
15821609
1610+
This message has `oneof`_ fields (mutually exclusive fields).
1611+
For each oneof, at most one member field can be set at the same time.
1612+
Setting any member of the oneof automatically clears all other
1613+
members.
1614+
1615+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
1616+
15831617
Attributes:
15841618
gcs_destination (google.cloud.asset_v1.types.IamPolicyAnalysisOutputConfig.GcsDestination):
15851619
Destination on Cloud Storage.
1620+
This field is a member of `oneof`_ ``destination``.
15861621
bigquery_destination (google.cloud.asset_v1.types.IamPolicyAnalysisOutputConfig.BigQueryDestination):
15871622
Destination on BigQuery.
1623+
This field is a member of `oneof`_ ``destination``.
15881624
"""
15891625

15901626
class GcsDestination(proto.Message):

packages/gapic-generator/tests/integration/goldens/asset/google/cloud/asset_v1/types/assets.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,13 @@ class Asset(proto.Message):
131131
types <https://cloud.google.com/asset-inventory/docs/supported-asset-types>`__
132132
for more information.
133133
134+
This message has `oneof`_ fields (mutually exclusive fields).
135+
For each oneof, at most one member field can be set at the same time.
136+
Setting any member of the oneof automatically clears all other
137+
members.
138+
139+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
140+
134141
Attributes:
135142
update_time (google.protobuf.timestamp_pb2.Timestamp):
136143
The last update timestamp of an asset. update_time is
@@ -171,12 +178,15 @@ class Asset(proto.Message):
171178
access_policy (google.identity.accesscontextmanager.v1.access_policy_pb2.AccessPolicy):
172179
Please also refer to the `access policy user
173180
guide <https://cloud.google.com/access-context-manager/docs/overview#access-policies>`__.
181+
This field is a member of `oneof`_ ``access_context_policy``.
174182
access_level (google.identity.accesscontextmanager.v1.access_level_pb2.AccessLevel):
175183
Please also refer to the `access level user
176184
guide <https://cloud.google.com/access-context-manager/docs/overview#access-levels>`__.
185+
This field is a member of `oneof`_ ``access_context_policy``.
177186
service_perimeter (google.identity.accesscontextmanager.v1.service_perimeter_pb2.ServicePerimeter):
178187
Please also refer to the `service perimeter user
179188
guide <https://cloud.google.com/vpc-service-controls/docs/overview>`__.
189+
This field is a member of `oneof`_ ``access_context_policy``.
180190
os_inventory (google.cloud.osconfig.v1.inventory_pb2.Inventory):
181191
A representation of runtime OS Inventory information. See
182192
`this
@@ -882,11 +892,20 @@ class Resource(proto.Message):
882892
class Access(proto.Message):
883893
r"""An IAM role or permission under analysis.
884894
895+
This message has `oneof`_ fields (mutually exclusive fields).
896+
For each oneof, at most one member field can be set at the same time.
897+
Setting any member of the oneof automatically clears all other
898+
members.
899+
900+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
901+
885902
Attributes:
886903
role (str):
887904
The role.
905+
This field is a member of `oneof`_ ``oneof_access``.
888906
permission (str):
889907
The permission.
908+
This field is a member of `oneof`_ ``oneof_access``.
890909
analysis_state (google.cloud.asset_v1.types.IamPolicyAnalysisState):
891910
The analysis state of this access.
892911
"""

packages/gapic-generator/tests/integration/goldens/logging/google/cloud/logging_v2/types/log_entry.py

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,13 @@
3636
class LogEntry(proto.Message):
3737
r"""An individual entry in a log.
3838
39+
This message has `oneof`_ fields (mutually exclusive fields).
40+
For each oneof, at most one member field can be set at the same time.
41+
Setting any member of the oneof automatically clears all other
42+
members.
43+
44+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
45+
3946
Attributes:
4047
log_name (str):
4148
Required. The resource name of the log to which this log
@@ -84,12 +91,15 @@ class LogEntry(proto.Message):
8491
8592
"type.googleapis.com/google.cloud.audit.AuditLog"
8693
"type.googleapis.com/google.appengine.logging.v1.RequestLog".
94+
This field is a member of `oneof`_ ``payload``.
8795
text_payload (str):
8896
The log entry payload, represented as a
8997
Unicode string (UTF-8).
98+
This field is a member of `oneof`_ ``payload``.
9099
json_payload (google.protobuf.struct_pb2.Struct):
91100
The log entry payload, represented as a
92101
structure that is expressed as a JSON object.
102+
This field is a member of `oneof`_ ``payload``.
93103
timestamp (google.protobuf.timestamp_pb2.Timestamp):
94104
Optional. The time the event described by the log entry
95105
occurred. This time is used to compute the log entry's age

packages/gapic-generator/tests/integration/goldens/logging/google/cloud/logging_v2/types/logging_config.py

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -195,6 +195,9 @@ class LogSink(proto.Message):
195195
created within a project, organization, billing account, or
196196
folder.
197197
198+
199+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
200+
198201
Attributes:
199202
name (str):
200203
Required. The client-assigned sink identifier, unique within
@@ -279,6 +282,7 @@ class LogSink(proto.Message):
279282
bigquery_options (google.cloud.logging_v2.types.BigQueryOptions):
280283
Optional. Options that affect sinks exporting
281284
data to BigQuery.
285+
This field is a member of `oneof`_ ``options``.
282286
create_time (google.protobuf.timestamp_pb2.Timestamp):
283287
Output only. The creation timestamp of the
284288
sink.

packages/gapic-generator/tests/integration/goldens/redis/google/cloud/redis_v1/types/cloud_redis.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -501,10 +501,13 @@ class GcsSource(proto.Message):
501501
class InputConfig(proto.Message):
502502
r"""The input content
503503
504+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
505+
504506
Attributes:
505507
gcs_source (google.cloud.redis_v1.types.GcsSource):
506508
Google Cloud Storage location where input
507509
content is located.
510+
This field is a member of `oneof`_ ``source``.
508511
"""
509512

510513
gcs_source = proto.Field(
@@ -558,10 +561,13 @@ class GcsDestination(proto.Message):
558561
class OutputConfig(proto.Message):
559562
r"""The output content
560563
564+
.. _oneof: https://proto-plus-python.readthedocs.io/en/stable/fields.html#oneofs-mutually-exclusive-fields
565+
561566
Attributes:
562567
gcs_destination (google.cloud.redis_v1.types.GcsDestination):
563568
Google Cloud Storage destination for output
564569
content.
570+
This field is a member of `oneof`_ ``destination``.
565571
"""
566572

567573
gcs_destination = proto.Field(

0 commit comments

Comments
 (0)