Skip to content

[BUG][TYPESCRIPT] Typescript generator generates incorrect code with only default response for objects #17046

@toebes

Description

@toebes

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
  1. java -jar openapi-generator-cli.jar generate -i test1.json -o gentest1 --additional-properties=useobjectParameters=true -g typescript
  2. Look at ObjectParamAIP.ts for the getPurchasesBAD and getPurchasesGOOD functions. Since the only difference between the swagger for the two is that getPurchasesGOOD has the default clause duplicated and changed to be 200, they should be the same, but the getPurchasesBAD is listed as returning void
    /**
     * 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.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions