Skip to content
Merged
Show file tree
Hide file tree
Changes from 4 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions scripts/utils.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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,
Expand Down
17 changes: 16 additions & 1 deletion scripts/utils.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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, '..');
Expand Down Expand Up @@ -84,7 +86,20 @@ 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();

// 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.
const shopperContextApi = apis.children.find(
api => api.name.original === 'shopper-context'
);

if (shopperContextApi) {
shopperContextApi.name = new Name('shopper-contexts');
}

// We are calling the init for children (which will call loadModel) since we can pass the updateName parameter as false (default was true).
// With this way the ApiModel doesn't change its name again from the loaded api model, which will use the raml title field.
await Promise.all(apis.children.map(api => (api as ApiModel).init(false)));

apis = addTemplates(apis, outputDir);
return apis;
Expand Down
1 change: 1 addition & 0 deletions src/static/helpers/slasHelper.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 = {
Expand Down