question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

TypeScript Fetch client generator error with WrapResponses enabled

See original GitHub issue

The TypeScript Fetch client generator with promises seems to cause some strange behaviour compared to for example the Angular2 client generator with the same options when handling 204 responses from a delete endpoint with the option WrapResponses = enabled.

For example, the Fetch client generator generates the following code to handle the 204 response:

if (status === 204) {
    return response.text().then((_responseText) => {
    return;
    });
}

Which will throw an error because the generated ProcessDelete method expects a return of type Promise<SwaggerResponse<void>>.

While the Angular2 generator generates the following code, with the same endpoint and the same generator settings:

if (status === 204) {
    const _responseText = response.text();
    return Observable.of<SwaggerResponse<void>>(<any>null);
}

Which is a valid return for the generated ProcessDelete method.

These are the settings i am using for respectively the fetch and angular generator:

new SwaggerToTypeScriptClientGeneratorSettings
            {
                ClassName = "{controller}Client",
                PromiseType = PromiseType.Promise,
                BaseUrlTokenName = "API_BASE_URL",
                ImportRequiredTypes = true,
                Template = TypeScriptTemplate.Fetch,
                WrapResponses = true,
                TypeScriptGeneratorSettings =
                {
                    MarkOptionalProperties = true,
                    TypeScriptVersion = 2.0m,
                }
            };
new SwaggerToTypeScriptClientGeneratorSettings
            {
                ClassName = "{controller}Client",
                Template = TypeScriptTemplate.Angular,
                GenerateOptionalParameters = true,
                WrapResponses = true,
                TypeScriptGeneratorSettings =
                {
                    TypeScriptVersion = 2.0m,
                }
            };

Am i doing/understanding something wrong or is this a bug in the fetch client generator template?

If you need any more information please let me know.

Thanks in advance

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:12 (9 by maintainers)

github_iconTop GitHub Comments

2reactions
RicoSutercommented, Nov 10, 2017

This is probably a bug - I dont use WrapResponses in any of my projects, so this is not as well tested as the other options… I even think that the angular code is wrong - it should always return a SwaggerResponse and never null…

1reaction
ml-devcommented, Nov 10, 2017

@RSuter I would agree that WrapResponse should always return a response object and never null.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Documentation for the typescript-fetch Generator
helpTxt, Generates a TypeScript client library using Fetch API (beta). ... With this option enabled, each enum will have a new case, ...
Read more >
OpenAPI 3.1 with openapi-generator-cli typescript-fetch
I would like to generate a typescript-fetch client using openapi-generator-cli. The specs were generated by Stoplight using OpenAPI 3.1 ...
Read more >
Using fetch with TypeScript
When migrating some code to TypeScript, I ran into a few little hurdles I want to share with you. The use case: In...
Read more >
How to use Swagger Codegen TypeScript Fetch Client
Has anyone successfully used the Swagger Code Generator to create a TypeScript Fetch client that can be used within the browser?
Read more >
openapi-typescript-fetch
A typed fetch client for openapi-typescript. ... Start using openapi-typescript-fetch in your project by running `npm i ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found