You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
When using multiple level of inheritance the dicriminators in the root type are not using the defined descriminator value. Instead they fallback to the typename of the derived type. This can be obersved in the example in my repository.
In my example I used NSwag to generate the open api spec (commited in the repo) and also to generate typescript clients (also commited in the repo). The spec contains the correct discriminator values but the typescript type generator uses the wrong one for the base type. This might be related to the fact that the spec only contains the descriminators in the intermediate type. I don't known enough about the spec to decide if the discrimainators should also be part of the base descriminator map or not.
staticfromJS(data: any): Base{data=typeofdata==='object' ? data : {};if(data["$type"]==="SealedA"){letresult=newSealedA();result.init(data);returnresult;}if(data["$type"]==="Intermediate"){thrownewError("The abstract class 'Intermediate' cannot be instantiated.");}if(data["$type"]==="SealedB"){letresult=newSealedB();result.init(data);returnresult;}thrownewError("The abstract class 'Base' cannot be instantiated.");}
staticoverridefromJS(data: any): Intermediate{data=typeofdata==='object' ? data : {};if(data["$type"]==="seal-a"){letresult=newSealedA();result.init(data);returnresult;}if(data["$type"]==="seal-b"){letresult=newSealedB();result.init(data);returnresult;}thrownewError("The abstract class 'Intermediate' cannot be instantiated.");}
The text was updated successfully, but these errors were encountered:
When using multiple level of inheritance the dicriminators in the root type are not using the defined descriminator value. Instead they fallback to the typename of the derived type. This can be obersved in the example in my repository.
In my example I used NSwag to generate the open api spec (commited in the repo) and also to generate typescript clients (also commited in the repo). The spec contains the correct discriminator values but the typescript type generator uses the wrong one for the base type. This might be related to the fact that the spec only contains the descriminators in the intermediate type. I don't known enough about the spec to decide if the discrimainators should also be part of the base descriminator map or not.
Wrong descriminator values in typescript base type
correct types in typescript intermediate type
The text was updated successfully, but these errors were encountered: