From 11ad581d99481f08ee749d4a36c3c36f0d6315b7 Mon Sep 17 00:00:00 2001 From: Dave Supplee Date: Thu, 8 Nov 2018 13:53:30 -0800 Subject: [PATCH 1/3] account for placeholders in additional bindings --- .../transformer/php/PhpGapicSurfaceTransformer.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) diff --git a/src/main/java/com/google/api/codegen/transformer/php/PhpGapicSurfaceTransformer.java b/src/main/java/com/google/api/codegen/transformer/php/PhpGapicSurfaceTransformer.java index c120134308..a061f4d683 100644 --- a/src/main/java/com/google/api/codegen/transformer/php/PhpGapicSurfaceTransformer.java +++ b/src/main/java/com/google/api/codegen/transformer/php/PhpGapicSurfaceTransformer.java @@ -64,6 +64,7 @@ import com.google.protobuf.Descriptors.FieldDescriptor; import java.util.ArrayList; import java.util.Arrays; +import java.util.HashSet; import java.util.List; import java.util.Map; import java.util.Set; @@ -361,11 +362,14 @@ private RestMethodConfigView generateRestMethodConfigView(HttpRule httpRule, Sur List additionalBindings = new ArrayList<>(); Map.Entry entry = getHttpMethodEntry(httpRule); String uriTemplate = entry.getValue(); - Set templateVars = PathTemplate.create(uriTemplate).vars(); + Set templateVars = new HashSet(); + templateVars.addAll(PathTemplate.create(uriTemplate).vars()); if (httpRule.getAdditionalBindingsCount() > 0) { for (HttpRule additionalBindingHttpRule : httpRule.getAdditionalBindingsList()) { - additionalBindings.add(getHttpMethodEntry(additionalBindingHttpRule).getValue()); + String additionalBindingTemplate = getHttpMethodEntry(additionalBindingHttpRule).getValue(); + templateVars.addAll(PathTemplate.create(additionalBindingTemplate).vars()); + additionalBindings.add(additionalBindingTemplate); } } From 0a9d59df3f30ad4eb493c801f9f8378f8006a21a Mon Sep 17 00:00:00 2001 From: Dave Supplee Date: Thu, 8 Nov 2018 16:19:52 -0800 Subject: [PATCH 2/3] update proto file to enable testing of additional bindings with varied placeholders --- .../google/api/codegen/testsrc/libraryproto/library.proto | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/src/test/java/com/google/api/codegen/testsrc/libraryproto/library.proto b/src/test/java/com/google/api/codegen/testsrc/libraryproto/library.proto index e1cc8ace42..09a64ca302 100644 --- a/src/test/java/com/google/api/codegen/testsrc/libraryproto/library.proto +++ b/src/test/java/com/google/api/codegen/testsrc/libraryproto/library.proto @@ -131,7 +131,7 @@ service LibraryService { option (google.api.http) = { post: "/v1/{name=archives/*/books/*}" additional_bindings { - post: "/v1/{name=bookShelves/*/books/*}" + post: "/v1/{alt_book_name=bookShelves/*/books/*}" } }; } @@ -583,6 +583,10 @@ message GetBookFromAnywhereRequest { message GetBookFromAbsolutelyAnywhereRequest { // The name of the book to retrieve. string name = 1; + + // An alternate book name, used to test proper processing of placeholders + // within additional bindings. + string alt_book_name = 2; } // Request message for LibraryService.UpdateBookIndex. From 92b16447369e9a9980001be30769b61b8c79e184 Mon Sep 17 00:00:00 2001 From: Dave Supplee Date: Thu, 8 Nov 2018 16:20:05 -0800 Subject: [PATCH 3/3] update baseline files accordingly --- .../configgen/testdata/library_config.baseline | 2 ++ .../gapic/testdata/nodejs/nodejs_library.baseline | 7 +++++++ .../codegen/gapic/testdata/php/php_library.baseline | 13 ++++++++++++- .../gapic/testdata/py/python_library.baseline | 4 ++++ .../gapic/testdata/ruby/ruby_library.baseline | 11 ++++++++++- 5 files changed, 35 insertions(+), 2 deletions(-) diff --git a/src/test/java/com/google/api/codegen/configgen/testdata/library_config.baseline b/src/test/java/com/google/api/codegen/configgen/testdata/library_config.baseline index db531f8dee..77a31ea869 100644 --- a/src/test/java/com/google/api/codegen/configgen/testdata/library_config.baseline +++ b/src/test/java/com/google/api/codegen/configgen/testdata/library_config.baseline @@ -440,9 +440,11 @@ interfaces: groups: - parameters: - name + - alt_book_name # FIXME: Configure which fields are required. required_fields: - name + - alt_book_name # FIXME: Configure the retryable codes for this method. retry_codes_name: non_idempotent # FIXME: Configure the retryable params for this method. diff --git a/src/test/java/com/google/api/codegen/gapic/testdata/nodejs/nodejs_library.baseline b/src/test/java/com/google/api/codegen/gapic/testdata/nodejs/nodejs_library.baseline index 0c724a5954..1f8459f430 100644 --- a/src/test/java/com/google/api/codegen/gapic/testdata/nodejs/nodejs_library.baseline +++ b/src/test/java/com/google/api/codegen/gapic/testdata/nodejs/nodejs_library.baseline @@ -1562,6 +1562,10 @@ const GetBookFromAnywhereRequest = { * @property {string} name * The name of the book to retrieve. * + * @property {string} altBookName + * An alternate book name, used to test proper processing of placeholders + * within additional bindings. + * * @typedef GetBookFromAbsolutelyAnywhereRequest * @memberof google.example.library.v1 * @see [google.example.library.v1.GetBookFromAbsolutelyAnywhereRequest definition in proto format]{@link https://github.com/googleapis/googleapis/blob/master/library.proto} @@ -4602,6 +4606,9 @@ class LibraryServiceClient { * The request object that will be sent. * @param {string} request.name * The name of the book to retrieve. + * @param {string} [request.altBookName] + * An alternate book name, used to test proper processing of placeholders + * within additional bindings. * @param {Object} [options] * Optional parameters. You can override the default settings for this call, e.g, timeout, * retries, paginations, etc. See [gax.CallOptions]{@link https://googleapis.github.io/gax-nodejs/global.html#CallOptions} for the details. diff --git a/src/test/java/com/google/api/codegen/gapic/testdata/php/php_library.baseline b/src/test/java/com/google/api/codegen/gapic/testdata/php/php_library.baseline index 0e21d020c1..63a3cb5bbe 100644 --- a/src/test/java/com/google/api/codegen/gapic/testdata/php/php_library.baseline +++ b/src/test/java/com/google/api/codegen/gapic/testdata/php/php_library.baseline @@ -1335,6 +1335,9 @@ class LibraryServiceGapicClient * @param string $name The name of the book to retrieve. * @param array $optionalArgs { * Optional. + * @type string $altBookName + * An alternate book name, used to test proper processing of placeholders + * within additional bindings. * @type RetrySettings|array $retrySettings * Retry settings to use for this call. Can be a * {@see Google\ApiCore\RetrySettings} object, or an associative array @@ -1351,6 +1354,9 @@ class LibraryServiceGapicClient { $request = new GetBookFromAbsolutelyAnywhereRequest(); $request->setName($name); + if (isset($optionalArgs['altBookName'])) { + $request->setAltBookName($optionalArgs['altBookName']); + } return $this->startCall( 'GetBookFromAbsolutelyAnywhere', @@ -2638,7 +2644,7 @@ return [ 'additionalBindings' => [ [ 'method' => 'post', - 'uriTemplate' => '/v1/{name=bookShelves/*/books/*}', + 'uriTemplate' => '/v1/{alt_book_name=bookShelves/*/books/*}', ], ], 'placeholders' => [ @@ -2647,6 +2653,11 @@ return [ 'getName', ], ], + 'alt_book_name' => [ + 'getters' => [ + 'getAltBookName', + ], + ], ] ], 'UpdateBookIndex' => [ diff --git a/src/test/java/com/google/api/codegen/gapic/testdata/py/python_library.baseline b/src/test/java/com/google/api/codegen/gapic/testdata/py/python_library.baseline index 1590ce348a..f4b71ff25c 100644 --- a/src/test/java/com/google/api/codegen/gapic/testdata/py/python_library.baseline +++ b/src/test/java/com/google/api/codegen/gapic/testdata/py/python_library.baseline @@ -2279,6 +2279,7 @@ class LibraryServiceClient(object): def get_book_from_absolutely_anywhere( self, name, + alt_book_name=None, retry=google.api_core.gapic_v1.method.DEFAULT, timeout=google.api_core.gapic_v1.method.DEFAULT, metadata=None): @@ -2296,6 +2297,8 @@ class LibraryServiceClient(object): Args: name (str): The name of the book to retrieve. + alt_book_name (str): An alternate book name, used to test proper processing of placeholders + within additional bindings. retry (Optional[google.api_core.retry.Retry]): A retry object used to retry requests. If ``None`` is specified, requests will not be retried. @@ -2326,6 +2329,7 @@ class LibraryServiceClient(object): request = library_pb2.GetBookFromAbsolutelyAnywhereRequest( name=name, + alt_book_name=alt_book_name, ) return self._inner_api_calls['get_book_from_absolutely_anywhere'](request, retry=retry, timeout=timeout, metadata=metadata) diff --git a/src/test/java/com/google/api/codegen/gapic/testdata/ruby/ruby_library.baseline b/src/test/java/com/google/api/codegen/gapic/testdata/ruby/ruby_library.baseline index d9da772058..c25d0896d6 100644 --- a/src/test/java/com/google/api/codegen/gapic/testdata/ruby/ruby_library.baseline +++ b/src/test/java/com/google/api/codegen/gapic/testdata/ruby/ruby_library.baseline @@ -2388,6 +2388,10 @@ module Google # @!attribute [rw] name # @return [String] # The name of the book to retrieve. + # @!attribute [rw] alt_book_name + # @return [String] + # An alternate book name, used to test proper processing of placeholders + # within additional bindings. class GetBookFromAbsolutelyAnywhereRequest; end # Request message for LibraryService.UpdateBookIndex. @@ -3781,6 +3785,9 @@ module Library # # @param name [String] # The name of the book to retrieve. + # @param alt_book_name [String] + # An alternate book name, used to test proper processing of placeholders + # within additional bindings. # @param options [Google::Gax::CallOptions] # Overrides the default settings for this call, e.g, timeout, # retries, etc. @@ -3798,10 +3805,12 @@ module Library def get_book_from_absolutely_anywhere \ name, + alt_book_name: nil, options: nil, &block req = { - name: name + name: name, + alt_book_name: alt_book_name }.delete_if { |_, v| v.nil? } req = Google::Gax::to_proto(req, Google::Example::Library::V1::GetBookFromAbsolutelyAnywhereRequest) @get_book_from_absolutely_anywhere.call(req, options, &block)