Bug Report Checklist
Description
I use a "exotic" discriminator property name: @type. This leads to polymorphism issues when generating a typescript-fetch client, because the @ is swallowed by something.
openapi-generator version
generator version 6.2.0
https://github.com/helt/openapi-generator-discriminator-quirks/blob/9b8dbebb8168991b855c3c7b864548a9c6142ec3/middleware/openapitools.json#L4
OpenAPI declaration file content or url
The openapi spec of the bad example:
https://github.com/helt/openapi-generator-discriminator-quirks/blob/9b8dbebb8168991b855c3c7b864548a9c6142ec3/middleware/openapi-bad.json#L10
Openapi spec of the good example:
https://github.com/helt/openapi-generator-discriminator-quirks/blob/9b8dbebb8168991b855c3c7b864548a9c6142ec3/middleware/openapi-good.json#L10
Generation Details
go into the middleware directory of the repro repo and run
Steps to reproduce
look into https://github.com/helt/openapi-generator-discriminator-quirks/blob/master/middleware/modules/typescript-fetch-bad/src/models/Animal.ts which has a portion like this:
For easier repro, I also added the generating spring boot + openapi app.
Related issues/PRs
Suggest a fix
https://github.com/helt/openapi-generator-discriminator-quirks/blob/9b8dbebb8168991b855c3c7b864548a9c6142ec3/middleware/modules/typescript-fetch-bad/src/models/Animal.ts#L60
I think the discriminator property has been altered by the code generator.
export function AnimalFromJSONTyped(
json: any,
ignoreDiscriminator: boolean
): Animal {
if (json === undefined || json === null) {
return json;
}
if (!ignoreDiscriminator) {
if (json["fantatsticClass"] === "fish") { // 👈 should read json["@fantatsticClass"]
return FishFromJSONTyped(json, true);
}
if (json["fantatsticClass"] === "mammal") { // 👈 this one too.
return MammalFromJSONTyped(json, true);
}
}
return {
fantatsticClass: json["@fantatsticClass"],
label: !exists(json, "label") ? undefined : json["label"],
};
}
Bug Report Checklist
Description
I use a "exotic" discriminator property name:
@type. This leads to polymorphism issues when generating a typescript-fetch client, because the@is swallowed by something.openapi-generator version
generator version 6.2.0
https://github.com/helt/openapi-generator-discriminator-quirks/blob/9b8dbebb8168991b855c3c7b864548a9c6142ec3/middleware/openapitools.json#L4
OpenAPI declaration file content or url
The openapi spec of the bad example:
https://github.com/helt/openapi-generator-discriminator-quirks/blob/9b8dbebb8168991b855c3c7b864548a9c6142ec3/middleware/openapi-bad.json#L10
Openapi spec of the good example:
https://github.com/helt/openapi-generator-discriminator-quirks/blob/9b8dbebb8168991b855c3c7b864548a9c6142ec3/middleware/openapi-good.json#L10
Generation Details
go into the
middlewaredirectory of the repro repo and runSteps to reproduce
look into https://github.com/helt/openapi-generator-discriminator-quirks/blob/master/middleware/modules/typescript-fetch-bad/src/models/Animal.ts which has a portion like this:
For easier repro, I also added the generating spring boot + openapi app.
Related issues/PRs
Suggest a fix
https://github.com/helt/openapi-generator-discriminator-quirks/blob/9b8dbebb8168991b855c3c7b864548a9c6142ec3/middleware/modules/typescript-fetch-bad/src/models/Animal.ts#L60
I think the discriminator property has been altered by the code generator.