OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript] `oneOf` + `allOf` breaks serialization

Open
#19,868 7 comments 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

Issue: Bug
Dominant language
Java
Stars
26.8k
Forks
7.7k
PR merge metrics
PR metrics pending

Description

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?
  • 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

When using an API that uses a oneOf union containing several allOf elements, trying to send/receive data will fail with the error typeMap[type].getAttributeTypeMap is not a function. The underlying reason is that no discriminator value or mapping is generated for this value.

Prior to #19494 this worked fine, but as of 7.9.0 trying to run this schema will crash.

openapi-generator version

7.9.0, this is a regression.

OpenAPI declaration file content or url
openapi: 3.0.1
info:
  title: fruity
  version: 0.0.1
paths:
  /:
    get:
      responses:
        "200":
          description: get a fruit
          content:
            application/json:
              schema:
                $ref: "#/components/schemas/Fruit"
components:
  schemas:
    Apple:
      title: Apple
      type: object
      properties:
        variety:
          type: string
          description: The type of apple
      required:
        - variety
    Banana:
      title: Banana
      type: object
      properties:
        ripeness:
          type: number
          description: How ripe the banana is from 0 to 1
    Fruit:
      title: Fruit
      oneOf:
        - type: object
          allOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - apple
            - $ref: '#/components/schemas/Apple'
          required:
            - type
        - type: object
          allOf:
            - type: object
              properties:
                type:
                  type: string
                  enum:
                    - banana
            - $ref: '#/components/schemas/Banana'
          required:
            - type
Generation Details

Generated with v7.9.0.

Steps to reproduce

Generate the above yaml using the typescript generator, then try to use the API. It will fail with typeMap[type].getAttributeTypeMap is not a function

Related issues/PRs

Not as far as I could tell.

Suggest a fix

I don't have an exact fix in mind since I don't fully understand how this mapping logic is supposed to work.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start by generating the supplied YAML with the TypeScript generator and reproduce the failure in the generated oneOf/allOf serialization path. Trace the typeMap handling and discriminator or mapping generation, then verify that requests and responses work for both Apple and Banana and add a regression test if the generator's existing test structure supports it.

Written by the indexing model from the issue text.

Assessment

Tech stack
typescript
Domain
api, tooling
Issue type
Bug
Difficulty
4/5
Estimated time
3-5 days
Activity status
Stale
Clarity
Mostly clear
Newbie friendliness
35/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.