diff --git a/templates/cjs/typescript_gapic/_util.njk b/templates/cjs/typescript_gapic/_util.njk index 1b07e4513..65d1599e2 100644 --- a/templates/cjs/typescript_gapic/_util.njk +++ b/templates/cjs/typescript_gapic/_util.njk @@ -39,7 +39,7 @@ limitations under the License. {%- macro printCommentsPageStream(method, generatedName) -%} {{- printPageStreamHeader(method) -}} {{- printRequest(method) -}} - {{- printCommentsForParams(method) -}} + {{- printCommentsForParams(method, "stream") -}} {{- printOptions() -}} {{- printReturnPageStream(method, generatedName) }} {%- endmacro -%} @@ -47,7 +47,7 @@ limitations under the License. {%- macro printCommentsPageAsync(method, generatedName) -%} {{- printPageAsyncHeader(method) -}} {{- printRequest(method) -}} - {{- printCommentsForParams(method) -}} + {{- printCommentsForParams(method, "async") -}} {{- printOptions() -}} {{- printReturnPageAsync(method, generatedName) }} {%- endmacro -%} @@ -93,30 +93,21 @@ limitations under the License. {%- endif %} {%- endmacro -%} -{%- macro printCommentsForParams(method) -%} +{%- macro printCommentsForParams(method, asyncOrStream) -%} {% if not method.clientStreaming %} {%- set commentsMap = method.paramComment -%} {%- for oneComment in commentsMap -%} {%- set type = oneComment.paramType -%} {%- if type.startsWith('.') %} -{# TODO: coleleah - add logic here for if it's maxResults paramter allow a number too #} -{# method allows wrappers -is a paginated call not async or stream -the paramter here is max_results -it's a uint32 #} -{{ generatedName | dump }} - {%- if method.maxResultsParameter and method.pagingResponseType and printRequestField(oneComment)=="request.maxResults" and (type == ".google.protobuf.UInt32Value" or type == ".google.protobuf.Int32Value")%} - // pepperoni - * @param { {{- type.substring(1) -}} | number } {{ printRequestField(oneComment) }} - + {%- if method.maxResultsParameter + and method.pagingResponseType + and printRequestField(oneComment)=="request.maxResults" + and not asyncOrStream + and (type == ".google.protobuf.UInt32Value" or type == ".google.protobuf.Int32Value")%} + * @param { {{- type.substring(1) -}} | number } {{ printRequestField(oneComment) }} {%- else %} - * @param { {{- type.substring(1) -}} } {{ printRequestField(oneComment) }} {%- endif -%} - - - - {%- else %} * @param { {{- convertParamType(oneComment.paramType) -}} } {{ printRequestField(oneComment) }} {%- endif -%} diff --git a/templates/cjs/typescript_gapic/src/$version/$service_client.ts.njk b/templates/cjs/typescript_gapic/src/$version/$service_client.ts.njk index d6a1e1a55..2b3bee54b 100644 --- a/templates/cjs/typescript_gapic/src/$version/$service_client.ts.njk +++ b/templates/cjs/typescript_gapic/src/$version/$service_client.ts.njk @@ -894,16 +894,16 @@ export class {{ service.name }}Client { {{ util.toInterface(method.outputInterface) }} ]>|void { request = request || {}; -{%- if method.maxResultsParameter %} - // the underlying API expects a UInt32Value or Int32Value object - // users can pass this directly, but if they have passed a number as they - // would for an AIP compliant paginated call, convert if for them - if(request.maxResults && typeof request.maxResults === "number"){ - const maxResultsObject = {"value": request.maxResults} - request.maxResults = maxResultsObject - } + {%- if method.maxResultsParameter %} + // the underlying API expects a UInt32Value or Int32Value object + // users can pass this directly, but if they have passed a number as they + // would for an AIP compliant paginated call, convert if for them + if(request.maxResults && typeof request.maxResults === "number"){ + const maxResultsObject = {"value": request.maxResults} + request.maxResults = maxResultsObject + } -{%- endif %} + {%- endif %} {%- for field in method.autoPopulatedFields %} if (!request.{{ field.toCamelCase() }}) { diff --git a/templates/esm/typescript_gapic/_util.njk b/templates/esm/typescript_gapic/_util.njk index 89802e385..65d1599e2 100644 --- a/templates/esm/typescript_gapic/_util.njk +++ b/templates/esm/typescript_gapic/_util.njk @@ -39,7 +39,7 @@ limitations under the License. {%- macro printCommentsPageStream(method, generatedName) -%} {{- printPageStreamHeader(method) -}} {{- printRequest(method) -}} - {{- printCommentsForParams(method) -}} + {{- printCommentsForParams(method, "stream") -}} {{- printOptions() -}} {{- printReturnPageStream(method, generatedName) }} {%- endmacro -%} @@ -47,7 +47,7 @@ limitations under the License. {%- macro printCommentsPageAsync(method, generatedName) -%} {{- printPageAsyncHeader(method) -}} {{- printRequest(method) -}} - {{- printCommentsForParams(method) -}} + {{- printCommentsForParams(method, "async") -}} {{- printOptions() -}} {{- printReturnPageAsync(method, generatedName) }} {%- endmacro -%} @@ -93,13 +93,21 @@ limitations under the License. {%- endif %} {%- endmacro -%} -{%- macro printCommentsForParams(method) -%} +{%- macro printCommentsForParams(method, asyncOrStream) -%} {% if not method.clientStreaming %} {%- set commentsMap = method.paramComment -%} {%- for oneComment in commentsMap -%} {%- set type = oneComment.paramType -%} {%- if type.startsWith('.') %} + {%- if method.maxResultsParameter + and method.pagingResponseType + and printRequestField(oneComment)=="request.maxResults" + and not asyncOrStream + and (type == ".google.protobuf.UInt32Value" or type == ".google.protobuf.Int32Value")%} + * @param { {{- type.substring(1) -}} | number } {{ printRequestField(oneComment) }} + {%- else %} * @param { {{- type.substring(1) -}} } {{ printRequestField(oneComment) }} + {%- endif -%} {%- else %} * @param { {{- convertParamType(oneComment.paramType) -}} } {{ printRequestField(oneComment) }} {%- endif -%} diff --git a/typescript/test/unit/proto.ts b/typescript/test/unit/proto.ts index cc6f3d4f9..8e09abf0c 100644 --- a/typescript/test/unit/proto.ts +++ b/typescript/test/unit/proto.ts @@ -1240,7 +1240,7 @@ describe('src/schema/proto.ts', () => { assert.deepStrictEqual(proto.services['service'].paging.length, 0); }); }); - describe('should support pagination for allowlisted APIs that use UInt32 wrappers and max_results', () => { + describe('should support pagination for allowlisted APIs that use UInt32/Int32 wrappers and max_results', () => { it('should be page field if allowlisted with wrappers and use "max_results" as field name', () => { const fd = {} as protos.google.protobuf.FileDescriptorProto; fd.name = 'google/cloud/bigquery/v2/cats.proto';