Describe 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
Hi @nascosto do you know which version of @autorest/modelerfour got picked, it should get displayed at the beginning in the logs? This functionality was added relatively recently.
Otherwise can you share the spec you used?
@autorest/modelerfour' (4.19.0->4.19.0)
swagger.json.txt
It is actually the version of @autorest/core you have is just before the feature was added (in 3.2.0)
https://github.com/Azure/autorest/blob/master/packages/extensions/core/CHANGELOG.md#320
try to update to latest
You are right. Thanks.
Generation works properly for C# and Java, but TypeScript is still doing the same thing from before. Shall I post on that project?
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.
--use:@autorest/modelerfour@~4.18.1
Confirmed. That worked. Thanks again!