Skip to content
GitLab
Projects Groups Snippets
  • /
  • Help
    • Help
    • Support
    • Community forum
    • Submit feedback
    • Contribute to GitLab
  • Sign in / Register
  • O openapi-generator
  • Project information
    • Project information
    • Activity
    • Labels
    • Members
  • Repository
    • Repository
    • Files
    • Commits
    • Branches
    • Tags
    • Contributors
    • Graph
    • Compare
  • Issues 3,476
    • Issues 3,476
    • List
    • Boards
    • Service Desk
    • Milestones
  • Merge requests 402
    • Merge requests 402
  • CI/CD
    • CI/CD
    • Pipelines
    • Jobs
    • Schedules
  • Deployments
    • Deployments
    • Environments
    • Releases
  • Packages and registries
    • Packages and registries
    • Package Registry
    • Infrastructure Registry
  • Monitor
    • Monitor
    • Incidents
  • Analytics
    • Analytics
    • Value stream
    • CI/CD
    • Repository
  • Wiki
    • Wiki
  • Snippets
    • Snippets
  • Activity
  • Graph
  • Create a new issue
  • Jobs
  • Commits
  • Issue Boards
Collapse sidebar
  • OpenAPI Tools
  • openapi-generator
  • Issues
  • #7407
Closed
Open
Issue created Sep 12, 2020 by Administrator@rootContributor1 of 5 checklist items completed1/5 checklist items

[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.

Assignee
Assign to
Time tracking