@trayio/tray-openapi 5.35.0-unstable.fd7158a → 6.0.0
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/dist/OpenApiCodecs.d.ts +4 -207
- package/dist/OpenApiCodecs.d.ts.map +1 -1
- package/dist/OpenApiCodecs.js +3 -3
- package/dist/OpenApiSchemaImporter.d.ts +2 -2
- package/dist/OpenApiSchemaImporter.d.ts.map +1 -1
- package/dist/OpenApiSchemaImporter.js +55 -33
- package/dist/OpenApiSchemaImporter.unit.test.js +13 -24
- package/dist/OpenApiSchemaTransformer.d.ts +2 -2
- package/dist/OpenApiSchemaTransformer.d.ts.map +1 -1
- package/dist/OpenApiSchemaTransformer.js +25 -2
- package/dist/OpenApiSchemaTransformer.unit.test.js +44 -30
- package/dist/OpenApiTypeDescriptors.d.ts +32 -389
- package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
- package/dist/OpenApiTypeDescriptors.js +109 -80
- package/dist/file-generators/GenerateHandler.d.ts +2 -2
- package/dist/file-generators/GenerateHandler.d.ts.map +1 -1
- package/dist/file-generators/GenerateHandler.js +78 -75
- package/dist/file-generators/GenerateHandler.unit.test.js +97 -73
- package/dist/file-generators/GenerateHandlerTest.d.ts +2 -2
- package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -1
- package/dist/file-generators/GenerateHandlerTest.js +76 -69
- package/dist/file-generators/GenerateHandlerTest.unit.test.js +230 -206
- package/dist/file-generators/GenerateOperationJson.d.ts +2 -2
- package/dist/file-generators/GenerateOperationJson.d.ts.map +1 -1
- package/dist/file-generators/GenerateOperationJson.js +29 -4
- package/dist/file-generators/GenerateOperationJson.unit.test.js +49 -25
- package/dist/file-generators/SchemaGenerator.d.ts.map +1 -1
- package/dist/file-generators/SchemaGenerator.js +37 -14
- package/dist/file-generators/types/GenerateInputSchema.d.ts +2 -2
- package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateInputSchema.js +95 -88
- package/dist/file-generators/types/GenerateInputSchema.test.js +91 -60
- package/dist/file-generators/types/GenerateInputType.test.js +169 -143
- package/dist/file-generators/types/GenerateInputTypes.d.ts +2 -2
- package/dist/file-generators/types/GenerateInputTypes.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateInputTypes.js +28 -7
- package/dist/file-generators/types/GenerateOutput.d.ts +6 -4
- package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateOutput.js +57 -46
- package/dist/file-generators/types/GenerateOutput.test.js +62 -35
- package/package.json +8 -6
|
@@ -1,90 +1,119 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
4
|
-
const
|
|
26
|
+
exports.openApiSpecTypeDescriptor = exports.openApiSpecPathTypeDescriptor = exports.parameterSchemaTypeDescriptor = exports.schemaObjectTypeCodec = exports.schemaObjectTypeDescriptor = exports.baseSchemaObjectSchemaTypeDescriptor = void 0;
|
|
27
|
+
const t = __importStar(require("io-ts"));
|
|
28
|
+
const io_ts_types_1 = require("io-ts-types");
|
|
5
29
|
const TypeCodec_1 = require("@trayio/commons/codec/TypeCodec");
|
|
6
|
-
//
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
const
|
|
41
|
-
|
|
30
|
+
// Type Descriptors
|
|
31
|
+
const nonArraySchemaObjectType = t.keyof({
|
|
32
|
+
boolean: null,
|
|
33
|
+
object: null,
|
|
34
|
+
number: null,
|
|
35
|
+
string: null,
|
|
36
|
+
integer: null,
|
|
37
|
+
});
|
|
38
|
+
exports.baseSchemaObjectSchemaTypeDescriptor = t.recursion('baseSchema', () => t.type({
|
|
39
|
+
title: (0, io_ts_types_1.optionFromNullable)(t.string),
|
|
40
|
+
additionalProperties: (0, io_ts_types_1.optionFromNullable)(t.union([t.boolean, exports.schemaObjectTypeDescriptor])),
|
|
41
|
+
properties: (0, io_ts_types_1.optionFromNullable)(t.record(t.string, exports.schemaObjectTypeDescriptor)),
|
|
42
|
+
required: (0, io_ts_types_1.optionFromNullable)(t.array(t.string)),
|
|
43
|
+
allOf: (0, io_ts_types_1.optionFromNullable)(t.array(exports.schemaObjectTypeDescriptor)),
|
|
44
|
+
oneOf: (0, io_ts_types_1.optionFromNullable)(t.array(exports.schemaObjectTypeDescriptor)),
|
|
45
|
+
anyOf: (0, io_ts_types_1.optionFromNullable)(t.array(exports.schemaObjectTypeDescriptor)),
|
|
46
|
+
not: (0, io_ts_types_1.optionFromNullable)(exports.schemaObjectTypeDescriptor),
|
|
47
|
+
in: (0, io_ts_types_1.optionFromNullable)(t.string),
|
|
48
|
+
nullable: (0, io_ts_types_1.optionFromNullable)(t.boolean),
|
|
49
|
+
default: (0, io_ts_types_1.optionFromNullable)(t.union([
|
|
50
|
+
t.string,
|
|
51
|
+
t.number,
|
|
52
|
+
t.boolean,
|
|
53
|
+
t.array(t.union([t.string, t.number, t.boolean])),
|
|
54
|
+
])),
|
|
55
|
+
enum: (0, io_ts_types_1.optionFromNullable)(t.array(t.union([t.string, t.number, t.boolean]))),
|
|
56
|
+
}));
|
|
57
|
+
const arraySchemaObjectSchemaTypeDescriptor = t.recursion('ArraySchema', () => t.intersection([
|
|
58
|
+
exports.baseSchemaObjectSchemaTypeDescriptor,
|
|
59
|
+
t.type({
|
|
60
|
+
type: (0, io_ts_types_1.optionFromNullable)(t.literal('array')),
|
|
61
|
+
items: exports.schemaObjectTypeDescriptor,
|
|
62
|
+
}),
|
|
63
|
+
]));
|
|
64
|
+
const nonArraySchemaObjectSchemaTypeDescriptor = t.recursion('nonArraySchema', () => t.intersection([
|
|
65
|
+
exports.baseSchemaObjectSchemaTypeDescriptor,
|
|
66
|
+
t.type({
|
|
67
|
+
type: (0, io_ts_types_1.optionFromNullable)(nonArraySchemaObjectType),
|
|
68
|
+
}),
|
|
69
|
+
]));
|
|
70
|
+
// TODO: do we need the schemaObjectTypeDescriptor AND the schemaObjectTypeCodec?
|
|
71
|
+
// Added the schemaObjectTypeCodec in order to use the RemoveNullValuesCodec to remove O.none values instead of sestting them to null
|
|
72
|
+
exports.schemaObjectTypeDescriptor = t.recursion('schemaObject', () => t.union([
|
|
73
|
+
arraySchemaObjectSchemaTypeDescriptor,
|
|
74
|
+
nonArraySchemaObjectSchemaTypeDescriptor,
|
|
75
|
+
]));
|
|
76
|
+
exports.schemaObjectTypeCodec = TypeCodec_1.TypeCodec.fromDescriptor(exports.schemaObjectTypeDescriptor);
|
|
77
|
+
const componentSchemaTypeDescriptor = t.type({
|
|
78
|
+
schemas: (0, io_ts_types_1.optionFromNullable)(t.record(t.string, exports.schemaObjectTypeDescriptor)),
|
|
42
79
|
});
|
|
43
|
-
const
|
|
44
|
-
schema:
|
|
80
|
+
const mediaTypeTypeDescriptor = t.type({
|
|
81
|
+
schema: (0, io_ts_types_1.optionFromNullable)(exports.schemaObjectTypeDescriptor),
|
|
45
82
|
});
|
|
46
|
-
const
|
|
47
|
-
content:
|
|
83
|
+
const openApiSpecRequestBodyTypeDescriptor = t.type({
|
|
84
|
+
content: t.record(t.string, mediaTypeTypeDescriptor),
|
|
48
85
|
});
|
|
49
|
-
const
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
description: effect_1.Schema.String,
|
|
53
|
-
content: effect_1.Schema.OptionFromNullishOr(effect_1.Schema.mutable(effect_1.Schema.Record({ key: effect_1.Schema.String, value: mediaTypeSchema })), null),
|
|
54
|
-
}),
|
|
86
|
+
const openApiSpecResponsesTypeDescriptor = t.record(t.string, t.type({
|
|
87
|
+
description: t.string,
|
|
88
|
+
content: (0, io_ts_types_1.optionFromNullable)(t.record(t.string, mediaTypeTypeDescriptor)),
|
|
55
89
|
}));
|
|
56
|
-
exports.
|
|
57
|
-
name:
|
|
58
|
-
in:
|
|
59
|
-
description:
|
|
60
|
-
required:
|
|
61
|
-
schema: exports.
|
|
90
|
+
exports.parameterSchemaTypeDescriptor = t.type({
|
|
91
|
+
name: t.string,
|
|
92
|
+
in: t.string,
|
|
93
|
+
description: (0, io_ts_types_1.optionFromNullable)(t.string),
|
|
94
|
+
required: (0, io_ts_types_1.optionFromNullable)(t.boolean),
|
|
95
|
+
schema: exports.schemaObjectTypeDescriptor,
|
|
62
96
|
});
|
|
63
|
-
exports.
|
|
64
|
-
description:
|
|
65
|
-
summary:
|
|
66
|
-
tags:
|
|
67
|
-
operationId:
|
|
68
|
-
parameters:
|
|
69
|
-
requestBody:
|
|
70
|
-
responses:
|
|
97
|
+
exports.openApiSpecPathTypeDescriptor = t.type({
|
|
98
|
+
description: (0, io_ts_types_1.optionFromNullable)(t.string),
|
|
99
|
+
summary: (0, io_ts_types_1.optionFromNullable)(t.string),
|
|
100
|
+
tags: (0, io_ts_types_1.optionFromNullable)(t.array(t.string)),
|
|
101
|
+
operationId: t.string,
|
|
102
|
+
parameters: (0, io_ts_types_1.optionFromNullable)(t.array(exports.parameterSchemaTypeDescriptor)),
|
|
103
|
+
requestBody: (0, io_ts_types_1.optionFromNullable)(openApiSpecRequestBodyTypeDescriptor),
|
|
104
|
+
responses: (0, io_ts_types_1.optionFromNullable)(openApiSpecResponsesTypeDescriptor),
|
|
71
105
|
});
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
version: effect_1.Schema.String,
|
|
86
|
-
}),
|
|
87
|
-
servers: effect_1.Schema.mutable(effect_1.Schema.Array(effect_1.Schema.Struct({ url: effect_1.Schema.String }))),
|
|
88
|
-
paths: effect_1.Schema.mutable(effect_1.Schema.Record({ key: effect_1.Schema.String, value: pathsByMethodSchema })),
|
|
89
|
-
components: componentSchemaSchema,
|
|
106
|
+
const httpKeys = t.keyof({
|
|
107
|
+
get: null,
|
|
108
|
+
post: null,
|
|
109
|
+
put: null,
|
|
110
|
+
patch: null,
|
|
111
|
+
delete: null,
|
|
112
|
+
});
|
|
113
|
+
exports.openApiSpecTypeDescriptor = t.type({
|
|
114
|
+
openapi: t.string,
|
|
115
|
+
info: t.type({ title: t.string, description: t.string, version: t.string }),
|
|
116
|
+
servers: t.array(t.type({ url: t.string })),
|
|
117
|
+
paths: t.record(t.string, TypeCodec_1.TypeCodec.partialRecord(httpKeys, exports.openApiSpecPathTypeDescriptor)),
|
|
118
|
+
components: componentSchemaTypeDescriptor,
|
|
90
119
|
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import * as E from 'fp-ts/Either';
|
|
2
2
|
import { SchemaObject } from '../OpenApiTypeDescriptors';
|
|
3
3
|
type HandlerHttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
4
4
|
export type GenerateHandlerInput = {
|
|
@@ -10,6 +10,6 @@ export type GenerateHandlerInput = {
|
|
|
10
10
|
httpPath: string;
|
|
11
11
|
input: SchemaObject;
|
|
12
12
|
};
|
|
13
|
-
export declare const generateHandler: ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, httpPath, input, }: GenerateHandlerInput) =>
|
|
13
|
+
export declare const generateHandler: ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, httpPath, input, }: GenerateHandlerInput) => E.Either<Error, string>;
|
|
14
14
|
export {};
|
|
15
15
|
//# sourceMappingURL=GenerateHandler.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateHandler.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandler.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GenerateHandler.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandler.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,YAAY,EAAoB,MAAM,2BAA2B,CAAC;AAE3E,KAAK,iBAAiB,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE,MAAM,MAAM,oBAAoB,GAAG;IAClC,uBAAuB,EAAE,MAAM,CAAC;IAChC,uBAAuB,EAAE,MAAM,CAAC;IAChC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,QAAQ,EAAE,MAAM,CAAC;IACjB,KAAK,EAAE,YAAY,CAAC;CACpB,CAAC;AAiNF,eAAO,MAAM,eAAe,wHAQzB,oBAAoB,KAAG,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAqB9C,CAAC"}
|
|
@@ -1,20 +1,41 @@
|
|
|
1
1
|
"use strict";
|
|
2
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
3
|
+
if (k2 === undefined) k2 = k;
|
|
4
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
5
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
6
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
7
|
+
}
|
|
8
|
+
Object.defineProperty(o, k2, desc);
|
|
9
|
+
}) : (function(o, m, k, k2) {
|
|
10
|
+
if (k2 === undefined) k2 = k;
|
|
11
|
+
o[k2] = m[k];
|
|
12
|
+
}));
|
|
13
|
+
var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (function(o, v) {
|
|
14
|
+
Object.defineProperty(o, "default", { enumerable: true, value: v });
|
|
15
|
+
}) : function(o, v) {
|
|
16
|
+
o["default"] = v;
|
|
17
|
+
});
|
|
18
|
+
var __importStar = (this && this.__importStar) || function (mod) {
|
|
19
|
+
if (mod && mod.__esModule) return mod;
|
|
20
|
+
var result = {};
|
|
21
|
+
if (mod != null) for (var k in mod) if (k !== "default" && Object.prototype.hasOwnProperty.call(mod, k)) __createBinding(result, mod, k);
|
|
22
|
+
__setModuleDefault(result, mod);
|
|
23
|
+
return result;
|
|
24
|
+
};
|
|
2
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
26
|
exports.generateHandler = void 0;
|
|
4
|
-
const
|
|
5
|
-
const
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
},
|
|
17
|
-
});
|
|
27
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
28
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
29
|
+
const getInputVariable = (name, type) => O.fold(() => `input.${name}`, (inputType) => {
|
|
30
|
+
switch (inputType) {
|
|
31
|
+
case 'integer':
|
|
32
|
+
case 'boolean':
|
|
33
|
+
case 'number':
|
|
34
|
+
return `input.${name}.toString()`;
|
|
35
|
+
default:
|
|
36
|
+
return `input.${name}`;
|
|
37
|
+
}
|
|
38
|
+
})(type);
|
|
18
39
|
const generateRequestHandlerInputs = (inputs, bodyInputs) => {
|
|
19
40
|
if (bodyInputs.length > 0) {
|
|
20
41
|
let containsNullable = false;
|
|
@@ -53,69 +74,54 @@ const handleOptionalInput = (inputString, name, requiredInputs) => {
|
|
|
53
74
|
};
|
|
54
75
|
const constructInputs = (properties, requiredInputs) => {
|
|
55
76
|
const inputsArray = Object.entries(properties);
|
|
56
|
-
const requiredInputsArray =
|
|
77
|
+
const requiredInputsArray = O.getOrElse(() => [])(requiredInputs);
|
|
57
78
|
const bodyInputs = [];
|
|
58
79
|
const handlerInput = inputsArray.map(([name, input], index) => {
|
|
59
80
|
let inputMapping = '';
|
|
60
|
-
return
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
return inputMapping;
|
|
86
|
-
},
|
|
87
|
-
});
|
|
81
|
+
return O.fold(() => '', (inputIn) => {
|
|
82
|
+
switch (inputIn) {
|
|
83
|
+
case 'body':
|
|
84
|
+
bodyInputs.push({
|
|
85
|
+
input: `${name}: input.${name}`,
|
|
86
|
+
nullable: O.getOrElse(() => {
|
|
87
|
+
if (requiredInputsArray.includes(name)) {
|
|
88
|
+
return false;
|
|
89
|
+
}
|
|
90
|
+
return true;
|
|
91
|
+
})(input.nullable),
|
|
92
|
+
});
|
|
93
|
+
break;
|
|
94
|
+
case 'path':
|
|
95
|
+
inputMapping = handleOptionalInput(`requestBuilder = requestBuilder.addPathParameter("${name}", ${getInputVariable(name, input.type)});`, name, requiredInputsArray);
|
|
96
|
+
break;
|
|
97
|
+
case 'query':
|
|
98
|
+
inputMapping = handleOptionalInput(`requestBuilder = requestBuilder.addQueryString("${name}", ${getInputVariable(name, input.type)});`, name, requiredInputsArray);
|
|
99
|
+
break;
|
|
100
|
+
case 'header':
|
|
101
|
+
inputMapping = handleOptionalInput(`requestBuilder = requestBuilder.addHeader("${name}", ${getInputVariable(name, input.type)});`, name, requiredInputsArray);
|
|
102
|
+
break;
|
|
103
|
+
}
|
|
104
|
+
return inputMapping;
|
|
105
|
+
})(input.in);
|
|
88
106
|
});
|
|
89
107
|
return generateRequestHandlerInputs(handlerInput, bodyInputs);
|
|
90
108
|
};
|
|
91
|
-
const handleInput = (inputs) =>
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
});
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
onNone: () => acc,
|
|
99
|
-
onSome: (inValue) => {
|
|
100
|
-
if (inValue === 'path') {
|
|
101
|
-
return acc.replace(`{${name}}`, `:${name}`);
|
|
102
|
-
}
|
|
103
|
-
return acc;
|
|
104
|
-
},
|
|
105
|
-
}), path),
|
|
106
|
-
});
|
|
109
|
+
const handleInput = (inputs) => O.fold(() => 'request.withoutBody()', (properties) => `{${constructInputs(properties, inputs.required)}}`)(inputs.properties);
|
|
110
|
+
const generatePath = (path, inputs) => O.fold(() => path, (properties) => Object.entries(properties).reduce((acc, [name, input]) => O.fold(() => acc, (inValue) => {
|
|
111
|
+
if (inValue === 'path') {
|
|
112
|
+
return acc.replace(`{${name}}`, `:${name}`);
|
|
113
|
+
}
|
|
114
|
+
return acc;
|
|
115
|
+
})(input.in), path))(inputs.properties);
|
|
107
116
|
const generateImports = (connectorNamePascalCase, operationNamePascalCase, inputs) => {
|
|
108
|
-
const requiredInputs =
|
|
109
|
-
const containsNullable =
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
return false;
|
|
117
|
-
})),
|
|
118
|
-
});
|
|
117
|
+
const requiredInputs = O.getOrElse(() => [])(inputs.required);
|
|
118
|
+
const containsNullable = O.fold(() => false, (properties) => !!Object.entries(properties).find(([name, input]) => O.getOrElse(() => {
|
|
119
|
+
const inputIn = O.getOrElse(() => '')(input.in);
|
|
120
|
+
if (!requiredInputs.includes(name) && inputIn === 'body') {
|
|
121
|
+
return true;
|
|
122
|
+
}
|
|
123
|
+
return false;
|
|
124
|
+
})(input.nullable)))(inputs.properties);
|
|
119
125
|
const imports = [
|
|
120
126
|
'import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";',
|
|
121
127
|
];
|
|
@@ -130,8 +136,7 @@ const generateImports = (connectorNamePascalCase, operationNamePascalCase, input
|
|
|
130
136
|
`import { globalConfigHttp } from "../GlobalConfig";`,
|
|
131
137
|
].join('\n');
|
|
132
138
|
};
|
|
133
|
-
const generateHandler = ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, httpPath, input, }) =>
|
|
134
|
-
try: () => `${generateImports(connectorNamePascalCase, operationNamePascalCase, input)}
|
|
139
|
+
const generateHandler = ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, httpPath, input, }) => E.tryCatch(() => `${generateImports(connectorNamePascalCase, operationNamePascalCase, input)}
|
|
135
140
|
|
|
136
141
|
export const ${operationNameCamelCase}Handler = OperationHandlerSetup.configureHandler<
|
|
137
142
|
${connectorNamePascalCase}Auth,
|
|
@@ -144,7 +149,5 @@ const generateHandler = ({ connectorNamePascalCase, operationNamePascalCase, ope
|
|
|
144
149
|
.handleRequest((ctx, input, request) => ${handleInput(input)})
|
|
145
150
|
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
|
|
146
151
|
)
|
|
147
|
-
);`,
|
|
148
|
-
catch: (error) => new Error(`Failed to generate handler: ${error}`),
|
|
149
|
-
});
|
|
152
|
+
);`, (error) => new Error(`Failed to generate handler: ${error}`));
|
|
150
153
|
exports.generateHandler = generateHandler;
|