diff --git a/package.json b/package.json index 23fe797e..b3b01f14 100644 --- a/package.json +++ b/package.json @@ -177,11 +177,11 @@ "bundlesize": [ { "path": "lib/**/*.js", - "maxSize": "46 kB" + "maxSize": "48 kB" }, { "path": "commerce-sdk-isomorphic-with-deps.tgz", - "maxSize": "400 kB" + "maxSize": "410 kB" } ], "proxy": "https://SHORTCODE.api.commercecloud.salesforce.com" diff --git a/scripts/utils.ts b/scripts/utils.ts index 0000b83d..865f2e7f 100644 --- a/scripts/utils.ts +++ b/scripts/utils.ts @@ -46,6 +46,10 @@ export function registerPartials(): void { 'operationsPartial', path.join(TEMPLATE_DIRECTORY, 'operations.ts.hbs') ); + registerPartial( + 'paramKeysPartial', + path.join(TEMPLATE_DIRECTORY, 'paramKeys.ts.hbs') + ); } function addTemplates(apis: ApiMetadata, outputBasePath: string): ApiMetadata { diff --git a/src/test/parameters.test.ts b/src/test/parameters.test.ts index e29be4de..d5b48e5d 100644 --- a/src/test/parameters.test.ts +++ b/src/test/parameters.test.ts @@ -25,6 +25,13 @@ describe('Parameters', () => { .reply(200, MOCK_RESPONSE) ); + it('has a list of parameter keys (and the required ones)', () => { + // eslint-disable-next-line + expect(ShopperSearch.paramKeys?.productSearch).toBeDefined(); + // eslint-disable-next-line + expect(ShopperSearch.paramKeys?.productSearchRequired).toBeDefined(); + }); + it('can all be specified in config (no method parameters object)', async () => { const searchClient = new ShopperSearch({ parameters: { diff --git a/templates/client.ts.hbs b/templates/client.ts.hbs index 8246ea31..b452c97d 100644 --- a/templates/client.ts.hbs +++ b/templates/client.ts.hbs @@ -80,13 +80,12 @@ export type {{name.upperCamelCase}}Parameters = {{name.upperCamelCase}}PathParam * * * API Version: {{metadata.version}}
-* Last Updated: {{metadata.updatedDate}}
+* Last Updated: {{metadata.updatedDate}}
*
-{{#if (eq (lowercase metadata.categories.[CC Version Status].[0]) "beta")}} -* @beta +* {{#if (eq (lowercase metadata.categories.[CC Version Status].[0]) "beta")}} +* @beta * {{/if}} -* - +* */ export class {{name.upperCamelCase}}> { // baseUri is not required on ClientConfig, but we know that we provide one in the class constructor @@ -101,6 +100,6 @@ export class {{name.upperCamelCase}} & { baseUri: string }; } + {{> paramKeysPartial model}} {{> operationsPartial model}} - } diff --git a/templates/operations.ts.hbs b/templates/operations.ts.hbs index 09612264..93f8fb1e 100644 --- a/templates/operations.ts.hbs +++ b/templates/operations.ts.hbs @@ -1,5 +1,6 @@ {{#each encodes.endPoints}} {{#each operations}} + /** * {{{formatForTsDoc description}}} * @@ -193,7 +194,7 @@ method: "{{loud method}}", headers, {{#if (isRequestWithPayload request)}}body: this.clientConfig.transformRequest(options.body, headers){{/if}} - }, + }, this.clientConfig, rawResponse ) diff --git a/templates/paramKeys.ts.hbs b/templates/paramKeys.ts.hbs new file mode 100644 index 00000000..e86279cd --- /dev/null +++ b/templates/paramKeys.ts.hbs @@ -0,0 +1,24 @@ +static readonly paramKeys = { + {{#each encodes.endPoints}} + {{#each operations}} + {{{name}}}: [ + {{#each ../parameters}} + '{{{name}}}', + {{/each}} + {{#each request.queryParameters}} + '{{{name}}}', + {{/each}} + ], + {{{name}}}Required: [ + {{#each ../parameters}} + '{{{name}}}', + {{/each}} + {{#each request.queryParameters}} + {{#if (is required "true")}} + '{{{name}}}', + {{/if}} + {{/each}} + ], + {{/each}} + {{/each}} +} as const;