-
-
Notifications
You must be signed in to change notification settings - Fork 7.4k
Closed
Closed
Copy link
Labels
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
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
- Create a new config
bin/configs/typescript-fetch-self-import-issue.yaml - 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"- Run
./bin/generate-samples.sh ./bin/configs/typescript-fetch-self-import-issue.yaml
- 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
henrikkampshoff, Nikos410, Digirik, dodgex, jproples and 13 more