OpenAPITools / OpenAPITools/openapi-generator
[BUG] ApiProperty oneOf does not work with typescript-node generator
Nobody has claimed this yet.
- 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
ApiProperty "oneOf" does not generate correctly with typescript-node, but works fine for typescript-angular.
DTO code below:
@Expose()
@ApiProperty({
oneOf: [
{
type: "string",
example: "USD",
},
{ type: "number", example: 5 },
{ type: "boolean", example: true },
],
description: "The value of the setting.",
})
readonly value: string | number | boolean;
And in the typescript generation it creates:
export type SettingResponseValue = boolean | number | string;
Whereas for the node generation it creates:
export class SettingResponseValue {
static discriminator: string | undefined = undefined;
static attributeTypeMap: Array<{name: string, baseName: string, type: string}> = [
];
static getAttributeTypeMap() {
return SettingResponseValue.attributeTypeMap;
}
}
Even though it is based off the same DTO.
openapi-generator version
2.7.0
OpenAPI declaration file content or url
"value": {
"oneOf": [
{
"type": "string",
"example": "USD"
},
{
"type": "number",
"example": 5
},
{
"type": "boolean",
"example": true
}
],
"description": "The value of the setting in string format."
}
Relevant part of the validated spec from: https://apidevtools.org/swagger-parser/online/
Generation Details
openapi-generator-cli generate -i https://path-to-open-api-json -g typescript-node -o ../../package-name -p npmName=@company/package-name --git-repo-id package-name --git-user-id Company-User
Steps to reproduce
Create a DTO with a property like this:
@Expose()
@ApiProperty({
oneOf: [
{
type: "string",
example: "USD",
},
{ type: "number", example: 5 },
{ type: "boolean", example: true },
],
description: "The value of the setting.",
})
readonly value: string | number | boolean;
And run generation, once for typescript-node and once for typescript-angular. Angular generates correctly, node does not.
Related issues/PRs
Suggest a fix
Can this be made to work at least like the typescript generation?
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 by reproducing the supplied oneOf property with the typescript-node generator command, then compare its output with the typescript-angular result. Trace the typescript-node handling of oneOf and verify the generated model represents the string, number, and boolean alternatives as expected; add or run a regression test if the generator's test entry point is identified.
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
- 42/100