@trayio/tray-openapi 4.13.0 → 4.14.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/OpenApiTypeDescriptors.d.ts +1 -0
- package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
- package/dist/OpenApiTypeDescriptors.js +1 -0
- package/dist/file-generators/GenerateHandler.d.ts.map +1 -1
- package/dist/file-generators/GenerateHandler.js +34 -6
- package/dist/file-generators/GenerateHandler.test.js +103 -245
- package/dist/file-generators/GenerateHandlerTest.js +1 -1
- package/dist/file-generators/GenerateHandlerTest.test.js +63 -295
- package/dist/file-generators/SchemaGenerator.d.ts +3 -0
- package/dist/file-generators/SchemaGenerator.d.ts.map +1 -0
- package/dist/file-generators/SchemaGenerator.js +43 -0
- package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateInputSchema.js +3 -0
- package/dist/file-generators/types/GenerateInputSchema.test.js +18 -95
- package/dist/file-generators/types/GenerateInputType.test.js +40 -192
- package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateOutput.js +1 -0
- package/dist/file-generators/types/GenerateOutput.test.js +21 -105
- package/dist/file-generators/types/JsonSchemaToTypescriptOptions.d.ts +1 -0
- package/dist/file-generators/types/JsonSchemaToTypescriptOptions.d.ts.map +1 -1
- package/dist/file-generators/types/JsonSchemaToTypescriptOptions.js +1 -0
- package/dist/templates/connector-template.zip +0 -0
- package/package.json +1 -1
|
@@ -100,6 +100,7 @@ export type BaseSchemaObject = {
|
|
|
100
100
|
anyOf: O.Option<SchemaObject[]>;
|
|
101
101
|
not: O.Option<SchemaObject>;
|
|
102
102
|
in: O.Option<string>;
|
|
103
|
+
nullable: O.Option<boolean>;
|
|
103
104
|
default: O.Option<string | number | boolean | Array<string | number | boolean>>;
|
|
104
105
|
};
|
|
105
106
|
export declare const baseSchemaObjectSchemaTypeDescriptor: t.Type<BaseSchem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,EAAE,CAAC,CAAC,IAAI,CACxD,gBAAgB,EAChB,OAAO,CA0BP,CAAC;AA4BF,eAAO,MAAM,0BAA0B,EAAE,CAAC,CAAC,IAAI,CAAC,YAAY,EAAE,OAAO,CAMnE,CAAC;AAEH,eAAO,MAAM,qBAAqB,wDAEjC,CAAC;AAuBF,eAAO,MAAM,6BAA6B,EAAE,CAAC,CAAC,IAAI,CAAC,SAAS,EAAE,OAAO,CAQpE,CAAC;AAEF,eAAO,MAAM,6BAA6B,EAAE,CAAC,CAAC,IAAI,CAAC,IAAI,EAAE,OAAO,CAQ9D,CAAC;AAUH,eAAO,MAAM,yBAAyB,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAWpE,CAAC"}
|
|
@@ -45,6 +45,7 @@ exports.baseSchemaObjectSchemaTypeDescriptor = t.recursion('baseSchema', () => t
|
|
|
45
45
|
anyOf: (0, io_ts_types_1.optionFromNullable)(t.array(exports.schemaObjectTypeDescriptor)),
|
|
46
46
|
not: (0, io_ts_types_1.optionFromNullable)(exports.schemaObjectTypeDescriptor),
|
|
47
47
|
in: (0, io_ts_types_1.optionFromNullable)(t.string),
|
|
48
|
+
nullable: (0, io_ts_types_1.optionFromNullable)(t.boolean),
|
|
48
49
|
default: (0, io_ts_types_1.optionFromNullable)(t.union([
|
|
49
50
|
t.string,
|
|
50
51
|
t.number,
|
|
@@ -1 +1 @@
|
|
|
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;
|
|
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;AAqMF,eAAO,MAAM,eAAe,wHAQzB,oBAAoB,KAAG,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAqB9C,CAAC"}
|
|
@@ -38,7 +38,20 @@ const getInputVariable = (name, type) => O.fold(() => `input.${name}`, (inputTyp
|
|
|
38
38
|
})(type);
|
|
39
39
|
const generateRequestHandlerInputs = (inputs, bodyInputs) => {
|
|
40
40
|
if (bodyInputs.length > 0) {
|
|
41
|
-
|
|
41
|
+
let containsNullable = false;
|
|
42
|
+
const bodyInputProperties = bodyInputs.map(({ input, nullable }) => {
|
|
43
|
+
if (nullable) {
|
|
44
|
+
containsNullable = true;
|
|
45
|
+
}
|
|
46
|
+
return input;
|
|
47
|
+
});
|
|
48
|
+
let constructedBodyProperty = `return requestBuilder.withBodyAsJson(`;
|
|
49
|
+
if (containsNullable) {
|
|
50
|
+
constructedBodyProperty = `return requestBuilder.withBodyAsJson(castUndefinedPropertyToNull({ ${bodyInputProperties.join(',')} }))`;
|
|
51
|
+
}
|
|
52
|
+
else {
|
|
53
|
+
constructedBodyProperty = `return requestBuilder.withBodyAsJson({ ${bodyInputProperties.join(',')} })`;
|
|
54
|
+
}
|
|
42
55
|
if (inputs[0] === 'requestBuilder.') {
|
|
43
56
|
const cleanInput = inputs.filter((item) => item !== '');
|
|
44
57
|
return cleanInput
|
|
@@ -68,7 +81,10 @@ const constructInputs = (properties, requiredInputs) => {
|
|
|
68
81
|
return O.fold(() => '', (inputIn) => {
|
|
69
82
|
switch (inputIn) {
|
|
70
83
|
case 'body':
|
|
71
|
-
bodyInputs.push(
|
|
84
|
+
bodyInputs.push({
|
|
85
|
+
input: `${name}: input.${name}`,
|
|
86
|
+
nullable: O.getOrElse(() => false)(input.nullable),
|
|
87
|
+
});
|
|
72
88
|
break;
|
|
73
89
|
case 'path':
|
|
74
90
|
inputMapping = handleOptionalInput(`requestBuilder = requestBuilder.addPathParameter("${name}", ${getInputVariable(name, input.type)});`, name, requiredInputsArray);
|
|
@@ -92,10 +108,22 @@ const generatePath = (path, inputs) => O.fold(() => path, (properties) => Object
|
|
|
92
108
|
}
|
|
93
109
|
return acc;
|
|
94
110
|
})(input.in), path))(inputs.properties);
|
|
95
|
-
const
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
import {
|
|
111
|
+
const generateImports = (connectorNamePascalCase, operationNamePascalCase, inputs) => {
|
|
112
|
+
const containsNullable = O.fold(() => false, (properties) => !!Object.entries(properties).find(([_, input]) => O.getOrElse(() => false)(input.nullable)))(inputs.properties);
|
|
113
|
+
const imports = [
|
|
114
|
+
'import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";',
|
|
115
|
+
];
|
|
116
|
+
if (containsNullable) {
|
|
117
|
+
imports.push('import { castUndefinedPropertyToNull } from "@trayio/commons/dynamictype/DynamicType";');
|
|
118
|
+
}
|
|
119
|
+
return [
|
|
120
|
+
...imports,
|
|
121
|
+
`import { ${connectorNamePascalCase}Auth } from "../${connectorNamePascalCase}Auth";`,
|
|
122
|
+
`import { ${operationNamePascalCase}Input } from "./input";`,
|
|
123
|
+
`import { ${operationNamePascalCase}Output } from "./output";`,
|
|
124
|
+
].join('\n');
|
|
125
|
+
};
|
|
126
|
+
const generateHandler = ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, httpPath, input, }) => E.tryCatch(() => `${generateImports(connectorNamePascalCase, operationNamePascalCase, input)}
|
|
99
127
|
|
|
100
128
|
export const ${operationNameCamelCase}Handler = OperationHandlerSetup.configureHandler<
|
|
101
129
|
${connectorNamePascalCase}Auth,
|
|
@@ -26,25 +26,14 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
26
26
|
const E = __importStar(require("fp-ts/Either"));
|
|
27
27
|
const O = __importStar(require("fp-ts/Option"));
|
|
28
28
|
const GenerateHandler_1 = require("./GenerateHandler");
|
|
29
|
+
const SchemaGenerator_1 = require("./SchemaGenerator");
|
|
29
30
|
const getGenerateHandlerInput = (input) => ({
|
|
30
31
|
connectorNamePascalCase: 'OpenApiTest',
|
|
31
32
|
operationNamePascalCase: 'GetPhoto',
|
|
32
33
|
operationNameCamelCase: 'getPhoto',
|
|
33
34
|
httpMethod: 'get',
|
|
34
35
|
baseUrl: 'https://jsonplaceholder.typicode.com',
|
|
35
|
-
input: {
|
|
36
|
-
title: O.none,
|
|
37
|
-
properties: O.none,
|
|
38
|
-
additionalProperties: O.none,
|
|
39
|
-
required: O.none,
|
|
40
|
-
allOf: O.none,
|
|
41
|
-
oneOf: O.none,
|
|
42
|
-
anyOf: O.none,
|
|
43
|
-
not: O.none,
|
|
44
|
-
in: O.none,
|
|
45
|
-
type: O.none,
|
|
46
|
-
default: O.none,
|
|
47
|
-
},
|
|
36
|
+
input: (0, SchemaGenerator_1.generateNonArraySchemaObject)({}),
|
|
48
37
|
httpPath: '/photos',
|
|
49
38
|
...input,
|
|
50
39
|
});
|
|
@@ -53,9 +42,9 @@ describe('GenerateHandler', () => {
|
|
|
53
42
|
const payload = getGenerateHandlerInput({});
|
|
54
43
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
55
44
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
45
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
46
|
+
import { GetPhotoInput } from "./input";
|
|
47
|
+
import { GetPhotoOutput } from "./output";
|
|
59
48
|
|
|
60
49
|
export const getPhotoHandler = OperationHandlerSetup.configureHandler<
|
|
61
50
|
OpenApiTestAuth,
|
|
@@ -71,42 +60,26 @@ describe('GenerateHandler', () => {
|
|
|
71
60
|
);`)).toEqual(generatedHandler);
|
|
72
61
|
});
|
|
73
62
|
it('it should generate a handler with a path parameter', () => {
|
|
74
|
-
const input = {
|
|
63
|
+
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
75
64
|
type: O.some('object'),
|
|
76
|
-
title: O.none,
|
|
77
65
|
properties: O.some({
|
|
78
|
-
photoId: {
|
|
79
|
-
title: O.none,
|
|
66
|
+
photoId: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
80
67
|
type: O.some('string'),
|
|
81
68
|
in: O.some('path'),
|
|
82
|
-
|
|
83
|
-
additionalProperties: O.none,
|
|
84
|
-
required: O.none,
|
|
85
|
-
allOf: O.none,
|
|
86
|
-
oneOf: O.none,
|
|
87
|
-
anyOf: O.none,
|
|
88
|
-
not: O.none,
|
|
89
|
-
default: O.none,
|
|
90
|
-
},
|
|
69
|
+
}),
|
|
91
70
|
}),
|
|
92
71
|
required: O.some(['photoId']),
|
|
93
72
|
additionalProperties: O.some(false),
|
|
94
|
-
|
|
95
|
-
oneOf: O.none,
|
|
96
|
-
anyOf: O.none,
|
|
97
|
-
not: O.none,
|
|
98
|
-
in: O.none,
|
|
99
|
-
default: O.none,
|
|
100
|
-
};
|
|
73
|
+
});
|
|
101
74
|
const payload = getGenerateHandlerInput({
|
|
102
75
|
input,
|
|
103
76
|
httpPath: '/photos/{photoId}',
|
|
104
77
|
});
|
|
105
78
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
106
79
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
80
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
81
|
+
import { GetPhotoInput } from "./input";
|
|
82
|
+
import { GetPhotoOutput } from "./output";
|
|
110
83
|
|
|
111
84
|
export const getPhotoHandler = OperationHandlerSetup.configureHandler<
|
|
112
85
|
OpenApiTestAuth,
|
|
@@ -122,39 +95,23 @@ describe('GenerateHandler', () => {
|
|
|
122
95
|
);`)).toEqual(generatedHandler);
|
|
123
96
|
});
|
|
124
97
|
it('it should generate a handler with a body input as json', () => {
|
|
125
|
-
const input = {
|
|
98
|
+
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
126
99
|
type: O.some('object'),
|
|
127
|
-
title: O.none,
|
|
128
100
|
properties: O.some({
|
|
129
|
-
photoId: {
|
|
130
|
-
title: O.none,
|
|
101
|
+
photoId: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
131
102
|
type: O.some('string'),
|
|
132
103
|
in: O.some('body'),
|
|
133
|
-
|
|
134
|
-
additionalProperties: O.none,
|
|
135
|
-
required: O.none,
|
|
136
|
-
allOf: O.none,
|
|
137
|
-
oneOf: O.none,
|
|
138
|
-
anyOf: O.none,
|
|
139
|
-
not: O.none,
|
|
140
|
-
default: O.none,
|
|
141
|
-
},
|
|
104
|
+
}),
|
|
142
105
|
}),
|
|
143
106
|
required: O.some(['photoId']),
|
|
144
107
|
additionalProperties: O.some(false),
|
|
145
|
-
|
|
146
|
-
oneOf: O.none,
|
|
147
|
-
anyOf: O.none,
|
|
148
|
-
not: O.none,
|
|
149
|
-
in: O.none,
|
|
150
|
-
default: O.none,
|
|
151
|
-
};
|
|
108
|
+
});
|
|
152
109
|
const payload = getGenerateHandlerInput({ input });
|
|
153
110
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
154
111
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
112
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
113
|
+
import { GetPhotoInput } from "./input";
|
|
114
|
+
import { GetPhotoOutput } from "./output";
|
|
158
115
|
|
|
159
116
|
export const getPhotoHandler = OperationHandlerSetup.configureHandler<
|
|
160
117
|
OpenApiTestAuth,
|
|
@@ -170,39 +127,23 @@ describe('GenerateHandler', () => {
|
|
|
170
127
|
);`)).toEqual(generatedHandler);
|
|
171
128
|
});
|
|
172
129
|
it('it should generate a handler with a query string input', () => {
|
|
173
|
-
const input = {
|
|
130
|
+
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
174
131
|
type: O.some('object'),
|
|
175
|
-
title: O.none,
|
|
176
132
|
properties: O.some({
|
|
177
|
-
id: {
|
|
178
|
-
title: O.none,
|
|
133
|
+
id: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
179
134
|
type: O.some('string'),
|
|
180
135
|
in: O.some('query'),
|
|
181
|
-
|
|
182
|
-
additionalProperties: O.none,
|
|
183
|
-
required: O.none,
|
|
184
|
-
allOf: O.none,
|
|
185
|
-
oneOf: O.none,
|
|
186
|
-
anyOf: O.none,
|
|
187
|
-
not: O.none,
|
|
188
|
-
default: O.none,
|
|
189
|
-
},
|
|
136
|
+
}),
|
|
190
137
|
}),
|
|
191
138
|
required: O.some(['id']),
|
|
192
139
|
additionalProperties: O.some(false),
|
|
193
|
-
|
|
194
|
-
oneOf: O.none,
|
|
195
|
-
anyOf: O.none,
|
|
196
|
-
not: O.none,
|
|
197
|
-
in: O.none,
|
|
198
|
-
default: O.none,
|
|
199
|
-
};
|
|
140
|
+
});
|
|
200
141
|
const payload = getGenerateHandlerInput({ input });
|
|
201
142
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
202
143
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
144
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
145
|
+
import { GetPhotoInput } from "./input";
|
|
146
|
+
import { GetPhotoOutput } from "./output";
|
|
206
147
|
|
|
207
148
|
export const getPhotoHandler = OperationHandlerSetup.configureHandler<
|
|
208
149
|
OpenApiTestAuth,
|
|
@@ -218,39 +159,23 @@ describe('GenerateHandler', () => {
|
|
|
218
159
|
);`)).toEqual(generatedHandler);
|
|
219
160
|
});
|
|
220
161
|
it('it should generate a handler with a header input', () => {
|
|
221
|
-
const input = {
|
|
162
|
+
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
222
163
|
type: O.some('object'),
|
|
223
|
-
title: O.none,
|
|
224
164
|
properties: O.some({
|
|
225
|
-
'Content-Type': {
|
|
226
|
-
title: O.none,
|
|
165
|
+
'Content-Type': (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
227
166
|
type: O.some('string'),
|
|
228
167
|
in: O.some('header'),
|
|
229
|
-
|
|
230
|
-
additionalProperties: O.none,
|
|
231
|
-
required: O.none,
|
|
232
|
-
allOf: O.none,
|
|
233
|
-
oneOf: O.none,
|
|
234
|
-
anyOf: O.none,
|
|
235
|
-
not: O.none,
|
|
236
|
-
default: O.none,
|
|
237
|
-
},
|
|
168
|
+
}),
|
|
238
169
|
}),
|
|
239
170
|
required: O.some(['Content-Type']),
|
|
240
171
|
additionalProperties: O.some(false),
|
|
241
|
-
|
|
242
|
-
oneOf: O.none,
|
|
243
|
-
anyOf: O.none,
|
|
244
|
-
not: O.none,
|
|
245
|
-
in: O.none,
|
|
246
|
-
default: O.none,
|
|
247
|
-
};
|
|
172
|
+
});
|
|
248
173
|
const payload = getGenerateHandlerInput({ input });
|
|
249
174
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
250
175
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
251
|
-
|
|
252
|
-
|
|
253
|
-
|
|
176
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
177
|
+
import { GetPhotoInput } from "./input";
|
|
178
|
+
import { GetPhotoOutput } from "./output";
|
|
254
179
|
|
|
255
180
|
export const getPhotoHandler = OperationHandlerSetup.configureHandler<
|
|
256
181
|
OpenApiTestAuth,
|
|
@@ -266,39 +191,22 @@ describe('GenerateHandler', () => {
|
|
|
266
191
|
);`)).toEqual(generatedHandler);
|
|
267
192
|
});
|
|
268
193
|
it('it should generate a handler and transform number type to string for input', () => {
|
|
269
|
-
const input = {
|
|
194
|
+
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
270
195
|
type: O.some('object'),
|
|
271
|
-
title: O.none,
|
|
272
196
|
properties: O.some({
|
|
273
|
-
'Content-Type': {
|
|
274
|
-
title: O.none,
|
|
197
|
+
'Content-Type': (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
275
198
|
type: O.some('integer'),
|
|
276
199
|
in: O.some('header'),
|
|
277
|
-
|
|
278
|
-
additionalProperties: O.none,
|
|
279
|
-
required: O.none,
|
|
280
|
-
allOf: O.none,
|
|
281
|
-
oneOf: O.none,
|
|
282
|
-
anyOf: O.none,
|
|
283
|
-
not: O.none,
|
|
284
|
-
default: O.none,
|
|
285
|
-
},
|
|
200
|
+
}),
|
|
286
201
|
}),
|
|
287
|
-
required: O.none,
|
|
288
202
|
additionalProperties: O.some(false),
|
|
289
|
-
|
|
290
|
-
oneOf: O.none,
|
|
291
|
-
anyOf: O.none,
|
|
292
|
-
not: O.none,
|
|
293
|
-
in: O.none,
|
|
294
|
-
default: O.none,
|
|
295
|
-
};
|
|
203
|
+
});
|
|
296
204
|
const payload = getGenerateHandlerInput({ input });
|
|
297
205
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
298
206
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
299
|
-
|
|
300
|
-
|
|
301
|
-
|
|
207
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
208
|
+
import { GetPhotoInput } from "./input";
|
|
209
|
+
import { GetPhotoOutput } from "./output";
|
|
302
210
|
|
|
303
211
|
export const getPhotoHandler = OperationHandlerSetup.configureHandler<
|
|
304
212
|
OpenApiTestAuth,
|
|
@@ -314,68 +222,34 @@ describe('GenerateHandler', () => {
|
|
|
314
222
|
);`)).toEqual(generatedHandler);
|
|
315
223
|
});
|
|
316
224
|
it('it should generate a handler with a query string and path param input', () => {
|
|
317
|
-
const input = {
|
|
225
|
+
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
318
226
|
type: O.some('object'),
|
|
319
|
-
title: O.none,
|
|
320
227
|
properties: O.some({
|
|
321
|
-
id: {
|
|
322
|
-
title: O.none,
|
|
228
|
+
id: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
323
229
|
type: O.some('string'),
|
|
324
230
|
in: O.some('query'),
|
|
325
|
-
|
|
326
|
-
|
|
327
|
-
required: O.none,
|
|
328
|
-
allOf: O.none,
|
|
329
|
-
oneOf: O.none,
|
|
330
|
-
anyOf: O.none,
|
|
331
|
-
not: O.none,
|
|
332
|
-
default: O.none,
|
|
333
|
-
},
|
|
334
|
-
photoId: {
|
|
335
|
-
title: O.none,
|
|
231
|
+
}),
|
|
232
|
+
photoId: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
336
233
|
type: O.some('string'),
|
|
337
234
|
in: O.some('path'),
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
required: O.none,
|
|
341
|
-
allOf: O.none,
|
|
342
|
-
oneOf: O.none,
|
|
343
|
-
anyOf: O.none,
|
|
344
|
-
not: O.none,
|
|
345
|
-
default: O.none,
|
|
346
|
-
},
|
|
347
|
-
commentId: {
|
|
348
|
-
title: O.none,
|
|
235
|
+
}),
|
|
236
|
+
commentId: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
349
237
|
type: O.some('string'),
|
|
350
238
|
in: O.some('path'),
|
|
351
|
-
|
|
352
|
-
additionalProperties: O.none,
|
|
353
|
-
required: O.none,
|
|
354
|
-
allOf: O.none,
|
|
355
|
-
oneOf: O.none,
|
|
356
|
-
anyOf: O.none,
|
|
357
|
-
not: O.none,
|
|
358
|
-
default: O.none,
|
|
359
|
-
},
|
|
239
|
+
}),
|
|
360
240
|
}),
|
|
361
241
|
required: O.some(['photoId']),
|
|
362
242
|
additionalProperties: O.some(false),
|
|
363
|
-
|
|
364
|
-
oneOf: O.none,
|
|
365
|
-
anyOf: O.none,
|
|
366
|
-
not: O.none,
|
|
367
|
-
in: O.none,
|
|
368
|
-
default: O.none,
|
|
369
|
-
};
|
|
243
|
+
});
|
|
370
244
|
const payload = getGenerateHandlerInput({
|
|
371
245
|
input,
|
|
372
246
|
httpPath: '/photos/{photoId}/{commentId}',
|
|
373
247
|
});
|
|
374
248
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
375
249
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
250
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
251
|
+
import { GetPhotoInput } from "./input";
|
|
252
|
+
import { GetPhotoOutput } from "./output";
|
|
379
253
|
|
|
380
254
|
export const getPhotoHandler = OperationHandlerSetup.configureHandler<
|
|
381
255
|
OpenApiTestAuth,
|
|
@@ -391,52 +265,27 @@ describe('GenerateHandler', () => {
|
|
|
391
265
|
);`)).toEqual(generatedHandler);
|
|
392
266
|
});
|
|
393
267
|
it('it should generate a handler with a query string and body param input', () => {
|
|
394
|
-
const input = {
|
|
268
|
+
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
395
269
|
type: O.some('object'),
|
|
396
|
-
title: O.none,
|
|
397
270
|
properties: O.some({
|
|
398
|
-
id: {
|
|
399
|
-
title: O.none,
|
|
271
|
+
id: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
400
272
|
type: O.some('string'),
|
|
401
273
|
in: O.some('query'),
|
|
402
|
-
|
|
403
|
-
|
|
404
|
-
required: O.none,
|
|
405
|
-
allOf: O.none,
|
|
406
|
-
oneOf: O.none,
|
|
407
|
-
anyOf: O.none,
|
|
408
|
-
not: O.none,
|
|
409
|
-
default: O.none,
|
|
410
|
-
},
|
|
411
|
-
photoId: {
|
|
412
|
-
title: O.none,
|
|
274
|
+
}),
|
|
275
|
+
photoId: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
413
276
|
type: O.some('string'),
|
|
414
277
|
in: O.some('body'),
|
|
415
|
-
|
|
416
|
-
additionalProperties: O.none,
|
|
417
|
-
required: O.none,
|
|
418
|
-
allOf: O.none,
|
|
419
|
-
oneOf: O.none,
|
|
420
|
-
anyOf: O.none,
|
|
421
|
-
not: O.none,
|
|
422
|
-
default: O.none,
|
|
423
|
-
},
|
|
278
|
+
}),
|
|
424
279
|
}),
|
|
425
280
|
required: O.some(['id', 'photoId']),
|
|
426
281
|
additionalProperties: O.some(false),
|
|
427
|
-
|
|
428
|
-
oneOf: O.none,
|
|
429
|
-
anyOf: O.none,
|
|
430
|
-
not: O.none,
|
|
431
|
-
in: O.none,
|
|
432
|
-
default: O.none,
|
|
433
|
-
};
|
|
282
|
+
});
|
|
434
283
|
const payload = getGenerateHandlerInput({ input });
|
|
435
284
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
436
285
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
286
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
287
|
+
import { GetPhotoInput } from "./input";
|
|
288
|
+
import { GetPhotoOutput } from "./output";
|
|
440
289
|
|
|
441
290
|
export const getPhotoHandler = OperationHandlerSetup.configureHandler<
|
|
442
291
|
OpenApiTestAuth,
|
|
@@ -452,52 +301,27 @@ describe('GenerateHandler', () => {
|
|
|
452
301
|
);`)).toEqual(generatedHandler);
|
|
453
302
|
});
|
|
454
303
|
it('it should generate a handler with an optional query string and body param input', () => {
|
|
455
|
-
const input = {
|
|
304
|
+
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
456
305
|
type: O.some('object'),
|
|
457
|
-
title: O.none,
|
|
458
306
|
properties: O.some({
|
|
459
|
-
id: {
|
|
460
|
-
title: O.none,
|
|
307
|
+
id: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
461
308
|
type: O.some('string'),
|
|
462
309
|
in: O.some('query'),
|
|
463
|
-
|
|
464
|
-
|
|
465
|
-
required: O.none,
|
|
466
|
-
allOf: O.none,
|
|
467
|
-
oneOf: O.none,
|
|
468
|
-
anyOf: O.none,
|
|
469
|
-
not: O.none,
|
|
470
|
-
default: O.none,
|
|
471
|
-
},
|
|
472
|
-
photoId: {
|
|
473
|
-
title: O.none,
|
|
310
|
+
}),
|
|
311
|
+
photoId: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
474
312
|
type: O.some('string'),
|
|
475
313
|
in: O.some('body'),
|
|
476
|
-
|
|
477
|
-
additionalProperties: O.none,
|
|
478
|
-
required: O.none,
|
|
479
|
-
allOf: O.none,
|
|
480
|
-
oneOf: O.none,
|
|
481
|
-
anyOf: O.none,
|
|
482
|
-
not: O.none,
|
|
483
|
-
default: O.none,
|
|
484
|
-
},
|
|
314
|
+
}),
|
|
485
315
|
}),
|
|
486
316
|
required: O.some(['photoId']),
|
|
487
317
|
additionalProperties: O.some(false),
|
|
488
|
-
|
|
489
|
-
oneOf: O.none,
|
|
490
|
-
anyOf: O.none,
|
|
491
|
-
not: O.none,
|
|
492
|
-
in: O.none,
|
|
493
|
-
default: O.none,
|
|
494
|
-
};
|
|
318
|
+
});
|
|
495
319
|
const payload = getGenerateHandlerInput({ input });
|
|
496
320
|
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
497
321
|
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
498
|
-
|
|
499
|
-
|
|
500
|
-
|
|
322
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
323
|
+
import { GetPhotoInput } from "./input";
|
|
324
|
+
import { GetPhotoOutput } from "./output";
|
|
501
325
|
|
|
502
326
|
export const getPhotoHandler = OperationHandlerSetup.configureHandler<
|
|
503
327
|
OpenApiTestAuth,
|
|
@@ -512,4 +336,38 @@ describe('GenerateHandler', () => {
|
|
|
512
336
|
)
|
|
513
337
|
);`)).toEqual(generatedHandler);
|
|
514
338
|
});
|
|
339
|
+
it('it should generate a handler with a nullable body input', () => {
|
|
340
|
+
const input = (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
341
|
+
type: O.some('object'),
|
|
342
|
+
properties: O.some({
|
|
343
|
+
photoId: (0, SchemaGenerator_1.generateNonArraySchemaObject)({
|
|
344
|
+
type: O.some('string'),
|
|
345
|
+
in: O.some('body'),
|
|
346
|
+
nullable: O.some(true),
|
|
347
|
+
}),
|
|
348
|
+
}),
|
|
349
|
+
required: O.none,
|
|
350
|
+
additionalProperties: O.some(false),
|
|
351
|
+
});
|
|
352
|
+
const payload = getGenerateHandlerInput({ input });
|
|
353
|
+
const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
|
|
354
|
+
expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
355
|
+
import { castUndefinedPropertyToNull } from "@trayio/commons/dynamictype/DynamicType";
|
|
356
|
+
import { OpenApiTestAuth } from "../OpenApiTestAuth";
|
|
357
|
+
import { GetPhotoInput } from "./input";
|
|
358
|
+
import { GetPhotoOutput } from "./output";
|
|
359
|
+
|
|
360
|
+
export const getPhotoHandler = OperationHandlerSetup.configureHandler<
|
|
361
|
+
OpenApiTestAuth,
|
|
362
|
+
GetPhotoInput,
|
|
363
|
+
GetPhotoOutput
|
|
364
|
+
>((handler) =>
|
|
365
|
+
handler.usingHttp((http) =>
|
|
366
|
+
http
|
|
367
|
+
.get("https://jsonplaceholder.typicode.com/photos")
|
|
368
|
+
.handleRequest((ctx, input, request) => {let requestBuilder = request; return requestBuilder.withBodyAsJson(castUndefinedPropertyToNull({ photoId: input.photoId }))})
|
|
369
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
|
|
370
|
+
)
|
|
371
|
+
);`)).toEqual(generatedHandler);
|
|
372
|
+
});
|
|
515
373
|
});
|
|
@@ -51,7 +51,7 @@ const getDefaultValue = (prop) => (0, function_1.pipe)(prop.default, O.fold(() =
|
|
|
51
51
|
if (defaultEntry.length === 0) {
|
|
52
52
|
return getDefaultValue({ ...prop, default: O.none });
|
|
53
53
|
}
|
|
54
|
-
return defaultEntry[0]
|
|
54
|
+
return `'${defaultEntry[0]}'`;
|
|
55
55
|
}
|
|
56
56
|
switch (typeof defaultEntry) {
|
|
57
57
|
case 'string':
|