Skip to content

Commit

Permalink
Support isResponseOptional in typescript-fetch generator OpenAPITools…
Browse files Browse the repository at this point in the history
  • Loading branch information
sindremb authored Jan 18, 2024
1 parent d810d7c commit 3756c3b
Showing 1 changed file with 30 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -351,21 +351,49 @@ export class {{classname}} extends runtime.BaseAPI {
{{/isDeprecated}}
*/
{{^useSingleRequestParameter}}
async {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}}, {{/allParams}}initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<{{{returnType}}}{{^returnType}}void{{/returnType}}> {
async {{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{#isEnum}}{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{#isNullable}} | null{{/isNullable}}{{/isEnum}}, {{/allParams}}initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<{{{returnType}}}{{#returnType}}{{#isResponseOptional}} | null | undefined {{/isResponseOptional}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
{{#returnType}}
const response = await this.{{nickname}}Raw({{#allParams.0}}{ {{#allParams}}{{paramName}}: {{paramName}}{{^-last}}, {{/-last}}{{/allParams}} }, {{/allParams.0}}initOverrides);
{{#isResponseOptional}}
switch (response.raw.status) {
{{#responses}}
{{#is2xx}}
case {{code}}:
return {{#dataType}}await response.value(){{/dataType}}{{^dataType}}null{{/dataType}};
{{/is2xx}}
{{/responses}}
default:
return await response.value();
}
{{/isResponseOptional}}
{{^isResponseOptional}}
return await response.value();
{{/isResponseOptional}}
{{/returnType}}
{{^returnType}}
await this.{{nickname}}Raw({{#allParams.0}}{ {{#allParams}}{{paramName}}: {{paramName}}{{^-last}}, {{/-last}}{{/allParams}} }, {{/allParams.0}}initOverrides);
{{/returnType}}
}
{{/useSingleRequestParameter}}
{{#useSingleRequestParameter}}
async {{nickname}}({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request{{^hasRequiredParams}} = {}{{/hasRequiredParams}}, {{/allParams.0}}initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<{{{returnType}}}{{^returnType}}void{{/returnType}}> {
async {{nickname}}({{#allParams.0}}requestParameters: {{#prefixParameterInterfaces}}{{classname}}{{/prefixParameterInterfaces}}{{operationIdCamelCase}}Request{{^hasRequiredParams}} = {}{{/hasRequiredParams}}, {{/allParams.0}}initOverrides?: RequestInit | runtime.InitOverrideFunction): Promise<{{{returnType}}}{{#returnType}}{{#isResponseOptional}} | null | undefined {{/isResponseOptional}}{{/returnType}}{{^returnType}}void{{/returnType}}> {
{{#returnType}}
const response = await this.{{nickname}}Raw({{#allParams.0}}requestParameters, {{/allParams.0}}initOverrides);
{{#isResponseOptional}}
switch (response.raw.status) {
{{#responses}}
{{#is2xx}}
case {{code}}:
return {{#dataType}}await response.value(){{/dataType}}{{^dataType}}null{{/dataType}};
{{/is2xx}}
{{/responses}}
default:
return await response.value();
}
{{/isResponseOptional}}
{{^isResponseOptional}}
return await response.value();
{{/isResponseOptional}}
{{/returnType}}
{{^returnType}}
await this.{{nickname}}Raw({{#allParams.0}}requestParameters, {{/allParams.0}}initOverrides);
Expand Down

0 comments on commit 3756c3b

Please sign in to comment.