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
and then generated for TypeScript by $(NSwagExe_Net80) openapi2tsclientdon't follow Microsoft's expectations. This is because the generated inherintance toJSON code adds the descriminator in the super class, which gets called after serializing all the fields of the subclass. This results in the descriminator not being the first field, resulting in the following error when trying to send the DTO to the API:
"errors": {
"superClassParameterDto": [
"The superClassParameterDto field is required."
],
"$.$type": [
"The metadata property is either not supported by the type or is not the first property in the deserialized JSON object. Path: $.$type | LineNumber: 0 | BytePositionInLine: 9286."
]
},
Create a TypeScript client as described above, with polymorphic DTOs where the subclasses have own, different fields. Try to use the API that accepts the super class.
Expected behavior
The generated DTOs should have the discriminator as the first field.
Additional context
We've implemented a workaround to 'overrides' and wraps the generated TS DTOs' .toJSON() method so that it first creates the descriminator field before calling the oroginal .toJSON(). A data['$type'] = ''; is enough, it just needs to be there first and will be properly filled out by the generated code later.
The text was updated successfully, but these errors were encountered:
Describe the bug
System.Text.Json
based polymorphic C# DTOs that are annotated withand then generated for TypeScript by
$(NSwagExe_Net80) openapi2tsclient
don't follow Microsoft's expectations. This is because the generated inherintancetoJSON
code adds the descriminator in the super class, which gets called after serializing all the fields of the subclass. This results in the descriminator not being the first field, resulting in the following error when trying to send the DTO to the API:Version used
To Reproduce
Create a TypeScript client as described above, with polymorphic DTOs where the subclasses have own, different fields. Try to use the API that accepts the super class.
Expected behavior
The generated DTOs should have the discriminator as the first field.
Additional context
We've implemented a workaround to 'overrides' and wraps the generated TS DTOs'
.toJSON()
method so that it first creates the descriminator field before calling the oroginal.toJSON()
. Adata['$type'] = '';
is enough, it just needs to be there first and will be properly filled out by the generated code later.The text was updated successfully, but these errors were encountered: