Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: move context from namespace to class scope #1605

Closed
wants to merge 6 commits into from
Closed
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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