OpenAPITools / OpenAPITools/openapi-generator

[BUG] Typescript-axios discriminator child-models has addition wrong self import

Open
#6,868 1 comment 0 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
  • [ x ] Have you provided a full/minimal spec to reproduce the issue?
  • [ x ] Have you validated the input using an OpenAPI validator (example)?
  • [ x ] What's the version of OpenAPI Generator used?
  • [ x ] Have you search for related issues/PRs?
  • [ x ] What's the actual output vs expected output?
  • [Optional] Bounty to sponsor the fix (example)
Description

Import declaration conflicts with local declaration of Result1

import { Result1 } from './result1';
import { Result1AllOf } from './result1-all-of';
import { Result2 } from './result2';
import { ResultBase } from './result-base';

/**
 * @type Result1
 * @export
 */
export type Result1 = Result1AllOf & ResultBase;
openapi-generator version

Latest docker image from master, 5.0.0

OpenAPI declaration file content or url
openapi: 3.0.3
info:
  version: 0.0.1
  title: TS discriminator bad imports example

paths: {}

components:
  schemas:

    Result1:
      allOf:
        - $ref: '#/components/schemas/ResultBase'
        - type: object
          properties:
            result1Property:
              type: string

    Result2:
      allOf:
        - $ref: '#/components/schemas/ResultBase'
        - type: object
          properties:
            result2Property:
              type: string

    ResultBase:
      type: object
      description: "Common fields for all results objects"
      properties:
        result_type:
          type: integer
      discriminator:
        propertyName: result_type
        mapping:
          1: "#/components/schemas/Result1"
          2: "#/components/schemas/Result2"

{
  "withSeparateModelsAndApi": true,
  "apiPackage": "api",
  "modelPackage": "models",
  "legacyDiscriminatorBehavior": false
}

ts-discriminator-import.zip

Command line used for generation
docker run --rm -v "${PWD}:/local" openapitools/openapi-generator-cli generate \
-i /local/openapi.yml -g typescript-axios -o /local/generated \
-c /local/settings.json

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

Use the provided openapi.yml and settings.json with the documented Docker command to reproduce the generated TypeScript Axios models. Inspect the generated Result1 model and related imports, then verify that Result1 is not imported into the file where it is declared. Confirm the fix by regenerating the client and checking that the conflicting self-import and TypeScript error are gone.

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
Clearly specified
Newbie friendliness
45/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.