@sw-tsdk/plugin-connector 2.10.0 → 2.11.2-alpha.39
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 +25 -25
- package/lib/commands/action/add.d.ts +2 -2
- package/lib/commands/action/add.js +14 -8
- package/lib/commands/action/add.js.map +1 -1
- package/lib/commands/action/generate/data.d.ts +4 -4
- package/lib/commands/action/generate/data.js +23 -13
- package/lib/commands/action/generate/data.js.map +1 -1
- package/lib/commands/action/generate/input.d.ts +4 -4
- package/lib/commands/action/generate/input.js +19 -11
- package/lib/commands/action/generate/input.js.map +1 -1
- package/lib/commands/action/generate/output.d.ts +4 -4
- package/lib/commands/action/generate/output.js +19 -11
- package/lib/commands/action/generate/output.js.map +1 -1
- package/lib/commands/action/run/image.d.ts +9 -9
- package/lib/commands/action/run/image.js +39 -27
- package/lib/commands/action/run/image.js.map +1 -1
- package/lib/commands/action/run/local.d.ts +11 -11
- package/lib/commands/action/run/local.js +51 -35
- package/lib/commands/action/run/local.js.map +1 -1
- package/lib/commands/asset/add.d.ts +2 -2
- package/lib/commands/asset/add.js +12 -7
- package/lib/commands/asset/add.js.map +1 -1
- package/lib/commands/connector/build.d.ts +10 -10
- package/lib/commands/connector/build.js +37 -20
- package/lib/commands/connector/build.js.map +1 -1
- package/lib/commands/connector/create/openapi.d.ts +12 -11
- package/lib/commands/connector/create/openapi.js +117 -60
- package/lib/commands/connector/create/openapi.js.map +1 -1
- package/lib/commands/connector/create/source.d.ts +2 -2
- package/lib/commands/connector/create/source.js +12 -6
- package/lib/commands/connector/create/source.js.map +1 -1
- package/lib/commands/connector/create.d.ts +10 -10
- package/lib/commands/connector/create.js +24 -11
- package/lib/commands/connector/create.js.map +1 -1
- package/lib/commands/connector/logo.d.ts +2 -2
- package/lib/commands/connector/logo.js +10 -5
- package/lib/commands/connector/logo.js.map +1 -1
- package/lib/commands/connector/sign.d.ts +6 -6
- package/lib/commands/connector/sign.js +24 -13
- package/lib/commands/connector/sign.js.map +1 -1
- package/lib/commands/connector/update.d.ts +3 -3
- package/lib/commands/connector/update.js +14 -8
- package/lib/commands/connector/update.js.map +1 -1
- package/lib/commands/connector/validate.d.ts +4 -4
- package/lib/commands/connector/validate.js +22 -14
- package/lib/commands/connector/validate.js.map +1 -1
- package/lib/common.js +4 -0
- package/lib/common.js.map +1 -1
- package/lib/templates/assets/http_bearer.yaml +1 -2
- package/lib/types/connector-types.d.ts +2 -2
- package/oclif.manifest.json +1007 -1
- package/package.json +13 -13
|
@@ -34,13 +34,13 @@ class Build extends core_2.Base {
|
|
|
34
34
|
try {
|
|
35
35
|
await node_fs_1.promises.access(directory);
|
|
36
36
|
}
|
|
37
|
-
catch
|
|
37
|
+
catch {
|
|
38
38
|
this.error(`Could not access ${directory}`);
|
|
39
39
|
}
|
|
40
40
|
const docker = new docker_1.Docker();
|
|
41
|
-
core_1.
|
|
41
|
+
core_1.ux.action.start('Checking for docker...');
|
|
42
42
|
await docker.ping();
|
|
43
|
-
core_1.
|
|
43
|
+
core_1.ux.action.stop();
|
|
44
44
|
const dockerFileDir = `${directory}/Dockerfile`;
|
|
45
45
|
if ((0, node_fs_1.existsSync)(dockerFileDir)) {
|
|
46
46
|
await node_fs_1.promises.rm(dockerFileDir);
|
|
@@ -86,48 +86,65 @@ class Build extends core_2.Base {
|
|
|
86
86
|
}
|
|
87
87
|
exports.Build = Build;
|
|
88
88
|
Build.description = 'Builds a local docker image of the connector.';
|
|
89
|
-
Build.flags =
|
|
89
|
+
Build.flags = {
|
|
90
|
+
...core_2.Base.flags,
|
|
91
|
+
template: core_1.Flags.string({
|
|
90
92
|
description: 'connector language',
|
|
91
|
-
options: ['python_37_swimlane', 'node_18', 'python_39_definition', 'python_310_definition', 'python_311_definition'],
|
|
93
|
+
options: ['python_37_swimlane', 'node_18', 'node_20', 'python_39_definition', 'python_310_definition', 'python_311_definition'],
|
|
92
94
|
required: false,
|
|
93
|
-
}),
|
|
95
|
+
}),
|
|
96
|
+
'compile-override': core_1.Flags.string({
|
|
94
97
|
hidden: true,
|
|
95
98
|
default: 'Compile.Dockerfile',
|
|
96
|
-
}),
|
|
99
|
+
}),
|
|
100
|
+
'runner-override': core_1.Flags.string({
|
|
97
101
|
hidden: true,
|
|
98
102
|
default: 'Runner.Dockerfile',
|
|
99
|
-
}),
|
|
103
|
+
}),
|
|
104
|
+
'runtime-override': core_1.Flags.string({
|
|
100
105
|
hidden: true,
|
|
101
|
-
}),
|
|
106
|
+
}),
|
|
107
|
+
directory: core_1.Flags.string({
|
|
102
108
|
char: 'd',
|
|
103
109
|
description: 'root directory of the repository.',
|
|
104
110
|
default: './',
|
|
105
|
-
}),
|
|
111
|
+
}),
|
|
112
|
+
save: core_1.Flags.boolean({
|
|
106
113
|
description: 'saves a signed docker image as tar in local directory.',
|
|
107
|
-
}),
|
|
114
|
+
}),
|
|
115
|
+
squash: core_1.Flags.boolean({
|
|
108
116
|
description: 'squashes the docker layers.',
|
|
109
117
|
hidden: true,
|
|
110
|
-
}),
|
|
118
|
+
}),
|
|
119
|
+
'force-rebuild': core_1.Flags.boolean({
|
|
111
120
|
char: 'f',
|
|
112
121
|
description: 'forces nocache on the image build',
|
|
113
|
-
}),
|
|
122
|
+
}),
|
|
123
|
+
platform: core_1.Flags.string({
|
|
114
124
|
hidden: true,
|
|
115
125
|
default: 'linux/amd64',
|
|
116
|
-
}),
|
|
126
|
+
}),
|
|
127
|
+
'signing-password': core_1.Flags.string({
|
|
117
128
|
description: 'password used for the private key (ENV: TURBINE_SIGNING_PASSWORD)',
|
|
118
129
|
default: '',
|
|
119
130
|
env: 'TURBINE_SIGNING_PASSWORD',
|
|
120
|
-
}),
|
|
131
|
+
}),
|
|
132
|
+
'key-name': core_1.Flags.string({
|
|
121
133
|
description: 'name used for the key (default: username_yyyy-MM-dd)',
|
|
122
|
-
}),
|
|
134
|
+
}),
|
|
135
|
+
'skip-upload': core_1.Flags.boolean({
|
|
123
136
|
hidden: true,
|
|
124
|
-
}),
|
|
137
|
+
}),
|
|
138
|
+
registry: core_1.Flags.string({
|
|
125
139
|
description: 'registry to use for signing',
|
|
126
140
|
default: 'localhost:5000',
|
|
127
|
-
}),
|
|
141
|
+
}),
|
|
142
|
+
output: core_1.Flags.string({
|
|
128
143
|
char: 'o',
|
|
129
144
|
description: 'output path to where to store the image.',
|
|
130
|
-
}),
|
|
145
|
+
}),
|
|
146
|
+
help: core_1.Flags.help({
|
|
131
147
|
char: 'h',
|
|
132
|
-
})
|
|
148
|
+
}),
|
|
149
|
+
};
|
|
133
150
|
//# sourceMappingURL=build.js.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/commands/connector/build.ts"],"names":[],"mappings":";;;;AAAA,
|
|
1
|
+
{"version":3,"file":"build.js","sourceRoot":"","sources":["../../../src/commands/connector/build.ts"],"names":[],"mappings":";;;;AAAA,sCAAqC;AACrC,wCAAkC;AAClC,yCAAuC;AACvC,qCAAyD;AACzD,kDAAiD;AACjD,iCAA2B;AAC3B,4CAAsC;AACtC,6DAAyC;AACzC,uCAAkC;AAClC,+CAAwC;AACxC,wGAA6D;AAE7D,qCAAqC;AACrC,MAAa,KAAM,SAAQ,WAAI;IAiE7B,KAAK,CAAC,GAAG;QACP,MAAM,EAAC,KAAK,EAAC,GAAG,MAAM,IAAI,CAAC,KAAK,CAAC,KAAK,CAAC,CAAA;QAEvC,IAAI,EAAC,SAAS,EAAC,GAAG,KAAK,CAAA;QACvB,MAAM,EACJ,IAAI,EACJ,QAAQ,EACR,kBAAkB,EAAE,eAAe,EACnC,iBAAiB,EAAE,cAAc,EACjC,kBAAkB,EAAE,eAAe,EACnC,eAAe,EAAE,OAAO,EACxB,QAAQ,EACR,MAAM,EACN,QAAQ,EACR,MAAM,GAEP,GAAG,KAAK,CAAA;QAET,IAAI,EACF,kBAAkB,EAAE,eAAe,EACnC,UAAU,EAAE,OAAO,GACpB,GAAG,KAAK,CAAA;QAET,SAAS,GA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wD;KACtE,CAAC;IACF,MAAM,EAAE,YAAK,CAAC,OAAO,CAAC;QACpB,WAAW,EAAE,6BAA6B;QAC1C,MAAM,EAAE,IAAI;KACb,CAAC;IACF,eAAe,EAAE,YAAK,CAAC,OAAO,CAAC;QAC7B,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,mCAAmC;KACjD,CAAC;IACF,QAAQ,EAAE,YAAK,CAAC,MAAM,CAAC;QACrB,MAAM,EAAE,IAAI;QACZ,OAAO,EAAE,aAAa;KACvB,CAAC;IACF,kBAAkB,EAAE,YAAK,CAAC,MAAM,CAAC;QAC/B,WAAW,EAAE,mEAAmE;QAChF,OAAO,EAAE,EAAE;QACX,GAAG,EAAE,0BAA0B;KAChC,CAAC;IACF,UAAU,EAAE,YAAK,CAAC,MAAM,CAAC;QACvB,WAAW,EAAE,sDAAsD;KACpE,CAAC;IACF,aAAa,EAAE,YAAK,CAAC,OAAO,CAAC;QAC3B,MAAM,EAAE,IAAI;KACb,CAAC;IACF,QAAQ,EAAE,YAAK,CAAC,MAAM,CAAC;QACrB,WAAW,EAAE,6BAA6B;QAC1C,OAAO,EAAE,gBAAgB;KAC1B,CAAC;IACF,MAAM,EAAE,YAAK,CAAC,MAAM,CAAC;QACnB,IAAI,EAAE,GAAG;QACT,WAAW,EAAE,0CAA0C;KACxD,CAAC;IACF,IAAI,EAAE,YAAK,CAAC,IAAI,CAAC;QACf,IAAI,EAAE,GAAG;KACV,CAAC;CACH,CAAA"}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { Base } from '@sw-tsdk/core';
|
|
2
|
-
import { Action,
|
|
2
|
+
import { Action, InnerProperty, Input, Output, Property } from '@sw-tsdk/connector';
|
|
3
3
|
export declare class OpenAPI extends Base {
|
|
4
4
|
static description: string;
|
|
5
5
|
defaultTemplate: string;
|
|
@@ -8,16 +8,16 @@ export declare class OpenAPI extends Base {
|
|
|
8
8
|
currentContext: any;
|
|
9
9
|
referenceMapped: string[];
|
|
10
10
|
static flags: {
|
|
11
|
-
directory: import("@oclif/core/lib/interfaces").OptionFlag<string>;
|
|
12
|
-
vendor: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
13
|
-
product: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
14
|
-
keywords: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
15
|
-
description: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
16
|
-
logoPath: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
17
|
-
author: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
18
|
-
authorEmail: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
19
|
-
homepage: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
20
|
-
specs: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined>;
|
|
11
|
+
directory: import("@oclif/core/lib/interfaces").OptionFlag<string, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
12
|
+
vendor: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
13
|
+
product: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
14
|
+
keywords: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
15
|
+
description: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
16
|
+
logoPath: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
17
|
+
author: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
18
|
+
authorEmail: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
19
|
+
homepage: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
20
|
+
specs: import("@oclif/core/lib/interfaces").OptionFlag<string | undefined, import("@oclif/core/lib/interfaces/parser").CustomOptions>;
|
|
21
21
|
help: import("@oclif/core/lib/interfaces").BooleanFlag<void>;
|
|
22
22
|
};
|
|
23
23
|
run(): Promise<void>;
|
|
@@ -43,4 +43,5 @@ export declare class OpenAPI extends Base {
|
|
|
43
43
|
generateJsonSchema(data: any, io: Output | Input): Promise<Output | Input>;
|
|
44
44
|
generateAttachmentSchema(data: any, io: Input | Output): Promise<Input | Output>;
|
|
45
45
|
getDataBody(data: any): Promise<any>;
|
|
46
|
+
private buildRequired;
|
|
46
47
|
}
|
|
@@ -4,7 +4,7 @@ exports.OpenAPI = void 0;
|
|
|
4
4
|
const tslib_1 = require("tslib");
|
|
5
5
|
/* eslint-disable camelcase */
|
|
6
6
|
const core_1 = require("@oclif/core");
|
|
7
|
-
const node_path_1 =
|
|
7
|
+
const node_path_1 = require("node:path");
|
|
8
8
|
const core_2 = require("@sw-tsdk/core");
|
|
9
9
|
const fs_extra_1 = require("fs-extra");
|
|
10
10
|
const inquirer_1 = tslib_1.__importDefault(require("inquirer"));
|
|
@@ -14,6 +14,7 @@ const fs = tslib_1.__importStar(require("node:fs"));
|
|
|
14
14
|
const common_1 = require("../../../common");
|
|
15
15
|
const connector_1 = require("@sw-tsdk/connector");
|
|
16
16
|
const json_schema_ref_parser_1 = tslib_1.__importDefault(require("@apidevtools/json-schema-ref-parser"));
|
|
17
|
+
const snake_case_1 = require("snake-case");
|
|
17
18
|
class OpenAPI extends core_2.Base {
|
|
18
19
|
constructor() {
|
|
19
20
|
super(...arguments);
|
|
@@ -21,16 +22,14 @@ class OpenAPI extends core_2.Base {
|
|
|
21
22
|
this.codeRegex = /^2\d{2}$/;
|
|
22
23
|
}
|
|
23
24
|
async run() {
|
|
24
|
-
var _a;
|
|
25
25
|
const { flags } = await this.parse(OpenAPI);
|
|
26
26
|
const { directory, specs } = flags;
|
|
27
27
|
if (!specs) {
|
|
28
|
-
|
|
28
|
+
throw new Error('OpenAPI Specs are required');
|
|
29
29
|
}
|
|
30
30
|
if (!(await (0, core_2.fileExists)(specs))) {
|
|
31
|
-
core_1.
|
|
31
|
+
core_1.ux.error('OpenAPI Specs does not exist');
|
|
32
32
|
}
|
|
33
|
-
const name = node_path_1.default.basename(specs).replace(/\.[^./]+$/, '');
|
|
34
33
|
const masterQuestions = [
|
|
35
34
|
{
|
|
36
35
|
type: 'input',
|
|
@@ -79,7 +78,17 @@ class OpenAPI extends core_2.Base {
|
|
|
79
78
|
];
|
|
80
79
|
const filteredQuestions = masterQuestions.filter(q => !flags[q.name]);
|
|
81
80
|
const answers = Object.assign(await inquirer_1.default.prompt(filteredQuestions), flags);
|
|
82
|
-
const
|
|
81
|
+
const vendor = answers.vendor;
|
|
82
|
+
const product = answers.product;
|
|
83
|
+
let name;
|
|
84
|
+
if (vendor.toLowerCase() === product.toLowerCase() || !product) {
|
|
85
|
+
name = answers.vendor.toLowerCase();
|
|
86
|
+
}
|
|
87
|
+
else {
|
|
88
|
+
const string = `${answers.vendor} ${answers.product}`;
|
|
89
|
+
name = (0, snake_case_1.snakeCase)(string.toLocaleLowerCase());
|
|
90
|
+
}
|
|
91
|
+
const connectorDirectory = (0, node_path_1.basename)(directory) === `t_${name}` ? directory : (0, node_path_1.join)(directory, `t_${name}`);
|
|
83
92
|
await (0, fs_extra_1.ensureDir)(connectorDirectory);
|
|
84
93
|
const connector = {
|
|
85
94
|
vendor: answers.vendor,
|
|
@@ -112,7 +121,7 @@ class OpenAPI extends core_2.Base {
|
|
|
112
121
|
},
|
|
113
122
|
},
|
|
114
123
|
};
|
|
115
|
-
core_1.
|
|
124
|
+
core_1.ux.action.start('Generating data.');
|
|
116
125
|
const connectorFolder = (0, node_path_1.join)(connectorDirectory, 'connector');
|
|
117
126
|
await (0, fs_extra_1.ensureDir)(connectorFolder);
|
|
118
127
|
const configFolder = (0, node_path_1.join)(connectorFolder, 'config');
|
|
@@ -123,18 +132,21 @@ class OpenAPI extends core_2.Base {
|
|
|
123
132
|
await (0, fs_extra_1.ensureDir)(actionsFolder);
|
|
124
133
|
const codeFolder = (0, node_path_1.join)(connectorFolder, 'code');
|
|
125
134
|
await (0, fs_extra_1.ensureDir)(codeFolder);
|
|
126
|
-
let spec = js_yaml_1.default.load(await fs.promises.readFile(specs, '
|
|
135
|
+
let spec = js_yaml_1.default.load(await fs.promises.readFile(specs, 'utf8'));
|
|
127
136
|
if (JSON.stringify(spec).includes('$ref')) {
|
|
128
137
|
spec = await json_schema_ref_parser_1.default.dereference(spec);
|
|
129
138
|
}
|
|
130
139
|
this.specData = spec;
|
|
131
|
-
if (
|
|
140
|
+
if (spec?.components?.securitySchemes && Object.keys(spec.components.securitySchemes).length > 0) {
|
|
132
141
|
await this.createAssets(spec.components.securitySchemes, assetsFolder);
|
|
133
142
|
}
|
|
134
143
|
let basePath = '/';
|
|
135
|
-
if (
|
|
136
|
-
const
|
|
137
|
-
basePath
|
|
144
|
+
if (spec?.servers && spec?.servers.length > 0) {
|
|
145
|
+
const serverUrl = spec.servers[0].url;
|
|
146
|
+
if (serverUrl !== basePath) {
|
|
147
|
+
const url = new URL(serverUrl);
|
|
148
|
+
basePath = url.pathname;
|
|
149
|
+
}
|
|
138
150
|
}
|
|
139
151
|
await this.createActionsFromPaths(spec.paths, actionsFolder, basePath);
|
|
140
152
|
// write connector.yaml from answers
|
|
@@ -145,7 +157,8 @@ class OpenAPI extends core_2.Base {
|
|
|
145
157
|
}
|
|
146
158
|
async createActionsFromPaths(paths, actionFolder, basePath, index = 0) {
|
|
147
159
|
const pathsKeys = Object.keys(paths);
|
|
148
|
-
const action =
|
|
160
|
+
// const action = paths[pathsKeys[index]]
|
|
161
|
+
const action = (0, connector_1.removeCirculars)(paths[pathsKeys[index]]);
|
|
149
162
|
await this.buildActions(action, actionFolder, pathsKeys[index], basePath);
|
|
150
163
|
if (index < pathsKeys.length - 1) {
|
|
151
164
|
return this.createActionsFromPaths(paths, actionFolder, basePath, index + 1);
|
|
@@ -165,11 +178,22 @@ class OpenAPI extends core_2.Base {
|
|
|
165
178
|
}
|
|
166
179
|
}
|
|
167
180
|
async createActionData(action, endpoint, method) {
|
|
168
|
-
const actionWords = action.operationId
|
|
169
|
-
|
|
181
|
+
const actionWords = action.operationId?.split(/(?=[A-Z])/) ??
|
|
182
|
+
endpoint.split('/')
|
|
183
|
+
.map(x => x.replace(/{([^}]*)}/, 'by_$1'))
|
|
184
|
+
.filter(Boolean);
|
|
185
|
+
let name = actionWords
|
|
170
186
|
.map((item) => item.toLowerCase())
|
|
171
187
|
.join('_');
|
|
172
|
-
|
|
188
|
+
if (name.length > 50) {
|
|
189
|
+
core_1.ux.warn(`Truncated name: ${name}`);
|
|
190
|
+
name = name.slice(0, 50);
|
|
191
|
+
}
|
|
192
|
+
let title = actionWords.join(' ');
|
|
193
|
+
if (title.length > 50) {
|
|
194
|
+
core_1.ux.warn(`Truncated name: ${name}`);
|
|
195
|
+
title = title.slice(0, 50);
|
|
196
|
+
}
|
|
173
197
|
const builtAction = {
|
|
174
198
|
schema: 'action/1',
|
|
175
199
|
title,
|
|
@@ -185,7 +209,6 @@ class OpenAPI extends core_2.Base {
|
|
|
185
209
|
return builtAction;
|
|
186
210
|
}
|
|
187
211
|
async createInputs(action) {
|
|
188
|
-
var _a;
|
|
189
212
|
let input = {
|
|
190
213
|
type: 'object',
|
|
191
214
|
properties: {},
|
|
@@ -196,31 +219,34 @@ class OpenAPI extends core_2.Base {
|
|
|
196
219
|
title: 'Headers',
|
|
197
220
|
type: 'object',
|
|
198
221
|
properties: await this.buildInnerObject(headers, {}),
|
|
199
|
-
required: headers
|
|
222
|
+
required: headers?.required,
|
|
200
223
|
} : null;
|
|
224
|
+
this.buildRequired(input.properties.headers);
|
|
201
225
|
const parameters = await this.getInnerData(action.parameters, 'query', 'in');
|
|
202
226
|
parameters ? (input.properties.parameters = {
|
|
203
227
|
title: 'Parameters',
|
|
204
228
|
type: 'object',
|
|
205
229
|
properties: await this.buildInnerObject(parameters, {}),
|
|
206
|
-
required: parameters
|
|
230
|
+
required: parameters?.required,
|
|
207
231
|
}) : null;
|
|
232
|
+
this.buildRequired(input.properties.parameters);
|
|
208
233
|
const pathParameters = await this.getInnerData(action.parameters, 'path', 'in');
|
|
209
234
|
pathParameters ? (input.properties.path_parameters = {
|
|
210
235
|
title: 'Path Parameters',
|
|
211
236
|
type: 'object',
|
|
212
237
|
properties: await this.buildInnerObject(pathParameters, {}),
|
|
213
|
-
required: pathParameters
|
|
238
|
+
required: pathParameters?.required,
|
|
214
239
|
}) : null;
|
|
215
240
|
}
|
|
216
|
-
|
|
241
|
+
this.buildRequired(input.properties.path_parameters);
|
|
242
|
+
if (action?.requestBody?.content) {
|
|
217
243
|
const dataBody = await this.getDataBody(action.requestBody.content);
|
|
218
244
|
dataBody ?
|
|
219
245
|
(input.properties.data_body = {
|
|
220
246
|
title: 'Data Body',
|
|
221
247
|
type: 'object',
|
|
222
248
|
properties: await this.buildInnerObject(dataBody, {}),
|
|
223
|
-
required: dataBody
|
|
249
|
+
required: dataBody?.required,
|
|
224
250
|
}) : null;
|
|
225
251
|
input = await this.generateAttachmentSchema(action.requestBody.content, input);
|
|
226
252
|
input = await this.generateJsonSchema(action.requestBody.content, input);
|
|
@@ -228,7 +254,6 @@ class OpenAPI extends core_2.Base {
|
|
|
228
254
|
return input;
|
|
229
255
|
}
|
|
230
256
|
async createOutput(action) {
|
|
231
|
-
var _a;
|
|
232
257
|
const { data, code } = this.getStatusCodeObject(action.responses);
|
|
233
258
|
let output = {
|
|
234
259
|
type: 'object',
|
|
@@ -249,16 +274,16 @@ class OpenAPI extends core_2.Base {
|
|
|
249
274
|
title: 'Response headers',
|
|
250
275
|
type: 'object',
|
|
251
276
|
properties: await this.buildInnerObject(this.formatData(data.headers), {}),
|
|
252
|
-
required:
|
|
277
|
+
required: data.headers?.required,
|
|
253
278
|
examples: data.headers.examples,
|
|
254
279
|
} : null;
|
|
255
|
-
if (data
|
|
280
|
+
if (data?.content) {
|
|
256
281
|
const dataBody = await this.getDataBody(data.content);
|
|
257
282
|
dataBody ? (output.properties.data = {
|
|
258
283
|
title: 'Data Body',
|
|
259
284
|
type: 'object',
|
|
260
285
|
properties: await this.buildInnerObject(dataBody, {}),
|
|
261
|
-
required: dataBody
|
|
286
|
+
required: dataBody?.required,
|
|
262
287
|
}) : null;
|
|
263
288
|
const text = await this.getInnerData(data.content, 'text/plain', 'content');
|
|
264
289
|
text ? (output.properties.response_text = {
|
|
@@ -289,7 +314,7 @@ class OpenAPI extends core_2.Base {
|
|
|
289
314
|
return this.filterByList(allowed, object);
|
|
290
315
|
}
|
|
291
316
|
if (type === 'in') {
|
|
292
|
-
const allowed = Object.keys(object).filter(key =>
|
|
317
|
+
const allowed = Object.keys(object).filter(key => object[key]?.in === path);
|
|
293
318
|
return this.filterByList(allowed, object);
|
|
294
319
|
}
|
|
295
320
|
return null;
|
|
@@ -302,7 +327,7 @@ class OpenAPI extends core_2.Base {
|
|
|
302
327
|
return list;
|
|
303
328
|
}
|
|
304
329
|
filterByList(list, object) {
|
|
305
|
-
if (
|
|
330
|
+
if (list?.length > 0) {
|
|
306
331
|
return list.map((key) => {
|
|
307
332
|
return object[key];
|
|
308
333
|
});
|
|
@@ -310,28 +335,29 @@ class OpenAPI extends core_2.Base {
|
|
|
310
335
|
return null;
|
|
311
336
|
}
|
|
312
337
|
async buildObject(object, key) {
|
|
313
|
-
var _a, _b, _c, _d, _e, _f, _g, _h;
|
|
314
338
|
const currentObject = {
|
|
315
|
-
title:
|
|
316
|
-
type:
|
|
339
|
+
title: object?.name || key,
|
|
340
|
+
type: object?.schema?.type || object?.type,
|
|
317
341
|
};
|
|
318
|
-
|
|
319
|
-
if ((
|
|
342
|
+
object?.required ? currentObject.required = object?.required : null;
|
|
343
|
+
if ((object?.schema?.type === 'object' || object?.type === 'object') && object?.properties) {
|
|
320
344
|
currentObject.properties = await this.buildInnerObject(object, {});
|
|
321
345
|
}
|
|
322
|
-
if (
|
|
323
|
-
|
|
324
|
-
|
|
346
|
+
if (object?.schema?.type === 'array' || object?.type === 'array') {
|
|
347
|
+
const innerItem = object?.schema?.items || object?.items;
|
|
348
|
+
currentObject.items = await this.buildItems(innerItem);
|
|
349
|
+
const required = object?.schema?.items?.required || object?.items?.required;
|
|
325
350
|
required ? currentObject.items.required = required : null;
|
|
326
351
|
}
|
|
327
352
|
return currentObject;
|
|
328
353
|
}
|
|
329
354
|
async buildItems(items) {
|
|
330
|
-
if (
|
|
331
|
-
|
|
355
|
+
if (items?.type === 'object' && items?.properties) {
|
|
356
|
+
const innerItems = await this.buildInnerObject(items, {});
|
|
357
|
+
return { type: 'object', properties: innerItems };
|
|
332
358
|
}
|
|
333
359
|
return {
|
|
334
|
-
type: items
|
|
360
|
+
type: items?.type,
|
|
335
361
|
};
|
|
336
362
|
}
|
|
337
363
|
getStatusCodeObject(response) {
|
|
@@ -349,17 +375,16 @@ class OpenAPI extends core_2.Base {
|
|
|
349
375
|
return currentContext;
|
|
350
376
|
}
|
|
351
377
|
async buildInnerObject(object, currentObject, index = 0) {
|
|
352
|
-
|
|
353
|
-
const properties = Object.keys((object === null || object === void 0 ? void 0 : object.properties) || object);
|
|
378
|
+
const properties = Object.keys(object?.properties || object);
|
|
354
379
|
const currentProperty = properties[index];
|
|
355
|
-
currentObject[
|
|
380
|
+
currentObject[object?.properties ? currentProperty : object[currentProperty].name] = await this.buildObject(object?.properties?.[currentProperty] || object[currentProperty], currentProperty);
|
|
356
381
|
if (index < properties.length - 1) {
|
|
357
382
|
return this.buildInnerObject(object, currentObject, index + 1);
|
|
358
383
|
}
|
|
359
384
|
return currentObject;
|
|
360
385
|
}
|
|
361
386
|
existReferences(object, found = [], index = 0) {
|
|
362
|
-
const keys =
|
|
387
|
+
const keys = object?.items ? Object.keys(object.items) : Object.keys(object);
|
|
363
388
|
if (keys.length === 0) {
|
|
364
389
|
return found;
|
|
365
390
|
}
|
|
@@ -370,7 +395,7 @@ class OpenAPI extends core_2.Base {
|
|
|
370
395
|
!found.includes(currentObject)) {
|
|
371
396
|
found.push(currentObject);
|
|
372
397
|
}
|
|
373
|
-
if (
|
|
398
|
+
if (currentObject?.type === 'object' || currentObject?.type === 'array') {
|
|
374
399
|
found = this.existReferences(currentObject.properties || currentObject.items || currentObject.additionalProperties, found);
|
|
375
400
|
}
|
|
376
401
|
if (!currentObject.type && currentObject.$ref) {
|
|
@@ -387,38 +412,40 @@ class OpenAPI extends core_2.Base {
|
|
|
387
412
|
const currentScheme = securitySchemes[currentKey];
|
|
388
413
|
const schemaType = securitySchemes[currentKey].type;
|
|
389
414
|
switch (schemaType) {
|
|
390
|
-
case 'http':
|
|
415
|
+
case 'http': {
|
|
391
416
|
currentKey = securitySchemes[currentKey].scheme === 'basic' ?
|
|
392
417
|
connector_1.SecuritySchemeEnum.basicAuth : connector_1.SecuritySchemeEnum.bearerAuth;
|
|
393
418
|
break;
|
|
394
|
-
|
|
419
|
+
}
|
|
420
|
+
case 'oauth2': {
|
|
395
421
|
currentKey = currentScheme.flows.clientCredentials ?
|
|
396
422
|
connector_1.SecuritySchemeEnum.oAuth2ClientCredentials :
|
|
397
423
|
connector_1.SecuritySchemeEnum.oAuth2Password;
|
|
398
424
|
break;
|
|
399
|
-
|
|
425
|
+
}
|
|
426
|
+
case 'apiKey': {
|
|
400
427
|
currentKey = connector_1.SecuritySchemeEnum.ApiKeyAuth;
|
|
401
428
|
break;
|
|
429
|
+
}
|
|
402
430
|
}
|
|
403
|
-
await (0, fs_extra_1.copy)((0, node_path_1.join)(__dirname, '..', '..', '..', 'templates', 'assets', `${currentKey}.yaml`), (0, node_path_1.join)(assetFolder, `${currentKey}.yaml`)
|
|
431
|
+
await (0, fs_extra_1.copy)((0, node_path_1.join)(__dirname, '..', '..', '..', 'templates', 'assets', `${currentKey}.yaml`), (0, node_path_1.join)(assetFolder, `${currentKey}.yaml`));
|
|
404
432
|
if (keys.length - 1 > index) {
|
|
405
433
|
return this.createAssets(securitySchemes, assetFolder, index + 1);
|
|
406
434
|
}
|
|
407
435
|
}
|
|
408
436
|
async generateJsonSchema(data, io) {
|
|
409
|
-
|
|
410
|
-
let jsonData = await this.getInnerData((data === null || data === void 0 ? void 0 : data.content) || data, 'application/json', 'content');
|
|
437
|
+
let jsonData = await this.getInnerData(data?.content || data, 'application/json', 'content');
|
|
411
438
|
if (!jsonData) {
|
|
412
|
-
jsonData = await this.getInnerData(
|
|
439
|
+
jsonData = await this.getInnerData(data?.content || data, '*/*', 'content');
|
|
413
440
|
}
|
|
414
441
|
jsonData ? io.properties.json_body = {
|
|
415
442
|
title: 'Json Body',
|
|
416
|
-
type: jsonData
|
|
417
|
-
required: jsonData
|
|
443
|
+
type: jsonData?.type,
|
|
444
|
+
required: jsonData?.required,
|
|
418
445
|
} : null;
|
|
419
446
|
if (jsonData && !jsonData.$ref) {
|
|
420
|
-
|
|
421
|
-
(
|
|
447
|
+
io?.properties?.json_body ?
|
|
448
|
+
(jsonData?.type === 'object' ?
|
|
422
449
|
io.properties.json_body.properties = await this.buildInnerObject(jsonData, {}) :
|
|
423
450
|
io.properties.json_body.items = await this.buildItems(jsonData.items)) : null;
|
|
424
451
|
}
|
|
@@ -435,7 +462,7 @@ class OpenAPI extends core_2.Base {
|
|
|
435
462
|
additionalProperties: false,
|
|
436
463
|
properties: await this.buildInnerObject(attachments, {}),
|
|
437
464
|
},
|
|
438
|
-
required: attachments
|
|
465
|
+
required: attachments?.required,
|
|
439
466
|
} : null;
|
|
440
467
|
return io;
|
|
441
468
|
}
|
|
@@ -443,15 +470,45 @@ class OpenAPI extends core_2.Base {
|
|
|
443
470
|
const exclude = ['application/json', 'multipart/form-data'];
|
|
444
471
|
return this.getInnerData(data, exclude, 'content');
|
|
445
472
|
}
|
|
473
|
+
buildRequired(item, subitem) {
|
|
474
|
+
if (!item) {
|
|
475
|
+
return;
|
|
476
|
+
}
|
|
477
|
+
for (const [key, value] of Object.entries(item)) {
|
|
478
|
+
if (value?.required === true && subitem) {
|
|
479
|
+
if (!Array.isArray(subitem.required)) {
|
|
480
|
+
subitem.required = [];
|
|
481
|
+
}
|
|
482
|
+
subitem.required.push(key);
|
|
483
|
+
delete value.required;
|
|
484
|
+
}
|
|
485
|
+
}
|
|
486
|
+
if (item.properties) {
|
|
487
|
+
this.buildRequired(item.properties, item);
|
|
488
|
+
}
|
|
489
|
+
}
|
|
446
490
|
}
|
|
447
491
|
exports.OpenAPI = OpenAPI;
|
|
448
492
|
OpenAPI.description = 'Scaffold a new connector';
|
|
449
|
-
OpenAPI.flags =
|
|
493
|
+
OpenAPI.flags = {
|
|
494
|
+
...core_2.Base.flags,
|
|
495
|
+
directory: core_1.Flags.string({
|
|
450
496
|
char: 'd',
|
|
451
497
|
description: 'root directory for where to store connectors, the connector directory will be generated.',
|
|
452
498
|
default: './',
|
|
453
|
-
}),
|
|
499
|
+
}),
|
|
500
|
+
vendor: core_1.Flags.string({ description: 'Vendor (e.g. CrowdStrike)' }),
|
|
501
|
+
product: core_1.Flags.string({ description: 'Product (e.g. Falcon)' }),
|
|
502
|
+
keywords: core_1.Flags.string({ char: 'k', description: 'Please enter keyword (Comma-Separated)' }),
|
|
503
|
+
description: core_1.Flags.string({ description: 'Description (e.g. CrowdStrike Host Query API)' }),
|
|
504
|
+
logoPath: core_1.Flags.string({ description: 'URL or absolute path to logo file' }),
|
|
505
|
+
author: core_1.Flags.string({ description: 'Connector Author' }),
|
|
506
|
+
authorEmail: core_1.Flags.string({ description: 'Connector Author Email' }),
|
|
507
|
+
homepage: core_1.Flags.string({ description: 'Connector Author Support URL' }),
|
|
508
|
+
specs: core_1.Flags.string({
|
|
454
509
|
char: 'o',
|
|
455
|
-
description: '
|
|
456
|
-
}),
|
|
510
|
+
description: 'path to the spec file',
|
|
511
|
+
}),
|
|
512
|
+
help: core_1.Flags.help({ char: 'h' }),
|
|
513
|
+
};
|
|
457
514
|
//# sourceMappingURL=openapi.js.map
|