OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript-node] Missing type argument when using oneOf, $ref & Array

Open
#10,000 1 comment 1 reaction 0 assignees View on GitHub

Nobody has claimed this yet.

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

Description

Description

When using oneOf with $ref and the content of $ref is an array, the generator ignores the type of the array which leads to the typescript error:
Error:(20, 20) TS2314: Generic type 'Array<T>' requires 1 type argument(s).

export class Schema1MyData {
    'data'?: any | Array;    // this should be Array<string>!
//...
openapi-generator version

5.2.0

OpenAPI declaration file content
openapi: 3.0.1
info:
  title: Test
  version: 1.0.0

paths:
  /test:
    get:
      summary: tmp
      responses:
        '200':
          description: Test
          content:
            application/json:
              schema:
                $ref: '#/components/schemas/Schema1'

components:
  schemas:
    Schema1:
      type: object
      properties:
        myData:
          type: object
          properties:
            data:
              oneOf:
                - $ref: '#/components/schemas/Schema2'
                - $ref: '#/components/schemas/Schema3'

    Schema2:
      type: object
      additionalProperties:
        type: string

    Schema3:
      type: array
      items:
        type: string

Command line used for generation

--generator-name=typescript-node

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

Reproduce the issue with the supplied OpenAPI 3.0.1 declaration and --generator-name=typescript-node, checking the generated type for Schema1MyData.data. No source file or test is named in the report, so trace the typescript-node generator from that reproduction. Done means the generated property uses the referenced array element type, such as Array, without the TypeScript generic-argument error.

Written by the indexing model from the issue text.

Assessment

Tech stack
java, typescript
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 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.