api-typescript-generator
Advanced tools
Comparing version 2.2.5 to 2.2.6
@@ -70,3 +70,3 @@ export interface CommonHttpClientOptions { | ||
} | ||
type ResponseByMediaType<T extends CommonHttpClientResponse<unknown>, K extends string> = T extends any ? ((a: T) => void) extends (a: { | ||
type ResponseByMediaType<T extends CommonHttpClientResponse<unknown>, K extends string> = T extends unknown ? ((a: T) => void) extends (a: { | ||
mediaType: K; | ||
@@ -73,0 +73,0 @@ status: infer _Status; |
@@ -210,6 +210,4 @@ "use strict"; | ||
}); | ||
if (response.headers.has('set-cookie')) { | ||
if ('getSetCookie' in response.headers) { | ||
headers['set-cookie'] = response.headers.getSetCookie(); | ||
} | ||
if (response.headers.has('set-cookie') && 'getSetCookie' in response.headers) { | ||
headers['set-cookie'] = response.headers.getSetCookie(); | ||
} | ||
@@ -216,0 +214,0 @@ return { |
@@ -222,3 +222,6 @@ export interface CommonHttpClientOptions { | ||
type ResponseByMediaType<T extends CommonHttpClientResponse<unknown>, K extends string> = T extends any | ||
/** | ||
* `extends unknown` is a trick to split the union into individual types. | ||
*/ | ||
type ResponseByMediaType<T extends CommonHttpClientResponse<unknown>, K extends string> = T extends unknown | ||
? ((a: T) => void) extends (a: { | ||
@@ -391,6 +394,4 @@ mediaType: K; | ||
}); | ||
if (response.headers.has('set-cookie')) { | ||
if ('getSetCookie' in response.headers) { | ||
headers['set-cookie'] = (response.headers as {getSetCookie(): string[]}).getSetCookie(); | ||
} | ||
if (response.headers.has('set-cookie') && 'getSetCookie' in response.headers) { | ||
headers['set-cookie'] = (response.headers as {getSetCookie(): string[]}).getSetCookie(); | ||
} | ||
@@ -397,0 +398,0 @@ return { |
@@ -8,5 +8,5 @@ import * as commonHttpClient from './common-http-client'; | ||
const classInstance = this.constructor as typeof CommonHttpService; | ||
if (!classInstance.initialized) { | ||
if (classInstance.initialized !== true) { | ||
classInstance.initialized = true; | ||
if (classInstance.initialize) { | ||
if (classInstance.initialize !== undefined) { | ||
classInstance.initialize(); | ||
@@ -20,3 +20,3 @@ } | ||
protected static initialized: boolean | undefined; | ||
protected static initialize: () => void | undefined; | ||
protected static initialize: (() => void) | undefined; | ||
} |
@@ -462,6 +462,22 @@ "use strict"; | ||
caseEntries = Object.entries(cases); | ||
let prefIfStatement = (0, types_1.ifStatement)(buildCondition(caseEntries[0][0]), buildStatement(caseEntries[0][1], caseEntries[0][0])); | ||
const ifBlockInfos = caseEntries.map(([key, value]) => ({ | ||
condition: buildCondition(key), | ||
statement: buildStatement(value, key) | ||
})); | ||
const resultingIfBlocks = []; | ||
while (ifBlockInfos.length > 0) { | ||
const info = ifBlockInfos.shift(); | ||
for (let i = 0; i < ifBlockInfos.length; i++) { | ||
if (R.equals(ifBlockInfos[i].statement, info.statement)) { | ||
info.condition = (0, types_1.logicalExpression)('||', info.condition, ifBlockInfos[i].condition); | ||
ifBlockInfos.splice(i, 1); | ||
i--; | ||
} | ||
} | ||
resultingIfBlocks.push((0, types_1.ifStatement)(info.condition, info.statement)); | ||
} | ||
let prefIfStatement = resultingIfBlocks.shift(); | ||
const result = prefIfStatement; | ||
for (let i = 1; i < caseEntries.length; i++) { | ||
const newIfStatement = (0, types_1.ifStatement)(buildCondition(caseEntries[i][0]), buildStatement(caseEntries[i][1], caseEntries[i][0])); | ||
while (resultingIfBlocks.length > 0) { | ||
const newIfStatement = resultingIfBlocks.shift(); | ||
prefIfStatement.alternate = newIfStatement; | ||
@@ -468,0 +484,0 @@ prefIfStatement = newIfStatement; |
{ | ||
"name": "api-typescript-generator", | ||
"version": "2.2.5", | ||
"version": "2.2.6", | ||
"description": "Generates OpenAPI TypeScript client. Extremely fast and flexible.", | ||
@@ -5,0 +5,0 @@ "license": "MIT", |
@@ -222,3 +222,6 @@ export interface CommonHttpClientOptions { | ||
type ResponseByMediaType<T extends CommonHttpClientResponse<unknown>, K extends string> = T extends any | ||
/** | ||
* `extends unknown` is a trick to split the union into individual types. | ||
*/ | ||
type ResponseByMediaType<T extends CommonHttpClientResponse<unknown>, K extends string> = T extends unknown | ||
? ((a: T) => void) extends (a: { | ||
@@ -391,6 +394,4 @@ mediaType: K; | ||
}); | ||
if (response.headers.has('set-cookie')) { | ||
if ('getSetCookie' in response.headers) { | ||
headers['set-cookie'] = (response.headers as {getSetCookie(): string[]}).getSetCookie(); | ||
} | ||
if (response.headers.has('set-cookie') && 'getSetCookie' in response.headers) { | ||
headers['set-cookie'] = (response.headers as {getSetCookie(): string[]}).getSetCookie(); | ||
} | ||
@@ -397,0 +398,0 @@ return { |
@@ -8,5 +8,5 @@ import * as commonHttpClient from './common-http-client'; | ||
const classInstance = this.constructor as typeof CommonHttpService; | ||
if (!classInstance.initialized) { | ||
if (classInstance.initialized !== true) { | ||
classInstance.initialized = true; | ||
if (classInstance.initialize) { | ||
if (classInstance.initialize !== undefined) { | ||
classInstance.initialize(); | ||
@@ -20,3 +20,3 @@ } | ||
protected static initialized: boolean | undefined; | ||
protected static initialize: () => void | undefined; | ||
protected static initialize: (() => void) | undefined; | ||
} |
@@ -13,2 +13,3 @@ import * as fs from 'fs'; | ||
identifier, | ||
IfStatement, | ||
ifStatement, | ||
@@ -18,2 +19,3 @@ isIdentifier, | ||
isVariableDeclaration, | ||
logicalExpression, | ||
memberExpression, | ||
@@ -560,12 +562,22 @@ newExpression, | ||
caseEntries = Object.entries(cases); | ||
let prefIfStatement = ifStatement( | ||
buildCondition(caseEntries[0][0]), | ||
buildStatement(caseEntries[0][1], caseEntries[0][0]) | ||
); | ||
const ifBlockInfos: {condition: Expression; statement: Statement}[] = caseEntries.map(([key, value]) => ({ | ||
condition: buildCondition(key), | ||
statement: buildStatement(value, key) | ||
})); | ||
const resultingIfBlocks: IfStatement[] = []; | ||
while (ifBlockInfos.length > 0) { | ||
const info = ifBlockInfos.shift()!; | ||
for (let i = 0; i < ifBlockInfos.length; i++) { | ||
if (R.equals(ifBlockInfos[i].statement, info.statement)) { | ||
info.condition = logicalExpression('||', info.condition, ifBlockInfos[i].condition); | ||
ifBlockInfos.splice(i, 1); | ||
i--; | ||
} | ||
} | ||
resultingIfBlocks.push(ifStatement(info.condition, info.statement)); | ||
} | ||
let prefIfStatement = resultingIfBlocks.shift()!; | ||
const result = prefIfStatement; | ||
for (let i = 1; i < caseEntries.length; i++) { | ||
const newIfStatement = ifStatement( | ||
buildCondition(caseEntries[i][0]), | ||
buildStatement(caseEntries[i][1], caseEntries[i][0]) | ||
); | ||
while (resultingIfBlocks.length > 0) { | ||
const newIfStatement = resultingIfBlocks.shift()!; | ||
prefIfStatement.alternate = newIfStatement; | ||
@@ -572,0 +584,0 @@ prefIfStatement = newIfStatement; |
735312
13921