OpenAPITools / OpenAPITools/openapi-generator

[BUG][typescript-axios] Using the allOf description with a combination of $ref and an object results in a wrong typing

Open
#9,162 6 comments 4 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Client: TypeScript 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

Using the typescript-axios generator fails to properly generate the client when using allOf with a combination of a $ref and an object.

openapi-generator version

5.1.0

OpenAPI declaration file content or url

swagger.yml:

openapi: 3.0.2
info:
  title: hello
  version: 1.0.0
components:
  schemas:
    SomeSchema:
      type: object
      properties:
        some_prop:
          type: integer
paths:
  /foobar:
    get:
      responses:
        '200':
          description: ok
          content:
            application/json:
              schema:
                allOf:
                  - $ref: '#/components/schemas/SomeSchema'
                  - type: object
                    properties:
                      foobar: 
                        type: string
Generation Details
openapi-generator-cli generate -i http://localhost:8000/swagger.yml -g typescript-axios -o foo
Steps to reproduce
  1. Run the above script
  2. Look at the generated api.ts
  3. Notice that foobarGet returns AxiosPromise<SomeSchema & object>

I would expect the return type to be AxiosPromise<SomeSchema & { foobar?: string }>

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

Run the stated openapi-generator-cli command against the provided swagger.yml and inspect the generated api.ts, focusing on the typescript-axios handling of the allOf response. Done means the generated foobarGet return type includes SomeSchema & { foobar?: string } rather than SomeSchema & object, while preserving the reproduction behavior.

Written by the indexing model from the issue text.

Assessment

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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.