Discriminator value and expected deserialization value do not match
See original GitHub issueDescribe the bug I may be doing this wrong, it looks like deserialization is using the component schema name instead of the discriminator name when generating the client (validated with C# and TypeScript) for string discriminators.
If I have a discriminator like this:
"discriminator": {
"propertyName": "type",
"mapping": {
"AccountCreatedV1": "#/components/schemas/AccountCreatedV1EventResponse",
"AccountDeletedV1": "#/components/schemas/AccountDeletedV1EventResponse",
"AccountUpdatedV1": "#/components/schemas/AccountUpdatedV1EventResponse"
}
}
The serialization code for C# looks like this
internal static EventResponseV1 DeserializeEventResponseV1(JsonElement element)
{
if (element.TryGetProperty("type", out JsonElement discriminator))
{
switch (discriminator.GetString())
{
case "AccountCreatedV1EventResponse": return AccountCreatedV1EventResponse.DeserializeAccountCreatedV1EventResponse(element);
case "AccountDeletedV1EventResponse": return AccountDeletedV1EventResponse.DeserializeAccountDeletedV1EventResponse(element);
case "AccountUpdatedV1EventResponse": return AccountUpdatedV1EventResponse.DeserializeAccountUpdatedV1EventResponse(element);
}
}
Expected behavior I would expect the switch statement to use the discriminator name specified in the swagger.json
Additional context @autorest/core: 3.1.3 @autorest/csharp: v3.0.0-beta.20210428.4
Issue Analytics
- State:
- Created 2 years ago
- Comments:7 (3 by maintainers)
Top Results From Across the Web
c# - MongoDB Unknown discriminator value => deserialize to ...
I'd like to deserialize MyProperty to a simple generic BsonDocument or to a string.
Read more >The error is: The discriminator field name "type" for base-class ...
Hi, i have a problem with @Discriminator for abstract class. For example, this structure of classes don't work correctly when I try to...
Read more >Migrate from Newtonsoft.Json to System.Text.Json - .NET
Learn how to migrate from Newtonsoft.Json to System.Text.Json. Includes sample code.
Read more >Inheritance in Jackson | Baeldung
This tutorial will demonstrate how to handle inclusion of subtype metadata and ignoring properties inherited from superclasses with Jackson.
Read more >24 JBO-24000 to JBO-80008 - Oracle Help Center
Cause: The database value does not match the cached value for this entity object. This could happen when another user or operation has...
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Confirmed. That worked. Thanks again!
that change involved changing core and modelerfour. Modelerfour version is usually fixed by whatever generator pick, so my guess is it just locked to an older version before this was supported. You can set the version manually and/or file an issue on the autorest.typescript repo for them to update.