diff --git a/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache b/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache index 7d5c01878949..d7eb29c1d522 100644 --- a/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache +++ b/modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache @@ -56,12 +56,11 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole if (Array.isArray(json)) { if (json.every(item => typeof item === 'object')) { {{/-first}} - if (json.every(item => instanceOf{{{.}}}(item))) { - return json.map(value => {{{.}}}FromJSONTyped(value, true)); + if (json.every(item => instanceOf{{{.}}}(item as object))) { + return json.map(item => {{{.}}}FromJSONTyped(item, true)); } {{#-last}} } - return json; } {{/-last}} {{/oneOfArrays}} @@ -70,15 +69,15 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole {{#items}} {{#isDateType}} if (Array.isArray(json)) { - if (json.every(item => !(isNaN(new Date(json).getTime()))) { - return json.map(value => new Date(json); + if (json.every(item => !(isNaN(new Date(item).getTime())))) { + return json.map(item => new Date(item)); } } {{/isDateType}} {{#isDateTimeType}} if (Array.isArray(json)) { - if (json.every(item => !(isNaN(new Date(json).getTime()))) { - return json.map(value => new Date(json); + if (json.every(item => !(isNaN(new Date(item).getTime())))) { + return json.map(item => new Date(item)); } } {{/isDateTimeType}} @@ -161,12 +160,11 @@ export function {{classname}}ToJSONTyped(value?: {{classname}} | null, ignoreDis if (Array.isArray(value)) { if (value.every(item => typeof item === 'object')) { {{/-first}} - if (value.every(item => instanceOf{{{.}}}(item))) { - return value.map(value => {{{.}}}ToJSON(value as {{{.}}})); + if (value.every(item => instanceOf{{{.}}}(item as object))) { + return value.map(item => {{{.}}}ToJSON(item as {{{.}}})); } {{#-last}} } - return value; } {{/-last}} {{/oneOfArrays}} @@ -175,15 +173,15 @@ export function {{classname}}ToJSONTyped(value?: {{classname}} | null, ignoreDis {{#items}} {{#isDateType}} if (Array.isArray(value)) { - if (value.every(item => item instanceof Date) { - return value.map(value => value.toISOString().substring(0,10))); + if (value.every(item => item instanceof Date)) { + return value.map(item => item.toISOString().substring(0,10)); } } {{/isDateType}} {{#isDateTimeType}} if (Array.isArray(value)) { - if (value.every(item => item instanceof Date) { - return value.map(value => value.toISOString(); + if (value.every(item => item instanceof Date)) { + return value.map(item => item.toISOString()); } } {{/isDateTimeType}} diff --git a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestArrayResponse.ts b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestArrayResponse.ts index 29e0eb1017e3..4de44b9f6d9e 100644 --- a/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestArrayResponse.ts +++ b/samples/client/petstore/typescript-fetch/builds/oneOf/models/TestArrayResponse.ts @@ -44,14 +44,13 @@ export function TestArrayResponseFromJSONTyped(json: any, ignoreDiscriminator: b } if (Array.isArray(json)) { if (json.every(item => typeof item === 'object')) { - if (json.every(item => instanceOfTestA(item))) { - return json.map(value => TestAFromJSONTyped(value, true)); + if (json.every(item => instanceOfTestA(item as object))) { + return json.map(item => TestAFromJSONTyped(item, true)); } - if (json.every(item => instanceOfTestB(item))) { - return json.map(value => TestBFromJSONTyped(value, true)); + if (json.every(item => instanceOfTestB(item as object))) { + return json.map(item => TestBFromJSONTyped(item, true)); } } - return json; } if (Array.isArray(json)) { if (json.every(item => typeof item === 'string')) { @@ -71,14 +70,13 @@ export function TestArrayResponseToJSONTyped(value?: TestArrayResponse | null, i } if (Array.isArray(value)) { if (value.every(item => typeof item === 'object')) { - if (value.every(item => instanceOfTestA(item))) { - return value.map(value => TestAToJSON(value as TestA)); + if (value.every(item => instanceOfTestA(item as object))) { + return value.map(item => TestAToJSON(item as TestA)); } - if (value.every(item => instanceOfTestB(item))) { - return value.map(value => TestBToJSON(value as TestB)); + if (value.every(item => instanceOfTestB(item as object))) { + return value.map(item => TestBToJSON(item as TestB)); } } - return value; } if (Array.isArray(value)) { if (value.every(item => typeof item === 'string')) {