diff --git a/templates/typescript_gapic/_util.njk b/templates/typescript_gapic/_util.njk index 1491aa838..c54d2dd6e 100644 --- a/templates/typescript_gapic/_util.njk +++ b/templates/typescript_gapic/_util.njk @@ -68,7 +68,7 @@ limitations under the License. {%- macro printCommentsForService(service) -%} {%- set lines = service.comments -%} {% for line in lines %} - * {{ line | safe}} + * {{ line | safe}} {%- endfor %} {%- endmacro -%} diff --git a/templates/typescript_gapic/src/$version/$service_client.ts.njk b/templates/typescript_gapic/src/$version/$service_client.ts.njk index 41188b9ab..7d4d8e07e 100644 --- a/templates/typescript_gapic/src/$version/$service_client.ts.njk +++ b/templates/typescript_gapic/src/$version/$service_client.ts.njk @@ -68,10 +68,11 @@ export interface PaginationResponse< rawResponse?: ResponseObject; } {% endif %} + +/** +{{- util.printCommentsForService(service) }} + */ export class {{ service.name }}Client { - /** - {{- util.printCommentsForService(service) }} - */ private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; private _innerApiCalls: {[name: string]: Function}; {%- if (service.pathTemplates.length > 0) %} @@ -99,10 +100,8 @@ export class {{ service.name }}Client { * Developer's Console, e.g. 'grape-spaceship-123'. We will also check * the environment variable GCLOUD_PROJECT for your project ID. If your * app is running in an environment which supports - * {@@link - * https://developers.google.com/identity/protocols/application-default-credentials - * Application Default Credentials}, your project ID will be detected - * automatically. + * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. * @param {function} [options.promise] - Custom promise module to use instead * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the @@ -144,10 +143,8 @@ export class {{ service.name }}Client { // Determine the client header string. const clientHeader = [ - `grpc/${gaxGrpc.grpcVersion}`, `gax/${gaxModule.version}`, `gapic/${version}`, - `gl-web/${gaxModule.version}` ]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); @@ -255,7 +252,7 @@ export class {{ service.name }}Client { this._innerApiCalls = {}; // Put together the "service stub" for - // google.showcase.v1alpha2.Echo. + // {{api.naming.protoPackage}}.{{ service.name }}. const {{ service.name.toCamelCase() }}Stub = gaxGrpc.createStub( opts.fallback ? (protos as protobuf.Root).lookupService('{{api.naming.protoPackage}}.{{ service.name }}') : @@ -263,6 +260,8 @@ export class {{ service.name }}Client { (protos as any).{{api.naming.protoPackage}}.{{ service.name }}, opts) as Promise<{[method: string]: Function}>; + // Iterate over each of the methods that the service provides + // and create an API call method for each. const {{ service.name.toCamelCase() }}StubMethods = [ {%- set stubMethodsJoiner = joiner(', ') -%} @@ -281,7 +280,7 @@ export class {{ service.name }}Client { throw err; }); - this._innerApiCalls[methodName] = gax.createApiCall( + this._innerApiCalls[methodName] = gaxModule.createApiCall( innerCallPromise, defaults[methodName], this._descriptors.page[methodName] || @@ -290,12 +289,14 @@ export class {{ service.name }}Client { ); } } + /** * The DNS address for this API service. */ static get servicePath() { return '{{ api.hostName }}'; } + /** * The DNS address for this API service - same as servicePath(), * exists for compatibility reasons. @@ -329,13 +330,13 @@ export class {{ service.name }}Client { {%- endif %} } + getProjectId(): Promise; + getProjectId(callback: Callback): void; /** * Return the project ID used by this class. * @param {function(Error, string)} callback - the callback to * be called with the current project Id. */ - getProjectId(): Promise; - getProjectId(callback: Callback): void; getProjectId(callback?: Callback): Promise|void { if (callback) { diff --git a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline index f33d4d028..9e6e47d69 100644 --- a/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline +++ b/typescript/test/testdata/keymanager/src/v1/key_management_service_client.ts.baseline @@ -61,20 +61,21 @@ export interface PaginationResponse< rawResponse?: ResponseObject; } + +/** + * Google Cloud Key Management Service + * + * Manages cryptographic keys and operations using those keys. Implements a REST + * model with the following objects: + * + * * [KeyRing][google.cloud.kms.v1.KeyRing] + * * [CryptoKey][google.cloud.kms.v1.CryptoKey] + * * [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] + * + * If you are using manual gRPC libraries, see + * [Using gRPC with Cloud KMS](https://cloud.google.com/kms/docs/grpc). + */ export class KeyManagementServiceClient { - /** - * Google Cloud Key Management Service - * - * Manages cryptographic keys and operations using those keys. Implements a REST - * model with the following objects: - * - * * [KeyRing][google.cloud.kms.v1.KeyRing] - * * [CryptoKey][google.cloud.kms.v1.CryptoKey] - * * [CryptoKeyVersion][google.cloud.kms.v1.CryptoKeyVersion] - * - * If you are using manual gRPC libraries, see - * [Using gRPC with Cloud KMS](https://cloud.google.com/kms/docs/grpc). - */ private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; private _innerApiCalls: {[name: string]: Function}; auth: gax.GoogleAuth; @@ -99,10 +100,8 @@ export class KeyManagementServiceClient { * Developer's Console, e.g. 'grape-spaceship-123'. We will also check * the environment variable GCLOUD_PROJECT for your project ID. If your * app is running in an environment which supports - * {@@link - * https://developers.google.com/identity/protocols/application-default-credentials - * Application Default Credentials}, your project ID will be detected - * automatically. + * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. * @param {function} [options.promise] - Custom promise module to use instead * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the @@ -144,10 +143,8 @@ export class KeyManagementServiceClient { // Determine the client header string. const clientHeader = [ - `grpc/${gaxGrpc.grpcVersion}`, `gax/${gaxModule.version}`, `gapic/${version}`, - `gl-web/${gaxModule.version}` ]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); @@ -196,7 +193,7 @@ export class KeyManagementServiceClient { this._innerApiCalls = {}; // Put together the "service stub" for - // google.showcase.v1alpha2.Echo. + // google.cloud.kms.v1.KeyManagementService. const keyManagementServiceStub = gaxGrpc.createStub( opts.fallback ? (protos as protobuf.Root).lookupService('google.cloud.kms.v1.KeyManagementService') : @@ -204,6 +201,8 @@ export class KeyManagementServiceClient { (protos as any).google.cloud.kms.v1.KeyManagementService, opts) as Promise<{[method: string]: Function}>; + // Iterate over each of the methods that the service provides + // and create an API call method for each. const keyManagementServiceStubMethods = ['listKeyRings', 'listCryptoKeys', 'listCryptoKeyVersions', 'listImportJobs', 'getKeyRing', 'getCryptoKey', 'getCryptoKeyVersion', 'getPublicKey', 'getImportJob', 'createKeyRing', 'createCryptoKey', 'createCryptoKeyVersion', 'importCryptoKeyVersion', 'createImportJob', 'updateCryptoKey', 'updateCryptoKeyVersion', 'encrypt', 'decrypt', 'asymmetricSign', 'asymmetricDecrypt', 'updateCryptoKeyPrimaryVersion', 'destroyCryptoKeyVersion', 'restoreCryptoKeyVersion']; @@ -216,7 +215,7 @@ export class KeyManagementServiceClient { throw err; }); - this._innerApiCalls[methodName] = gax.createApiCall( + this._innerApiCalls[methodName] = gaxModule.createApiCall( innerCallPromise, defaults[methodName], this._descriptors.page[methodName] || @@ -225,12 +224,14 @@ export class KeyManagementServiceClient { ); } } + /** * The DNS address for this API service. */ static get servicePath() { return 'cloudkms.googleapis.com'; } + /** * The DNS address for this API service - same as servicePath(), * exists for compatibility reasons. @@ -257,13 +258,13 @@ export class KeyManagementServiceClient { ]; } + getProjectId(): Promise; + getProjectId(callback: Callback): void; /** * Return the project ID used by this class. * @param {function(Error, string)} callback - the callback to * be called with the current project Id. */ - getProjectId(): Promise; - getProjectId(callback: Callback): void; getProjectId(callback?: Callback): Promise|void { if (callback) { diff --git a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline index c1d3c45ea..6fff43538 100644 --- a/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline +++ b/typescript/test/testdata/showcase/src/v1beta1/echo_client.ts.baseline @@ -64,13 +64,14 @@ export interface PaginationResponse< rawResponse?: ResponseObject; } + +/** + * This service is used showcase the four main types of rpcs - unary, server + * side streaming, client side streaming, and bidirectional streaming. This + * service also exposes methods that explicitly implement server delay, and + * paginated calls. + */ export class EchoClient { - /** - * This service is used showcase the four main types of rpcs - unary, server - * side streaming, client side streaming, and bidirectional streaming. This - * service also exposes methods that explicitly implement server delay, and - * paginated calls. - */ private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; private _innerApiCalls: {[name: string]: Function}; auth: gax.GoogleAuth; @@ -95,10 +96,8 @@ export class EchoClient { * Developer's Console, e.g. 'grape-spaceship-123'. We will also check * the environment variable GCLOUD_PROJECT for your project ID. If your * app is running in an environment which supports - * {@@link - * https://developers.google.com/identity/protocols/application-default-credentials - * Application Default Credentials}, your project ID will be detected - * automatically. + * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. * @param {function} [options.promise] - Custom promise module to use instead * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the @@ -140,10 +139,8 @@ export class EchoClient { // Determine the client header string. const clientHeader = [ - `grpc/${gaxGrpc.grpcVersion}`, `gax/${gaxModule.version}`, `gapic/${version}`, - `gl-web/${gaxModule.version}` ]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); @@ -217,7 +214,7 @@ export class EchoClient { this._innerApiCalls = {}; // Put together the "service stub" for - // google.showcase.v1alpha2.Echo. + // google.showcase.v1beta1.Echo. const echoStub = gaxGrpc.createStub( opts.fallback ? (protos as protobuf.Root).lookupService('google.showcase.v1beta1.Echo') : @@ -225,6 +222,8 @@ export class EchoClient { (protos as any).google.showcase.v1beta1.Echo, opts) as Promise<{[method: string]: Function}>; + // Iterate over each of the methods that the service provides + // and create an API call method for each. const echoStubMethods = ['echo', 'expand', 'collect', 'chat', 'pagedExpand', 'wait']; @@ -237,7 +236,7 @@ export class EchoClient { throw err; }); - this._innerApiCalls[methodName] = gax.createApiCall( + this._innerApiCalls[methodName] = gaxModule.createApiCall( innerCallPromise, defaults[methodName], this._descriptors.page[methodName] || @@ -246,12 +245,14 @@ export class EchoClient { ); } } + /** * The DNS address for this API service. */ static get servicePath() { return 'localhost'; } + /** * The DNS address for this API service - same as servicePath(), * exists for compatibility reasons. @@ -275,13 +276,13 @@ export class EchoClient { return []; } + getProjectId(): Promise; + getProjectId(callback: Callback): void; /** * Return the project ID used by this class. * @param {function(Error, string)} callback - the callback to * be called with the current project Id. */ - getProjectId(): Promise; - getProjectId(callback: Callback): void; getProjectId(callback?: Callback): Promise|void { if (callback) { diff --git a/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline b/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline index c126ce31f..ed024ceda 100644 --- a/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline +++ b/typescript/test/testdata/texttospeech/src/v1/text_to_speech_client.ts.baseline @@ -48,10 +48,11 @@ export interface Callback< + +/** + * Service that implements Google Cloud Text-to-Speech API. + */ export class TextToSpeechClient { - /** - * Service that implements Google Cloud Text-to-Speech API. - */ private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; private _innerApiCalls: {[name: string]: Function}; auth: gax.GoogleAuth; @@ -76,10 +77,8 @@ export class TextToSpeechClient { * Developer's Console, e.g. 'grape-spaceship-123'. We will also check * the environment variable GCLOUD_PROJECT for your project ID. If your * app is running in an environment which supports - * {@@link - * https://developers.google.com/identity/protocols/application-default-credentials - * Application Default Credentials}, your project ID will be detected - * automatically. + * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. * @param {function} [options.promise] - Custom promise module to use instead * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the @@ -121,10 +120,8 @@ export class TextToSpeechClient { // Determine the client header string. const clientHeader = [ - `grpc/${gaxGrpc.grpcVersion}`, `gax/${gaxModule.version}`, `gapic/${version}`, - `gl-web/${gaxModule.version}` ]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); @@ -159,7 +156,7 @@ export class TextToSpeechClient { this._innerApiCalls = {}; // Put together the "service stub" for - // google.showcase.v1alpha2.Echo. + // google.cloud.texttospeech.v1.TextToSpeech. const textToSpeechStub = gaxGrpc.createStub( opts.fallback ? (protos as protobuf.Root).lookupService('google.cloud.texttospeech.v1.TextToSpeech') : @@ -167,6 +164,8 @@ export class TextToSpeechClient { (protos as any).google.cloud.texttospeech.v1.TextToSpeech, opts) as Promise<{[method: string]: Function}>; + // Iterate over each of the methods that the service provides + // and create an API call method for each. const textToSpeechStubMethods = ['listVoices', 'synthesizeSpeech']; @@ -179,7 +178,7 @@ export class TextToSpeechClient { throw err; }); - this._innerApiCalls[methodName] = gax.createApiCall( + this._innerApiCalls[methodName] = gaxModule.createApiCall( innerCallPromise, defaults[methodName], this._descriptors.page[methodName] || @@ -188,12 +187,14 @@ export class TextToSpeechClient { ); } } + /** * The DNS address for this API service. */ static get servicePath() { return 'texttospeech.googleapis.com'; } + /** * The DNS address for this API service - same as servicePath(), * exists for compatibility reasons. @@ -219,13 +220,13 @@ export class TextToSpeechClient { ]; } + getProjectId(): Promise; + getProjectId(callback: Callback): void; /** * Return the project ID used by this class. * @param {function(Error, string)} callback - the callback to * be called with the current project Id. */ - getProjectId(): Promise; - getProjectId(callback: Callback): void; getProjectId(callback?: Callback): Promise|void { if (callback) { diff --git a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline index 664f7d29e..5fc8e7465 100644 --- a/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline +++ b/typescript/test/testdata/translate/src/v3beta1/translation_service_client.ts.baseline @@ -64,10 +64,11 @@ export interface PaginationResponse< rawResponse?: ResponseObject; } + +/** + * Provides natural language translation operations. + */ export class TranslationServiceClient { - /** - * Provides natural language translation operations. - */ private _descriptors: Descriptors = {page: {}, stream: {}, longrunning: {}}; private _innerApiCalls: {[name: string]: Function}; private _pathTemplates: {[name: string]: gax.PathTemplate}; @@ -93,10 +94,8 @@ export class TranslationServiceClient { * Developer's Console, e.g. 'grape-spaceship-123'. We will also check * the environment variable GCLOUD_PROJECT for your project ID. If your * app is running in an environment which supports - * {@@link - * https://developers.google.com/identity/protocols/application-default-credentials - * Application Default Credentials}, your project ID will be detected - * automatically. + * {@link https://developers.google.com/identity/protocols/application-default-credentials Application Default Credentials}, + * your project ID will be detected automatically. * @param {function} [options.promise] - Custom promise module to use instead * of native Promises. * @param {string} [options.apiEndpoint] - The domain name of the @@ -138,10 +137,8 @@ export class TranslationServiceClient { // Determine the client header string. const clientHeader = [ - `grpc/${gaxGrpc.grpcVersion}`, `gax/${gaxModule.version}`, `gapic/${version}`, - `gl-web/${gaxModule.version}` ]; if (typeof process !== 'undefined' && 'versions' in process) { clientHeader.push(`gl-node/${process.versions.node}`); @@ -235,7 +232,7 @@ export class TranslationServiceClient { this._innerApiCalls = {}; // Put together the "service stub" for - // google.showcase.v1alpha2.Echo. + // google.cloud.translation.v3beta1.TranslationService. const translationServiceStub = gaxGrpc.createStub( opts.fallback ? (protos as protobuf.Root).lookupService('google.cloud.translation.v3beta1.TranslationService') : @@ -243,6 +240,8 @@ export class TranslationServiceClient { (protos as any).google.cloud.translation.v3beta1.TranslationService, opts) as Promise<{[method: string]: Function}>; + // Iterate over each of the methods that the service provides + // and create an API call method for each. const translationServiceStubMethods = ['translateText', 'detectLanguage', 'getSupportedLanguages', 'batchTranslateText', 'createGlossary', 'listGlossaries', 'getGlossary', 'deleteGlossary']; @@ -255,7 +254,7 @@ export class TranslationServiceClient { throw err; }); - this._innerApiCalls[methodName] = gax.createApiCall( + this._innerApiCalls[methodName] = gaxModule.createApiCall( innerCallPromise, defaults[methodName], this._descriptors.page[methodName] || @@ -264,12 +263,14 @@ export class TranslationServiceClient { ); } } + /** * The DNS address for this API service. */ static get servicePath() { return 'translate.googleapis.com'; } + /** * The DNS address for this API service - same as servicePath(), * exists for compatibility reasons. @@ -296,13 +297,13 @@ export class TranslationServiceClient { ]; } + getProjectId(): Promise; + getProjectId(callback: Callback): void; /** * Return the project ID used by this class. * @param {function(Error, string)} callback - the callback to * be called with the current project Id. */ - getProjectId(): Promise; - getProjectId(callback: Callback): void; getProjectId(callback?: Callback): Promise|void { if (callback) {