@apimatic/cli 1.0.1-alpha.1 → 1.0.1-alpha.5

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.
Files changed (38) hide show
  1. package/README.md +64 -49
  2. package/bin/run +3 -3
  3. package/lib/client-utils/sdk-client.d.ts +1 -1
  4. package/lib/client-utils/sdk-client.js +3 -3
  5. package/lib/commands/api/index.js +4 -5
  6. package/lib/commands/api/transform.d.ts +1 -2
  7. package/lib/commands/api/transform.js +23 -81
  8. package/lib/commands/api/validate.d.ts +0 -2
  9. package/lib/commands/api/validate.js +16 -37
  10. package/lib/commands/auth/index.js +5 -5
  11. package/lib/commands/auth/login.js +4 -2
  12. package/lib/commands/auth/logout.js +1 -1
  13. package/lib/commands/auth/status.js +1 -1
  14. package/lib/commands/portal/generate.d.ts +1 -11
  15. package/lib/commands/portal/generate.js +23 -60
  16. package/lib/commands/portal/index.js +3 -3
  17. package/lib/commands/sdk/generate.d.ts +1 -0
  18. package/lib/commands/sdk/generate.js +35 -83
  19. package/lib/commands/sdk/index.js +2 -2
  20. package/lib/controllers/api/transform.d.ts +7 -0
  21. package/lib/controllers/api/transform.js +59 -0
  22. package/lib/controllers/api/validate.d.ts +5 -0
  23. package/lib/controllers/api/validate.js +32 -0
  24. package/lib/controllers/portal/generate.d.ts +2 -0
  25. package/lib/controllers/portal/generate.js +49 -0
  26. package/lib/controllers/sdk/generate.d.ts +4 -0
  27. package/lib/controllers/sdk/generate.js +64 -0
  28. package/lib/types/api/transform.d.ts +33 -0
  29. package/lib/types/api/transform.js +17 -0
  30. package/lib/types/api/validate.d.ts +12 -0
  31. package/lib/types/api/validate.js +2 -0
  32. package/lib/types/portal/generate.d.ts +9 -0
  33. package/lib/types/portal/generate.js +2 -0
  34. package/lib/types/sdk/generate.d.ts +22 -0
  35. package/lib/types/sdk/generate.js +12 -0
  36. package/oclif.manifest.json +1 -1
  37. package/package.json +2 -2
  38. package/CHANGELOG.md +0 -6
package/README.md CHANGED
@@ -1,13 +1,10 @@
1
1
  @apimatic/cli
2
2
  =============
3
-
4
3
  The official CLI for APIMatic.
5
-
6
4
  [![oclif](https://img.shields.io/badge/cli-oclif-brightgreen.svg)](https://oclif.io)
7
5
  [![Version](https://img.shields.io/npm/v/@apimatic/cli.svg)](https://npmjs.org/package/@apimatic/cli)
8
6
  [![Downloads/week](https://img.shields.io/npm/dw/@apimatic/cli.svg)](https://npmjs.org/package/@apimatic/cli)
9
7
  [![License](https://img.shields.io/npm/l/@apimatic/cli.svg)](https://github.com/apimatic/apimatic-cli/blob/master/package.json)
10
-
11
8
  <!-- toc -->
12
9
  * [Usage](#usage)
13
10
  * [Commands](#commands)
@@ -19,14 +16,13 @@ $ npm install -g @apimatic/cli
19
16
  $ apimatic COMMAND
20
17
  running command...
21
18
  $ apimatic (-v|--version|version)
22
- @apimatic/cli/1.0.1-alpha.1 linux-x64 node-v14.18.1
19
+ @apimatic/cli/1.0.1-alpha.5 linux-x64 node-v16.13.0
23
20
  $ apimatic --help [COMMAND]
24
21
  USAGE
25
22
  $ apimatic COMMAND
26
23
  ...
27
24
  ```
28
25
  <!-- usagestop -->
29
-
30
26
  # Commands
31
27
  <!-- commands -->
32
28
  * [`apimatic api`](#apimatic-api)
@@ -45,7 +41,7 @@ USAGE
45
41
 
46
42
  ## `apimatic api`
47
43
 
48
- lists all commands related to the APIMatic API.
44
+ Manage APIs
49
45
 
50
46
  ```
51
47
  USAGE
@@ -55,60 +51,67 @@ EXAMPLE
55
51
  $ apimatic api --help
56
52
  ```
57
53
 
58
- _See code: [src/commands/api/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/api/index.ts)_
54
+ _See code: [src/commands/api/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.5/src/commands/api/index.ts)_
59
55
 
60
56
  ## `apimatic api:transform`
61
57
 
62
- Transforms your API specification to any supported format of your choice from amongst[10+ different formats](https://www.apimatic.io/transformer/#supported-formats).
58
+ 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.
63
59
 
64
60
  ```
65
61
  USAGE
66
62
  $ apimatic api:transform
67
63
 
68
64
  OPTIONS
69
- --auth-key=auth-key override current auth-key
70
-
71
- --destination=destination [default: /home/runner/work/apimatic-cli/apimatic-cli/cli/src/commands/api] path to
72
- transformed file
73
-
65
+ -f, --force overwrite if same file exist in the destination
66
+ --auth-key=auth-key override current authentication state with an authentication key
67
+ --destination=destination [default: ./] directory to download transformed file to
74
68
  --file=file path to the API specification file to transform
75
69
 
76
70
  --format=format (required) specification format to transform API specification into
77
71
  (OpenApi3Json|OpenApi3Yaml|APIMATIC|WADL2009|WADL2006|WSDL|
78
72
  Swagger10|Swagger20|SwaggerYaml|RAML|RAML10|Postman10|Postman20)
79
73
 
80
- --url=url URL to the API specification file to transform
74
+ --url=url URL to the API specification file to transform. Can be used in place of the --file option
75
+ if the API specification is publicly available.
81
76
 
82
- EXAMPLE
77
+ EXAMPLES
83
78
  $ apimatic api:transform --format="OpenApi3Json" --file="./specs/sample.json" --destination="D:/"
84
79
  Success! Your transformed file is located at D:/Transformed_OpenApi3Json.json
80
+
81
+ $ apimatic api:transform --format=RAML --url="https://petstore.swagger.io/v2/swagger.json" --destination="D:/"
82
+ Success! Your transformed file is located at D:/swagger_raml.yaml
85
83
  ```
86
84
 
87
- _See code: [src/commands/api/transform.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/api/transform.ts)_
85
+ _See code: [src/commands/api/transform.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.5/src/commands/api/transform.ts)_
88
86
 
89
87
  ## `apimatic api:validate`
90
88
 
91
- Validates the provided API specification file for any syntactical and semantic errors
89
+ Validate the syntactic and semantic correctness of an API specification
92
90
 
93
91
  ```
94
92
  USAGE
95
93
  $ apimatic api:validate
96
94
 
97
95
  OPTIONS
98
- --auth-key=auth-key override current auth-key
99
- --file=file path to the API specification file to validate
100
- --url=url URL to the specification file to validate
96
+ --auth-key=auth-key override current authentication state with an authentication key
97
+ --file=file Path to the API specification file to validate
101
98
 
102
- EXAMPLE
99
+ --url=url URL to the specification file to validate. Can be used in place of the --file option if the API
100
+ specification is publicly available.
101
+
102
+ EXAMPLES
103
103
  $ apimatic api:validate --file="./specs/sample.json"
104
104
  Specification file provided is valid
105
+
106
+ $ apimatic api:validate --url=https://petstore.swagger.io/v2/swagger.json
107
+ Specification file provided is valid
105
108
  ```
106
109
 
107
- _See code: [src/commands/api/validate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/api/validate.ts)_
110
+ _See code: [src/commands/api/validate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.5/src/commands/api/validate.ts)_
108
111
 
109
112
  ## `apimatic auth`
110
113
 
111
- invokes subcommands related to authentication.
114
+ Manage this CLI's authentication state.
112
115
 
113
116
  ```
114
117
  USAGE
@@ -118,11 +121,11 @@ EXAMPLE
118
121
  $ apimatic auth --help
119
122
  ```
120
123
 
121
- _See code: [src/commands/auth/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/auth/index.ts)_
124
+ _See code: [src/commands/auth/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.5/src/commands/auth/index.ts)_
122
125
 
123
126
  ## `apimatic auth:login`
124
127
 
125
- login to your APIMatic account
128
+ Login using your APIMatic credentials or an API Key
126
129
 
127
130
  ```
128
131
  USAGE
@@ -131,19 +134,22 @@ USAGE
131
134
  OPTIONS
132
135
  --auth-key=auth-key Set authentication key for all commands
133
136
 
134
- EXAMPLE
137
+ EXAMPLES
135
138
  $ apimatic auth:login
136
139
  Please enter your registered email: apimatic-user@gmail.com
137
140
  Please enter your password: *********
138
141
 
139
142
  You have successfully logged into APIMatic
143
+
144
+ $ apimatic auth:login --auth-key=xxxxxx
145
+ Authentication key successfully set
140
146
  ```
141
147
 
142
- _See code: [src/commands/auth/login.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/auth/login.ts)_
148
+ _See code: [src/commands/auth/login.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.5/src/commands/auth/login.ts)_
143
149
 
144
150
  ## `apimatic auth:logout`
145
151
 
146
- logout of APIMatic
152
+ Clear local login credentials
147
153
 
148
154
  ```
149
155
  USAGE
@@ -154,11 +160,11 @@ EXAMPLE
154
160
  Logged out
155
161
  ```
156
162
 
157
- _See code: [src/commands/auth/logout.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/auth/logout.ts)_
163
+ _See code: [src/commands/auth/logout.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.5/src/commands/auth/logout.ts)_
158
164
 
159
165
  ## `apimatic auth:status`
160
166
 
161
- checks current logged-in account
167
+ View current authentication state
162
168
 
163
169
  ```
164
170
  USAGE
@@ -169,7 +175,7 @@ EXAMPLE
169
175
  Currently logged in as apimatic-client@gmail.com
170
176
  ```
171
177
 
172
- _See code: [src/commands/auth/status.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/auth/status.ts)_
178
+ _See code: [src/commands/auth/status.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.5/src/commands/auth/status.ts)_
173
179
 
174
180
  ## `apimatic autocomplete [SHELL]`
175
181
 
@@ -209,11 +215,11 @@ OPTIONS
209
215
  --all see all commands in CLI
210
216
  ```
211
217
 
212
- _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.7/src/commands/help.ts)_
218
+ _See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.10/src/commands/help.ts)_
213
219
 
214
220
  ## `apimatic portal`
215
221
 
216
- invokes subcommands related to the API Portal.
222
+ Manage API documentation portals
217
223
 
218
224
  ```
219
225
  USAGE
@@ -223,32 +229,33 @@ EXAMPLE
223
229
  $apimatic portal --help
224
230
  ```
225
231
 
226
- _See code: [src/commands/portal/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/portal/index.ts)_
232
+ _See code: [src/commands/portal/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.5/src/commands/portal/index.ts)_
227
233
 
228
234
  ## `apimatic portal:generate`
229
235
 
230
- Generate static docs portal on premise
236
+ 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)
231
237
 
232
238
  ```
233
239
  USAGE
234
240
  $ apimatic portal:generate
235
241
 
236
242
  OPTIONS
237
- --auth-key=auth-key override current auth-key
243
+ -f, --force overwrite if a portal exists in the destination
244
+ --auth-key=auth-key override current authentication state with an authentication key
238
245
  --destination=destination [default: ./] path to the downloaded portal
239
- --folder=folder folder to generate the portal with
240
- --zip zip the portal
246
+ --folder=folder path to the input directory containing API specifications and config files
247
+ --zip download the generated portal as a .zip archive
241
248
 
242
249
  EXAMPLE
243
250
  $ apimatic portal:generate --folder="./portal/" --destination="D:/"
244
251
  Your portal has been generated at D:/
245
252
  ```
246
253
 
247
- _See code: [src/commands/portal/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/portal/generate.ts)_
254
+ _See code: [src/commands/portal/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.5/src/commands/portal/generate.ts)_
248
255
 
249
256
  ## `apimatic sdk`
250
257
 
251
- invokes subcommands related to your SDKs.
258
+ Generate and manage SDKs for APIs
252
259
 
253
260
  ```
254
261
  USAGE
@@ -258,7 +265,7 @@ EXAMPLE
258
265
  $apimatic sdk --help
259
266
  ```
260
267
 
261
- _See code: [src/commands/sdk/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/sdk/index.ts)_
268
+ _See code: [src/commands/sdk/index.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.5/src/commands/sdk/index.ts)_
262
269
 
263
270
  ## `apimatic sdk:generate`
264
271
 
@@ -269,9 +276,10 @@ USAGE
269
276
  $ apimatic sdk:generate
270
277
 
271
278
  OPTIONS
272
- --auth-key=auth-key override current auth-key
273
- --destination=destination [default: ./] path to downloaded SDK (used with download flag)
274
- --file=file path to the API specification to generate SDK
279
+ -f, --force overwrite if an SDK already exists in the destination
280
+ --auth-key=auth-key override current authentication state with an authentication key
281
+ --destination=destination [default: ./] directory to download the generated SDK to
282
+ --file=file path to the API specification to generate SDKs for
275
283
 
276
284
  --platform=platform (required) language platform for sdk
277
285
  Simple: CSHARP|JAVA|PYTHON|RUBY|PHP|TYPESCRIPT
@@ -279,14 +287,21 @@ OPTIONS
279
287
  JAVA_ECLIPSE_JRE_LIB|PHP_GENERIC_LIB|PYTHON_GENERIC_LIB|RUBY_GENERIC_LIB|
280
288
  TS_GENERIC_LIB
281
289
 
282
- --url=url URL to the API specification to generate SDK
290
+ --url=url URL to the API specification to generate SDKs for. Can be used in place of the --file
291
+ option if the API specification is publicly available.
283
292
 
284
- --zip zip the SDK (used with download flag)
293
+ --zip download the generated SDK as a .zip archive
285
294
 
286
- EXAMPLE
295
+ EXAMPLES
287
296
  $ apimatic sdk:generate --platform="CSHARP" --file="./specs/sample.json"
288
- SDK generated successfully
297
+ Generating SDK... done
298
+ Downloading SDK... done
299
+ Success! Your SDK is located at swagger_sdk_csharp
300
+ $ apimatic sdk:generate --platform="CSHARP" --url=https://petstore.swagger.io/v2/swagger.json
301
+ Generating SDK... done
302
+ Downloading SDK... done
303
+ Success! Your SDK is located at swagger_sdk_csharp
289
304
  ```
290
305
 
291
- _See code: [src/commands/sdk/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.1/src/commands/sdk/generate.ts)_
306
+ _See code: [src/commands/sdk/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.5/src/commands/sdk/generate.ts)_
292
307
  <!-- commandsstop -->
package/bin/run CHANGED
@@ -1,5 +1,5 @@
1
1
  #!/usr/bin/env node
2
+ /* eslint-disable no-undef */
3
+ /* eslint-disable @typescript-eslint/no-var-requires */
2
4
 
3
- require('@oclif/command').run()
4
- .then(require('@oclif/command/flush'))
5
- .catch(require('@oclif/errors/handle'))
5
+ require("@oclif/command").run().then(require("@oclif/command/flush")).catch(require("@oclif/errors/handle"));
@@ -1,4 +1,4 @@
1
- import { Client } from "@apimatic/apimatic-sdk-for-js";
1
+ import { Client } from "@apimatic/sdk";
2
2
  export declare class SDKClient {
3
3
  private static instance;
4
4
  private static authAPI;
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  exports.SDKClient = void 0;
4
4
  const base64 = require("base-64");
5
5
  const axios_1 = require("axios");
6
- const apimatic_sdk_for_js_1 = require("@apimatic/apimatic-sdk-for-js");
6
+ const sdk_1 = require("@apimatic/sdk");
7
7
  const auth_manager_1 = require("./auth-manager");
8
8
  const env_1 = require("../config/env");
9
9
  class SDKClient {
@@ -84,7 +84,7 @@ class SDKClient {
84
84
  }
85
85
  async getClient(overrideAuthKey, configDir) {
86
86
  if (overrideAuthKey) {
87
- return new apimatic_sdk_for_js_1.Client({
87
+ return new sdk_1.Client({
88
88
  timeout: 0,
89
89
  authorization: `X-Auth-Key ${overrideAuthKey}`
90
90
  });
@@ -95,7 +95,7 @@ class SDKClient {
95
95
  storedAuthInfo = { email: "", authKey: "" };
96
96
  }
97
97
  if (storedAuthInfo.authKey !== "") {
98
- return new apimatic_sdk_for_js_1.Client({
98
+ return new sdk_1.Client({
99
99
  timeout: 0,
100
100
  authorization: `X-Auth-Key ${storedAuthInfo.authKey}`
101
101
  });
@@ -3,7 +3,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const command_1 = require("@oclif/command");
4
4
  class Api extends command_1.Command {
5
5
  async run() {
6
- this.log(`lists all commands related to the APIMatic API.
6
+ this.log(`Manage APIs
7
7
 
8
8
  USAGE
9
9
  $ apimatic api
@@ -12,11 +12,10 @@ EXAMPLE
12
12
  $ apimatic api --help
13
13
 
14
14
  COMMANDS
15
- api:transform Transforms your API specification to any supported format of your choice from amongst[10+ different
16
- formats](https://www.apimatic.io/transformer/#supported-formats).
17
- api:validate Validates the provided API specification file for any syntactical and semantic errors`);
15
+ api:transform 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.
16
+ api:validate Validate the syntactic and semantic correctness of an API specification`);
18
17
  }
19
18
  }
20
19
  exports.default = Api;
21
- Api.description = "lists all commands related to the APIMatic API.";
20
+ Api.description = "Manage APIs";
22
21
  Api.examples = ["$ apimatic api --help"];
@@ -1,4 +1,3 @@
1
- import { ApiValidationSummary } from "@apimatic/apimatic-sdk-for-js";
2
1
  import { flags, Command } from "@oclif/command";
3
2
  export default class Transform extends Command {
4
3
  static description: string;
@@ -8,8 +7,8 @@ export default class Transform extends Command {
8
7
  file: flags.IOptionFlag<string>;
9
8
  url: flags.IOptionFlag<string>;
10
9
  destination: flags.IOptionFlag<string>;
10
+ force: import("@oclif/parser/lib/flags").IBooleanFlag<boolean>;
11
11
  "auth-key": flags.IOptionFlag<string | undefined>;
12
12
  };
13
- printValidationMessages: (apiValidationSummary: ApiValidationSummary | undefined) => void;
14
13
  run(): Promise<void>;
15
14
  }
@@ -3,89 +3,24 @@ Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const fs = require("fs-extra");
4
4
  const path = require("path");
5
5
  const cli_ux_1 = require("cli-ux");
6
- const apimatic_sdk_for_js_1 = require("@apimatic/apimatic-sdk-for-js");
6
+ const sdk_1 = require("@apimatic/sdk");
7
7
  const command_1 = require("@oclif/command");
8
8
  const sdk_client_1 = require("../../client-utils/sdk-client");
9
9
  const utils_1 = require("../../utils/utils");
10
- const DestinationFormats = {
11
- OpenApi3Json: "json",
12
- OpenApi3Yaml: "yaml",
13
- APIMATIC: "json",
14
- WADL2009: "xml",
15
- WSDL: "xml",
16
- Swagger10: "json",
17
- Swagger20: "json",
18
- SwaggerYaml: "yaml",
19
- RAML: "yaml",
20
- RAML10: "yaml",
21
- Postman10: "json",
22
- Postman20: "json"
23
- };
24
- async function getTransformationId({ file, url, format }, transformationController) {
25
- cli_ux_1.default.action.start("Transforming API specification");
26
- let generation;
27
- if (file) {
28
- const fileDescriptor = new apimatic_sdk_for_js_1.FileWrapper(fs.createReadStream(file));
29
- generation = await transformationController.transformViaFile(fileDescriptor, format);
30
- }
31
- else if (url) {
32
- const body = {
33
- url: url,
34
- exportFormat: format
35
- };
36
- generation = await transformationController.transformViaURL(body);
37
- }
38
- else {
39
- throw new Error("Please provide a specification file");
40
- }
41
- cli_ux_1.default.action.stop();
42
- return generation.result;
43
- }
44
- async function downloadTransformationFile({ id, destinationFilePath, transformationController }) {
45
- cli_ux_1.default.action.start("Downloading Transformed file");
46
- const { result } = await transformationController.downloadTransformedFile(id);
47
- if (result.readable) {
48
- await utils_1.writeFileUsingReadableStream(result, destinationFilePath);
49
- }
50
- else {
51
- throw new Error("Couldn't save transformation file");
52
- }
53
- cli_ux_1.default.action.stop();
54
- return destinationFilePath;
55
- }
56
- // Get valid platform from user's input, convert simple platform to valid Platforms enum value
57
- function getValidFormat(format) {
58
- if (Object.keys(apimatic_sdk_for_js_1.ExportFormats).find((exportFormat) => exportFormat === format)) {
59
- return apimatic_sdk_for_js_1.ExportFormats[format];
60
- }
61
- else {
62
- const formats = Object.keys(apimatic_sdk_for_js_1.ExportFormats).join("|");
63
- throw new Error(`Please provide a valid platform i.e. ${formats}`);
64
- }
65
- }
10
+ const transform_1 = require("../../types/api/transform");
11
+ const transform_2 = require("../../controllers/api/transform");
66
12
  class Transform extends command_1.Command {
67
- constructor() {
68
- super(...arguments);
69
- this.printValidationMessages = (apiValidationSummary) => {
70
- const warnings = (apiValidationSummary === null || apiValidationSummary === void 0 ? void 0 : apiValidationSummary.warnings) || [];
71
- const errors = (apiValidationSummary === null || apiValidationSummary === void 0 ? void 0 : apiValidationSummary.errors.join("\n")) || "";
72
- warnings.forEach((warning) => {
73
- this.warn(utils_1.replaceHTML(warning));
74
- });
75
- if (apiValidationSummary && apiValidationSummary.errors.length > 0) {
76
- this.error(utils_1.replaceHTML(errors));
77
- }
78
- };
79
- }
80
13
  async run() {
81
14
  const { flags } = this.parse(Transform);
82
15
  const fileName = flags.file ? utils_1.getFileNameFromPath(flags.file) : utils_1.getFileNameFromPath(flags.url);
83
- const destinationFormat = DestinationFormats[flags.format];
16
+ const destinationFormat = transform_1.DestinationFormats[flags.format];
84
17
  const destinationFilePath = path.join(flags.destination, `${fileName}_${flags.format}.${destinationFormat}`.toLowerCase());
85
- if (fs.existsSync(destinationFilePath)) {
18
+ // Check if destination file already exist and throw error if force flag is not set
19
+ if (fs.existsSync(destinationFilePath) && !flags.force) {
86
20
  throw new Error(`Can't download transformed file to path ${destinationFilePath}, because it already exists`);
87
21
  }
88
22
  try {
23
+ // Check if paths provided are valid
89
24
  if (flags.file && !(await fs.pathExists(flags.file))) {
90
25
  throw new Error(`Transformation file: ${flags.file} does not exist`);
91
26
  }
@@ -94,10 +29,10 @@ class Transform extends command_1.Command {
94
29
  }
95
30
  const overrideAuthKey = flags["auth-key"] ? flags["auth-key"] : null;
96
31
  const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
97
- const transformationController = new apimatic_sdk_for_js_1.TransformationController(client);
98
- const { id, apiValidationSummary } = await getTransformationId(flags, transformationController);
99
- this.printValidationMessages(apiValidationSummary);
100
- const savedTransformationFile = await downloadTransformationFile({
32
+ const transformationController = new sdk_1.TransformationController(client);
33
+ const { id, apiValidationSummary } = await transform_2.getTransformationId(flags, transformationController);
34
+ transform_2.printValidationMessages(apiValidationSummary, this.warn, this.error);
35
+ const savedTransformationFile = await transform_2.downloadTransformationFile({
101
36
  id,
102
37
  destinationFilePath,
103
38
  transformationController
@@ -136,22 +71,29 @@ class Transform extends command_1.Command {
136
71
  }
137
72
  }
138
73
  exports.default = Transform;
139
- Transform.description = `Transforms your API specification to any supported format of your choice from amongst[10+ different formats](https://www.apimatic.io/transformer/#supported-formats).`;
74
+ 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.`;
140
75
  Transform.examples = [
141
76
  `$ apimatic api:transform --format="OpenApi3Json" --file="./specs/sample.json" --destination="D:/"
142
77
  Success! Your transformed file is located at D:/Transformed_OpenApi3Json.json
78
+ `,
79
+ `$ apimatic api:transform --format=RAML --url="https://petstore.swagger.io/v2/swagger.json" --destination="D:/"
80
+ Success! Your transformed file is located at D:/swagger_raml.yaml
143
81
  `
144
82
  ];
145
83
  Transform.flags = {
146
84
  format: command_1.flags.string({
147
- parse: (format) => getValidFormat(format.toUpperCase()),
85
+ parse: (format) => transform_2.getValidFormat(format.toUpperCase()),
148
86
  required: true,
149
87
  description: `specification format to transform API specification into
150
88
  (OpenApi3Json|OpenApi3Yaml|APIMATIC|WADL2009|WADL2006|WSDL|
151
89
  Swagger10|Swagger20|SwaggerYaml|RAML|RAML10|Postman10|Postman20)`
152
90
  }),
153
91
  file: command_1.flags.string({ default: "", description: "path to the API specification file to transform" }),
154
- url: command_1.flags.string({ default: "", description: "URL to the API specification file to transform" }),
155
- destination: command_1.flags.string({ default: __dirname, description: "path to transformed file" }),
156
- "auth-key": command_1.flags.string({ description: "override current auth-key" })
92
+ url: command_1.flags.string({
93
+ default: "",
94
+ 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."
95
+ }),
96
+ destination: command_1.flags.string({ default: "./", description: "directory to download transformed file to" }),
97
+ force: command_1.flags.boolean({ char: "f", default: false, description: "overwrite if same file exist in the destination" }),
98
+ "auth-key": command_1.flags.string({ description: "override current authentication state with an authentication key" })
157
99
  };
@@ -1,4 +1,3 @@
1
- import { ApiValidationSummary } from "@apimatic/apimatic-sdk-for-js";
2
1
  import { flags, Command } from "@oclif/command";
3
2
  export default class Validate extends Command {
4
3
  static description: string;
@@ -8,6 +7,5 @@ export default class Validate extends Command {
8
7
  url: flags.IOptionFlag<string>;
9
8
  "auth-key": flags.IOptionFlag<string | undefined>;
10
9
  };
11
- printValidationMessages: ({ warnings, errors }: ApiValidationSummary) => void;
12
10
  run(): Promise<void>;
13
11
  }
@@ -1,40 +1,13 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
3
  const fs = require("fs-extra");
4
- const cli_ux_1 = require("cli-ux");
5
- const apimatic_sdk_for_js_1 = require("@apimatic/apimatic-sdk-for-js");
4
+ const sdk_1 = require("@apimatic/sdk");
6
5
  const command_1 = require("@oclif/command");
7
6
  const sdk_client_1 = require("../../client-utils/sdk-client");
8
7
  const utils_1 = require("../../utils/utils");
9
- async function getValidation({ file, url }, apiValidationController) {
10
- let validation;
11
- cli_ux_1.default.action.start("Validating specification file");
12
- if (file) {
13
- const fileDescriptor = new apimatic_sdk_for_js_1.FileWrapper(fs.createReadStream(file));
14
- validation = await apiValidationController.validateAPIViaFile(fileDescriptor);
15
- }
16
- else if (url) {
17
- validation = await apiValidationController.validateAPIViaURL(url);
18
- }
19
- else {
20
- throw new Error("Please provide a specification file");
21
- }
22
- cli_ux_1.default.action.stop();
23
- return validation.result;
24
- }
8
+ const transform_1 = require("../../controllers/api/transform");
9
+ const validate_1 = require("../../controllers/api/validate");
25
10
  class Validate extends command_1.Command {
26
- constructor() {
27
- super(...arguments);
28
- this.printValidationMessages = ({ warnings, errors }) => {
29
- warnings.forEach((warning) => {
30
- this.warn(`${utils_1.replaceHTML(warning)}`);
31
- });
32
- if (errors.length > 0) {
33
- const singleLineError = errors.join("\n");
34
- this.error(utils_1.replaceHTML(singleLineError));
35
- }
36
- };
37
- }
38
11
  async run() {
39
12
  const { flags } = this.parse(Validate);
40
13
  try {
@@ -43,9 +16,9 @@ class Validate extends command_1.Command {
43
16
  }
44
17
  const overrideAuthKey = flags["auth-key"] ? flags["auth-key"] : null;
45
18
  const client = await sdk_client_1.SDKClient.getInstance().getClient(overrideAuthKey, this.config.configDir);
46
- const apiValidationController = new apimatic_sdk_for_js_1.APIValidationExternalApisController(client);
47
- const validationSummary = await getValidation(flags, apiValidationController);
48
- this.printValidationMessages(validationSummary);
19
+ const apiValidationController = new sdk_1.APIValidationExternalApisController(client);
20
+ const validationSummary = await validate_1.getValidation(flags, apiValidationController);
21
+ transform_1.printValidationMessages(validationSummary, this.warn, this.error);
49
22
  validationSummary.success
50
23
  ? this.log("Specification file provided is valid")
51
24
  : this.error("Specification file provided is invalid");
@@ -71,15 +44,21 @@ class Validate extends command_1.Command {
71
44
  }
72
45
  }
73
46
  exports.default = Validate;
74
- Validate.description = "Validates the provided API specification file for any syntactical and semantic errors";
47
+ Validate.description = "Validate the syntactic and semantic correctness of an API specification";
75
48
  Validate.examples = [
76
49
  `$ apimatic api:validate --file="./specs/sample.json"
77
50
  Specification file provided is valid
51
+ `,
52
+ `$ apimatic api:validate --url=https://petstore.swagger.io/v2/swagger.json
53
+ Specification file provided is valid
78
54
  `
79
55
  ];
80
56
  Validate.flags = {
81
- file: command_1.flags.string({ default: "", description: "path to the API specification file to validate" }),
82
- url: command_1.flags.string({ default: "", description: "URL to the specification file to validate" }),
57
+ file: command_1.flags.string({ default: "", description: "Path to the API specification file to validate" }),
58
+ url: command_1.flags.string({
59
+ default: "",
60
+ description: "URL to the specification file to validate. Can be used in place of the --file option if the API specification is publicly available."
61
+ }),
83
62
  // docs: flags.boolean({ default: false, description: "Validate specification for docs generation" }), // Next tier, not included in API spec
84
- "auth-key": command_1.flags.string({ description: "override current auth-key" })
63
+ "auth-key": command_1.flags.string({ description: "override current authentication state with an authentication key" })
85
64
  };
@@ -5,7 +5,7 @@ class Auth extends command_1.Command {
5
5
  constructor() {
6
6
  super(...arguments);
7
7
  this.run = async () => {
8
- this.log(`invokes subcommands related to authentication.
8
+ this.log(`Manage this CLI's authentication state.
9
9
 
10
10
  USAGE
11
11
  $ apimatic auth
@@ -14,12 +14,12 @@ EXAMPLE
14
14
  $ apimatic auth --help
15
15
 
16
16
  COMMANDS
17
- auth:login login to your APIMatic account
18
- auth:logout logout of APIMatic
19
- auth:status checks current logged-in account`);
17
+ auth:login Login using your APIMatic credentials or an API Key
18
+ auth:logout Clear local login credentials
19
+ auth:status View current authentication state`);
20
20
  };
21
21
  }
22
22
  }
23
23
  exports.default = Auth;
24
- Auth.description = "invokes subcommands related to authentication.";
24
+ Auth.description = "Manage this CLI's authentication state.";
25
25
  Auth.examples = ["$ apimatic auth --help"];