Skip to content

Commit 045a9c1

Browse files
authored
fix: support backwards compatible changes in discriminators (#20983)
Closes #20982
1 parent 701b6bd commit 045a9c1

File tree

6 files changed

+7
-7
lines changed

6 files changed

+7
-7
lines changed

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

+1-1
Original file line numberDiff line numberDiff line change
@@ -126,7 +126,7 @@ export function {{classname}}ToJSONTyped(value?: {{#hasReadOnly}}Omit<{{classnam
126126
return {{modelName}}ToJSONTyped(value as {{modelName}}, ignoreDiscriminator);
127127
{{/discriminator.mappedModels}}
128128
default:
129-
throw new Error(`No variant of {{classname}} exists with '{{discriminator.propertyName}}=${value['{{discriminator.propertyName}}']}'`);
129+
return value;
130130
}
131131
}
132132
{{/discriminator}}

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

+2-2
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ export function {{classname}}FromJSONTyped(json: any, ignoreDiscriminator: boole
2727
return Object.assign({}, {{modelName}}FromJSONTyped(json, true), { {{discriminator.propertyName}}: '{{mappingName}}' } as const);
2828
{{/discriminator.mappedModels}}
2929
default:
30-
throw new Error(`No variant of {{classname}} exists with '{{discriminator.propertyName}}=${json['{{discriminator.propertyName}}']}'`);
30+
return json;
3131
}
3232
{{/discriminator}}
3333
{{^discriminator}}
@@ -56,7 +56,7 @@ export function {{classname}}ToJSONTyped(value?: {{classname}} | null, ignoreDis
5656
return Object.assign({}, {{modelName}}ToJSON(value), { {{discriminator.propertyName}}: '{{mappingName}}' } as const);
5757
{{/discriminator.mappedModels}}
5858
default:
59-
throw new Error(`No variant of {{classname}} exists with '{{discriminator.propertyName}}=${value['{{discriminator.propertyName}}']}'`);
59+
return json;
6060
}
6161
{{/discriminator}}
6262

samples/client/others/typescript-fetch/self-import-issue/models/AbstractUserDto.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -96,7 +96,7 @@ export function AbstractUserDtoToJSONTyped(value?: AbstractUserDto | null, ignor
9696
case 'remote-authenticated':
9797
return RemoteAuthenticatedUserDtoToJSONTyped(value as RemoteAuthenticatedUserDto, ignoreDiscriminator);
9898
default:
99-
throw new Error(`No variant of AbstractUserDto exists with 'type=${value['type']}'`);
99+
return value;
100100
}
101101
}
102102

samples/client/petstore/typescript-fetch/builds/default-v3.0/models/Animal.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function AnimalToJSONTyped(value?: Animal | null, ignoreDiscriminator: bo
8282
case 'DOG':
8383
return DogToJSONTyped(value as Dog, ignoreDiscriminator);
8484
default:
85-
throw new Error(`No variant of Animal exists with 'className=${value['className']}'`);
85+
return value;
8686
}
8787
}
8888

samples/client/petstore/typescript-fetch/builds/default-v3.0/models/ParentWithNullable.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ export function ParentWithNullableToJSONTyped(value?: ParentWithNullable | null,
8585
case 'ChildWithNullable':
8686
return ChildWithNullableToJSONTyped(value as ChildWithNullable, ignoreDiscriminator);
8787
default:
88-
throw new Error(`No variant of ParentWithNullable exists with 'type=${value['type']}'`);
88+
return value;
8989
}
9090
}
9191

samples/client/petstore/typescript-fetch/builds/snakecase-discriminator/models/Animal.ts

+1-1
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,7 @@ export function AnimalToJSONTyped(value?: Animal | null, ignoreDiscriminator: bo
8282
case 'DOG':
8383
return DogToJSONTyped(value as Dog, ignoreDiscriminator);
8484
default:
85-
throw new Error(`No variant of Animal exists with 'className=${value['className']}'`);
85+
return value;
8686
}
8787
}
8888

0 commit comments

Comments
 (0)