Skip to content

Commit

Permalink
Fix googleapis#1594 move context from namespace to class scope
Browse files Browse the repository at this point in the history
  • Loading branch information
ajaaym committed Feb 19, 2019
1 parent 4c56cb2 commit 2233076
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 7 deletions.
7 changes: 3 additions & 4 deletions src/generator/templates/api-endpoint.njk
Expand Up @@ -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 %}
Expand All @@ -67,22 +66,22 @@ 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 }};
{% endfor %}
{% 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 %}
}
Expand Down
2 changes: 1 addition & 1 deletion src/generator/templates/method-partial.njk
Expand Up @@ -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) {
Expand Down
6 changes: 4 additions & 2 deletions src/generator/templates/resource-partial.njk
Expand Up @@ -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 %}
}
Expand Down

0 comments on commit 2233076

Please sign in to comment.