@apimatic/cli 1.0.1-alpha.8 → 1.1.0-alpha.2
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 +13 -12
- package/lib/client-utils/auth-manager.js +1 -1
- package/lib/client-utils/sdk-client.d.ts +1 -1
- package/lib/client-utils/sdk-client.js +1 -1
- package/lib/commands/api/transform.js +18 -11
- package/lib/commands/api/validate.js +17 -5
- package/lib/commands/auth/login.js +2 -2
- package/lib/commands/portal/generate.js +11 -3
- package/lib/commands/sdk/generate.js +14 -9
- package/lib/config/env.d.ts +1 -1
- package/lib/config/env.js +1 -1
- package/lib/controllers/api/transform.d.ts +1 -3
- package/lib/controllers/api/transform.js +2 -12
- package/lib/controllers/api/validate.d.ts +1 -3
- package/lib/controllers/api/validate.js +1 -11
- package/lib/controllers/portal/generate.js +3 -3
- package/lib/types/api/transform.d.ts +1 -4
- package/lib/types/api/transform.js +2 -1
- package/lib/types/utils.d.ts +14 -0
- package/lib/types/utils.js +2 -0
- package/lib/utils/utils.d.ts +2 -0
- package/lib/utils/utils.js +17 -3
- package/package.json +2 -4
- package/oclif.manifest.json +0 -1
package/README.md
CHANGED
|
@@ -15,11 +15,11 @@ The official CLI for APIMatic.
|
|
|
15
15
|
# Usage
|
|
16
16
|
<!-- usage -->
|
|
17
17
|
```sh-session
|
|
18
|
-
$ npm install -g @apimatic/cli
|
|
18
|
+
$ npm install -g @apimatic/cli@1.0.1-alpha.3
|
|
19
19
|
$ apimatic COMMAND
|
|
20
20
|
running command...
|
|
21
21
|
$ apimatic (-v|--version|version)
|
|
22
|
-
@apimatic/cli/
|
|
22
|
+
@apimatic/cli/0.0.0-alpha.3 linux-x64 node-v16.13.0
|
|
23
23
|
$ apimatic --help [COMMAND]
|
|
24
24
|
USAGE
|
|
25
25
|
$ apimatic COMMAND
|
|
@@ -57,8 +57,8 @@ OPTIONS
|
|
|
57
57
|
--file=file path to the API specification file to transform
|
|
58
58
|
|
|
59
59
|
--format=format (required) specification format to transform API specification into
|
|
60
|
-
|
|
61
|
-
|
|
60
|
+
APIMATIC|WADL2009|WSDL|SWAGGER10|SWAGGER20|SWAGGERYAML|OAS3|OPENAPI3YAML|APIBLUEPRINT|RAML|
|
|
61
|
+
RAML10|POSTMAN10|POSTMAN20|GRAPHQLSCHEMA
|
|
62
62
|
|
|
63
63
|
--url=url URL to the API specification file to transform. Can be used in place of the --file option
|
|
64
64
|
if the API specification is publicly available.
|
|
@@ -71,7 +71,7 @@ EXAMPLES
|
|
|
71
71
|
Success! Your transformed file is located at D:/swagger_raml.yaml
|
|
72
72
|
```
|
|
73
73
|
|
|
74
|
-
_See code: [src/commands/api/transform.ts](https://github.com/apimatic/apimatic-cli/blob/
|
|
74
|
+
_See code: [src/commands/api/transform.ts](https://github.com/apimatic/apimatic-cli/blob/v0.0.0-alpha.3/src/commands/api/transform.ts)_
|
|
75
75
|
|
|
76
76
|
## `apimatic api:validate`
|
|
77
77
|
|
|
@@ -96,7 +96,7 @@ EXAMPLES
|
|
|
96
96
|
Specification file provided is valid
|
|
97
97
|
```
|
|
98
98
|
|
|
99
|
-
_See code: [src/commands/api/validate.ts](https://github.com/apimatic/apimatic-cli/blob/
|
|
99
|
+
_See code: [src/commands/api/validate.ts](https://github.com/apimatic/apimatic-cli/blob/v0.0.0-alpha.3/src/commands/api/validate.ts)_
|
|
100
100
|
|
|
101
101
|
## `apimatic auth:login`
|
|
102
102
|
|
|
@@ -120,7 +120,7 @@ EXAMPLES
|
|
|
120
120
|
Authentication key successfully set
|
|
121
121
|
```
|
|
122
122
|
|
|
123
|
-
_See code: [src/commands/auth/login.ts](https://github.com/apimatic/apimatic-cli/blob/
|
|
123
|
+
_See code: [src/commands/auth/login.ts](https://github.com/apimatic/apimatic-cli/blob/v0.0.0-alpha.3/src/commands/auth/login.ts)_
|
|
124
124
|
|
|
125
125
|
## `apimatic auth:logout`
|
|
126
126
|
|
|
@@ -135,7 +135,7 @@ EXAMPLE
|
|
|
135
135
|
Logged out
|
|
136
136
|
```
|
|
137
137
|
|
|
138
|
-
_See code: [src/commands/auth/logout.ts](https://github.com/apimatic/apimatic-cli/blob/
|
|
138
|
+
_See code: [src/commands/auth/logout.ts](https://github.com/apimatic/apimatic-cli/blob/v0.0.0-alpha.3/src/commands/auth/logout.ts)_
|
|
139
139
|
|
|
140
140
|
## `apimatic auth:status`
|
|
141
141
|
|
|
@@ -150,7 +150,7 @@ EXAMPLE
|
|
|
150
150
|
Currently logged in as apimatic-client@gmail.com
|
|
151
151
|
```
|
|
152
152
|
|
|
153
|
-
_See code: [src/commands/auth/status.ts](https://github.com/apimatic/apimatic-cli/blob/
|
|
153
|
+
_See code: [src/commands/auth/status.ts](https://github.com/apimatic/apimatic-cli/blob/v0.0.0-alpha.3/src/commands/auth/status.ts)_
|
|
154
154
|
|
|
155
155
|
## `apimatic autocomplete [SHELL]`
|
|
156
156
|
|
|
@@ -190,7 +190,7 @@ OPTIONS
|
|
|
190
190
|
--all see all commands in CLI
|
|
191
191
|
```
|
|
192
192
|
|
|
193
|
-
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.
|
|
193
|
+
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.14/src/commands/help.ts)_
|
|
194
194
|
|
|
195
195
|
## `apimatic portal:generate`
|
|
196
196
|
|
|
@@ -212,7 +212,7 @@ EXAMPLE
|
|
|
212
212
|
Your portal has been generated at D:/
|
|
213
213
|
```
|
|
214
214
|
|
|
215
|
-
_See code: [src/commands/portal/generate.ts](https://github.com/apimatic/apimatic-cli/blob/
|
|
215
|
+
_See code: [src/commands/portal/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v0.0.0-alpha.3/src/commands/portal/generate.ts)_
|
|
216
216
|
|
|
217
217
|
## `apimatic sdk:generate`
|
|
218
218
|
|
|
@@ -247,11 +247,12 @@ EXAMPLES
|
|
|
247
247
|
Generating SDK... done
|
|
248
248
|
Downloading SDK... done
|
|
249
249
|
Success! Your SDK is located at swagger_sdk_csharp
|
|
250
|
+
|
|
250
251
|
$ apimatic sdk:generate --platform="CSHARP" --url=https://petstore.swagger.io/v2/swagger.json
|
|
251
252
|
Generating SDK... done
|
|
252
253
|
Downloading SDK... done
|
|
253
254
|
Success! Your SDK is located at swagger_sdk_csharp
|
|
254
255
|
```
|
|
255
256
|
|
|
256
|
-
_See code: [src/commands/sdk/generate.ts](https://github.com/apimatic/apimatic-cli/blob/
|
|
257
|
+
_See code: [src/commands/sdk/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v0.0.0-alpha.3/src/commands/sdk/generate.ts)_
|
|
257
258
|
<!-- commandsstop -->
|
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.setAuthInfo = exports.getAuthInfo = void 0;
|
|
4
|
-
const fs = require("fs-extra");
|
|
5
4
|
const path = require("path");
|
|
5
|
+
const fs = require("fs-extra");
|
|
6
6
|
/**
|
|
7
7
|
*
|
|
8
8
|
* @param {string} configDir <- Directory with user configuration
|
|
@@ -4,8 +4,8 @@ exports.SDKClient = void 0;
|
|
|
4
4
|
const base64 = require("base-64");
|
|
5
5
|
const axios_1 = require("axios");
|
|
6
6
|
const sdk_1 = require("@apimatic/sdk");
|
|
7
|
-
const auth_manager_1 = require("./auth-manager");
|
|
8
7
|
const env_1 = require("../config/env");
|
|
8
|
+
const auth_manager_1 = require("./auth-manager");
|
|
9
9
|
class SDKClient {
|
|
10
10
|
constructor() {
|
|
11
11
|
this.setAuthKey = (authKey, configDir) => {
|
|
@@ -1,18 +1,19 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const fs = require("fs-extra");
|
|
4
3
|
const path = require("path");
|
|
5
|
-
const
|
|
6
|
-
const sdk_1 = require("@apimatic/sdk");
|
|
4
|
+
const fs = require("fs-extra");
|
|
7
5
|
const command_1 = require("@oclif/command");
|
|
6
|
+
const sdk_1 = require("@apimatic/sdk");
|
|
8
7
|
const sdk_client_1 = require("../../client-utils/sdk-client");
|
|
9
8
|
const utils_1 = require("../../utils/utils");
|
|
9
|
+
const utils_2 = require("../../utils/utils");
|
|
10
10
|
const transform_1 = require("../../types/api/transform");
|
|
11
11
|
const transform_2 = require("../../controllers/api/transform");
|
|
12
|
+
const formats = Object.keys(sdk_1.ExportFormats).join("|");
|
|
12
13
|
class Transform extends command_1.Command {
|
|
13
14
|
async run() {
|
|
14
15
|
const { flags } = this.parse(Transform);
|
|
15
|
-
const fileName = flags.file ?
|
|
16
|
+
const fileName = flags.file ? utils_2.getFileNameFromPath(flags.file) : utils_2.getFileNameFromPath(flags.url);
|
|
16
17
|
const destinationFormat = transform_1.DestinationFormats[flags.format];
|
|
17
18
|
const destinationFilePath = path.join(flags.destination, `${fileName}_${flags.format}.${destinationFormat}`.toLowerCase());
|
|
18
19
|
// Check if destination file already exist and throw error if force flag is not set
|
|
@@ -31,7 +32,12 @@ class Transform extends command_1.Command {
|
|
|
31
32
|
const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
|
|
32
33
|
const transformationController = new sdk_1.TransformationController(client);
|
|
33
34
|
const { id, apiValidationSummary } = await transform_2.getTransformationId(flags, transformationController);
|
|
34
|
-
|
|
35
|
+
const logFunctions = {
|
|
36
|
+
log: this.log,
|
|
37
|
+
warn: this.warn,
|
|
38
|
+
error: this.error
|
|
39
|
+
};
|
|
40
|
+
utils_1.printValidationMessages(apiValidationSummary, logFunctions);
|
|
35
41
|
const savedTransformationFile = await transform_2.downloadTransformationFile({
|
|
36
42
|
id,
|
|
37
43
|
destinationFilePath,
|
|
@@ -40,26 +46,28 @@ class Transform extends command_1.Command {
|
|
|
40
46
|
this.log(`Success! Your transformed file is located at ${savedTransformationFile}`);
|
|
41
47
|
}
|
|
42
48
|
catch (error) {
|
|
43
|
-
cli_ux_1.default.action.stop();
|
|
44
49
|
if (error.result) {
|
|
45
50
|
const apiError = error;
|
|
46
51
|
// TODO: Hopefully, this type-cast won't be necessary when the SDK is
|
|
47
52
|
// updated to throw the right exception type for this status code.
|
|
48
53
|
const result = apiError.result;
|
|
49
54
|
if (apiError.statusCode === 422 && result && "errors" in result && Array.isArray(result.errors)) {
|
|
50
|
-
this.error(
|
|
55
|
+
this.error(utils_2.replaceHTML(`${result.errors}`));
|
|
51
56
|
}
|
|
52
57
|
else if (apiError.statusCode === 422 && apiError.body && typeof apiError.body === "string") {
|
|
53
58
|
this.error(JSON.parse(apiError.body)["dto.FileUrl"][0]);
|
|
54
59
|
}
|
|
55
60
|
else if (apiError.statusCode === 401 && apiError.body && typeof apiError.body === "string") {
|
|
56
|
-
this.error(
|
|
61
|
+
this.error("You are not authorized to perform this action");
|
|
57
62
|
}
|
|
58
63
|
else if (apiError.statusCode === 500) {
|
|
59
64
|
this.error(apiError.message);
|
|
60
65
|
}
|
|
61
66
|
}
|
|
62
|
-
else if (error.statusCode === 401
|
|
67
|
+
else if (error.statusCode === 401) {
|
|
68
|
+
this.error("You are not authorized to perform this action");
|
|
69
|
+
}
|
|
70
|
+
else if (error.statusCode === 402 &&
|
|
63
71
|
error.body &&
|
|
64
72
|
typeof error.body === "string") {
|
|
65
73
|
this.error(error.body);
|
|
@@ -85,8 +93,7 @@ Transform.flags = {
|
|
|
85
93
|
parse: (format) => transform_2.getValidFormat(format.toUpperCase()),
|
|
86
94
|
required: true,
|
|
87
95
|
description: `specification format to transform API specification into
|
|
88
|
-
|
|
89
|
-
Swagger20|SwaggerYaml|RAML|RAML10|Postman10|Postman20)`
|
|
96
|
+
${formats}`
|
|
90
97
|
}),
|
|
91
98
|
file: command_1.flags.string({
|
|
92
99
|
parse: (input) => path.resolve(input),
|
|
@@ -1,12 +1,11 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
const fs = require("fs-extra");
|
|
4
|
-
const sdk_1 = require("@apimatic/sdk");
|
|
5
4
|
const command_1 = require("@oclif/command");
|
|
5
|
+
const sdk_1 = require("@apimatic/sdk");
|
|
6
6
|
const sdk_client_1 = require("../../client-utils/sdk-client");
|
|
7
|
-
const utils_1 = require("../../utils/utils");
|
|
8
|
-
const transform_1 = require("../../controllers/api/transform");
|
|
9
7
|
const validate_1 = require("../../controllers/api/validate");
|
|
8
|
+
const utils_1 = require("../../utils/utils");
|
|
10
9
|
class Validate extends command_1.Command {
|
|
11
10
|
async run() {
|
|
12
11
|
const { flags } = this.parse(Validate);
|
|
@@ -18,7 +17,12 @@ class Validate extends command_1.Command {
|
|
|
18
17
|
const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
|
|
19
18
|
const apiValidationController = new sdk_1.APIValidationExternalApisController(client);
|
|
20
19
|
const validationSummary = await validate_1.getValidation(flags, apiValidationController);
|
|
21
|
-
|
|
20
|
+
const logFunctions = {
|
|
21
|
+
log: this.log,
|
|
22
|
+
warn: this.warn,
|
|
23
|
+
error: this.error
|
|
24
|
+
};
|
|
25
|
+
utils_1.printValidationMessages(validationSummary, logFunctions);
|
|
22
26
|
validationSummary.success
|
|
23
27
|
? this.log("Specification file provided is valid")
|
|
24
28
|
: this.error("Specification file provided is invalid");
|
|
@@ -31,12 +35,20 @@ class Validate extends command_1.Command {
|
|
|
31
35
|
this.error(utils_1.replaceHTML(result.modelState["exception Error"][0]));
|
|
32
36
|
}
|
|
33
37
|
else if (error.body && apiError.statusCode === 401) {
|
|
34
|
-
this.error(
|
|
38
|
+
this.error("You are not authorized to perform this action");
|
|
35
39
|
}
|
|
36
40
|
else {
|
|
37
41
|
this.error(error.message);
|
|
38
42
|
}
|
|
39
43
|
}
|
|
44
|
+
else if (error.statusCode === 401) {
|
|
45
|
+
this.error("You are not authorized to perform this action");
|
|
46
|
+
}
|
|
47
|
+
else if (error.statusCode === 402 &&
|
|
48
|
+
error.body &&
|
|
49
|
+
typeof error.body === "string") {
|
|
50
|
+
this.error(error.body);
|
|
51
|
+
}
|
|
40
52
|
else {
|
|
41
53
|
this.error(`${error.message}`);
|
|
42
54
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const command_1 = require("@oclif/command");
|
|
4
3
|
const cli_ux_1 = require("cli-ux");
|
|
5
|
-
const
|
|
4
|
+
const command_1 = require("@oclif/command");
|
|
6
5
|
const utils_1 = require("../../utils/utils");
|
|
6
|
+
const sdk_client_1 = require("../../client-utils/sdk-client");
|
|
7
7
|
class Login extends command_1.Command {
|
|
8
8
|
async run() {
|
|
9
9
|
const { flags } = this.parse(Login);
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const fs = require("fs-extra");
|
|
4
3
|
const path = require("path");
|
|
4
|
+
const fs = require("fs-extra");
|
|
5
5
|
const command_1 = require("@oclif/command");
|
|
6
6
|
const sdk_1 = require("@apimatic/sdk");
|
|
7
7
|
const sdk_client_1 = require("../../client-utils/sdk-client");
|
|
@@ -59,16 +59,24 @@ class PortalGenerate extends command_1.Command {
|
|
|
59
59
|
}
|
|
60
60
|
}
|
|
61
61
|
else if (apiResponse.status === 401 && responseData.length > 0) {
|
|
62
|
-
this.error(
|
|
62
|
+
this.error("You are not authorized to perform this action");
|
|
63
63
|
}
|
|
64
64
|
else if (apiResponse.status === 403 && apiResponse.statusText) {
|
|
65
|
-
return this.error(
|
|
65
|
+
return this.error("Your subscription does not allow on premise portal generation");
|
|
66
66
|
}
|
|
67
67
|
else {
|
|
68
68
|
return this.error(apiError.message);
|
|
69
69
|
}
|
|
70
70
|
}
|
|
71
71
|
}
|
|
72
|
+
else if (error.statusCode === 401) {
|
|
73
|
+
this.error("You are not authorized to perform this action");
|
|
74
|
+
}
|
|
75
|
+
else if (error.statusCode === 402 &&
|
|
76
|
+
error.body &&
|
|
77
|
+
typeof error.body === "string") {
|
|
78
|
+
this.error(error.body);
|
|
79
|
+
}
|
|
72
80
|
else {
|
|
73
81
|
this.error(`${error.message}`);
|
|
74
82
|
}
|
|
@@ -1,11 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
const fs = require("fs-extra");
|
|
4
3
|
const path = require("path");
|
|
5
|
-
const
|
|
6
|
-
const sdk_1 = require("@apimatic/sdk");
|
|
4
|
+
const fs = require("fs-extra");
|
|
7
5
|
const command_1 = require("@oclif/command");
|
|
8
6
|
const sdk_client_1 = require("../../client-utils/sdk-client");
|
|
7
|
+
const sdk_1 = require("@apimatic/sdk");
|
|
9
8
|
const utils_1 = require("../../utils/utils");
|
|
10
9
|
const generate_1 = require("../../controllers/sdk/generate");
|
|
11
10
|
class SdkGenerate extends command_1.Command {
|
|
@@ -45,7 +44,6 @@ class SdkGenerate extends command_1.Command {
|
|
|
45
44
|
this.log(`Success! Your SDK is located at ${sdkPath}`);
|
|
46
45
|
}
|
|
47
46
|
catch (error) {
|
|
48
|
-
cli_ux_1.default.action.stop();
|
|
49
47
|
if (error.result) {
|
|
50
48
|
const apiError = error;
|
|
51
49
|
const result = apiError.result;
|
|
@@ -56,7 +54,7 @@ class SdkGenerate extends command_1.Command {
|
|
|
56
54
|
}
|
|
57
55
|
}
|
|
58
56
|
else if (apiError.statusCode === 401 && apiError.body && typeof apiError.body === "string") {
|
|
59
|
-
this.error(
|
|
57
|
+
this.error("You are not authorized to perform this action");
|
|
60
58
|
}
|
|
61
59
|
else if (apiError.statusCode === 500 &&
|
|
62
60
|
apiError.body &&
|
|
@@ -74,6 +72,14 @@ class SdkGenerate extends command_1.Command {
|
|
|
74
72
|
this.error(utils_1.replaceHTML(result.message));
|
|
75
73
|
}
|
|
76
74
|
}
|
|
75
|
+
else if (error.statusCode === 401) {
|
|
76
|
+
this.error("You are not authorized to perform this action");
|
|
77
|
+
}
|
|
78
|
+
else if (error.statusCode === 402 &&
|
|
79
|
+
error.body &&
|
|
80
|
+
typeof error.body === "string") {
|
|
81
|
+
this.error(utils_1.replaceHTML(error.body));
|
|
82
|
+
}
|
|
77
83
|
else {
|
|
78
84
|
this.error(`${error.message}`);
|
|
79
85
|
}
|
|
@@ -88,9 +94,7 @@ SdkGenerate.flags = {
|
|
|
88
94
|
required: true,
|
|
89
95
|
description: `language platform for sdk
|
|
90
96
|
Simple: CSHARP|JAVA|PYTHON|RUBY|PHP|TYPESCRIPT
|
|
91
|
-
Legacy: CS_NET_STANDARD_LIB|
|
|
92
|
-
JAVA_ECLIPSE_JRE_LIB|PHP_GENERIC_LIB|PYTHON_GENERIC_LIB|RUBY_GENERIC_LIB|
|
|
93
|
-
TS_GENERIC_LIB`
|
|
97
|
+
Legacy: CS_NET_STANDARD_LIB|JAVA_ECLIPSE_JRE_LIB|PHP_GENERIC_LIB|PYTHON_GENERIC_LIB|RUBY_GENERIC_LIB|TS_GENERIC_LIB`
|
|
94
98
|
}),
|
|
95
99
|
file: command_1.flags.string({
|
|
96
100
|
parse: (input) => path.resolve(input),
|
|
@@ -122,7 +126,8 @@ SdkGenerate.examples = [
|
|
|
122
126
|
Generating SDK... done
|
|
123
127
|
Downloading SDK... done
|
|
124
128
|
Success! Your SDK is located at swagger_sdk_csharp`,
|
|
125
|
-
|
|
129
|
+
`
|
|
130
|
+
$ apimatic sdk:generate --platform="CSHARP" --url=https://petstore.swagger.io/v2/swagger.json
|
|
126
131
|
Generating SDK... done
|
|
127
132
|
Downloading SDK... done
|
|
128
133
|
Success! Your SDK is located at swagger_sdk_csharp
|
package/lib/config/env.d.ts
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export declare const baseURL = "https://
|
|
1
|
+
export declare const baseURL = "https://www.apimatic.io/api";
|
package/lib/config/env.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
|
-
import Command from "@oclif/command";
|
|
2
|
-
import { ApiValidationSummary, ExportFormats, Transformation, TransformationController } from "@apimatic/sdk";
|
|
3
1
|
import { DownloadTransformationParams, TransformationIdParams } from "../../types/api/transform";
|
|
2
|
+
import { ExportFormats, Transformation, TransformationController } from "@apimatic/sdk";
|
|
4
3
|
export declare const getTransformationId: ({ file, url, format }: TransformationIdParams, transformationController: TransformationController) => Promise<Transformation>;
|
|
5
4
|
export declare const downloadTransformationFile: ({ id, destinationFilePath, transformationController }: DownloadTransformationParams) => Promise<string>;
|
|
6
5
|
export declare const getValidFormat: (format: string) => ExportFormats;
|
|
7
|
-
export declare const printValidationMessages: (apiValidationSummary: ApiValidationSummary | undefined, warn: Command["warn"], error: Command["error"]) => void;
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getValidFormat = exports.downloadTransformationFile = exports.getTransformationId = void 0;
|
|
4
4
|
const cli_ux_1 = require("cli-ux");
|
|
5
5
|
const fs = require("fs-extra");
|
|
6
|
-
const sdk_1 = require("@apimatic/sdk");
|
|
7
6
|
const utils_1 = require("../../utils/utils");
|
|
7
|
+
const sdk_1 = require("@apimatic/sdk");
|
|
8
8
|
exports.getTransformationId = async ({ file, url, format }, transformationController) => {
|
|
9
9
|
cli_ux_1.default.action.start("Transforming API specification");
|
|
10
10
|
let generation;
|
|
@@ -47,13 +47,3 @@ exports.getValidFormat = (format) => {
|
|
|
47
47
|
throw new Error(`Please provide a valid platform i.e. ${formats}`);
|
|
48
48
|
}
|
|
49
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
|
-
};
|
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import Command from "@oclif/command";
|
|
2
|
-
import { APIValidationExternalApisController, ApiValidationSummary } from "@apimatic/sdk";
|
|
3
1
|
import { GetValidationParams } from "../../types/api/validate";
|
|
2
|
+
import { APIValidationExternalApisController, ApiValidationSummary } from "@apimatic/sdk";
|
|
4
3
|
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;
|
|
@@ -1,10 +1,9 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.getValidation = void 0;
|
|
4
4
|
const cli_ux_1 = require("cli-ux");
|
|
5
5
|
const fs = require("fs-extra");
|
|
6
6
|
const core_1 = require("@apimatic/core");
|
|
7
|
-
const utils_1 = require("../../utils/utils");
|
|
8
7
|
exports.getValidation = async ({ file, url }, apiValidationController) => {
|
|
9
8
|
let validation;
|
|
10
9
|
cli_ux_1.default.action.start("Validating specification file");
|
|
@@ -21,12 +20,3 @@ exports.getValidation = async ({ file, url }, apiValidationController) => {
|
|
|
21
20
|
cli_ux_1.default.action.stop();
|
|
22
21
|
return validation.result;
|
|
23
22
|
};
|
|
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
|
-
};
|
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
3
|
exports.downloadDocsPortal = void 0;
|
|
4
|
+
const cli_ux_1 = require("cli-ux");
|
|
4
5
|
const fs = require("fs-extra");
|
|
5
6
|
const FormData = require("form-data");
|
|
6
|
-
const cli_ux_1 = require("cli-ux");
|
|
7
|
-
const auth_manager_1 = require("../../client-utils/auth-manager");
|
|
8
7
|
const env_1 = require("../../config/env");
|
|
9
8
|
const utils_1 = require("../../utils/utils");
|
|
9
|
+
const auth_manager_1 = require("../../client-utils/auth-manager");
|
|
10
10
|
const axios_1 = require("axios");
|
|
11
11
|
// TODO: Remove after SDK is patched
|
|
12
12
|
const downloadPortalAxios = async (zippedBuildFilePath, overrideAuthKey, configDir) => {
|
|
@@ -14,7 +14,7 @@ const downloadPortalAxios = async (zippedBuildFilePath, overrideAuthKey, configD
|
|
|
14
14
|
const authInfo = await auth_manager_1.getAuthInfo(configDir);
|
|
15
15
|
formData.append("file", fs.createReadStream(zippedBuildFilePath));
|
|
16
16
|
const config = {
|
|
17
|
-
headers: Object.assign({ Authorization: authInfo ? `X-Auth-Key ${
|
|
17
|
+
headers: Object.assign({ Authorization: authInfo || overrideAuthKey ? `X-Auth-Key ${(authInfo === null || authInfo === void 0 ? void 0 : authInfo.authKey.trim()) || overrideAuthKey}` : "" }, formData.getHeaders()),
|
|
18
18
|
responseType: "arraybuffer"
|
|
19
19
|
};
|
|
20
20
|
const { data } = await axios_1.default.post(`${env_1.baseURL}/portal`, formData, config);
|
|
@@ -1,9 +1,5 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
import { TransformationController } from "@apimatic/sdk";
|
|
3
|
-
export declare type AuthenticationError = {
|
|
4
|
-
statusCode: number;
|
|
5
|
-
body: string;
|
|
6
|
-
};
|
|
7
3
|
export declare type TransformationIdParams = {
|
|
8
4
|
file: string;
|
|
9
5
|
url: string;
|
|
@@ -30,4 +26,5 @@ export declare const DestinationFormats: {
|
|
|
30
26
|
RAML10: string;
|
|
31
27
|
Postman10: string;
|
|
32
28
|
Postman20: string;
|
|
29
|
+
GraphQlSchema: string;
|
|
33
30
|
};
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
export declare type ValidationMessages = {
|
|
2
|
+
messages: string[];
|
|
3
|
+
warnings: string[];
|
|
4
|
+
errors: string[];
|
|
5
|
+
};
|
|
6
|
+
export declare type loggers = {
|
|
7
|
+
log: (message: string) => void;
|
|
8
|
+
warn: (message: string) => void;
|
|
9
|
+
error: (message: string) => void;
|
|
10
|
+
};
|
|
11
|
+
export declare type AuthenticationError = {
|
|
12
|
+
statusCode: number;
|
|
13
|
+
body: string;
|
|
14
|
+
};
|
package/lib/utils/utils.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
/// <reference types="node" />
|
|
2
2
|
/// <reference types="mocha" />
|
|
3
|
+
import { loggers, ValidationMessages } from "../types/utils";
|
|
3
4
|
export declare const unzipFile: (stream: NodeJS.ReadableStream, destination: string) => Promise<unknown>;
|
|
4
5
|
export declare const deleteFile: (filePath: string) => Promise<void>;
|
|
5
6
|
export declare const writeFileUsingReadableStream: (stream: NodeJS.ReadableStream, destinationPath: string) => Promise<unknown>;
|
|
@@ -16,3 +17,4 @@ export declare const stopProgress: (isError?: boolean) => void | null;
|
|
|
16
17
|
export declare const replaceHTML: (string: string) => string;
|
|
17
18
|
export declare const isJSONParsable: (json: string) => boolean;
|
|
18
19
|
export declare const getFileNameFromPath: (filePath: string) => string;
|
|
20
|
+
export declare const printValidationMessages: ({ warnings, errors, messages }: ValidationMessages, { log, warn, error }: loggers) => void;
|
package/lib/utils/utils.js
CHANGED
|
@@ -1,12 +1,12 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.getFileNameFromPath = exports.isJSONParsable = exports.replaceHTML = exports.stopProgress = exports.startProgress = exports.zipDirectory = exports.writeFileUsingReadableStream = exports.deleteFile = exports.unzipFile = void 0;
|
|
4
|
-
const
|
|
3
|
+
exports.printValidationMessages = exports.getFileNameFromPath = exports.isJSONParsable = exports.replaceHTML = exports.stopProgress = exports.startProgress = exports.zipDirectory = exports.writeFileUsingReadableStream = exports.deleteFile = exports.unzipFile = void 0;
|
|
4
|
+
const cli_ux_1 = require("cli-ux");
|
|
5
5
|
const path = require("path");
|
|
6
|
+
const fs = require("fs-extra");
|
|
6
7
|
const archiver = require("archiver");
|
|
7
8
|
const unzipper = require("unzipper");
|
|
8
9
|
const stripTags = require("striptags");
|
|
9
|
-
const cli_ux_1 = require("cli-ux");
|
|
10
10
|
exports.unzipFile = (stream, destination) => {
|
|
11
11
|
return new Promise((resolve, reject) => {
|
|
12
12
|
stream.pipe(unzipper.Extract({ path: destination }));
|
|
@@ -105,3 +105,17 @@ exports.isJSONParsable = (json) => {
|
|
|
105
105
|
exports.getFileNameFromPath = (filePath) => {
|
|
106
106
|
return path.basename(filePath).split(".")[0];
|
|
107
107
|
};
|
|
108
|
+
exports.printValidationMessages = ({ warnings, errors, messages }, { log, warn, error }) => {
|
|
109
|
+
warnings = warnings || [];
|
|
110
|
+
messages = messages || [];
|
|
111
|
+
const singleError = errors.join("\n") || "";
|
|
112
|
+
messages.forEach((message) => {
|
|
113
|
+
log(`Info: ${exports.replaceHTML(message)}`);
|
|
114
|
+
});
|
|
115
|
+
warnings.forEach((warning) => {
|
|
116
|
+
warn(exports.replaceHTML(warning));
|
|
117
|
+
});
|
|
118
|
+
if (errors.length > 0) {
|
|
119
|
+
error(exports.replaceHTML(singleError));
|
|
120
|
+
}
|
|
121
|
+
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@apimatic/cli",
|
|
3
3
|
"description": "The official CLI for APIMatic.",
|
|
4
|
-
"version": "1.0
|
|
4
|
+
"version": "1.1.0-alpha.2",
|
|
5
5
|
"author": "APIMatic",
|
|
6
6
|
"bin": {
|
|
7
7
|
"apimatic": "./bin/run"
|
|
@@ -36,16 +36,14 @@
|
|
|
36
36
|
"build": "tsc -b",
|
|
37
37
|
"postpack": "rimraf oclif.manifest.json",
|
|
38
38
|
"posttest": "eslint . --ext .ts --config .eslintrc",
|
|
39
|
-
"prepack": "rimraf lib && tsc -b && oclif-dev manifest && oclif-dev readme",
|
|
40
39
|
"test": "nyc --extension .ts mocha --forbid-only \"test/**/*.test.ts\"",
|
|
41
|
-
"version": "oclif-dev readme && git add README.md",
|
|
42
40
|
"prettier": "prettier \"src/**/*.{js,ts}\"",
|
|
43
41
|
"format": "prettier --write \"src/**/*.{js,ts}\"",
|
|
44
42
|
"lint": "eslint \"src/**/*.{js,ts}\"",
|
|
45
43
|
"lint:fix": "eslint --fix \"src/**/*.{js,ts}\" --quiet"
|
|
46
44
|
},
|
|
47
45
|
"dependencies": {
|
|
48
|
-
"@apimatic/sdk": "^0.0.1-alpha.
|
|
46
|
+
"@apimatic/sdk": "^0.0.1-alpha.10",
|
|
49
47
|
"@oclif/command": "^1.8.0",
|
|
50
48
|
"@oclif/config": "^1.17.0",
|
|
51
49
|
"@oclif/plugin-autocomplete": "^0.3.0",
|
package/oclif.manifest.json
DELETED
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":"1.0.1-alpha.8","commands":{"api:transform":{"id":"api:transform","description":"Transform API specifications from one format to another. Supports [10+ different formats](https://www.apimatic.io/transformer/#supported-formats) including OpenApi/Swagger, RAML, WSDL and Postman Collections.","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic api:transform --format=\"OpenApi3Json\" --file=\"./specs/sample.json\" --destination=\"D:/\"\nSuccess! Your transformed file is located at D:/Transformed_OpenApi3Json.json\n","$ apimatic api:transform --format=RAML --url=\"https://petstore.swagger.io/v2/swagger.json\" --destination=\"D:/\"\nSuccess! Your transformed file is located at D:/swagger_raml.yaml\n"],"flags":{"format":{"name":"format","type":"option","description":"specification format to transform API specification into\n(OpenApi3Json|OpenApi3Yaml|APIMATIC|WADL2009|WSDL|Swagger10|\nSwagger20|SwaggerYaml|RAML|RAML10|Postman10|Postman20)","required":true},"file":{"name":"file","type":"option","description":"path to the API specification file to transform","default":""},"url":{"name":"url","type":"option","description":"URL to the API specification file to transform. Can be used in place of the --file option if the API specification is publicly available.","default":""},"destination":{"name":"destination","type":"option","description":"directory to download transformed file to","default":"/home/runner/work/apimatic-cli/apimatic-cli/cli"},"force":{"name":"force","type":"boolean","char":"f","description":"overwrite if same file exist in the destination","allowNo":false},"auth-key":{"name":"auth-key","type":"option","description":"override current authentication state with an authentication key"}},"args":[]},"api:validate":{"id":"api:validate","description":"Validate the syntactic and semantic correctness of an API specification","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic api:validate --file=\"./specs/sample.json\"\nSpecification file provided is valid\n","$ apimatic api:validate --url=https://petstore.swagger.io/v2/swagger.json\nSpecification file provided is valid\n"],"flags":{"file":{"name":"file","type":"option","description":"Path to the API specification file to validate","default":""},"url":{"name":"url","type":"option","description":"URL to the specification file to validate. Can be used in place of the --file option if the API specification is publicly available.","default":""},"auth-key":{"name":"auth-key","type":"option","description":"override current authentication state with an authentication key"}},"args":[]},"auth:login":{"id":"auth:login","description":"Login using your APIMatic credentials or an API Key","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic auth:login\nPlease enter your registered email: apimatic-user@gmail.com\nPlease enter your password: *********\n\nYou have successfully logged into APIMatic\n","$ apimatic auth:login --auth-key=xxxxxx\nAuthentication key successfully set"],"flags":{"auth-key":{"name":"auth-key","type":"option","description":"Set authentication key for all commands","default":""}},"args":[]},"auth:logout":{"id":"auth:logout","description":"Clear local login credentials","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic auth:logout\nLogged out\n"],"flags":{},"args":[]},"auth:status":{"id":"auth:status","description":"View current authentication state","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic auth:status\nCurrently logged in as apimatic-client@gmail.com\n"],"flags":{},"args":[]},"portal:generate":{"id":"portal:generate","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)","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic portal:generate --folder=\"./portal/\" --destination=\"D:/\"\nYour portal has been generated at D:/\n"],"flags":{"folder":{"name":"folder","type":"option","description":"path to the input directory containing API specifications and config files","default":"./"},"destination":{"name":"destination","type":"option","description":"path to the downloaded portal","default":"/home/runner/work/apimatic-cli/apimatic-cli/cli"},"force":{"name":"force","type":"boolean","char":"f","description":"overwrite if a portal exists in the destination","allowNo":false},"zip":{"name":"zip","type":"boolean","description":"download the generated portal as a .zip archive","allowNo":false},"auth-key":{"name":"auth-key","type":"option","description":"override current authentication state with an authentication key","default":""}},"args":[]},"sdk:generate":{"id":"sdk:generate","description":"Generate SDK for your APIs","pluginName":"@apimatic/cli","pluginType":"core","aliases":[],"examples":["$ apimatic sdk:generate --platform=\"CSHARP\" --file=\"./specs/sample.json\"\nGenerating SDK... done\nDownloading SDK... done\nSuccess! Your SDK is located at swagger_sdk_csharp","$ apimatic sdk:generate --platform=\"CSHARP\" --url=https://petstore.swagger.io/v2/swagger.json\nGenerating SDK... done\nDownloading SDK... done\nSuccess! Your SDK is located at swagger_sdk_csharp\n"],"flags":{"platform":{"name":"platform","type":"option","description":"language platform for sdk\nSimple: CSHARP|JAVA|PYTHON|RUBY|PHP|TYPESCRIPT\nLegacy: CS_NET_STANDARD_LIB|CS_PORTABLE_NET_LIB|CS_UNIVERSAL_WINDOWS_PLATFORM_LIB|\n JAVA_ECLIPSE_JRE_LIB|PHP_GENERIC_LIB|PYTHON_GENERIC_LIB|RUBY_GENERIC_LIB|\n TS_GENERIC_LIB","required":true},"file":{"name":"file","type":"option","description":"path to the API specification to generate SDKs for","default":""},"url":{"name":"url","type":"option","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.","default":""},"destination":{"name":"destination","type":"option","description":"directory to download the generated SDK to","default":"/home/runner/work/apimatic-cli/apimatic-cli/cli"},"force":{"name":"force","type":"boolean","char":"f","description":"overwrite if an SDK already exists in the destination","allowNo":false},"zip":{"name":"zip","type":"boolean","description":"download the generated SDK as a .zip archive","allowNo":false},"auth-key":{"name":"auth-key","type":"option","description":"override current authentication state with an authentication key","default":""}},"args":[]}}}
|