OpenAPITools / OpenAPITools/openapi-generator
[BUG][TYPESCRIPT] Typescript generator generates incorrect code with only default response for objects
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
When an API uses the default response that has an object in it and no other responses, the generated code shows it as being returning a void
openapi-generator version
8.0.0-SNAPSHOT (and previous ones)
OpenAPI declaration file content or url
https://gist.github.com/toebes/55690b1c1176eec56a5140556532b471
Generation Details
- java -jar openapi-generator-cli.jar generate -i test1.json -o gentest1 --additional-properties=useobjectParameters=true -g typescript
- Look at
ObjectParamAIP.tsfor thegetPurchasesBADandgetPurchasesGOODfunctions. Since the only difference between the swagger for the two is thatgetPurchasesGOODhas the default clause duplicated and changed to be200, they should be the same, but thegetPurchasesBADis listed as returningvoid
/**
* This should be returning an object, not void.
* Summary of entry.
* @param param the request object
*/
public getPurchasesBADWithHttpInfo(param: DefaultApiGetPurchasesBADRequest = {}, options?: Configuration): Promise<HttpInfo<void>> {
return this.api.getPurchasesBADWithHttpInfo( options).toPromise();
}
/**
* This should be returning an object, not void.
* Summary of entry.
* @param param the request object
*/
public getPurchasesBAD(param: DefaultApiGetPurchasesBADRequest = {}, options?: Configuration): Promise<void> {
return this.api.getPurchasesBAD( options).toPromise();
}
/**
* This returns an object as expected.
* Get a list of all app purchases made by the current user.
* @param param the request object
*/
public getPurchasesGOODWithHttpInfo(param: DefaultApiGetPurchasesGOODRequest = {}, options?: Configuration): Promise<HttpInfo<GetPurchasesBADDefaultResponse>> {
return this.api.getPurchasesGOODWithHttpInfo( options).toPromise();
}
/**
* This returns an object as expected.
* Get a list of all app purchases made by the current user.
* @param param the request object
*/
public getPurchasesGOOD(param: DefaultApiGetPurchasesGOODRequest = {}, options?: Configuration): Promise<GetPurchasesBADDefaultResponse> {
return this.api.getPurchasesGOOD( options).toPromise();
}
Steps to reproduce
Using the test.json above and downloading the latest master:
java -jar openapi-generator-cli.jar generate -i test.json -o gentest -g typescript
Related issues/PRs
None found
Suggest a fix
In theory, the response.default should produce the same response as having both a response.200 and response.default. Given that the generated code returns GetPurchasesBADDefaultResponse indicates that it does expect the response for the two to be the same.
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
Reproduce the issue with test.json or the linked OpenAPI declaration using the TypeScript generator CLI, then inspect ObjectParamAIP.ts and compare getPurchasesBAD with getPurchasesGOOD. Done means a default-only object response is generated with the same object return type as the equivalent 200-plus-default response.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- typescript
- Domain
- tooling
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100