Skip to content

Commit

Permalink
update esm templates
Browse files Browse the repository at this point in the history
  • Loading branch information
leahecole committed Oct 23, 2024
1 parent 054087e commit d95c704
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 31 deletions.
27 changes: 9 additions & 18 deletions templates/cjs/typescript_gapic/_util.njk
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ limitations under the License.
{%- macro printCommentsPageStream(method, generatedName) -%}
{{- printPageStreamHeader(method) -}}
{{- printRequest(method) -}}
{{- printCommentsForParams(method) -}}
{{- printCommentsForParams(method, "stream") -}}
{{- printOptions() -}}
{{- printReturnPageStream(method, generatedName) }}
{%- endmacro -%}

{%- macro printCommentsPageAsync(method, generatedName) -%}
{{- printPageAsyncHeader(method) -}}
{{- printRequest(method) -}}
{{- printCommentsForParams(method) -}}
{{- printCommentsForParams(method, "async") -}}
{{- printOptions() -}}
{{- printReturnPageAsync(method, generatedName) }}
{%- endmacro -%}
Expand Down Expand Up @@ -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 -%}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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() }}) {
Expand Down
14 changes: 11 additions & 3 deletions templates/esm/typescript_gapic/_util.njk
Original file line number Diff line number Diff line change
Expand Up @@ -39,15 +39,15 @@ limitations under the License.
{%- macro printCommentsPageStream(method, generatedName) -%}
{{- printPageStreamHeader(method) -}}
{{- printRequest(method) -}}
{{- printCommentsForParams(method) -}}
{{- printCommentsForParams(method, "stream") -}}
{{- printOptions() -}}
{{- printReturnPageStream(method, generatedName) }}
{%- endmacro -%}

{%- macro printCommentsPageAsync(method, generatedName) -%}
{{- printPageAsyncHeader(method) -}}
{{- printRequest(method) -}}
{{- printCommentsForParams(method) -}}
{{- printCommentsForParams(method, "async") -}}
{{- printOptions() -}}
{{- printReturnPageAsync(method, generatedName) }}
{%- endmacro -%}
Expand Down Expand Up @@ -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 -%}
Expand Down
2 changes: 1 addition & 1 deletion typescript/test/unit/proto.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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';
Expand Down

0 comments on commit d95c704

Please sign in to comment.