Skip to content

Commit 8fb543d

Browse files
committed
fix: correct type checks for string and object arrays in modelOneOf.mustache
1 parent a0de89f commit 8fb543d

1 file changed

Lines changed: 7 additions & 7 deletions

File tree

modules/openapi-generator/src/main/resources/typescript-fetch/modelOneOf.mustache

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -45,8 +45,8 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole
4545
return {} as any;
4646
}
4747
{{#hasStringArrayOneOf}}
48-
if (Array.isArray(json) && json.every(item => item instanceof String)) {
49-
return json as Array<string>;
48+
if (Array.isArray(json) && json.every(item => typeof item === 'string')) {
49+
return json;
5050
}
5151
{{/hasStringArrayOneOf}}
5252
{{#oneOfModels}}
@@ -56,9 +56,9 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole
5656
{{/oneOfModels}}
5757
{{#oneOfArrays}}
5858
{{#-first}}
59-
if (Array.isArray(json) && json.every(item => item instanceof Object)) {
59+
if (Array.isArray(json) && json.every(item => typeof item === 'object')) {
6060
{{/-first}}
61-
if (json.every(item => instanceOf{{{.}}}(item as Object))) {
61+
if (json.every(item => instanceOf{{{.}}}(item))) {
6262
return json.map(value => {{{.}}}FromJSONTyped(value, true));
6363
}
6464
{{#-last}}
@@ -104,7 +104,7 @@ export function {{classname}}ToJSONTyped(value?: {{classname}} | null, ignoreDis
104104
return {};
105105
}
106106
{{#hasStringArrayOneOf}}
107-
if (Array.isArray(value) && value.every(item => item instanceof String)) {
107+
if (Array.isArray(value) && value.every(item => typeof item === 'string')) {
108108
return value;
109109
}
110110
{{/hasStringArrayOneOf}}
@@ -115,9 +115,9 @@ export function {{classname}}ToJSONTyped(value?: {{classname}} | null, ignoreDis
115115
{{/oneOfModels}}
116116
{{#oneOfArrays}}
117117
{{#-first}}
118-
if (Array.isArray(value) && value.every(item => item instanceof Object)) {
118+
if (Array.isArray(value) && value.every(item => typeof item === 'object')) {
119119
{{/-first}}
120-
if (value.every(item => instanceOf{{{.}}}(item as Object))) {
120+
if (value.every(item => instanceOf{{{.}}}(item))) {
121121
return value.map(value => {{{.}}}ToJSON(value as {{{.}}}));
122122
}
123123
{{#-last}}

0 commit comments

Comments
 (0)