Skip to content

Commit

Permalink
Merge pull request #4 from jmvtrinidad/use-fetch-from-datasource
Browse files Browse the repository at this point in the history
feat: use fetch from datasource and fetchParamCreator to create request
  • Loading branch information
lgandecki authored Sep 28, 2020
2 parents 9a69e6d + 44078ef commit c9a3e00
Showing 1 changed file with 6 additions and 43 deletions.
49 changes: 6 additions & 43 deletions lib/typescript-fetch/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -99,51 +99,14 @@ export class {{classname}}Api extends RESTDataSource {
super();
this.baseURL = baseUrl;
}
paramCreator = {{classname}}FetchParamCreator()
{{#operation}}
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Response{{/returnType}}> {
{{nickname}}({{#allParams}}{{paramName}}{{^required}}?{{/required}}: {{{dataType}}}, {{/allParams}}): Promise<{{#returnType}}{{{returnType}}}{{/returnType}}{{^returnType}}Response{{/returnType}}> {
const args = this.paramCreator.{{nickname}}({{#allParams}}{{paramName}}, {{/allParams}})

const localVarPath = `{{{path}}}`{{#pathParams}}
.replace(`{${"{{baseName}}"}}`, encodeURIComponent(String({{paramName}}))){{/pathParams}};

const localVarUrlObj = url.parse(localVarPath, true);

const localVarQueryParameter = {}
{{#queryParams}}
{{#isListContainer}}
if ({{paramName}}) {
{{#isCollectionFormatMulti}}
localVarQueryParameter['{{baseName}}'] = {{paramName}};
{{/isCollectionFormatMulti}}
{{^isCollectionFormatMulti}}
localVarQueryParameter['{{baseName}}'] = {{paramName}}.join(COLLECTION_FORMATS["{{collectionFormat}}"]);
{{/isCollectionFormatMulti}}
}
{{/isListContainer}}
{{^isListContainer}}
if ({{paramName}} !== undefined) {
{{#isDateTime}}
localVarQueryParameter['{{baseName}}'] = ({{paramName}} as any).toISOString();
{{/isDateTime}}
{{^isDateTime}}
{{#isDate}}
localVarQueryParameter['{{baseName}}'] = ({{paramName}} as any).toISOString();
{{/isDate}}
{{^isDate}}
localVarQueryParameter['{{baseName}}'] = {{paramName}};
{{/isDate}}
{{/isDateTime}}
}
{{/isListContainer}}

{{/queryParams}}

localVarUrlObj.query = Object.assign({}, localVarUrlObj.query, localVarQueryParameter);

delete localVarUrlObj.search;


return this.{{httpMethod}}(url.format(localVarUrlObj),{{#bodyParam}}{{paramName}}{{/bodyParam}})
}
// @ts-ignore
return this.fetch(Object.assign(args.options, { path: args.url }))
}
{{/operation}}
}

Expand Down

0 comments on commit c9a3e00

Please # to comment.