Skip to content

Commit

Permalink
Merge pull request #2 from xolvio/query-parameters
Browse files Browse the repository at this point in the history
feat: include query params in the query
  • Loading branch information
lgandecki authored Sep 23, 2020
2 parents b44b233 + 2b1f91d commit 789110f
Show file tree
Hide file tree
Showing 2 changed files with 38 additions and 3 deletions.
3 changes: 1 addition & 2 deletions lib/chimp-datasources-generator.js
Original file line number Diff line number Diff line change
Expand Up @@ -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 <directory> <api-location> [custom-data-source-import]")
.description(
Expand All @@ -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" +
Expand Down
38 changes: 37 additions & 1 deletion lib/typescript-fetch/api.mustache
Original file line number Diff line number Diff line change
Expand Up @@ -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}}
}
Expand Down

0 comments on commit 789110f

Please # to comment.