@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
package/README.md
CHANGED
|
@@ -19,7 +19,7 @@ $ npm install -g @apimatic/cli
|
|
|
19
19
|
$ apimatic COMMAND
|
|
20
20
|
running command...
|
|
21
21
|
$ apimatic (-v|--version|version)
|
|
22
|
-
@apimatic/cli/1.0.1-alpha.
|
|
22
|
+
@apimatic/cli/1.0.1-alpha.10 linux-x64 node-v16.13.0
|
|
23
23
|
$ apimatic --help [COMMAND]
|
|
24
24
|
USAGE
|
|
25
25
|
$ apimatic COMMAND
|
|
@@ -29,100 +29,78 @@ USAGE
|
|
|
29
29
|
|
|
30
30
|
# Commands
|
|
31
31
|
<!-- commands -->
|
|
32
|
-
* [`apimatic api`](#apimatic-api)
|
|
33
32
|
* [`apimatic api:transform`](#apimatic-apitransform)
|
|
34
33
|
* [`apimatic api:validate`](#apimatic-apivalidate)
|
|
35
|
-
* [`apimatic auth`](#apimatic-auth)
|
|
36
34
|
* [`apimatic auth:login`](#apimatic-authlogin)
|
|
37
35
|
* [`apimatic auth:logout`](#apimatic-authlogout)
|
|
38
36
|
* [`apimatic auth:status`](#apimatic-authstatus)
|
|
39
37
|
* [`apimatic autocomplete [SHELL]`](#apimatic-autocomplete-shell)
|
|
40
38
|
* [`apimatic help [COMMAND]`](#apimatic-help-command)
|
|
41
|
-
* [`apimatic portal`](#apimatic-portal)
|
|
42
39
|
* [`apimatic portal:generate`](#apimatic-portalgenerate)
|
|
43
|
-
* [`apimatic sdk`](#apimatic-sdk)
|
|
44
40
|
* [`apimatic sdk:generate`](#apimatic-sdkgenerate)
|
|
45
41
|
|
|
46
|
-
## `apimatic api`
|
|
47
|
-
|
|
48
|
-
lists all commands related to the APIMatic API.
|
|
49
|
-
|
|
50
|
-
```
|
|
51
|
-
USAGE
|
|
52
|
-
$ apimatic api
|
|
53
|
-
|
|
54
|
-
EXAMPLE
|
|
55
|
-
$ apimatic api --help
|
|
56
|
-
```
|
|
57
|
-
|
|
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)_
|
|
59
|
-
|
|
60
42
|
## `apimatic api:transform`
|
|
61
43
|
|
|
62
|
-
|
|
44
|
+
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
45
|
|
|
64
46
|
```
|
|
65
47
|
USAGE
|
|
66
48
|
$ apimatic api:transform
|
|
67
49
|
|
|
68
50
|
OPTIONS
|
|
69
|
-
|
|
51
|
+
-f, --force overwrite if same file exist in the destination
|
|
52
|
+
--auth-key=auth-key override current authentication state with an authentication key
|
|
70
53
|
|
|
71
|
-
--destination=destination [default: /home/runner/work/apimatic-cli/apimatic-cli/cli
|
|
72
|
-
transformed file
|
|
54
|
+
--destination=destination [default: /home/runner/work/apimatic-cli/apimatic-cli/cli] directory to download
|
|
55
|
+
transformed file to
|
|
73
56
|
|
|
74
57
|
--file=file path to the API specification file to transform
|
|
75
58
|
|
|
76
59
|
--format=format (required) specification format to transform API specification into
|
|
77
|
-
|
|
78
|
-
|
|
60
|
+
APIMATIC|WADL2009|WSDL|SWAGGER10|SWAGGER20|SWAGGERYAML|OAS3|OPENAPI3YAML|APIBLUEPRINT|RAML|
|
|
61
|
+
RAML10|POSTMAN10|POSTMAN20|GRAPHQLSCHEMA
|
|
79
62
|
|
|
80
|
-
--url=url URL to the API specification file to transform
|
|
63
|
+
--url=url URL to the API specification file to transform. Can be used in place of the --file option
|
|
64
|
+
if the API specification is publicly available.
|
|
81
65
|
|
|
82
|
-
|
|
66
|
+
EXAMPLES
|
|
83
67
|
$ apimatic api:transform --format="OpenApi3Json" --file="./specs/sample.json" --destination="D:/"
|
|
84
68
|
Success! Your transformed file is located at D:/Transformed_OpenApi3Json.json
|
|
69
|
+
|
|
70
|
+
$ apimatic api:transform --format=RAML --url="https://petstore.swagger.io/v2/swagger.json" --destination="D:/"
|
|
71
|
+
Success! Your transformed file is located at D:/swagger_raml.yaml
|
|
85
72
|
```
|
|
86
73
|
|
|
87
|
-
_See code: [src/commands/api/transform.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.
|
|
74
|
+
_See code: [src/commands/api/transform.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.10/src/commands/api/transform.ts)_
|
|
88
75
|
|
|
89
76
|
## `apimatic api:validate`
|
|
90
77
|
|
|
91
|
-
|
|
78
|
+
Validate the syntactic and semantic correctness of an API specification
|
|
92
79
|
|
|
93
80
|
```
|
|
94
81
|
USAGE
|
|
95
82
|
$ apimatic api:validate
|
|
96
83
|
|
|
97
84
|
OPTIONS
|
|
98
|
-
--auth-key=auth-key override current
|
|
99
|
-
--file=file
|
|
100
|
-
--url=url URL to the specification file to validate
|
|
85
|
+
--auth-key=auth-key override current authentication state with an authentication key
|
|
86
|
+
--file=file Path to the API specification file to validate
|
|
101
87
|
|
|
102
|
-
|
|
88
|
+
--url=url URL to the specification file to validate. Can be used in place of the --file option if the API
|
|
89
|
+
specification is publicly available.
|
|
90
|
+
|
|
91
|
+
EXAMPLES
|
|
103
92
|
$ apimatic api:validate --file="./specs/sample.json"
|
|
104
93
|
Specification file provided is valid
|
|
105
|
-
```
|
|
106
|
-
|
|
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)_
|
|
108
|
-
|
|
109
|
-
## `apimatic auth`
|
|
110
|
-
|
|
111
|
-
invokes subcommands related to authentication.
|
|
112
94
|
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
$ apimatic auth
|
|
116
|
-
|
|
117
|
-
EXAMPLE
|
|
118
|
-
$ apimatic auth --help
|
|
95
|
+
$ apimatic api:validate --url=https://petstore.swagger.io/v2/swagger.json
|
|
96
|
+
Specification file provided is valid
|
|
119
97
|
```
|
|
120
98
|
|
|
121
|
-
_See code: [src/commands/
|
|
99
|
+
_See code: [src/commands/api/validate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.10/src/commands/api/validate.ts)_
|
|
122
100
|
|
|
123
101
|
## `apimatic auth:login`
|
|
124
102
|
|
|
125
|
-
|
|
103
|
+
Login using your APIMatic credentials or an API Key
|
|
126
104
|
|
|
127
105
|
```
|
|
128
106
|
USAGE
|
|
@@ -131,19 +109,22 @@ USAGE
|
|
|
131
109
|
OPTIONS
|
|
132
110
|
--auth-key=auth-key Set authentication key for all commands
|
|
133
111
|
|
|
134
|
-
|
|
112
|
+
EXAMPLES
|
|
135
113
|
$ apimatic auth:login
|
|
136
114
|
Please enter your registered email: apimatic-user@gmail.com
|
|
137
115
|
Please enter your password: *********
|
|
138
116
|
|
|
139
117
|
You have successfully logged into APIMatic
|
|
118
|
+
|
|
119
|
+
$ apimatic auth:login --auth-key=xxxxxx
|
|
120
|
+
Authentication key successfully set
|
|
140
121
|
```
|
|
141
122
|
|
|
142
|
-
_See code: [src/commands/auth/login.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.
|
|
123
|
+
_See code: [src/commands/auth/login.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.10/src/commands/auth/login.ts)_
|
|
143
124
|
|
|
144
125
|
## `apimatic auth:logout`
|
|
145
126
|
|
|
146
|
-
|
|
127
|
+
Clear local login credentials
|
|
147
128
|
|
|
148
129
|
```
|
|
149
130
|
USAGE
|
|
@@ -154,11 +135,11 @@ EXAMPLE
|
|
|
154
135
|
Logged out
|
|
155
136
|
```
|
|
156
137
|
|
|
157
|
-
_See code: [src/commands/auth/logout.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.
|
|
138
|
+
_See code: [src/commands/auth/logout.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.10/src/commands/auth/logout.ts)_
|
|
158
139
|
|
|
159
140
|
## `apimatic auth:status`
|
|
160
141
|
|
|
161
|
-
|
|
142
|
+
View current authentication state
|
|
162
143
|
|
|
163
144
|
```
|
|
164
145
|
USAGE
|
|
@@ -169,7 +150,7 @@ EXAMPLE
|
|
|
169
150
|
Currently logged in as apimatic-client@gmail.com
|
|
170
151
|
```
|
|
171
152
|
|
|
172
|
-
_See code: [src/commands/auth/status.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.
|
|
153
|
+
_See code: [src/commands/auth/status.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.10/src/commands/auth/status.ts)_
|
|
173
154
|
|
|
174
155
|
## `apimatic autocomplete [SHELL]`
|
|
175
156
|
|
|
@@ -209,56 +190,29 @@ OPTIONS
|
|
|
209
190
|
--all see all commands in CLI
|
|
210
191
|
```
|
|
211
192
|
|
|
212
|
-
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.
|
|
213
|
-
|
|
214
|
-
## `apimatic portal`
|
|
215
|
-
|
|
216
|
-
invokes subcommands related to the API Portal.
|
|
217
|
-
|
|
218
|
-
```
|
|
219
|
-
USAGE
|
|
220
|
-
$ apimatic portal
|
|
221
|
-
|
|
222
|
-
EXAMPLE
|
|
223
|
-
$apimatic portal --help
|
|
224
|
-
```
|
|
225
|
-
|
|
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)_
|
|
193
|
+
_See code: [@oclif/plugin-help](https://github.com/oclif/plugin-help/blob/v3.2.12/src/commands/help.ts)_
|
|
227
194
|
|
|
228
195
|
## `apimatic portal:generate`
|
|
229
196
|
|
|
230
|
-
Generate static
|
|
197
|
+
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
198
|
|
|
232
199
|
```
|
|
233
200
|
USAGE
|
|
234
201
|
$ apimatic portal:generate
|
|
235
202
|
|
|
236
203
|
OPTIONS
|
|
237
|
-
|
|
238
|
-
--
|
|
239
|
-
--
|
|
240
|
-
--
|
|
204
|
+
-f, --force overwrite if a portal exists in the destination
|
|
205
|
+
--auth-key=auth-key override current authentication state with an authentication key
|
|
206
|
+
--destination=destination [default: /home/runner/work/apimatic-cli/apimatic-cli/cli] path to the downloaded portal
|
|
207
|
+
--folder=folder [default: ./] path to the input directory containing API specifications and config files
|
|
208
|
+
--zip download the generated portal as a .zip archive
|
|
241
209
|
|
|
242
210
|
EXAMPLE
|
|
243
211
|
$ apimatic portal:generate --folder="./portal/" --destination="D:/"
|
|
244
212
|
Your portal has been generated at D:/
|
|
245
213
|
```
|
|
246
214
|
|
|
247
|
-
_See code: [src/commands/portal/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.
|
|
248
|
-
|
|
249
|
-
## `apimatic sdk`
|
|
250
|
-
|
|
251
|
-
invokes subcommands related to your SDKs.
|
|
252
|
-
|
|
253
|
-
```
|
|
254
|
-
USAGE
|
|
255
|
-
$ apimatic sdk
|
|
256
|
-
|
|
257
|
-
EXAMPLE
|
|
258
|
-
$apimatic sdk --help
|
|
259
|
-
```
|
|
260
|
-
|
|
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)_
|
|
215
|
+
_See code: [src/commands/portal/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.10/src/commands/portal/generate.ts)_
|
|
262
216
|
|
|
263
217
|
## `apimatic sdk:generate`
|
|
264
218
|
|
|
@@ -269,9 +223,13 @@ USAGE
|
|
|
269
223
|
$ apimatic sdk:generate
|
|
270
224
|
|
|
271
225
|
OPTIONS
|
|
272
|
-
|
|
273
|
-
--
|
|
274
|
-
|
|
226
|
+
-f, --force overwrite if an SDK already exists in the destination
|
|
227
|
+
--auth-key=auth-key override current authentication state with an authentication key
|
|
228
|
+
|
|
229
|
+
--destination=destination [default: /home/runner/work/apimatic-cli/apimatic-cli/cli] directory to download the
|
|
230
|
+
generated SDK to
|
|
231
|
+
|
|
232
|
+
--file=file path to the API specification to generate SDKs for
|
|
275
233
|
|
|
276
234
|
--platform=platform (required) language platform for sdk
|
|
277
235
|
Simple: CSHARP|JAVA|PYTHON|RUBY|PHP|TYPESCRIPT
|
|
@@ -279,14 +237,22 @@ OPTIONS
|
|
|
279
237
|
JAVA_ECLIPSE_JRE_LIB|PHP_GENERIC_LIB|PYTHON_GENERIC_LIB|RUBY_GENERIC_LIB|
|
|
280
238
|
TS_GENERIC_LIB
|
|
281
239
|
|
|
282
|
-
--url=url URL to the API specification to generate
|
|
240
|
+
--url=url URL to the API specification to generate SDKs for. Can be used in place of the --file
|
|
241
|
+
option if the API specification is publicly available.
|
|
283
242
|
|
|
284
|
-
--zip
|
|
243
|
+
--zip download the generated SDK as a .zip archive
|
|
285
244
|
|
|
286
|
-
|
|
245
|
+
EXAMPLES
|
|
287
246
|
$ apimatic sdk:generate --platform="CSHARP" --file="./specs/sample.json"
|
|
288
|
-
SDK
|
|
247
|
+
Generating SDK... done
|
|
248
|
+
Downloading SDK... done
|
|
249
|
+
Success! Your SDK is located at swagger_sdk_csharp
|
|
250
|
+
|
|
251
|
+
$ apimatic sdk:generate --platform="CSHARP" --url=https://petstore.swagger.io/v2/swagger.json
|
|
252
|
+
Generating SDK... done
|
|
253
|
+
Downloading SDK... done
|
|
254
|
+
Success! Your SDK is located at swagger_sdk_csharp
|
|
289
255
|
```
|
|
290
256
|
|
|
291
|
-
_See code: [src/commands/sdk/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.
|
|
257
|
+
_See code: [src/commands/sdk/generate.ts](https://github.com/apimatic/apimatic-cli/blob/v1.0.1-alpha.10/src/commands/sdk/generate.ts)_
|
|
292
258
|
<!-- 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(
|
|
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"));
|
|
@@ -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
|
|
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
|
|
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
|
|
98
|
+
return new sdk_1.Client({
|
|
99
99
|
timeout: 0,
|
|
100
100
|
authorization: `X-Auth-Key ${storedAuthInfo.authKey}`
|
|
101
101
|
});
|
|
@@ -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
|
}
|
|
@@ -2,90 +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
|
-
const
|
|
11
|
-
|
|
12
|
-
|
|
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
|
-
}
|
|
9
|
+
const transform_1 = require("../../types/api/transform");
|
|
10
|
+
const transform_2 = require("../../controllers/api/transform");
|
|
11
|
+
const formats = Object.keys(sdk_1.ExportFormats).join("|");
|
|
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
|
|
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
|
|
98
|
-
const { id, apiValidationSummary } = await getTransformationId(flags, transformationController);
|
|
99
|
-
|
|
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
|
|
@@ -105,7 +40,6 @@ class Transform extends command_1.Command {
|
|
|
105
40
|
this.log(`Success! Your transformed file is located at ${savedTransformationFile}`);
|
|
106
41
|
}
|
|
107
42
|
catch (error) {
|
|
108
|
-
cli_ux_1.default.action.stop();
|
|
109
43
|
if (error.result) {
|
|
110
44
|
const apiError = error;
|
|
111
45
|
// TODO: Hopefully, this type-cast won't be necessary when the SDK is
|
|
@@ -136,22 +70,36 @@ class Transform extends command_1.Command {
|
|
|
136
70
|
}
|
|
137
71
|
}
|
|
138
72
|
exports.default = Transform;
|
|
139
|
-
Transform.description = `
|
|
73
|
+
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
74
|
Transform.examples = [
|
|
141
75
|
`$ apimatic api:transform --format="OpenApi3Json" --file="./specs/sample.json" --destination="D:/"
|
|
142
76
|
Success! Your transformed file is located at D:/Transformed_OpenApi3Json.json
|
|
77
|
+
`,
|
|
78
|
+
`$ apimatic api:transform --format=RAML --url="https://petstore.swagger.io/v2/swagger.json" --destination="D:/"
|
|
79
|
+
Success! Your transformed file is located at D:/swagger_raml.yaml
|
|
143
80
|
`
|
|
144
81
|
];
|
|
145
82
|
Transform.flags = {
|
|
146
83
|
format: command_1.flags.string({
|
|
147
|
-
parse: (format) => getValidFormat(format.toUpperCase()),
|
|
84
|
+
parse: (format) => transform_2.getValidFormat(format.toUpperCase()),
|
|
148
85
|
required: true,
|
|
149
86
|
description: `specification format to transform API specification into
|
|
150
|
-
|
|
151
|
-
|
|
87
|
+
${formats}`
|
|
88
|
+
}),
|
|
89
|
+
file: command_1.flags.string({
|
|
90
|
+
parse: (input) => path.resolve(input),
|
|
91
|
+
default: "",
|
|
92
|
+
description: "path to the API specification file to transform"
|
|
93
|
+
}),
|
|
94
|
+
url: command_1.flags.string({
|
|
95
|
+
default: "",
|
|
96
|
+
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."
|
|
97
|
+
}),
|
|
98
|
+
destination: command_1.flags.string({
|
|
99
|
+
parse: (input) => path.resolve(input),
|
|
100
|
+
default: path.resolve("./"),
|
|
101
|
+
description: "directory to download transformed file to"
|
|
152
102
|
}),
|
|
153
|
-
|
|
154
|
-
|
|
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" })
|
|
103
|
+
force: command_1.flags.boolean({ char: "f", default: false, description: "overwrite if same file exist in the destination" }),
|
|
104
|
+
"auth-key": command_1.flags.string({ description: "override current authentication state with an authentication key" })
|
|
157
105
|
};
|
|
@@ -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
|
|
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
|
-
|
|
10
|
-
|
|
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
|
|
47
|
-
const validationSummary = await getValidation(flags, apiValidationController);
|
|
48
|
-
|
|
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 = "
|
|
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: "
|
|
82
|
-
url: command_1.flags.string({
|
|
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
|
|
63
|
+
"auth-key": command_1.flags.string({ description: "override current authentication state with an authentication key" })
|
|
85
64
|
};
|
|
@@ -44,14 +44,16 @@ class Login extends command_1.Command {
|
|
|
44
44
|
}
|
|
45
45
|
}
|
|
46
46
|
exports.default = Login;
|
|
47
|
-
Login.description = "
|
|
47
|
+
Login.description = "Login using your APIMatic credentials or an API Key";
|
|
48
48
|
Login.examples = [
|
|
49
49
|
`$ apimatic auth:login
|
|
50
50
|
Please enter your registered email: apimatic-user@gmail.com
|
|
51
51
|
Please enter your password: *********
|
|
52
52
|
|
|
53
53
|
You have successfully logged into APIMatic
|
|
54
|
-
|
|
54
|
+
`,
|
|
55
|
+
`$ apimatic auth:login --auth-key=xxxxxx
|
|
56
|
+
Authentication key successfully set`
|
|
55
57
|
];
|
|
56
58
|
Login.flags = {
|
|
57
59
|
"auth-key": command_1.flags.string({ default: "", description: "Set authentication key for all commands" })
|
|
@@ -15,7 +15,7 @@ class Status extends command_1.Command {
|
|
|
15
15
|
}
|
|
16
16
|
}
|
|
17
17
|
exports.default = Status;
|
|
18
|
-
Status.description = "
|
|
18
|
+
Status.description = "View current authentication state";
|
|
19
19
|
Status.examples = [
|
|
20
20
|
`$ apimatic auth:status
|
|
21
21
|
Currently logged in as apimatic-client@gmail.com
|