diff --git a/scripts/utils.test.ts b/scripts/utils.test.ts index 6bb2687e..48277ed6 100644 --- a/scripts/utils.test.ts +++ b/scripts/utils.test.ts @@ -49,6 +49,7 @@ describe('setupApis', () => { it('loads our API modes', async () => { // Don't need to perform the init, and doing so will cause timeout. jest.spyOn(generate.ApiMetadata.prototype, 'init').mockResolvedValue(); + jest.spyOn(generate.ApiModel.prototype, 'init').mockResolvedValue(); const apis = await setupApis( API_DIRECTORY, diff --git a/scripts/utils.ts b/scripts/utils.ts index 86bc56d3..535f69a8 100644 --- a/scripts/utils.ts +++ b/scripts/utils.ts @@ -9,6 +9,8 @@ import addHelpers from 'handlebars-helpers'; import path from 'path'; import {readJsonSync} from 'fs-extra'; +import {Name} from '@commerce-apps/raml-toolkit/lib/common/structures/name'; +import {ApiModel} from '@commerce-apps/raml-toolkit/lib/generate'; import * as templateHelpers from './templateHelpers'; const PROJECT_ROOT = path.join(__dirname, '..'); @@ -67,6 +69,18 @@ function addTemplates(apis: ApiMetadata, outputBasePath: string): ApiMetadata { return apis; } +// Editing the name of the Shopper Context API Model so our name is used for generating class name. +// This is hard-coded for now but in the future if we handle the case where type name and title clash better, this can be removed. +function overwriteShopperContextName(apis: ApiMetadata): void { + const shopperContextApi = apis.children.find( + api => api.name.original === 'shopper-context' + ); + + if (shopperContextApi) { + shopperContextApi.name = new Name('shopper-contexts'); + } +} + /** * Primary driver, loads the apis and templates associated with those apis. * @@ -84,7 +98,19 @@ export async function setupApis( // is necessary for generating the SDK (as part of the user agent header). // eslint-disable-next-line @typescript-eslint/no-unsafe-member-access apis.metadata.sdkVersion = await readJsonSync(PACKAGE_JSON).version; - await apis.init(); + + // TODO: @W-13013140. After this work is done, this function can be safely removed. + overwriteShopperContextName(apis); + + // We are calling the init for children (which will call loadModel) since we can pass the updateName parameter as false (default was true). + // We only call init(false) on shopper-context api so that our title overwrite can be reflected on the parsed api model. + await Promise.all( + apis.children.map(api => + api.name.original === 'shopper-contexts' + ? (api as ApiModel).init(false) + : api.init() + ) + ); apis = addTemplates(apis, outputDir); return apis; diff --git a/src/static/helpers/slasHelper.test.ts b/src/static/helpers/slasHelper.test.ts index 81f303d9..7ac20726 100644 --- a/src/static/helpers/slasHelper.test.ts +++ b/src/static/helpers/slasHelper.test.ts @@ -31,6 +31,7 @@ const expectedTokenResponse: TokenResponse = { usid: 'usid', customer_id: 'customer_id', enc_user_id: 'enc_user_id', + idp_access_token: 'idp', }; const parameters = {