From 1ec2c260532df9dd20d10b216d4bcb96793b3fde Mon Sep 17 00:00:00 2001 From: Ermolay Romanov Date: Tue, 18 Feb 2020 15:28:26 -0500 Subject: [PATCH] [BUG][typescript-rxjs] Fix nully type coalescing in Configuration getters (#5329) * [typescript-rxjs] fix coalescing in Configuration - eliminate nully "" (empty string) value via conditional check - use concrete "string" type in typeof check ("function" may be returned for Object types * [typescript-rxjs] update petstore sample * run petstore-all - run the script for updating all petstores ./bin/typescript-rxjs-petstore-all.sh --- .../main/resources/typescript-rxjs/runtime.mustache | 10 ++++++++-- .../petstore/typescript-rxjs/builds/default/runtime.ts | 10 ++++++++-- .../typescript-rxjs/builds/es6-target/runtime.ts | 10 ++++++++-- .../typescript-rxjs/builds/with-interfaces/runtime.ts | 10 ++++++++-- .../typescript-rxjs/builds/with-npm-version/runtime.ts | 10 ++++++++-- 5 files changed, 40 insertions(+), 10 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 a978bd7d2cc..366d9b5c441 100644 --- a/modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-rxjs/runtime.mustache @@ -36,12 +36,18 @@ export class Configuration { get apiKey(): ((name: string) => string) | undefined { const apiKey = this.configuration.apiKey; - return apiKey && (typeof apiKey === 'function' ? apiKey : () => apiKey); + if (!apiKey) { + return undefined; + } + return typeof apiKey === 'string' ? () => apiKey : apiKey; } get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { const accessToken = this.configuration.accessToken; - return accessToken && (typeof accessToken === 'function' ? accessToken : () => accessToken); + if (!accessToken) { + return undefined; + } + return typeof accessToken === 'string' ? () => accessToken : accessToken; } } diff --git a/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts b/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts index 40d2e7b3947..e4c93e87e51 100644 --- a/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/default/runtime.ts @@ -47,12 +47,18 @@ export class Configuration { get apiKey(): ((name: string) => string) | undefined { const apiKey = this.configuration.apiKey; - return apiKey && (typeof apiKey === 'function' ? apiKey : () => apiKey); + if (!apiKey) { + return undefined; + } + return typeof apiKey === 'string' ? () => apiKey : apiKey; } get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { const accessToken = this.configuration.accessToken; - return accessToken && (typeof accessToken === 'function' ? accessToken : () => accessToken); + if (!accessToken) { + return undefined; + } + return typeof accessToken === 'string' ? () => accessToken : accessToken; } } 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 40d2e7b3947..e4c93e87e51 100644 --- a/samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/es6-target/runtime.ts @@ -47,12 +47,18 @@ export class Configuration { get apiKey(): ((name: string) => string) | undefined { const apiKey = this.configuration.apiKey; - return apiKey && (typeof apiKey === 'function' ? apiKey : () => apiKey); + if (!apiKey) { + return undefined; + } + return typeof apiKey === 'string' ? () => apiKey : apiKey; } get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { const accessToken = this.configuration.accessToken; - return accessToken && (typeof accessToken === 'function' ? accessToken : () => accessToken); + if (!accessToken) { + return undefined; + } + return typeof accessToken === 'string' ? () => accessToken : accessToken; } } 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 40d2e7b3947..e4c93e87e51 100644 --- a/samples/client/petstore/typescript-rxjs/builds/with-interfaces/runtime.ts +++ b/samples/client/petstore/typescript-rxjs/builds/with-interfaces/runtime.ts @@ -47,12 +47,18 @@ export class Configuration { get apiKey(): ((name: string) => string) | undefined { const apiKey = this.configuration.apiKey; - return apiKey && (typeof apiKey === 'function' ? apiKey : () => apiKey); + if (!apiKey) { + return undefined; + } + return typeof apiKey === 'string' ? () => apiKey : apiKey; } get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { const accessToken = this.configuration.accessToken; - return accessToken && (typeof accessToken === 'function' ? accessToken : () => accessToken); + if (!accessToken) { + return undefined; + } + return typeof accessToken === 'string' ? () => accessToken : accessToken; } } 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 40d2e7b3947..e4c93e87e51 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 @@ -47,12 +47,18 @@ export class Configuration { get apiKey(): ((name: string) => string) | undefined { const apiKey = this.configuration.apiKey; - return apiKey && (typeof apiKey === 'function' ? apiKey : () => apiKey); + if (!apiKey) { + return undefined; + } + return typeof apiKey === 'string' ? () => apiKey : apiKey; } get accessToken(): ((name: string, scopes?: string[]) => string) | undefined { const accessToken = this.configuration.accessToken; - return accessToken && (typeof accessToken === 'function' ? accessToken : () => accessToken); + if (!accessToken) { + return undefined; + } + return typeof accessToken === 'string' ? () => accessToken : accessToken; } }