-
Notifications
You must be signed in to change notification settings - Fork 12
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: remove oneof wrappers in v2 (#629)
- Loading branch information
Showing
16 changed files
with
696 additions
and
33 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
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
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
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
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,77 @@ | ||
syntax = "proto3"; | ||
|
||
package testing.basiconeofnew; | ||
|
||
// php_namespace option not included; to test generating namespace from proto | ||
// package. | ||
|
||
option php_namespace = "Testing\\BasicOneofNew"; | ||
|
||
import "google/api/annotations.proto"; | ||
import "google/api/client.proto"; | ||
import "google/api/field_behavior.proto"; | ||
|
||
// This is a basic service. | ||
service BasicOneofNew { | ||
option (google.api.default_host) = "basic.example.com"; | ||
option (google.api.oauth_scopes) = "scope1,scope2"; | ||
|
||
// Test including method args with required oneofs. | ||
rpc AMethod(Request) returns (Response) { | ||
option (google.api.http) = { | ||
post: "/path:aMethod" | ||
body: "*" | ||
}; | ||
} | ||
} | ||
|
||
message PartOfRequestA {} | ||
|
||
message Request { | ||
int32 an_int = 1; | ||
|
||
oneof supplementary_data { | ||
// Supplemental request description. | ||
string extra_description = 2 [(google.api.field_behavior) = REQUIRED]; | ||
|
||
// Supplemental request summary. | ||
string extra_summary = 3 [(google.api.field_behavior) = REQUIRED]; | ||
|
||
// An extra request. | ||
PartOfRequestA extra_request = 4 [(google.api.field_behavior) = REQUIRED]; | ||
|
||
// An extra index. | ||
int32 extra_index = 5 [(google.api.field_behavior) = REQUIRED]; | ||
|
||
// An extra double. | ||
double extra_double = 6 [(google.api.field_behavior) = REQUIRED]; | ||
|
||
// An extra float. | ||
float extra_float = 7 [(google.api.field_behavior) = REQUIRED]; | ||
|
||
// An extra bool. | ||
bool extra_bool = 8 [(google.api.field_behavior) = REQUIRED]; | ||
} | ||
|
||
oneof optional_data { | ||
// An optional payload. | ||
string optional_payload = 10; | ||
|
||
// An optional count. | ||
int32 optional_count = 11; | ||
} | ||
|
||
message Other { | ||
oneof other_of { | ||
string first = 1 [(google.api.field_behavior) = REQUIRED]; | ||
|
||
string second = 2 [(google.api.field_behavior) = REQUIRED]; | ||
} | ||
} | ||
|
||
Other other = 12 [(google.api.field_behavior) = REQUIRED]; | ||
|
||
optional string required_optional = 13 [(google.api.field_behavior) = REQUIRED]; | ||
} | ||
|
||
message Response {} |
10 changes: 10 additions & 0 deletions
10
tests/Unit/ProtoTests/BasicOneofNew/basic-oneof-new_gapic.yaml
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,10 @@ | ||
type: google.api.Service | ||
config_version: 3 | ||
|
||
authentication: | ||
rules: | ||
- selector: 'testing.basic.BasicOneof.*' | ||
oauth: | ||
canonical_scopes: |- | ||
scope1, | ||
scope2 |
82 changes: 82 additions & 0 deletions
82
tests/Unit/ProtoTests/BasicOneofNew/out/samples/BasicOneofNewClient/a_method.php
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,82 @@ | ||
<?php | ||
/* | ||
* Copyright 2022 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 | ||
* | ||
* https://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 WARNING | ||
* This file was automatically generated - do not edit! | ||
*/ | ||
|
||
require_once __DIR__ . '/../../../vendor/autoload.php'; | ||
|
||
// [START basic_generated_BasicOneofNew_AMethod_sync] | ||
use Google\ApiCore\ApiException; | ||
use Testing\BasicOneofNew\Client\BasicOneofNewClient; | ||
use Testing\BasicOneofNew\Request; | ||
use Testing\BasicOneofNew\Request\Other; | ||
use Testing\BasicOneofNew\Response; | ||
|
||
/** | ||
* Test including method args with required oneofs. | ||
* | ||
* @param string $extraDescription Supplemental request description. | ||
* @param string $otherFirst | ||
* @param string $requiredOptional | ||
*/ | ||
function a_method_sample( | ||
string $extraDescription, | ||
string $otherFirst, | ||
string $requiredOptional | ||
): void { | ||
// Create a client. | ||
$basicOneofNewClient = new BasicOneofNewClient(); | ||
|
||
// Prepare the request message. | ||
$other = (new Other()) | ||
->setFirst($otherFirst); | ||
$request = (new Request()) | ||
->setExtraDescription($extraDescription) | ||
->setOther($other) | ||
->setRequiredOptional($requiredOptional); | ||
|
||
// Call the API and handle any network failures. | ||
try { | ||
/** @var Response $response */ | ||
$response = $basicOneofNewClient->aMethod($request); | ||
printf('Response data: %s' . PHP_EOL, $response->serializeToJsonString()); | ||
} catch (ApiException $ex) { | ||
printf('Call failed with message: %s' . PHP_EOL, $ex->getMessage()); | ||
} | ||
} | ||
|
||
/** | ||
* Helper to execute the sample. | ||
* | ||
* This sample has been automatically generated and should be regarded as a code | ||
* template only. It will require modifications to work: | ||
* - It may require correct/in-range values for request initialization. | ||
* - It may require specifying regional endpoints when creating the service client, | ||
* please see the apiEndpoint client configuration option for more details. | ||
*/ | ||
function callSample(): void | ||
{ | ||
$extraDescription = '[EXTRA_DESCRIPTION]'; | ||
$otherFirst = '[FIRST]'; | ||
$requiredOptional = '[REQUIRED_OPTIONAL]'; | ||
|
||
a_method_sample($extraDescription, $otherFirst, $requiredOptional); | ||
} | ||
// [END basic_generated_BasicOneofNew_AMethod_sync] |
Oops, something went wrong.