Skip to content
Merged
Show file tree
Hide file tree
Changes from all 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
26 changes: 6 additions & 20 deletions package-lock.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -47,7 +47,7 @@
"test": "tsx node_modules/mocha/bin/_mocha --forbid-only \"test/**/*.test.ts\" --timeout 99999"
},
"dependencies": {
"@apimatic/sdk": "0.2.0-alpha.8",
"@apimatic/sdk": "0.2.0-alpha.9",
"@clack/prompts": "1.0.0-alpha.1",
Comment thread
Ayeshas09 marked this conversation as resolved.
"@oclif/core": "^4.2.8",
"@oclif/plugin-autocomplete": "^3.2.24",
Expand Down
41 changes: 13 additions & 28 deletions src/actions/portal/toc/new-toc.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,12 +8,8 @@ import { TocContext } from '../../../types/toc-context.js';
import { FileService } from '../../../infrastructure/file-service.js';
import { BuildContext } from '../../../types/build-context.js';
import {
extractCallbacksForToc,
extractEndpointGroupsForToc,
extractModelsForToc,
extractWebhooksForToc,
SdlTocComponents
} from '../../../types/sdl/sdl.js';
TocComponents
} from '../../../types/toc/toc-components.js';
import { withDirPath } from '../../../infrastructure/tmp-extensions.js';
import { TempContext } from '../../../types/temp-context.js';
import { PortalService } from '../../../infrastructure/services/portal-service.js';
Expand Down Expand Up @@ -67,27 +63,20 @@ export class PortalNewTocAction {
return ActionResult.cancelled();
}

const sdlTocComponents: SdlTocComponents = await (async () => {
const defaultComponents = {
endpointGroups: new Map(),
models: [],
webhookGroups: new Map(),
callbackGroups: new Map()
};

const tocComponents: TocComponents = await (async () => {
const specDirectory = buildDirectory.join('spec');

if (!(await this.fileService.directoryExists(specDirectory))) {
this.prompts.fallingBackToDefault();
return defaultComponents;
return TocComponents.empty();
}

return await withDirPath(async (tempDirectory) => {
const tempContext = new TempContext(tempDirectory);
const specZipPath = await tempContext.zip(specDirectory);
const specFileStream = await this.fileService.getStream(specZipPath);
const result = await this.prompts.extractComponents(
this.portalService.generateSdl(specFileStream, this.configDirectory, this.commandMetadata),
const result = await this.prompts.extractTocData(
this.portalService.generateTocData(specFileStream, this.configDirectory, this.commandMetadata),
expandEndpoints,
expandModels,
expandWebhooks,
Expand All @@ -96,15 +85,10 @@ export class PortalNewTocAction {
specFileStream.close();
if (result.isErr()) {
this.prompts.fallingBackToDefault();
return defaultComponents;
return TocComponents.empty();
}

return {
endpointGroups: extractEndpointGroupsForToc(result.value),
models: extractModelsForToc(result.value),
webhookGroups: extractWebhooksForToc(result.value),
callbackGroups: extractCallbacksForToc(result.value)
};
return TocComponents.fromTocData(result.value);
});
})();
const contentContext = new ContentContext(contentDirectory);
Expand All @@ -119,10 +103,11 @@ export class PortalNewTocAction {
}

const toc = this.tocGenerator.createTocStructure(
{ data: sdlTocComponents.endpointGroups, expand: expandEndpoints },
{ data: sdlTocComponents.models, expand: expandModels },
{ data: sdlTocComponents.webhookGroups, expand: expandWebhooks },
{ data: sdlTocComponents.callbackGroups, expand: expandCallbacks },
tocComponents,
expandEndpoints,
expandModels,
expandWebhooks,
expandCallbacks,
contentGroups
);
const yamlString = this.tocGenerator.transformToYaml(toc);
Expand Down
Loading
Loading