From 2b1f91d8aaf5bc83aee35498c8efa48316bf6a57 Mon Sep 17 00:00:00 2001 From: lgandecki Date: Wed, 23 Sep 2020 10:26:43 +0200 Subject: [PATCH] feat: include query params in the query --- lib/chimp-datasources-generator.js | 3 +-- lib/typescript-fetch/api.mustache | 38 +++++++++++++++++++++++++++++- 2 files changed, 38 insertions(+), 3 deletions(-) diff --git a/lib/chimp-datasources-generator.js b/lib/chimp-datasources-generator.js index 87f4098..1985357 100755 --- a/lib/chimp-datasources-generator.js +++ b/lib/chimp-datasources-generator.js @@ -5,7 +5,6 @@ const program = require("commander"); const path = require("path"); const extractor = require("./helpers/customDataSourceExtractor"); -// import { BaseDataSource } from "@app/apis/BaseDataSource"; program .command("create [custom-data-source-import]") .description( @@ -15,7 +14,7 @@ program " chimp-datasources-generator create ./generated/external-apis https://domain.com/v3/api-docs.yaml\n" + " chimp-datasources-generator create ./generated/external-apis ./api-docs.yaml\n" + " You can also specify your own custom data source import:\n" + - 'chimp-datasources-generator create ./generated/external-apis ./api-docs.yaml "@app/apis/DataSource#DataSource"' + + 'chimp-datasources-generator create ./generated/external-apis ./api-docs.yaml "@app/apis/DataSource#DataSource"\n' + ' "@app/apis/DataSource#DataSource" will use an import of:\n' + ' import { DataSource } from "@app/apis/DataSource"\n' + " For a default import just use the path:\n" + diff --git a/lib/typescript-fetch/api.mustache b/lib/typescript-fetch/api.mustache index 5b0f597..044b90a 100644 --- a/lib/typescript-fetch/api.mustache +++ b/lib/typescript-fetch/api.mustache @@ -104,8 +104,44 @@ export class {{classname}}Api extends RESTDataSource { const localVarPath = `{{{path}}}`{{#pathParams}} .replace(`{${"{{baseName}}"}}`, encodeURIComponent(String({{paramName}}))){{/pathParams}}; + const localVarUrlObj = url.parse(localVarPath, true); - return this.{{httpMethod}}(localVarPath,{{#bodyParam}}{{paramName}}{{/bodyParam}}) + 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}}) } {{/operation}} }