@apimatic/cli 1.0.1-alpha.1 → 1.0.1-alpha.10
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +63 -97
- package/bin/run +3 -3
- package/lib/client-utils/sdk-client.d.ts +1 -1
- package/lib/client-utils/sdk-client.js +3 -3
- package/lib/commands/api/transform.d.ts +1 -2
- package/lib/commands/api/transform.js +34 -86
- package/lib/commands/api/validate.d.ts +0 -2
- package/lib/commands/api/validate.js +16 -37
- package/lib/commands/auth/login.js +4 -2
- package/lib/commands/auth/logout.js +1 -1
- package/lib/commands/auth/status.js +1 -1
- package/lib/commands/portal/generate.d.ts +1 -11
- package/lib/commands/portal/generate.js +26 -65
- package/lib/commands/sdk/generate.d.ts +1 -0
- package/lib/commands/sdk/generate.js +37 -86
- package/lib/controllers/api/transform.d.ts +7 -0
- package/lib/controllers/api/transform.js +59 -0
- package/lib/controllers/api/validate.d.ts +5 -0
- package/lib/controllers/api/validate.js +32 -0
- package/lib/controllers/portal/generate.d.ts +2 -0
- package/lib/controllers/portal/generate.js +49 -0
- package/lib/controllers/sdk/generate.d.ts +4 -0
- package/lib/controllers/sdk/generate.js +64 -0
- package/lib/types/api/transform.d.ts +34 -0
- package/lib/types/api/transform.js +18 -0
- package/lib/types/api/validate.d.ts +12 -0
- package/lib/types/api/validate.js +2 -0
- package/lib/types/portal/generate.d.ts +9 -0
- package/lib/types/portal/generate.js +2 -0
- package/lib/types/sdk/generate.d.ts +22 -0
- package/lib/types/sdk/generate.js +12 -0
- package/oclif.manifest.json +1 -1
- package/package.json +2 -2
- package/CHANGELOG.md +0 -6
- package/lib/commands/api/index.d.ts +0 -6
- package/lib/commands/api/index.js +0 -22
- package/lib/commands/auth/index.d.ts +0 -6
- package/lib/commands/auth/index.js +0 -25
- package/lib/commands/portal/index.d.ts +0 -6
- package/lib/commands/portal/index.js +0 -20
- package/lib/commands/sdk/index.d.ts +0 -6
- package/lib/commands/sdk/index.js +0 -21
|
@@ -1,23 +1,13 @@
|
|
|
1
|
-
import { DocsPortalManagementController } from "@apimatic/apimatic-sdk-for-js";
|
|
2
1
|
import { Command, flags } from "@oclif/command";
|
|
3
|
-
declare type GeneratePortalParams = {
|
|
4
|
-
zippedBuildFilePath: string;
|
|
5
|
-
generatedPortalFolderPath: string;
|
|
6
|
-
docsPortalController: DocsPortalManagementController;
|
|
7
|
-
overrideAuthKey: string | null;
|
|
8
|
-
zip: boolean;
|
|
9
|
-
};
|
|
10
2
|
export default class PortalGenerate extends Command {
|
|
11
3
|
static description: string;
|
|
12
4
|
static flags: {
|
|
13
5
|
folder: flags.IOptionFlag<string>;
|
|
14
6
|
destination: flags.IOptionFlag<string>;
|
|
7
|
+
force: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
15
8
|
zip: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
16
9
|
"auth-key": flags.IOptionFlag<string>;
|
|
17
10
|
};
|
|
18
11
|
static examples: string[];
|
|
19
|
-
downloadPortalAxios: (zippedBuildFilePath: string, overrideAuthKey: string | null) => Promise<any>;
|
|
20
|
-
downloadDocsPortal: ({ zippedBuildFilePath, generatedPortalFolderPath, overrideAuthKey, zip }: GeneratePortalParams) => Promise<string>;
|
|
21
12
|
run(): Promise<undefined>;
|
|
22
13
|
}
|
|
23
|
-
export {};
|
|
@@ -1,67 +1,27 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const fs = require("fs-extra");
|
|
4
|
-
const FormData = require("form-data");
|
|
5
4
|
const path = require("path");
|
|
6
|
-
const cli_ux_1 = require("cli-ux");
|
|
7
|
-
const apimatic_sdk_for_js_1 = require("@apimatic/apimatic-sdk-for-js");
|
|
8
5
|
const command_1 = require("@oclif/command");
|
|
6
|
+
const sdk_1 = require("@apimatic/sdk");
|
|
9
7
|
const sdk_client_1 = require("../../client-utils/sdk-client");
|
|
10
|
-
const
|
|
8
|
+
const generate_1 = require("../../controllers/portal/generate");
|
|
11
9
|
const utils_1 = require("../../utils/utils");
|
|
12
|
-
const auth_manager_1 = require("../../client-utils/auth-manager");
|
|
13
|
-
const axios_1 = require("axios");
|
|
14
10
|
class PortalGenerate extends command_1.Command {
|
|
15
|
-
constructor() {
|
|
16
|
-
super(...arguments);
|
|
17
|
-
// TODO: Remove after SDK is patched
|
|
18
|
-
this.downloadPortalAxios = async (zippedBuildFilePath, overrideAuthKey) => {
|
|
19
|
-
const formData = new FormData();
|
|
20
|
-
const authInfo = await auth_manager_1.getAuthInfo(this.config.configDir);
|
|
21
|
-
formData.append("file", fs.createReadStream(zippedBuildFilePath));
|
|
22
|
-
const config = {
|
|
23
|
-
headers: Object.assign({ Authorization: authInfo ? `X-Auth-Key ${overrideAuthKey || authInfo.authKey.trim()}` : "", "Content-Type": "multipart/form-data" }, formData.getHeaders()),
|
|
24
|
-
responseType: "arraybuffer"
|
|
25
|
-
};
|
|
26
|
-
const { data } = await axios_1.default.post(`${env_1.baseURL}/portal`, formData, config);
|
|
27
|
-
return data;
|
|
28
|
-
};
|
|
29
|
-
// Download Docs Portal
|
|
30
|
-
this.downloadDocsPortal = async ({ zippedBuildFilePath, generatedPortalFolderPath, overrideAuthKey, zip }) => {
|
|
31
|
-
const zippedPortalPath = path.join(generatedPortalFolderPath, "generated_portal.zip");
|
|
32
|
-
const portalPath = path.join(generatedPortalFolderPath, "generated_portal");
|
|
33
|
-
cli_ux_1.default.action.start("Downloading portal");
|
|
34
|
-
// Check if the build file exists for the user or not
|
|
35
|
-
if (!(await fs.pathExists(zippedBuildFilePath))) {
|
|
36
|
-
throw new Error("Build file doesn't exist");
|
|
37
|
-
}
|
|
38
|
-
// TODO: ***CRITICAL*** Remove this call once the SDK is patched
|
|
39
|
-
const data = await this.downloadPortalAxios(zippedBuildFilePath, overrideAuthKey);
|
|
40
|
-
await utils_1.deleteFile(zippedBuildFilePath);
|
|
41
|
-
await fs.writeFile(zippedPortalPath, data);
|
|
42
|
-
// TODO: Uncomment this code block when the SDK is patched
|
|
43
|
-
// const file: FileWrapper = new FileWrapper(fs.createReadStream(zippedBuildFilePath));
|
|
44
|
-
// const { result }: ApiResponse<NodeJS.ReadableStream | Blob> =
|
|
45
|
-
// await docsPortalController.generateOnPremPortalViaBuildInput(file);
|
|
46
|
-
// if ((data as NodeJS.ReadableStream).readable) {
|
|
47
|
-
// await writeFileUsingReadableStream(data as NodeJS.ReadableStream, zippedPortalPath);
|
|
48
|
-
if (!zip) {
|
|
49
|
-
await utils_1.unzipFile(fs.createReadStream(zippedPortalPath), portalPath);
|
|
50
|
-
await utils_1.deleteFile(zippedPortalPath);
|
|
51
|
-
}
|
|
52
|
-
cli_ux_1.default.action.stop();
|
|
53
|
-
return portalPath;
|
|
54
|
-
// } else {
|
|
55
|
-
// throw new Error("Couldn't download the portal");
|
|
56
|
-
// }
|
|
57
|
-
};
|
|
58
|
-
}
|
|
59
11
|
async run() {
|
|
60
12
|
const { flags } = this.parse(PortalGenerate);
|
|
61
13
|
const zip = flags.zip;
|
|
62
|
-
const
|
|
63
|
-
const
|
|
14
|
+
const sourceFolderPath = flags.folder;
|
|
15
|
+
const portalFolderPath = path.join(flags.destination, "generated_portal");
|
|
16
|
+
const zippedPortalPath = path.join(flags.destination, "generated_portal.zip");
|
|
64
17
|
const overrideAuthKey = flags["auth-key"] ? flags["auth-key"] : null;
|
|
18
|
+
// Check if at destination, portal already exists and throw error if force flag is not set for both zip and extracted
|
|
19
|
+
if (fs.existsSync(portalFolderPath) && !flags.force && !zip) {
|
|
20
|
+
throw new Error(`Can't download portal to path ${portalFolderPath}, because it already exists`);
|
|
21
|
+
}
|
|
22
|
+
else if (fs.existsSync(zippedPortalPath) && !flags.force && zip) {
|
|
23
|
+
throw new Error(`Can't download portal to path ${zippedPortalPath}, because it already exists`);
|
|
24
|
+
}
|
|
65
25
|
try {
|
|
66
26
|
if (!(await fs.pathExists(flags.destination))) {
|
|
67
27
|
throw new Error(`Destination path ${flags.destination} does not exist`);
|
|
@@ -70,20 +30,20 @@ class PortalGenerate extends command_1.Command {
|
|
|
70
30
|
throw new Error(`Portal build folder ${flags.folder} does not exist`);
|
|
71
31
|
}
|
|
72
32
|
const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
|
|
73
|
-
const docsPortalController = new
|
|
74
|
-
const zippedBuildFilePath = await utils_1.zipDirectory(
|
|
33
|
+
const docsPortalController = new sdk_1.DocsPortalManagementController(client);
|
|
34
|
+
const zippedBuildFilePath = await utils_1.zipDirectory(sourceFolderPath, flags.destination);
|
|
75
35
|
const generatePortalParams = {
|
|
76
36
|
zippedBuildFilePath,
|
|
77
|
-
|
|
37
|
+
portalFolderPath,
|
|
38
|
+
zippedPortalPath,
|
|
78
39
|
docsPortalController,
|
|
79
40
|
overrideAuthKey,
|
|
80
41
|
zip
|
|
81
42
|
};
|
|
82
|
-
const generatedPortalPath = await
|
|
83
|
-
this.log(`Your portal has been generated at ${generatedPortalPath}
|
|
43
|
+
const generatedPortalPath = await generate_1.downloadDocsPortal(generatePortalParams, this.config.configDir);
|
|
44
|
+
this.log(`Your portal has been generated at ${generatedPortalPath}`);
|
|
84
45
|
}
|
|
85
46
|
catch (error) {
|
|
86
|
-
cli_ux_1.default.action.stop();
|
|
87
47
|
if (error && error.response) {
|
|
88
48
|
const apiError = error;
|
|
89
49
|
const apiResponse = apiError.response;
|
|
@@ -98,7 +58,7 @@ class PortalGenerate extends command_1.Command {
|
|
|
98
58
|
return this.error(utils_1.replaceHTML(nestedErrors.message));
|
|
99
59
|
}
|
|
100
60
|
}
|
|
101
|
-
else if (apiResponse.status === 401 && responseData.length > 0
|
|
61
|
+
else if (apiResponse.status === 401 && responseData.length > 0) {
|
|
102
62
|
this.error(utils_1.replaceHTML(responseData));
|
|
103
63
|
}
|
|
104
64
|
else if (apiResponse.status === 403 && apiResponse.statusText) {
|
|
@@ -116,22 +76,23 @@ class PortalGenerate extends command_1.Command {
|
|
|
116
76
|
}
|
|
117
77
|
}
|
|
118
78
|
exports.default = PortalGenerate;
|
|
119
|
-
PortalGenerate.description = "Generate static
|
|
79
|
+
PortalGenerate.description = "Generate and download a static API Documentation portal. Requires an input directory containing API specifications, a config file and optionally, markdown guides. For details, refer to the [documentation](https://portal-api-docs.apimatic.io/#/http/generating-api-portal/build-file)";
|
|
120
80
|
PortalGenerate.flags = {
|
|
121
81
|
folder: command_1.flags.string({
|
|
122
82
|
parse: (input) => path.resolve(input),
|
|
123
|
-
default: "",
|
|
124
|
-
description: "
|
|
83
|
+
default: "./",
|
|
84
|
+
description: "path to the input directory containing API specifications and config files"
|
|
125
85
|
}),
|
|
126
86
|
destination: command_1.flags.string({
|
|
127
87
|
parse: (input) => path.resolve(input),
|
|
128
|
-
default: "./",
|
|
88
|
+
default: path.resolve("./"),
|
|
129
89
|
description: "path to the downloaded portal"
|
|
130
90
|
}),
|
|
131
|
-
|
|
91
|
+
force: command_1.flags.boolean({ char: "f", default: false, description: "overwrite if a portal exists in the destination" }),
|
|
92
|
+
zip: command_1.flags.boolean({ default: false, description: "download the generated portal as a .zip archive" }),
|
|
132
93
|
"auth-key": command_1.flags.string({
|
|
133
94
|
default: "",
|
|
134
|
-
description: "override current
|
|
95
|
+
description: "override current authentication state with an authentication key"
|
|
135
96
|
})
|
|
136
97
|
};
|
|
137
98
|
PortalGenerate.examples = [
|
|
@@ -6,6 +6,7 @@ export default class SdkGenerate extends Command {
|
|
|
6
6
|
file: flags.IOptionFlag<string>;
|
|
7
7
|
url: flags.IOptionFlag<string>;
|
|
8
8
|
destination: flags.IOptionFlag<string>;
|
|
9
|
+
force: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
9
10
|
zip: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
|
|
10
11
|
"auth-key": flags.IOptionFlag<string>;
|
|
11
12
|
};
|
|
@@ -2,79 +2,25 @@
|
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const fs = require("fs-extra");
|
|
4
4
|
const path = require("path");
|
|
5
|
-
const
|
|
6
|
-
const apimatic_sdk_for_js_1 = require("@apimatic/apimatic-sdk-for-js");
|
|
5
|
+
const sdk_1 = require("@apimatic/sdk");
|
|
7
6
|
const command_1 = require("@oclif/command");
|
|
8
7
|
const sdk_client_1 = require("../../client-utils/sdk-client");
|
|
9
8
|
const utils_1 = require("../../utils/utils");
|
|
10
|
-
|
|
11
|
-
(function (SimplePlatforms) {
|
|
12
|
-
SimplePlatforms["CSHARP"] = "CS_NET_STANDARD_LIB";
|
|
13
|
-
SimplePlatforms["JAVA"] = "JAVA_ECLIPSE_JRE_LIB";
|
|
14
|
-
SimplePlatforms["PHP"] = "PHP_GENERIC_LIB";
|
|
15
|
-
SimplePlatforms["PYTHON"] = "PYTHON_GENERIC_LIB";
|
|
16
|
-
SimplePlatforms["RUBY"] = "RUBY_GENERIC_LIB";
|
|
17
|
-
SimplePlatforms["TYPESCRIPT"] = "TS_GENERIC_LIB";
|
|
18
|
-
})(SimplePlatforms || (SimplePlatforms = {}));
|
|
19
|
-
async function getSDKGenerationId({ file, url, platform }, sdkGenerationController) {
|
|
20
|
-
cli_ux_1.default.action.start("Generating SDK");
|
|
21
|
-
let generation;
|
|
22
|
-
const sdkPlatform = getSDKPlatform(platform);
|
|
23
|
-
if (file) {
|
|
24
|
-
const fileDescriptor = new apimatic_sdk_for_js_1.FileWrapper(fs.createReadStream(file));
|
|
25
|
-
generation = await sdkGenerationController.generateSDKViaFile(fileDescriptor, sdkPlatform);
|
|
26
|
-
}
|
|
27
|
-
else if (url) {
|
|
28
|
-
// If url to spec file is provided
|
|
29
|
-
const body = {
|
|
30
|
-
url: url,
|
|
31
|
-
template: sdkPlatform
|
|
32
|
-
};
|
|
33
|
-
generation = await sdkGenerationController.generateSDKViaURL(body);
|
|
34
|
-
}
|
|
35
|
-
else {
|
|
36
|
-
throw new Error("Please provide a specification file");
|
|
37
|
-
}
|
|
38
|
-
cli_ux_1.default.action.stop();
|
|
39
|
-
return generation.result.id;
|
|
40
|
-
}
|
|
41
|
-
// Get valid platform from user's input, convert simple platform to valid Platforms enum value
|
|
42
|
-
function getSDKPlatform(platform) {
|
|
43
|
-
if (Object.keys(SimplePlatforms).includes(platform)) {
|
|
44
|
-
return SimplePlatforms[platform];
|
|
45
|
-
}
|
|
46
|
-
else if (Object.values(apimatic_sdk_for_js_1.Platforms).includes(platform)) {
|
|
47
|
-
return platform;
|
|
48
|
-
}
|
|
49
|
-
else {
|
|
50
|
-
const platforms = Object.keys(SimplePlatforms).concat(Object.values(apimatic_sdk_for_js_1.Platforms)).join("|");
|
|
51
|
-
throw new Error(`Please provide a valid platform i.e. ${platforms}`);
|
|
52
|
-
}
|
|
53
|
-
}
|
|
54
|
-
// Download Platform
|
|
55
|
-
async function downloadGeneratedSDK({ codeGenId, zippedSDKPath, sdkFolderPath, zip }, sdkGenerationController) {
|
|
56
|
-
cli_ux_1.default.action.start("Downloading SDK");
|
|
57
|
-
const { result } = await sdkGenerationController.downloadSDK(codeGenId);
|
|
58
|
-
if (result.readable) {
|
|
59
|
-
if (!zip) {
|
|
60
|
-
await utils_1.unzipFile(result, sdkFolderPath);
|
|
61
|
-
cli_ux_1.default.action.stop();
|
|
62
|
-
return sdkFolderPath;
|
|
63
|
-
}
|
|
64
|
-
else {
|
|
65
|
-
await utils_1.writeFileUsingReadableStream(result, zippedSDKPath);
|
|
66
|
-
cli_ux_1.default.action.stop();
|
|
67
|
-
return zippedSDKPath;
|
|
68
|
-
}
|
|
69
|
-
}
|
|
70
|
-
else {
|
|
71
|
-
throw new Error("Couldn't download the SDK");
|
|
72
|
-
}
|
|
73
|
-
}
|
|
9
|
+
const generate_1 = require("../../controllers/sdk/generate");
|
|
74
10
|
class SdkGenerate extends command_1.Command {
|
|
75
11
|
async run() {
|
|
76
12
|
const { flags } = this.parse(SdkGenerate);
|
|
77
13
|
const zip = flags.zip;
|
|
14
|
+
const fileName = flags.file ? utils_1.getFileNameFromPath(flags.file) : utils_1.getFileNameFromPath(flags.url);
|
|
15
|
+
const sdkFolderPath = path.join(flags.destination, `${fileName}_sdk_${flags.platform}`.toLowerCase());
|
|
16
|
+
const zippedSDKPath = path.join(flags.destination, `${fileName}_sdk_${flags.platform}.zip`.toLowerCase());
|
|
17
|
+
// Check if at destination, SDK already exists and throw error if force flag is not set for both zip and extracted
|
|
18
|
+
if (fs.existsSync(sdkFolderPath) && !flags.force && !zip) {
|
|
19
|
+
throw new Error(`Can't download SDK to path ${sdkFolderPath}, because it already exists`);
|
|
20
|
+
}
|
|
21
|
+
else if (fs.existsSync(zippedSDKPath) && !flags.force && zip) {
|
|
22
|
+
throw new Error(`Can't download SDK to path ${zippedSDKPath}, because it already exists`);
|
|
23
|
+
}
|
|
78
24
|
try {
|
|
79
25
|
if (!(await fs.pathExists(path.resolve(flags.destination)))) {
|
|
80
26
|
throw new Error(`Destination path ${flags.destination} does not exist`);
|
|
@@ -82,20 +28,11 @@ class SdkGenerate extends command_1.Command {
|
|
|
82
28
|
else if (!(await fs.pathExists(path.resolve(flags.file)))) {
|
|
83
29
|
throw new Error(`Specification file ${flags.file} does not exist`);
|
|
84
30
|
}
|
|
85
|
-
const fileName = flags.file ? utils_1.getFileNameFromPath(flags.file) : utils_1.getFileNameFromPath(flags.url);
|
|
86
|
-
const sdkFolderPath = path.join(flags.destination, `${fileName}_sdk_${flags.platform}`.toLowerCase());
|
|
87
|
-
const zippedSDKPath = path.join(flags.destination, `${fileName}_sdk_${flags.platform}.zip`.toLowerCase());
|
|
88
|
-
if (fs.existsSync(zippedSDKPath) && zip) {
|
|
89
|
-
throw new Error(`Can't generate SDK to path ${zippedSDKPath}, because it already exists`);
|
|
90
|
-
}
|
|
91
|
-
else if (fs.existsSync(sdkFolderPath) && !zip) {
|
|
92
|
-
throw new Error(`Can't generate SDK to path ${sdkFolderPath}, because it already exists`);
|
|
93
|
-
}
|
|
94
31
|
const overrideAuthKey = flags["auth-key"] ? flags["auth-key"] : null;
|
|
95
32
|
const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
|
|
96
|
-
const sdkGenerationController = new
|
|
33
|
+
const sdkGenerationController = new sdk_1.CodeGenerationExternalApisController(client);
|
|
97
34
|
// Get generation id for the specification and platform
|
|
98
|
-
const codeGenId = await getSDKGenerationId(flags, sdkGenerationController);
|
|
35
|
+
const codeGenId = await generate_1.getSDKGenerationId(flags, sdkGenerationController);
|
|
99
36
|
// If user wanted to download the SDK as well
|
|
100
37
|
const sdkDownloadParams = {
|
|
101
38
|
codeGenId,
|
|
@@ -103,11 +40,10 @@ class SdkGenerate extends command_1.Command {
|
|
|
103
40
|
sdkFolderPath,
|
|
104
41
|
zip
|
|
105
42
|
};
|
|
106
|
-
const sdkPath = await downloadGeneratedSDK(sdkDownloadParams, sdkGenerationController);
|
|
43
|
+
const sdkPath = await generate_1.downloadGeneratedSDK(sdkDownloadParams, sdkGenerationController);
|
|
107
44
|
this.log(`Success! Your SDK is located at ${sdkPath}`);
|
|
108
45
|
}
|
|
109
46
|
catch (error) {
|
|
110
|
-
cli_ux_1.default.action.stop();
|
|
111
47
|
if (error.result) {
|
|
112
48
|
const apiError = error;
|
|
113
49
|
const result = apiError.result;
|
|
@@ -157,22 +93,37 @@ Legacy: CS_NET_STANDARD_LIB|CS_PORTABLE_NET_LIB|CS_UNIVERSAL_WINDOWS_PLATFORM_LI
|
|
|
157
93
|
file: command_1.flags.string({
|
|
158
94
|
parse: (input) => path.resolve(input),
|
|
159
95
|
default: "",
|
|
160
|
-
description: "path to the API specification to generate
|
|
96
|
+
description: "path to the API specification to generate SDKs for"
|
|
97
|
+
}),
|
|
98
|
+
url: command_1.flags.string({
|
|
99
|
+
default: "",
|
|
100
|
+
description: "URL to the API specification to generate SDKs for. Can be used in place of the --file option if the API specification is publicly available."
|
|
161
101
|
}),
|
|
162
|
-
url: command_1.flags.string({ default: "", description: "URL to the API specification to generate SDK" }),
|
|
163
102
|
destination: command_1.flags.string({
|
|
164
103
|
parse: (input) => path.resolve(input),
|
|
165
|
-
default: "./",
|
|
166
|
-
description: "
|
|
104
|
+
default: path.resolve("./"),
|
|
105
|
+
description: "directory to download the generated SDK to"
|
|
106
|
+
}),
|
|
107
|
+
force: command_1.flags.boolean({
|
|
108
|
+
char: "f",
|
|
109
|
+
default: false,
|
|
110
|
+
description: "overwrite if an SDK already exists in the destination"
|
|
167
111
|
}),
|
|
168
|
-
zip: command_1.flags.boolean({ default: false, description: "
|
|
112
|
+
zip: command_1.flags.boolean({ default: false, description: "download the generated SDK as a .zip archive" }),
|
|
169
113
|
"auth-key": command_1.flags.string({
|
|
170
114
|
default: "",
|
|
171
|
-
description: "override current
|
|
115
|
+
description: "override current authentication state with an authentication key"
|
|
172
116
|
})
|
|
173
117
|
};
|
|
174
118
|
SdkGenerate.examples = [
|
|
175
119
|
`$ apimatic sdk:generate --platform="CSHARP" --file="./specs/sample.json"
|
|
176
|
-
SDK
|
|
120
|
+
Generating SDK... done
|
|
121
|
+
Downloading SDK... done
|
|
122
|
+
Success! Your SDK is located at swagger_sdk_csharp`,
|
|
123
|
+
`
|
|
124
|
+
$ apimatic sdk:generate --platform="CSHARP" --url=https://petstore.swagger.io/v2/swagger.json
|
|
125
|
+
Generating SDK... done
|
|
126
|
+
Downloading SDK... done
|
|
127
|
+
Success! Your SDK is located at swagger_sdk_csharp
|
|
177
128
|
`
|
|
178
129
|
];
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import Command from "@oclif/command";
|
|
2
|
+
import { ApiValidationSummary, ExportFormats, Transformation, TransformationController } from "@apimatic/sdk";
|
|
3
|
+
import { DownloadTransformationParams, TransformationIdParams } from "../../types/api/transform";
|
|
4
|
+
export declare const getTransformationId: ({ file, url, format }: TransformationIdParams, transformationController: TransformationController) => Promise<Transformation>;
|
|
5
|
+
export declare const downloadTransformationFile: ({ id, destinationFilePath, transformationController }: DownloadTransformationParams) => Promise<string>;
|
|
6
|
+
export declare const getValidFormat: (format: string) => ExportFormats;
|
|
7
|
+
export declare const printValidationMessages: (apiValidationSummary: ApiValidationSummary | undefined, warn: Command["warn"], error: Command["error"]) => void;
|
|
@@ -0,0 +1,59 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printValidationMessages = exports.getValidFormat = exports.downloadTransformationFile = exports.getTransformationId = void 0;
|
|
4
|
+
const cli_ux_1 = require("cli-ux");
|
|
5
|
+
const fs = require("fs-extra");
|
|
6
|
+
const sdk_1 = require("@apimatic/sdk");
|
|
7
|
+
const utils_1 = require("../../utils/utils");
|
|
8
|
+
exports.getTransformationId = async ({ file, url, format }, transformationController) => {
|
|
9
|
+
cli_ux_1.default.action.start("Transforming API specification");
|
|
10
|
+
let generation;
|
|
11
|
+
if (file) {
|
|
12
|
+
const fileDescriptor = new sdk_1.FileWrapper(fs.createReadStream(file));
|
|
13
|
+
generation = await transformationController.transformViaFile(fileDescriptor, format);
|
|
14
|
+
}
|
|
15
|
+
else if (url) {
|
|
16
|
+
const body = {
|
|
17
|
+
url: url,
|
|
18
|
+
exportFormat: format
|
|
19
|
+
};
|
|
20
|
+
generation = await transformationController.transformViaURL(body);
|
|
21
|
+
}
|
|
22
|
+
else {
|
|
23
|
+
throw new Error("Please provide a specification file");
|
|
24
|
+
}
|
|
25
|
+
cli_ux_1.default.action.stop();
|
|
26
|
+
return generation.result;
|
|
27
|
+
};
|
|
28
|
+
exports.downloadTransformationFile = async ({ id, destinationFilePath, transformationController }) => {
|
|
29
|
+
cli_ux_1.default.action.start("Downloading Transformed file");
|
|
30
|
+
const { result } = await transformationController.downloadTransformedFile(id);
|
|
31
|
+
if (result.readable) {
|
|
32
|
+
await utils_1.writeFileUsingReadableStream(result, destinationFilePath);
|
|
33
|
+
}
|
|
34
|
+
else {
|
|
35
|
+
throw new Error("Couldn't save transformation file");
|
|
36
|
+
}
|
|
37
|
+
cli_ux_1.default.action.stop();
|
|
38
|
+
return destinationFilePath;
|
|
39
|
+
};
|
|
40
|
+
// Get valid platform from user's input, convert simple platform to valid Platforms enum value
|
|
41
|
+
exports.getValidFormat = (format) => {
|
|
42
|
+
if (Object.keys(sdk_1.ExportFormats).find((exportFormat) => exportFormat === format)) {
|
|
43
|
+
return sdk_1.ExportFormats[format];
|
|
44
|
+
}
|
|
45
|
+
else {
|
|
46
|
+
const formats = Object.keys(sdk_1.ExportFormats).join("|");
|
|
47
|
+
throw new Error(`Please provide a valid platform i.e. ${formats}`);
|
|
48
|
+
}
|
|
49
|
+
};
|
|
50
|
+
exports.printValidationMessages = (apiValidationSummary, warn, error) => {
|
|
51
|
+
const warnings = (apiValidationSummary === null || apiValidationSummary === void 0 ? void 0 : apiValidationSummary.warnings) || [];
|
|
52
|
+
const errors = (apiValidationSummary === null || apiValidationSummary === void 0 ? void 0 : apiValidationSummary.errors.join("\n")) || "";
|
|
53
|
+
warnings.forEach((warning) => {
|
|
54
|
+
warn(utils_1.replaceHTML(warning));
|
|
55
|
+
});
|
|
56
|
+
if (apiValidationSummary && apiValidationSummary.errors.length > 0) {
|
|
57
|
+
error(utils_1.replaceHTML(errors));
|
|
58
|
+
}
|
|
59
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
import Command from "@oclif/command";
|
|
2
|
+
import { APIValidationExternalApisController, ApiValidationSummary } from "@apimatic/sdk";
|
|
3
|
+
import { GetValidationParams } from "../../types/api/validate";
|
|
4
|
+
export declare const getValidation: ({ file, url }: GetValidationParams, apiValidationController: APIValidationExternalApisController) => Promise<ApiValidationSummary>;
|
|
5
|
+
export declare const printValidationMessages: ({ warnings, errors }: ApiValidationSummary, warn: Command["warn"], error: Command["error"]) => void;
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.printValidationMessages = exports.getValidation = void 0;
|
|
4
|
+
const cli_ux_1 = require("cli-ux");
|
|
5
|
+
const fs = require("fs-extra");
|
|
6
|
+
const core_1 = require("@apimatic/core");
|
|
7
|
+
const utils_1 = require("../../utils/utils");
|
|
8
|
+
exports.getValidation = async ({ file, url }, apiValidationController) => {
|
|
9
|
+
let validation;
|
|
10
|
+
cli_ux_1.default.action.start("Validating specification file");
|
|
11
|
+
if (file) {
|
|
12
|
+
const fileDescriptor = new core_1.FileWrapper(fs.createReadStream(file));
|
|
13
|
+
validation = await apiValidationController.validateAPIViaFile(fileDescriptor);
|
|
14
|
+
}
|
|
15
|
+
else if (url) {
|
|
16
|
+
validation = await apiValidationController.validateAPIViaURL(url);
|
|
17
|
+
}
|
|
18
|
+
else {
|
|
19
|
+
throw new Error("Please provide a specification file");
|
|
20
|
+
}
|
|
21
|
+
cli_ux_1.default.action.stop();
|
|
22
|
+
return validation.result;
|
|
23
|
+
};
|
|
24
|
+
exports.printValidationMessages = ({ warnings, errors }, warn, error) => {
|
|
25
|
+
warnings.forEach((warning) => {
|
|
26
|
+
warn(`${utils_1.replaceHTML(warning)}`);
|
|
27
|
+
});
|
|
28
|
+
if (errors.length > 0) {
|
|
29
|
+
const singleLineError = errors.join("\n");
|
|
30
|
+
error(utils_1.replaceHTML(singleLineError));
|
|
31
|
+
}
|
|
32
|
+
};
|
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.downloadDocsPortal = void 0;
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
|
+
const FormData = require("form-data");
|
|
6
|
+
const cli_ux_1 = require("cli-ux");
|
|
7
|
+
const auth_manager_1 = require("../../client-utils/auth-manager");
|
|
8
|
+
const env_1 = require("../../config/env");
|
|
9
|
+
const utils_1 = require("../../utils/utils");
|
|
10
|
+
const axios_1 = require("axios");
|
|
11
|
+
// TODO: Remove after SDK is patched
|
|
12
|
+
const downloadPortalAxios = async (zippedBuildFilePath, overrideAuthKey, configDir) => {
|
|
13
|
+
const formData = new FormData();
|
|
14
|
+
const authInfo = await auth_manager_1.getAuthInfo(configDir);
|
|
15
|
+
formData.append("file", fs.createReadStream(zippedBuildFilePath));
|
|
16
|
+
const config = {
|
|
17
|
+
headers: Object.assign({ Authorization: authInfo ? `X-Auth-Key ${overrideAuthKey || authInfo.authKey.trim()}` : "", "Content-Type": "multipart/form-data" }, formData.getHeaders()),
|
|
18
|
+
responseType: "arraybuffer"
|
|
19
|
+
};
|
|
20
|
+
const { data } = await axios_1.default.post(`${env_1.baseURL}/portal`, formData, config);
|
|
21
|
+
return data;
|
|
22
|
+
};
|
|
23
|
+
// Download Docs Portal
|
|
24
|
+
exports.downloadDocsPortal = async ({ zippedBuildFilePath, portalFolderPath, zippedPortalPath, overrideAuthKey, zip }, configDir) => {
|
|
25
|
+
cli_ux_1.default.action.start("Downloading portal");
|
|
26
|
+
// Check if the build file exists for the user or not
|
|
27
|
+
if (!(await fs.pathExists(zippedBuildFilePath))) {
|
|
28
|
+
throw new Error("Build file doesn't exist");
|
|
29
|
+
}
|
|
30
|
+
// TODO: ***CRITICAL*** Remove this call once the SDK is patched
|
|
31
|
+
const data = await downloadPortalAxios(zippedBuildFilePath, overrideAuthKey, configDir);
|
|
32
|
+
await utils_1.deleteFile(zippedBuildFilePath);
|
|
33
|
+
await fs.writeFile(zippedPortalPath, data);
|
|
34
|
+
// TODO: Uncomment this code block when the SDK is patched
|
|
35
|
+
// const file: FileWrapper = new FileWrapper(fs.createReadStream(zippedBuildFilePath));
|
|
36
|
+
// const { result }: ApiResponse<NodeJS.ReadableStream | Blob> =
|
|
37
|
+
// await docsPortalController.generateOnPremPortalViaBuildInput(file);
|
|
38
|
+
// if ((data as NodeJS.ReadableStream).readable) {
|
|
39
|
+
// await writeFileUsingReadableStream(data as NodeJS.ReadableStream, zippedPortalPath);
|
|
40
|
+
if (!zip) {
|
|
41
|
+
await utils_1.unzipFile(fs.createReadStream(zippedPortalPath), portalFolderPath);
|
|
42
|
+
await utils_1.deleteFile(zippedPortalPath);
|
|
43
|
+
}
|
|
44
|
+
cli_ux_1.default.action.stop();
|
|
45
|
+
return zip ? zippedPortalPath : portalFolderPath;
|
|
46
|
+
// } else {
|
|
47
|
+
// throw new Error("Couldn't download the portal");
|
|
48
|
+
// }
|
|
49
|
+
};
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { CodeGenerationExternalApisController } from "@apimatic/sdk";
|
|
2
|
+
import { GenerationIdParams, DownloadSDKParams } from "../../types/sdk/generate";
|
|
3
|
+
export declare const getSDKGenerationId: ({ file, url, platform }: GenerationIdParams, sdkGenerationController: CodeGenerationExternalApisController) => Promise<string>;
|
|
4
|
+
export declare const downloadGeneratedSDK: ({ codeGenId, zippedSDKPath, sdkFolderPath, zip }: DownloadSDKParams, sdkGenerationController: CodeGenerationExternalApisController) => Promise<string>;
|
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.downloadGeneratedSDK = exports.getSDKGenerationId = void 0;
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
|
+
const cli_ux_1 = require("cli-ux");
|
|
6
|
+
const sdk_1 = require("@apimatic/sdk");
|
|
7
|
+
const core_1 = require("@apimatic/core");
|
|
8
|
+
const generate_1 = require("../../types/sdk/generate");
|
|
9
|
+
const utils_1 = require("../../utils/utils");
|
|
10
|
+
exports.getSDKGenerationId = async ({ file, url, platform }, sdkGenerationController) => {
|
|
11
|
+
cli_ux_1.default.action.start("Generating SDK");
|
|
12
|
+
let generation;
|
|
13
|
+
const sdkPlatform = getSDKPlatform(platform);
|
|
14
|
+
if (file) {
|
|
15
|
+
const fileDescriptor = new core_1.FileWrapper(fs.createReadStream(file));
|
|
16
|
+
generation = await sdkGenerationController.generateSDKViaFile(fileDescriptor, sdkPlatform);
|
|
17
|
+
}
|
|
18
|
+
else if (url) {
|
|
19
|
+
// If url to spec file is provided
|
|
20
|
+
const body = {
|
|
21
|
+
url: url,
|
|
22
|
+
template: sdkPlatform
|
|
23
|
+
};
|
|
24
|
+
generation = await sdkGenerationController.generateSDKViaURL(body);
|
|
25
|
+
}
|
|
26
|
+
else {
|
|
27
|
+
throw new Error("Please provide a specification file");
|
|
28
|
+
}
|
|
29
|
+
cli_ux_1.default.action.stop();
|
|
30
|
+
return generation.result.id;
|
|
31
|
+
};
|
|
32
|
+
// Get valid platform from user's input, convert simple platform to valid Platforms enum value
|
|
33
|
+
const getSDKPlatform = (platform) => {
|
|
34
|
+
if (Object.keys(generate_1.SimplePlatforms).includes(platform)) {
|
|
35
|
+
return generate_1.SimplePlatforms[platform];
|
|
36
|
+
}
|
|
37
|
+
else if (Object.values(sdk_1.Platforms).includes(platform)) {
|
|
38
|
+
return platform;
|
|
39
|
+
}
|
|
40
|
+
else {
|
|
41
|
+
const platforms = Object.keys(generate_1.SimplePlatforms).concat(Object.values(sdk_1.Platforms)).join("|");
|
|
42
|
+
throw new Error(`Please provide a valid platform i.e. ${platforms}`);
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
// Download Platform
|
|
46
|
+
exports.downloadGeneratedSDK = async ({ codeGenId, zippedSDKPath, sdkFolderPath, zip }, sdkGenerationController) => {
|
|
47
|
+
cli_ux_1.default.action.start("Downloading SDK");
|
|
48
|
+
const { result } = await sdkGenerationController.downloadSDK(codeGenId);
|
|
49
|
+
if (result.readable) {
|
|
50
|
+
if (!zip) {
|
|
51
|
+
await utils_1.unzipFile(result, sdkFolderPath);
|
|
52
|
+
cli_ux_1.default.action.stop();
|
|
53
|
+
return sdkFolderPath;
|
|
54
|
+
}
|
|
55
|
+
else {
|
|
56
|
+
await utils_1.writeFileUsingReadableStream(result, zippedSDKPath);
|
|
57
|
+
cli_ux_1.default.action.stop();
|
|
58
|
+
return zippedSDKPath;
|
|
59
|
+
}
|
|
60
|
+
}
|
|
61
|
+
else {
|
|
62
|
+
throw new Error("Couldn't download the SDK");
|
|
63
|
+
}
|
|
64
|
+
};
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/// <reference types="node" />
|
|
2
|
+
import { TransformationController } from "@apimatic/sdk";
|
|
3
|
+
export declare type AuthenticationError = {
|
|
4
|
+
statusCode: number;
|
|
5
|
+
body: string;
|
|
6
|
+
};
|
|
7
|
+
export declare type TransformationIdParams = {
|
|
8
|
+
file: string;
|
|
9
|
+
url: string;
|
|
10
|
+
format: string;
|
|
11
|
+
};
|
|
12
|
+
export declare type DownloadTransformationParams = {
|
|
13
|
+
id: string;
|
|
14
|
+
destinationFilePath: string;
|
|
15
|
+
transformationController: TransformationController;
|
|
16
|
+
};
|
|
17
|
+
export declare type TransformationData = {
|
|
18
|
+
result: NodeJS.ReadableStream | Blob;
|
|
19
|
+
};
|
|
20
|
+
export declare const DestinationFormats: {
|
|
21
|
+
OpenApi3Json: string;
|
|
22
|
+
OpenApi3Yaml: string;
|
|
23
|
+
APIMATIC: string;
|
|
24
|
+
WADL2009: string;
|
|
25
|
+
WSDL: string;
|
|
26
|
+
Swagger10: string;
|
|
27
|
+
Swagger20: string;
|
|
28
|
+
SwaggerYaml: string;
|
|
29
|
+
RAML: string;
|
|
30
|
+
RAML10: string;
|
|
31
|
+
Postman10: string;
|
|
32
|
+
Postman20: string;
|
|
33
|
+
GraphQlSchema: string;
|
|
34
|
+
};
|
|
@@ -0,0 +1,18 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.DestinationFormats = void 0;
|
|
4
|
+
exports.DestinationFormats = {
|
|
5
|
+
OpenApi3Json: "json",
|
|
6
|
+
OpenApi3Yaml: "yaml",
|
|
7
|
+
APIMATIC: "json",
|
|
8
|
+
WADL2009: "xml",
|
|
9
|
+
WSDL: "xml",
|
|
10
|
+
Swagger10: "json",
|
|
11
|
+
Swagger20: "json",
|
|
12
|
+
SwaggerYaml: "yaml",
|
|
13
|
+
RAML: "yaml",
|
|
14
|
+
RAML10: "yaml",
|
|
15
|
+
Postman10: "json",
|
|
16
|
+
Postman20: "json",
|
|
17
|
+
GraphQlSchema: "json"
|
|
18
|
+
};
|