Skip to content

Commit 3ae4374

Browse files
aliasghar98Ayeshas09saeedjamshaid
authored
feat: add container and input models in toc using new toc command (#276)
What was added? Container and input models are now included in toc.yml when --expand-models flag is used with the apimatic portal toc new command. --------- Co-authored-by: Ayesha <88117894+Ayeshas09@users.noreply.github.com> Co-authored-by: saeedjamshaid <saeed.jamshaid@outlook.com>
1 parent 2dcac18 commit 3ae4374

10 files changed

Lines changed: 318 additions & 356 deletions

File tree

package-lock.json

Lines changed: 6 additions & 20 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -47,7 +47,7 @@
4747
"test": "tsx node_modules/mocha/bin/_mocha --forbid-only \"test/**/*.test.ts\" --timeout 99999"
4848
},
4949
"dependencies": {
50-
"@apimatic/sdk": "0.2.0-alpha.8",
50+
"@apimatic/sdk": "0.2.0-alpha.9",
5151
"@clack/prompts": "1.0.0-alpha.1",
5252
"@oclif/core": "^4.2.8",
5353
"@oclif/plugin-autocomplete": "^3.2.24",

src/actions/portal/toc/new-toc.ts

Lines changed: 13 additions & 28 deletions
Original file line numberDiff line numberDiff line change
@@ -8,12 +8,8 @@ import { TocContext } from '../../../types/toc-context.js';
88
import { FileService } from '../../../infrastructure/file-service.js';
99
import { BuildContext } from '../../../types/build-context.js';
1010
import {
11-
extractCallbacksForToc,
12-
extractEndpointGroupsForToc,
13-
extractModelsForToc,
14-
extractWebhooksForToc,
15-
SdlTocComponents
16-
} from '../../../types/sdl/sdl.js';
11+
TocComponents
12+
} from '../../../types/toc/toc-components.js';
1713
import { withDirPath } from '../../../infrastructure/tmp-extensions.js';
1814
import { TempContext } from '../../../types/temp-context.js';
1915
import { PortalService } from '../../../infrastructure/services/portal-service.js';
@@ -67,27 +63,20 @@ export class PortalNewTocAction {
6763
return ActionResult.cancelled();
6864
}
6965

70-
const sdlTocComponents: SdlTocComponents = await (async () => {
71-
const defaultComponents = {
72-
endpointGroups: new Map(),
73-
models: [],
74-
webhookGroups: new Map(),
75-
callbackGroups: new Map()
76-
};
77-
66+
const tocComponents: TocComponents = await (async () => {
7867
const specDirectory = buildDirectory.join('spec');
7968

8069
if (!(await this.fileService.directoryExists(specDirectory))) {
8170
this.prompts.fallingBackToDefault();
82-
return defaultComponents;
71+
return TocComponents.empty();
8372
}
8473

8574
return await withDirPath(async (tempDirectory) => {
8675
const tempContext = new TempContext(tempDirectory);
8776
const specZipPath = await tempContext.zip(specDirectory);
8877
const specFileStream = await this.fileService.getStream(specZipPath);
89-
const result = await this.prompts.extractComponents(
90-
this.portalService.generateSdl(specFileStream, this.configDirectory, this.commandMetadata),
78+
const result = await this.prompts.extractTocData(
79+
this.portalService.generateTocData(specFileStream, this.configDirectory, this.commandMetadata),
9180
expandEndpoints,
9281
expandModels,
9382
expandWebhooks,
@@ -96,15 +85,10 @@ export class PortalNewTocAction {
9685
specFileStream.close();
9786
if (result.isErr()) {
9887
this.prompts.fallingBackToDefault();
99-
return defaultComponents;
88+
return TocComponents.empty();
10089
}
10190

102-
return {
103-
endpointGroups: extractEndpointGroupsForToc(result.value),
104-
models: extractModelsForToc(result.value),
105-
webhookGroups: extractWebhooksForToc(result.value),
106-
callbackGroups: extractCallbacksForToc(result.value)
107-
};
91+
return TocComponents.fromTocData(result.value);
10892
});
10993
})();
11094
const contentContext = new ContentContext(contentDirectory);
@@ -119,10 +103,11 @@ export class PortalNewTocAction {
119103
}
120104

121105
const toc = this.tocGenerator.createTocStructure(
122-
{ data: sdlTocComponents.endpointGroups, expand: expandEndpoints },
123-
{ data: sdlTocComponents.models, expand: expandModels },
124-
{ data: sdlTocComponents.webhookGroups, expand: expandWebhooks },
125-
{ data: sdlTocComponents.callbackGroups, expand: expandCallbacks },
106+
tocComponents,
107+
expandEndpoints,
108+
expandModels,
109+
expandWebhooks,
110+
expandCallbacks,
126111
contentGroups
127112
);
128113
const yamlString = this.tocGenerator.transformToYaml(toc);

0 commit comments

Comments
 (0)