TypeScript Fetch client generator error with WrapResponses enabled
See original GitHub issueThe 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:
- Created 6 years ago
- Comments:12 (9 by maintainers)
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…
@RSuter I would agree that WrapResponse should always return a response object and never null.