[Bug] JavaScript client generator should serialize/deserialize polymorphic types
Created by: ErikGrimes
Bug Report Checklist
-
Have you provided a full/minimal spec to reproduce the issue? -
Have you validated the input using an OpenAPI validator (example)? -
Have you tested with the latest master to confirm the issue still exists? - [x ] Have you searched for related issues/PRs?
-
What's the actual output vs expected output? -
[Optional] Sponsorship to speed up the bug fix or feature request (example)
Description
The generated ApiClient.js does not add the discriminator value to the output when it serializes a model. This prevents the server from processing requests where the concrete type is not known ahead of time.
Conversely, the generated ApiClient.js does not make use of the discriminator value to construct the correct concrete type when it deserializes a response.
openapi-generator version
4.3.2
OpenAPI declaration file content or url
components:
schemas:
Node:
type: 'object'
properties:
items:
type: 'array'
items:
$ref: '#/components/schemas/NodeItem'
NodeItem:
type: 'object'
discriminator:
propertyName: 'type'
mapping:
ConcreteItem: '#/components/schemas/ConcreteItem'
properties:
id:
type: 'string'
ConcreteItem:
allOf:
- $ref: '#/components/schemas/NodeItem'
- type: 'object'
properties:
prop1:
type: 'string'
Generation Details
Steps to reproduce
Related issues/PRs
Suggest a fix
The way I currently work around this is by editing the generated ApiClient.js and patching both callApi and convertToType.
Ideally, the generator would generate a ModelMapper, plug that directly into superagent, and allow the end user to replace it if they would like.