From 2f9aa282e52b2165f7c2d57e55ea013784f25e01 Mon Sep 17 00:00:00 2001 From: Ermolay Romanov Date: Tue, 19 May 2020 04:06:08 -0400 Subject: [PATCH] [typescript-rxjs] restore prototype inheritance for clone & its clients (#6001) * [typescript-rxjs] restore prototype inhertance - previously clone() and its clients in the BaseAPI class were generic - with removal of the generic argument, these methods became unavailable to the API classes inheriting from BaseAPI - original generic was imprecise, as these are not statics - return type of `this` is the correct notation * [typescript-rxjs] Chery-pick from #5465 by @denyo - this is done to prevent the changes slated for 5.0 from conflicting - apply destructuring changes from - denyo:feature/rxjs-statuscode-and-progress@673d67c --- .../src/main/resources/typescript-rxjs/runtime.mustache | 8 ++++---- .../petstore/typescript-rxjs/builds/default/runtime.ts | 8 ++++---- .../petstore/typescript-rxjs/builds/es6-target/runtime.ts | 8 ++++---- .../typescript-rxjs/builds/with-interfaces/runtime.ts | 8 ++++---- .../typescript-rxjs/builds/with-npm-version/runtime.ts | 8 ++++---- 5 files changed, 20 insertions(+), 20 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache b/modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache index 366d9b5c441..97989df889a 100644 --- a/modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache @@ -35,7 +35,7 @@ export class Configuration { } get apiKey(): ((name: string) => string) | undefined { - const apiKey = this.configuration.apiKey; + const { apiKey } = this.configuration; if (!apiKey) { return undefined; } @@ -43,7 +43,7 @@ export class Configuration { } get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { - const accessToken = this.configuration.accessToken; + const { accessToken } = this.configuration; if (!accessToken) { return undefined; } @@ -61,7 +61,7 @@ export class BaseAPI { this.middleware = configuration.middleware; } - withMiddleware = (middlewares: Middleware[]) => { + withMiddleware = (middlewares: Middleware[]): this => { const next = this.clone(); next.middleware = next.middleware.concat(middlewares); return next; @@ -121,7 +121,7 @@ export class BaseAPI { * Create a shallow clone of `this` by constructing a new instance * and then shallow cloning data members. */ - private clone = (): BaseAPI => + private clone = (): this => Object.assign(Object.create(Object.getPrototypeOf(this)), this); } diff --git a/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts b/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts index e4c93e87e51..ad383a11642 100644 --- a/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts @@ -46,7 +46,7 @@ export class Configuration { } get apiKey(): ((name: string) => string) | undefined { - const apiKey = this.configuration.apiKey; + const { apiKey } = this.configuration; if (!apiKey) { return undefined; } @@ -54,7 +54,7 @@ export class Configuration { } get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { - const accessToken = this.configuration.accessToken; + const { accessToken } = this.configuration; if (!accessToken) { return undefined; } @@ -72,7 +72,7 @@ export class BaseAPI { this.middleware = configuration.middleware; } - withMiddleware = (middlewares: Middleware[]) => { + withMiddleware = (middlewares: Middleware[]): this => { const next = this.clone(); next.middleware = next.middleware.concat(middlewares); return next; @@ -132,7 +132,7 @@ export class BaseAPI { * Create a shallow clone of `this` by constructing a new instance * and then shallow cloning data members. */ - private clone = (): BaseAPI => + private clone = (): this => Object.assign(Object.create(Object.getPrototypeOf(this)), this); } diff --git a/samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts b/samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts index e4c93e87e51..ad383a11642 100644 --- a/samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts @@ -46,7 +46,7 @@ export class Configuration { } get apiKey(): ((name: string) => string) | undefined { - const apiKey = this.configuration.apiKey; + const { apiKey } = this.configuration; if (!apiKey) { return undefined; } @@ -54,7 +54,7 @@ export class Configuration { } get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { - const accessToken = this.configuration.accessToken; + const { accessToken } = this.configuration; if (!accessToken) { return undefined; } @@ -72,7 +72,7 @@ export class BaseAPI { this.middleware = configuration.middleware; } - withMiddleware = (middlewares: Middleware[]) => { + withMiddleware = (middlewares: Middleware[]): this => { const next = this.clone(); next.middleware = next.middleware.concat(middlewares); return next; @@ -132,7 +132,7 @@ export class BaseAPI { * Create a shallow clone of `this` by constructing a new instance * and then shallow cloning data members. */ - private clone = (): BaseAPI => + private clone = (): this => Object.assign(Object.create(Object.getPrototypeOf(this)), this); } diff --git a/samples/client/petstore/typescript-rxjs/builds/with-interfaces/runtime.ts b/samples/client/petstore/typescript-rxjs/builds/with-interfaces/runtime.ts index e4c93e87e51..ad383a11642 100644 --- a/samples/client/petstore/typescript-rxjs/builds/with-interfaces/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/with-interfaces/runtime.ts @@ -46,7 +46,7 @@ export class Configuration { } get apiKey(): ((name: string) => string) | undefined { - const apiKey = this.configuration.apiKey; + const { apiKey } = this.configuration; if (!apiKey) { return undefined; } @@ -54,7 +54,7 @@ export class Configuration { } get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { - const accessToken = this.configuration.accessToken; + const { accessToken } = this.configuration; if (!accessToken) { return undefined; } @@ -72,7 +72,7 @@ export class BaseAPI { this.middleware = configuration.middleware; } - withMiddleware = (middlewares: Middleware[]) => { + withMiddleware = (middlewares: Middleware[]): this => { const next = this.clone(); next.middleware = next.middleware.concat(middlewares); return next; @@ -132,7 +132,7 @@ export class BaseAPI { * Create a shallow clone of `this` by constructing a new instance * and then shallow cloning data members. */ - private clone = (): BaseAPI => + private clone = (): this => Object.assign(Object.create(Object.getPrototypeOf(this)), this); } diff --git a/samples/client/petstore/typescript-rxjs/builds/with-npm-version/runtime.ts b/samples/client/petstore/typescript-rxjs/builds/with-npm-version/runtime.ts index e4c93e87e51..ad383a11642 100644 --- a/samples/client/petstore/typescript-rxjs/builds/with-npm-version/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/with-npm-version/runtime.ts @@ -46,7 +46,7 @@ export class Configuration { } get apiKey(): ((name: string) => string) | undefined { - const apiKey = this.configuration.apiKey; + const { apiKey } = this.configuration; if (!apiKey) { return undefined; } @@ -54,7 +54,7 @@ export class Configuration { } get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { - const accessToken = this.configuration.accessToken; + const { accessToken } = this.configuration; if (!accessToken) { return undefined; } @@ -72,7 +72,7 @@ export class BaseAPI { this.middleware = configuration.middleware; } - withMiddleware = (middlewares: Middleware[]) => { + withMiddleware = (middlewares: Middleware[]): this => { const next = this.clone(); next.middleware = next.middleware.concat(middlewares); return next; @@ -132,7 +132,7 @@ export class BaseAPI { * Create a shallow clone of `this` by constructing a new instance * and then shallow cloning data members. */ - private clone = (): BaseAPI => + private clone = (): this => Object.assign(Object.create(Object.getPrototypeOf(this)), this); }