OpenAPITools / OpenAPITools/openapi-generator
[BUG] Incorrect code is generated in typescript-fetch generator for oneOf construct
Open
Nobody has claimed this yet.
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
- Generated models contains incorrect import statements like
import {
ActionRequestStepDto | ActivityRequestStepDto | DownloadConfirmationRequestDto | LinkConfirmationRequestDto,
ActionRequestStepDto | ActivityRequestStepDto | DownloadConfirmationRequestDto | LinkConfirmationRequestDtoFromJSON,
ActionRequestStepDto | ActivityRequestStepDto | DownloadConfirmationRequestDto | LinkConfirmationRequestDtoFromJSONTyped,
ActionRequestStepDto | ActivityRequestStepDto | DownloadConfirmationRequestDto | LinkConfirmationRequestDtoToJSON,
} from './ActionRequestStepDto | ActivityRequestStepDto | DownloadConfirmationRequestDto | LinkConfirmationRequestDto';
- XXToJSON converter's maps are also wrong
'steps': ((value.steps as Array<any>).map(ActionRequestStepDto | ActivityRequestStepDto | DownloadConfirmationRequestDto | LinkConfirmationRequestDtoToJSON)),
- Inherited models contain duplicated imports
import {
AbstractRequestStepDto,
AbstractRequestStepDtoFromJSON,
AbstractRequestStepDtoFromJSONTyped,
AbstractRequestStepDtoToJSON,
} from './AbstractRequestStepDto';
import {
ActionRequestStepDto,
ActionRequestStepDtoFromJSON,
ActionRequestStepDtoFromJSONTyped,
ActionRequestStepDtoToJSON,
} from './ActionRequestStepDto';
import {
ActionRequestStepDtoAllOf,
ActionRequestStepDtoAllOfFromJSON,
ActionRequestStepDtoAllOfFromJSONTyped,
ActionRequestStepDtoAllOfToJSON,
} from './ActionRequestStepDtoAllOf';
import {
ActivityRequestStepDto,
ActivityRequestStepDtoFromJSON,
ActivityRequestStepDtoFromJSONTyped,
ActivityRequestStepDtoToJSON,
} from './ActivityRequestStepDto';
import {
DownloadConfirmationRequestDto,
DownloadConfirmationRequestDtoFromJSON,
DownloadConfirmationRequestDtoFromJSONTyped,
DownloadConfirmationRequestDtoToJSON,
} from './DownloadConfirmationRequestDto';
import {
LinkConfirmationRequestDto,
LinkConfirmationRequestDtoFromJSON,
LinkConfirmationRequestDtoFromJSONTyped,
LinkConfirmationRequestDtoToJSON,
} from './LinkConfirmationRequestDto';
import {
ActionRequestStepDtoFromJSONTyped,
ActivityRequestStepDtoFromJSONTyped,
DownloadConfirmationRequestDtoFromJSONTyped,
LinkConfirmationRequestDtoFromJSONTyped
} from './';
herer ^^^^^^^^^^^^^
- Generated model have circular references to it's own definition
export interface ActionRequestStepDto extends AbstractRequestStepDto {
export type AbstractRequestStepDto =
| ({ stepType: "ACTION" } & ActionRequestStepDto)
| ({ stepType: "ACTIVITY" } & ActivityRequestStepDto)
| ({ stepType: "ActionRequestStepDto" } & ActionRequestStepDto)
| ({ stepType: "ActivityRequestStepDto" } & ActivityRequestStepDto)
| ({ stepType: "DOWNLOAD_CONFIRMATION" } & DownloadConfirmationRequestDto)
| ({
stepType: "DownloadConfirmationRequestDto";
} & DownloadConfirmationRequestDto)
| ({ stepType: "LINK_CONFIRMATION" } & LinkConfirmationRequestDto)
| ({ stepType: "LinkConfirmationRequestDto" } & LinkConfirmationRequestDto);
Validator respose
This API is valid, but it cannot be shown because it contains circular references
toText@https://apitools.dev/swagger-parser/online/js/bundle.min.js:17:226677
openapi-generator version
5.4.0
OpenAPI declaration file content or url
https://gist.github.com/Dema/01985a4a8f78040adcdf02b7d5cb8d76
Generation Details
java -jar openapi-generator-cli generate -g typescript-fetch --additional-properties=typescriptThreePlus=true,enumPropertyNaming=original,supportsES6=true,legacyDiscriminatorBehavior=false,useOneOfInterfaces=true
Steps to reproduce
Related issues/PRs
Suggest a fix
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the OpenAPI declaration at the linked gist and run the provided openapi-generator-cli typescript-fetch command with its additional properties. Compare the generated imports, ToJSON mappings, inherited-model imports, and oneOf types with the reported output; done means these generated models no longer contain invalid or duplicated references.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- api, tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 45/100