Skip to content

[BUG][typescript-fetch] duplicate imports for models with a discriminator #15637

@GeroSchaarmann

Description

@GeroSchaarmann

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

After generating the client some imports where duplicated and the generated files with a discriminator have a self import.

openapi-generator version

6.6.0

OpenAPI declaration file content or url
openapi: "3.0.1"
info:
  title: Example
  version: "1"
paths: {}
components:
  schemas:
    BranchDto:
      type: object
      properties:
        name:
          type: string
    AbstractUserDto:
      type: object
      properties:
        username:
          type: string
        branch:
          "$ref": "#/components/schemas/BranchDto"
        type:
          type: string
      discriminator:
        propertyName: type
        mapping:
          internal-authenticated: "#/components/schemas/InternalAuthenticatedUserDto"
          remote-authenticated: "#/components/schemas/RemoteAuthenticatedUserDto"
    InternalAuthenticatedUserDto:
      type: object
      allOf:
        - "$ref": "#/components/schemas/AbstractUserDto"
    RemoteAuthenticatedUserDto:
      type: object
      allOf:
        - "$ref": "#/components/schemas/AbstractUserDto"
Generation Details

The AbstractUserDto.ts has multiple self imports (closer attention to the last import):

import {
    InternalAuthenticatedUserDtoFromJSON,
    InternalAuthenticatedUserDtoFromJSONTyped,
    InternalAuthenticatedUserDtoToJSON,
} from './InternalAuthenticatedUserDto';
import type { RemoteAuthenticatedUserDto } from './RemoteAuthenticatedUserDto';
import {
    RemoteAuthenticatedUserDtoFromJSON,
    RemoteAuthenticatedUserDtoFromJSONTyped,
    RemoteAuthenticatedUserDtoToJSON,
} from './RemoteAuthenticatedUserDto';
import {
    InternalAuthenticatedUserDtoFromJSONTyped,
    RemoteAuthenticatedUserDtoFromJSONTyped
} from './';

Also notice, the empty imports inside the RemoteAuthenticatedUserDto.ts:

import {
} from './';
Steps to reproduce
  1. Create a new config bin/configs/typescript-fetch-self-import-issue.yaml
  2. Fill the Config e.g.
generatorName: typescript-fetch
outputDir: samples/client/others/typescript-fetch/self-import-issue
inputSpec: modules/openapi-generator/src/test/resources/3_0/typescript-fetch/self-import-issue.yaml
templateDir: modules/openapi-generator/src/main/resources/typescript-fetch
additionalProperties:
  typescriptThreePlus: "true"
  legacyDiscriminatorBehavior: "false"
  1. Run
./bin/generate-samples.sh ./bin/configs/typescript-fetch-self-import-issue.yaml
  1. Inspect the above mentioned models in this path
samples/client/others/typescript-fetch/self-import-issue/models
Related issues/PRs
Suggest a fix

Remove the discriminator imports inside the modules/openapi-generator/src/main/resources/typescript-fetch/modelGeneric.mustachefile

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions