diff --git a/src/generator/templates/api-endpoint.njk b/src/generator/templates/api-endpoint.njk index 6d385b414a3..f344a7e784b 100644 --- a/src/generator/templates/api-endpoint.njk +++ b/src/generator/templates/api-endpoint.njk @@ -40,7 +40,6 @@ export interface Options extends GlobalOptions { version: '{{api.version|replace('\.', '_')}}'; } -let context: APIRequestContext; interface StandardParameters { {% for pname, p in api.parameters|dictsort %} @@ -67,7 +66,7 @@ interface StandardParameters { * @param {object=} options Options for {{ Name }} */ export class {{ Name }} { - + context: APIRequestContext; {% if api.resources %} {% for rname, r in api.resources|dictsort %} {{ rname }}: Resource${{ rname|capitalize }}; @@ -75,14 +74,14 @@ export class {{ Name }} { {% endif %} constructor(options: GlobalOptions, google?: GoogleConfigurable) { - context = { + this.context = { _options: options || {}, google }; {% if api.resources %} {% for rname, r in api.resources|dictsort %} - this.{{ rname }} = new Resource${{ rname|capitalize }}(); + this.{{ rname }} = new Resource${{ rname|capitalize }}(this.context); {% endfor %} {% endif %} } diff --git a/src/generator/templates/method-partial.njk b/src/generator/templates/method-partial.njk index 8048b133c75..cc58279dfe8 100644 --- a/src/generator/templates/method-partial.njk +++ b/src/generator/templates/method-partial.njk @@ -68,7 +68,7 @@ {% if m.mediaUpload.protocols.simple.path %}mediaUrl: (rootUrl + {{ ('/' + m.mediaUpload.protocols.simple.path)|buildurl|safe }}).replace(/([^:]\/)\/+/g, '$1'),{% endif %} requiredParams: [{% if m.parameterOrder.length %}'{{ m.parameterOrder|join("', '")|safe }}'{% endif %}], pathParams: [{% if pathParams.length %}'{{ pathParams|join("', '")|safe }}'{% endif %}], - context + context: this.context }; {% set responseType = "Schema$" + m.response.$ref|default() %} if (callback) { diff --git a/src/generator/templates/resource-partial.njk b/src/generator/templates/resource-partial.njk index 615ed4f960d..d1c5cdb3573 100644 --- a/src/generator/templates/resource-partial.njk +++ b/src/generator/templates/resource-partial.njk @@ -4,17 +4,19 @@ {% for rname, r in api.resources|dictsort %} {% set ClassName = classPath + rname|capitalize|camelify %} export class {{ ClassName }} { + context: APIRequestContext; {% if r.resources %} {% for rname, r2 in r.resources|dictsort %} {% set innerClassName = ClassName + "$" + rname|capitalize|camelify %} {{ rname|camelify }}: {{ innerClassName }}; {% endfor %} {% endif %} - constructor() { + constructor(context: APIRequestContext) { + this.context = context; {% if r.resources %} {% for rname, r2 in r.resources|dictsort %} {% set innerClassName = ClassName + "$" + rname|capitalize|camelify %} - this.{{ rname|camelify }} = new {{ innerClassName }}(); + this.{{ rname|camelify }} = new {{ innerClassName }}(this.context); {% endfor %} {% endif %} }