-
Notifications
You must be signed in to change notification settings - Fork 69
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix(snippetgen): don't create duplicate requests for required oneofs (#…
…1088) Some APIs mark every field in a oneof as "required" to express that the oneof itself is required. https://github.com/googleapis/googleapis/blob/55726d62556966c095a096aed1ffda5da231f36d/google/cloud/channel/v1/service.proto#L1057-L1069 ```proto // Request message for [CloudChannelService.ImportCustomer][google.cloud.channel.v1.CloudChannelService.ImportCustomer] message ImportCustomerRequest { // Specifies the identity of the transfer customer. // A customer's cloud_identity_id or domain is required to look up the // customer's Cloud Identity. For Team customers, only the cloud_identity_id // option is valid. oneof customer_identity { // Required. Customer domain. string domain = 2 [(google.api.field_behavior) = REQUIRED]; // Required. Customer's Cloud Identity ID string cloud_identity_id = 3 [(google.api.field_behavior) = REQUIRED]; } ... ``` This causes an error in the current logic since two requests are generated for the same field.
- Loading branch information
1 parent
309cc66
commit 5531795
Showing
4 changed files
with
118 additions
and
3 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
48 changes: 48 additions & 0 deletions
48
...gen/goldens/mollusca_generated_mollusca_v1_snippets_one_of_method_required_field_async.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# Generated code. DO NOT EDIT! | ||
# | ||
# Snippet for OneOfMethodRequiredField | ||
# NOTE: This snippet has been automatically generated for illustrative purposes only. | ||
# It may require modifications to work in your environment. | ||
|
||
# To install the latest published package dependency, execute the following: | ||
# python3 -m pip install animalia-mollusca | ||
|
||
|
||
# [START mollusca_generated_mollusca_v1_Snippets_OneOfMethodRequiredField_async] | ||
from animalia import mollusca_v1 | ||
|
||
|
||
async def sample_one_of_method_required_field(): | ||
"""Snippet for one_of_method_required_field""" | ||
|
||
# Create a client | ||
client = mollusca_v1.SnippetsAsyncClient() | ||
|
||
# Initialize request argument(s) | ||
request = mollusca_v1.OneOfRequestWithRequiredField( | ||
my_string="my_string_value", | ||
non_one_of_string="non_one_of_string_value", | ||
) | ||
|
||
# Make the request | ||
response = await client.one_of_method_required_field(request=request) | ||
|
||
# Handle response | ||
print(response) | ||
|
||
# [END mollusca_generated_mollusca_v1_Snippets_OneOfMethodRequiredField_async] |
48 changes: 48 additions & 0 deletions
48
...tgen/goldens/mollusca_generated_mollusca_v1_snippets_one_of_method_required_field_sync.py
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
# -*- coding: utf-8 -*- | ||
# Copyright 2020 Google LLC | ||
# | ||
# Licensed under the Apache License, Version 2.0 (the "License"); | ||
# you may not use this file except in compliance with the License. | ||
# You may obtain a copy of the License at | ||
# | ||
# http://www.apache.org/licenses/LICENSE-2.0 | ||
# | ||
# Unless required by applicable law or agreed to in writing, software | ||
# distributed under the License is distributed on an "AS IS" BASIS, | ||
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
# See the License for the specific language governing permissions and | ||
# limitations under the License. | ||
# | ||
# Generated code. DO NOT EDIT! | ||
# | ||
# Snippet for OneOfMethodRequiredField | ||
# NOTE: This snippet has been automatically generated for illustrative purposes only. | ||
# It may require modifications to work in your environment. | ||
|
||
# To install the latest published package dependency, execute the following: | ||
# python3 -m pip install animalia-mollusca | ||
|
||
|
||
# [START mollusca_generated_mollusca_v1_Snippets_OneOfMethodRequiredField_sync] | ||
from animalia import mollusca_v1 | ||
|
||
|
||
def sample_one_of_method_required_field(): | ||
"""Snippet for one_of_method_required_field""" | ||
|
||
# Create a client | ||
client = mollusca_v1.SnippetsClient() | ||
|
||
# Initialize request argument(s) | ||
request = mollusca_v1.OneOfRequestWithRequiredField( | ||
my_string="my_string_value", | ||
non_one_of_string="non_one_of_string_value", | ||
) | ||
|
||
# Make the request | ||
response = client.one_of_method_required_field(request=request) | ||
|
||
# Handle response | ||
print(response) | ||
|
||
# [END mollusca_generated_mollusca_v1_Snippets_OneOfMethodRequiredField_sync] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters