@trayio/tray-openapi 2.6.0 → 2.8.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/OpenApiSchemaImporter.d.ts +4 -2
- package/dist/OpenApiSchemaImporter.d.ts.map +1 -1
- package/dist/OpenApiSchemaImporter.js +49 -22
- package/dist/OpenApiSchemaImporter.test.js +58 -4
- package/dist/OpenApiTypeDescriptors.d.ts +10 -5
- package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
- package/dist/OpenApiTypeDescriptors.js +11 -1
- package/dist/ResolveOptionValues.d.ts +3 -0
- package/dist/ResolveOptionValues.d.ts.map +1 -0
- package/dist/{connector/input/TransformInput.js → ResolveOptionValues.js} +16 -27
- package/dist/ResolveOptionValues.test.d.ts +2 -0
- package/dist/ResolveOptionValues.test.d.ts.map +1 -0
- package/dist/ResolveOptionValues.test.js +91 -0
- package/dist/{GenerateHandler.d.ts → file-generators/GenerateHandler.d.ts} +2 -7
- package/dist/file-generators/GenerateHandler.d.ts.map +1 -0
- package/dist/{GenerateHandler.js → file-generators/GenerateHandler.js} +53 -16
- package/dist/file-generators/GenerateHandler.test.d.ts +2 -0
- package/dist/file-generators/GenerateHandler.test.d.ts.map +1 -0
- package/dist/{GenerateHander.test.js → file-generators/GenerateHandler.test.js} +119 -33
- package/dist/file-generators/GenerateHandlerTest.d.ts +9 -0
- package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -0
- package/dist/file-generators/GenerateHandlerTest.js +76 -0
- package/dist/file-generators/GenerateHandlerTest.test.d.ts +2 -0
- package/dist/file-generators/GenerateHandlerTest.test.d.ts.map +1 -0
- package/dist/file-generators/GenerateHandlerTest.test.js +355 -0
- package/dist/file-generators/GenerateOperationJson.d.ts +4 -0
- package/dist/file-generators/GenerateOperationJson.d.ts.map +1 -0
- package/dist/file-generators/GenerateOperationJson.js +43 -0
- package/dist/file-generators/GenerateOperationJson.test.d.ts +2 -0
- package/dist/file-generators/GenerateOperationJson.test.d.ts.map +1 -0
- package/dist/file-generators/GenerateOperationJson.test.js +77 -0
- package/dist/file-generators/types/GenerateInputSchema.d.ts +4 -0
- package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -0
- package/dist/{connector/input/ProcessInput.js → file-generators/types/GenerateInputSchema.js} +31 -14
- package/dist/file-generators/types/GenerateInputSchema.test.d.ts +2 -0
- package/dist/file-generators/types/GenerateInputSchema.test.d.ts.map +1 -0
- package/dist/{connector/input/ProcessInput.test.js → file-generators/types/GenerateInputSchema.test.js} +25 -14
- package/dist/file-generators/types/GenerateInputTypes.d.ts +4 -0
- package/dist/file-generators/types/GenerateInputTypes.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateInputTypes.js +39 -0
- package/dist/file-generators/types/GenerateOutput.d.ts +9 -0
- package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateOutput.js +54 -0
- package/dist/file-generators/types/GenerateOutput.test.d.ts +2 -0
- package/dist/file-generators/types/GenerateOutput.test.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateOutput.test.js +197 -0
- package/dist/file-generators/types/JsonSchemaToTypescriptOptions.d.ts.map +1 -0
- package/package.json +4 -2
- package/dist/GenerateHander.test.d.ts +0 -2
- package/dist/GenerateHander.test.d.ts.map +0 -1
- package/dist/GenerateHandler.d.ts.map +0 -1
- package/dist/connector/JsonSchemaToTypescriptOptions.d.ts.map +0 -1
- package/dist/connector/input/GenerateInput.d.ts +0 -8
- package/dist/connector/input/GenerateInput.d.ts.map +0 -1
- package/dist/connector/input/GenerateInput.js +0 -8
- package/dist/connector/input/GenerateInput.test.d.ts +0 -2
- package/dist/connector/input/GenerateInput.test.d.ts.map +0 -1
- package/dist/connector/input/GenerateInput.test.js +0 -133
- package/dist/connector/input/ProcessInput.d.ts +0 -4
- package/dist/connector/input/ProcessInput.d.ts.map +0 -1
- package/dist/connector/input/ProcessInput.test.d.ts +0 -2
- package/dist/connector/input/ProcessInput.test.d.ts.map +0 -1
- package/dist/connector/input/TransformInput.d.ts +0 -4
- package/dist/connector/input/TransformInput.d.ts.map +0 -1
- package/dist/connector/input/TransformInput.test.d.ts +0 -2
- package/dist/connector/input/TransformInput.test.d.ts.map +0 -1
- package/dist/connector/input/TransformInput.test.js +0 -75
- /package/dist/{connector → file-generators/types}/JsonSchemaToTypescriptOptions.d.ts +0 -0
- /package/dist/{connector → file-generators/types}/JsonSchemaToTypescriptOptions.js +0 -0
|
@@ -0,0 +1,355 @@
|
|
|
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
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
27
|
+
const GenerateHandlerTest_1 = require("./GenerateHandlerTest");
|
|
28
|
+
describe('GenerateHandlerTest', () => {
|
|
29
|
+
it('should generate a handler test with inputs and outputs', () => {
|
|
30
|
+
const input = {
|
|
31
|
+
operationNameCamelCase: 'getItem',
|
|
32
|
+
input: {
|
|
33
|
+
type: 'object',
|
|
34
|
+
properties: {
|
|
35
|
+
id: {
|
|
36
|
+
type: 'integer',
|
|
37
|
+
format: 'int64',
|
|
38
|
+
},
|
|
39
|
+
name: {
|
|
40
|
+
type: 'string',
|
|
41
|
+
},
|
|
42
|
+
},
|
|
43
|
+
required: ['id', 'name'],
|
|
44
|
+
additionalProperties: false,
|
|
45
|
+
},
|
|
46
|
+
output: {
|
|
47
|
+
type: 'object',
|
|
48
|
+
properties: {
|
|
49
|
+
id: {
|
|
50
|
+
type: 'integer',
|
|
51
|
+
format: 'int64',
|
|
52
|
+
},
|
|
53
|
+
name: {
|
|
54
|
+
type: 'string',
|
|
55
|
+
},
|
|
56
|
+
},
|
|
57
|
+
required: ['id'],
|
|
58
|
+
additionalProperties: false,
|
|
59
|
+
},
|
|
60
|
+
};
|
|
61
|
+
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
62
|
+
if (E.isLeft(result)) {
|
|
63
|
+
console.log(result.left);
|
|
64
|
+
throw new Error('Expected right');
|
|
65
|
+
}
|
|
66
|
+
expect(`import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
67
|
+
import { OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
68
|
+
import { getItemHandler } from './handler';
|
|
69
|
+
import '@trayio/cdk-runtime/connector/operation/OperationHandlerTestRunner';
|
|
70
|
+
|
|
71
|
+
OperationHandlerTestSetup.configureHandlerTest(getItemHandler, (handlerTest) =>
|
|
72
|
+
handlerTest
|
|
73
|
+
.usingHandlerContext('test')
|
|
74
|
+
.nothingBeforeAll()
|
|
75
|
+
.testCase('should ${input.operationNameCamelCase}', (testCase) =>
|
|
76
|
+
testCase
|
|
77
|
+
.givenNothing()
|
|
78
|
+
.when(() => ({ id: 2, name: 'test' }))
|
|
79
|
+
.then(({ output }) => {
|
|
80
|
+
// console.log(output);
|
|
81
|
+
const outputValue =
|
|
82
|
+
OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
83
|
+
expect(outputValue.id).toEqual(2);
|
|
84
|
+
expect(outputValue.name).toEqual('test');
|
|
85
|
+
})
|
|
86
|
+
.finallyDoNothing()
|
|
87
|
+
)
|
|
88
|
+
.nothingAfterAll()
|
|
89
|
+
);`.replace(/\s/g, '')).toEqual(result.right.replace(/\s/g, ''));
|
|
90
|
+
});
|
|
91
|
+
it('should generate a handler test with empty inputs', () => {
|
|
92
|
+
const input = {
|
|
93
|
+
operationNameCamelCase: 'getItem',
|
|
94
|
+
input: {},
|
|
95
|
+
output: {
|
|
96
|
+
type: 'object',
|
|
97
|
+
properties: {
|
|
98
|
+
success: {
|
|
99
|
+
type: 'boolean',
|
|
100
|
+
},
|
|
101
|
+
},
|
|
102
|
+
required: ['success'],
|
|
103
|
+
additionalProperties: false,
|
|
104
|
+
},
|
|
105
|
+
};
|
|
106
|
+
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
107
|
+
if (E.isLeft(result)) {
|
|
108
|
+
console.log(result.left);
|
|
109
|
+
throw new Error('Expected right');
|
|
110
|
+
}
|
|
111
|
+
expect(`import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
112
|
+
import { OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
113
|
+
import { getItemHandler } from './handler';
|
|
114
|
+
import '@trayio/cdk-runtime/connector/operation/OperationHandlerTestRunner';
|
|
115
|
+
|
|
116
|
+
OperationHandlerTestSetup.configureHandlerTest(getItemHandler, (handlerTest) =>
|
|
117
|
+
handlerTest
|
|
118
|
+
.usingHandlerContext('test')
|
|
119
|
+
.nothingBeforeAll()
|
|
120
|
+
.testCase('should ${input.operationNameCamelCase}', (testCase) =>
|
|
121
|
+
testCase
|
|
122
|
+
.givenNothing()
|
|
123
|
+
.when(() => ({}))
|
|
124
|
+
.then(({ output }) => {
|
|
125
|
+
// console.log(output);
|
|
126
|
+
const outputValue =
|
|
127
|
+
OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
128
|
+
expect(outputValue.success).toEqual(true);
|
|
129
|
+
})
|
|
130
|
+
.finallyDoNothing()
|
|
131
|
+
)
|
|
132
|
+
.nothingAfterAll()
|
|
133
|
+
);`.replace(/\s/g, '')).toEqual(result.right.replace(/\s/g, ''));
|
|
134
|
+
});
|
|
135
|
+
it('should generate a handler test with a basic object input and output type', () => {
|
|
136
|
+
const input = {
|
|
137
|
+
operationNameCamelCase: 'createPerson',
|
|
138
|
+
input: {
|
|
139
|
+
type: 'object',
|
|
140
|
+
properties: {
|
|
141
|
+
metadata: {
|
|
142
|
+
type: 'object',
|
|
143
|
+
properties: {
|
|
144
|
+
name: {
|
|
145
|
+
type: 'string',
|
|
146
|
+
},
|
|
147
|
+
age: {
|
|
148
|
+
type: 'integer',
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
},
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
output: {
|
|
155
|
+
type: 'object',
|
|
156
|
+
properties: {
|
|
157
|
+
parents: {
|
|
158
|
+
type: 'object',
|
|
159
|
+
properties: {
|
|
160
|
+
child: {
|
|
161
|
+
type: 'string',
|
|
162
|
+
},
|
|
163
|
+
},
|
|
164
|
+
},
|
|
165
|
+
},
|
|
166
|
+
},
|
|
167
|
+
};
|
|
168
|
+
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
169
|
+
if (E.isLeft(result)) {
|
|
170
|
+
console.log(result.left);
|
|
171
|
+
throw new Error('Expected right');
|
|
172
|
+
}
|
|
173
|
+
expect(`import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
174
|
+
import { OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
175
|
+
import { createPersonHandler } from './handler';
|
|
176
|
+
import '@trayio/cdk-runtime/connector/operation/OperationHandlerTestRunner';
|
|
177
|
+
|
|
178
|
+
OperationHandlerTestSetup.configureHandlerTest(createPersonHandler, (handlerTest) =>
|
|
179
|
+
handlerTest
|
|
180
|
+
.usingHandlerContext('test')
|
|
181
|
+
.nothingBeforeAll()
|
|
182
|
+
.testCase('should ${input.operationNameCamelCase}', (testCase) =>
|
|
183
|
+
testCase
|
|
184
|
+
.givenNothing()
|
|
185
|
+
.when(() => ({ metadata: { name: 'test', age: 2 }}))
|
|
186
|
+
.then(({ output }) => {
|
|
187
|
+
// console.log(output);
|
|
188
|
+
const outputValue =
|
|
189
|
+
OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
190
|
+
expect(outputValue.parents).toEqual({child: 'test'});
|
|
191
|
+
})
|
|
192
|
+
.finallyDoNothing()
|
|
193
|
+
)
|
|
194
|
+
.nothingAfterAll()
|
|
195
|
+
);`.replace(/\s/g, '')).toEqual(result.right.replace(/\s/g, ''));
|
|
196
|
+
});
|
|
197
|
+
it('should generate a handler test with a basic array input and output type', () => {
|
|
198
|
+
const input = {
|
|
199
|
+
operationNameCamelCase: 'listItems',
|
|
200
|
+
input: {
|
|
201
|
+
type: 'object',
|
|
202
|
+
properties: {
|
|
203
|
+
ids: {
|
|
204
|
+
type: 'array',
|
|
205
|
+
items: {
|
|
206
|
+
type: 'integer',
|
|
207
|
+
},
|
|
208
|
+
},
|
|
209
|
+
},
|
|
210
|
+
},
|
|
211
|
+
output: {
|
|
212
|
+
type: 'object',
|
|
213
|
+
properties: {
|
|
214
|
+
parents: {
|
|
215
|
+
type: 'array',
|
|
216
|
+
items: {
|
|
217
|
+
type: 'string',
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
},
|
|
221
|
+
},
|
|
222
|
+
};
|
|
223
|
+
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
224
|
+
if (E.isLeft(result)) {
|
|
225
|
+
console.log(result.left);
|
|
226
|
+
throw new Error('Expected right');
|
|
227
|
+
}
|
|
228
|
+
expect(`import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
229
|
+
import { OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
230
|
+
import { listItemsHandler } from './handler';
|
|
231
|
+
import '@trayio/cdk-runtime/connector/operation/OperationHandlerTestRunner';
|
|
232
|
+
|
|
233
|
+
OperationHandlerTestSetup.configureHandlerTest(listItemsHandler, (handlerTest) =>
|
|
234
|
+
handlerTest
|
|
235
|
+
.usingHandlerContext('test')
|
|
236
|
+
.nothingBeforeAll()
|
|
237
|
+
.testCase('should ${input.operationNameCamelCase}', (testCase) =>
|
|
238
|
+
testCase
|
|
239
|
+
.givenNothing()
|
|
240
|
+
.when(() => ({ ids: [2] }))
|
|
241
|
+
.then(({ output }) => {
|
|
242
|
+
// console.log(output);
|
|
243
|
+
const outputValue =
|
|
244
|
+
OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
245
|
+
expect(outputValue.parents).toEqual(['test']);
|
|
246
|
+
})
|
|
247
|
+
.finallyDoNothing()
|
|
248
|
+
)
|
|
249
|
+
.nothingAfterAll()
|
|
250
|
+
);`.replace(/\s/g, '')).toEqual(result.right.replace(/\s/g, ''));
|
|
251
|
+
});
|
|
252
|
+
it('should generate a handler test with a complex object output type', () => {
|
|
253
|
+
const input = {
|
|
254
|
+
operationNameCamelCase: 'listItems',
|
|
255
|
+
input: {},
|
|
256
|
+
output: {
|
|
257
|
+
type: 'object',
|
|
258
|
+
properties: {
|
|
259
|
+
parents: {
|
|
260
|
+
type: 'object',
|
|
261
|
+
properties: {
|
|
262
|
+
child: {
|
|
263
|
+
type: 'string',
|
|
264
|
+
},
|
|
265
|
+
valueList: {
|
|
266
|
+
type: 'array',
|
|
267
|
+
items: {
|
|
268
|
+
type: 'string',
|
|
269
|
+
},
|
|
270
|
+
},
|
|
271
|
+
},
|
|
272
|
+
},
|
|
273
|
+
},
|
|
274
|
+
},
|
|
275
|
+
};
|
|
276
|
+
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
277
|
+
if (E.isLeft(result)) {
|
|
278
|
+
console.log(result.left);
|
|
279
|
+
throw new Error('Expected right');
|
|
280
|
+
}
|
|
281
|
+
expect(`import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
282
|
+
import { OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
283
|
+
import { listItemsHandler } from './handler';
|
|
284
|
+
import '@trayio/cdk-runtime/connector/operation/OperationHandlerTestRunner';
|
|
285
|
+
|
|
286
|
+
OperationHandlerTestSetup.configureHandlerTest(listItemsHandler, (handlerTest) =>
|
|
287
|
+
handlerTest
|
|
288
|
+
.usingHandlerContext('test')
|
|
289
|
+
.nothingBeforeAll()
|
|
290
|
+
.testCase('should ${input.operationNameCamelCase}', (testCase) =>
|
|
291
|
+
testCase
|
|
292
|
+
.givenNothing()
|
|
293
|
+
.when(() => ({}))
|
|
294
|
+
.then(({ output }) => {
|
|
295
|
+
// console.log(output);
|
|
296
|
+
const outputValue =
|
|
297
|
+
OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
298
|
+
expect(outputValue.parents).toEqual({child: 'test', valueList: ['test']});
|
|
299
|
+
})
|
|
300
|
+
.finallyDoNothing()
|
|
301
|
+
)
|
|
302
|
+
.nothingAfterAll()
|
|
303
|
+
);`.replace(/\s/g, '')).toEqual(result.right.replace(/\s/g, ''));
|
|
304
|
+
});
|
|
305
|
+
it('should generate a handler test with a complex array output type', () => {
|
|
306
|
+
const input = {
|
|
307
|
+
operationNameCamelCase: 'listItems',
|
|
308
|
+
input: {},
|
|
309
|
+
output: {
|
|
310
|
+
type: 'object',
|
|
311
|
+
properties: {
|
|
312
|
+
parents: {
|
|
313
|
+
type: 'array',
|
|
314
|
+
items: {
|
|
315
|
+
type: 'object',
|
|
316
|
+
properties: {
|
|
317
|
+
child: {
|
|
318
|
+
type: 'string',
|
|
319
|
+
},
|
|
320
|
+
},
|
|
321
|
+
},
|
|
322
|
+
},
|
|
323
|
+
},
|
|
324
|
+
},
|
|
325
|
+
};
|
|
326
|
+
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
327
|
+
if (E.isLeft(result)) {
|
|
328
|
+
console.log(result.left);
|
|
329
|
+
throw new Error('Expected right');
|
|
330
|
+
}
|
|
331
|
+
expect(`import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
|
|
332
|
+
import { OperationHandlerResult } from '@trayio/cdk-dsl/connector/operation/OperationHandler';
|
|
333
|
+
import { listItemsHandler } from './handler';
|
|
334
|
+
import '@trayio/cdk-runtime/connector/operation/OperationHandlerTestRunner';
|
|
335
|
+
|
|
336
|
+
OperationHandlerTestSetup.configureHandlerTest(listItemsHandler, (handlerTest) =>
|
|
337
|
+
handlerTest
|
|
338
|
+
.usingHandlerContext('test')
|
|
339
|
+
.nothingBeforeAll()
|
|
340
|
+
.testCase('should ${input.operationNameCamelCase}', (testCase) =>
|
|
341
|
+
testCase
|
|
342
|
+
.givenNothing()
|
|
343
|
+
.when(() => ({}))
|
|
344
|
+
.then(({ output }) => {
|
|
345
|
+
// console.log(output);
|
|
346
|
+
const outputValue =
|
|
347
|
+
OperationHandlerResult.getSuccessfulValueOrFail(output);
|
|
348
|
+
expect(outputValue.parents).toEqual([{child: 'test'}]);
|
|
349
|
+
})
|
|
350
|
+
.finallyDoNothing()
|
|
351
|
+
)
|
|
352
|
+
.nothingAfterAll()
|
|
353
|
+
);`.replace(/\s/g, '')).toEqual(result.right.replace(/\s/g, ''));
|
|
354
|
+
});
|
|
355
|
+
});
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
2
|
+
import { FileStorage } from '@trayio/commons/file/File';
|
|
3
|
+
export declare const generateOperationJson: (fileStorage: FileStorage, operationDirPath: string, operationNameSnakeCase: string, operationNameKebabCase: string, operationDescription: string) => TE.TaskEither<Error, undefined>;
|
|
4
|
+
//# sourceMappingURL=GenerateOperationJson.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateOperationJson.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateOperationJson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAEvC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAGxD,eAAO,MAAM,qBAAqB,gBACpB,WAAW,oBACN,MAAM,0BACA,MAAM,0BACN,MAAM,wBACR,MAAM,KAC1B,GAAG,UAAU,CAAC,KAAK,EAAE,SAAS,CAoBhC,CAAC"}
|
|
@@ -0,0 +1,43 @@
|
|
|
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
|
+
};
|
|
25
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
+
exports.generateOperationJson = void 0;
|
|
27
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
28
|
+
const function_1 = require("fp-ts/function");
|
|
29
|
+
const stream_1 = require("stream");
|
|
30
|
+
const generateOperationJson = (fileStorage, operationDirPath, operationNameSnakeCase, operationNameKebabCase, operationDescription) => {
|
|
31
|
+
const operationJson = {
|
|
32
|
+
name: operationNameSnakeCase,
|
|
33
|
+
title: operationNameKebabCase,
|
|
34
|
+
description: operationDescription,
|
|
35
|
+
};
|
|
36
|
+
const writeOperationJson = fileStorage.write({
|
|
37
|
+
content: stream_1.Readable.from(JSON.stringify(operationJson)),
|
|
38
|
+
key: `${operationDirPath}/operation.json`,
|
|
39
|
+
metadata: { name: 'operation.json' },
|
|
40
|
+
});
|
|
41
|
+
return (0, function_1.pipe)(writeOperationJson, TE.mapLeft((error) => new Error(`Failed to generate operation.json for operation: ${error}`)), TE.map(() => undefined));
|
|
42
|
+
};
|
|
43
|
+
exports.generateOperationJson = generateOperationJson;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateOperationJson.test.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateOperationJson.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,77 @@
|
|
|
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
|
+
};
|
|
25
|
+
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
26
|
+
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
27
|
+
return new (P || (P = Promise))(function (resolve, reject) {
|
|
28
|
+
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
|
|
29
|
+
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
|
|
30
|
+
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
|
|
31
|
+
step((generator = generator.apply(thisArg, _arguments || [])).next());
|
|
32
|
+
});
|
|
33
|
+
};
|
|
34
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
36
|
+
const FakeFileStorage_1 = require("@trayio/commons/file/FakeFileStorage");
|
|
37
|
+
const GenerateOperationJson_1 = require("./GenerateOperationJson");
|
|
38
|
+
describe('generateOperationJson', () => {
|
|
39
|
+
const fileStorage = new FakeFileStorage_1.FakeFileStorage();
|
|
40
|
+
it('should generate operation.json file', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
const writeSpy = jest.spyOn(fileStorage, 'write');
|
|
42
|
+
const operationDirPath = '/path/to/operation';
|
|
43
|
+
const operationNameSnakeCase = 'get_photo';
|
|
44
|
+
const operationNameKebabCase = 'get-photo';
|
|
45
|
+
const operationDescription = 'Get photo operation';
|
|
46
|
+
const result = yield (0, GenerateOperationJson_1.generateOperationJson)(fileStorage, operationDirPath, operationNameSnakeCase, operationNameKebabCase, operationDescription)();
|
|
47
|
+
if (E.isLeft(result)) {
|
|
48
|
+
throw new Error('expected result to be right');
|
|
49
|
+
}
|
|
50
|
+
expect(writeSpy).toHaveBeenCalledWith({
|
|
51
|
+
content: expect.anything(),
|
|
52
|
+
key: '/path/to/operation/operation.json',
|
|
53
|
+
metadata: { name: 'operation.json' },
|
|
54
|
+
});
|
|
55
|
+
expect(result.right).toBeUndefined();
|
|
56
|
+
expect(fileStorage.files.has('/path/to/operation/operation.json')).toEqual(true);
|
|
57
|
+
}));
|
|
58
|
+
it('should generate correct data for operation.json', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
59
|
+
const operationDirPath = '/path/to/operation';
|
|
60
|
+
const operationNameSnakeCase = 'get_photo';
|
|
61
|
+
const operationNameKebabCase = 'get-photo';
|
|
62
|
+
const operationDescription = 'Get photo operation';
|
|
63
|
+
const result = yield (0, GenerateOperationJson_1.generateOperationJson)(fileStorage, operationDirPath, operationNameSnakeCase, operationNameKebabCase, operationDescription)();
|
|
64
|
+
if (E.isLeft(result)) {
|
|
65
|
+
throw new Error('expected result to be right');
|
|
66
|
+
}
|
|
67
|
+
const operationJson = fileStorage.files.get('/path/to/operation/operation.json');
|
|
68
|
+
if (operationJson === undefined) {
|
|
69
|
+
throw new Error('expected operationJson to be defined');
|
|
70
|
+
}
|
|
71
|
+
expect(operationJson.content.read()).toEqual(JSON.stringify({
|
|
72
|
+
name: 'get_photo',
|
|
73
|
+
title: 'get-photo',
|
|
74
|
+
description: 'Get photo operation',
|
|
75
|
+
}));
|
|
76
|
+
}));
|
|
77
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateInputSchema.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateInputSchema.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,IAAI,EAAa,MAAM,8BAA8B,CAAC;AAmE/D,eAAO,MAAM,mBAAmB,aAAc,IAAI,KAAG,WAsBpD,CAAC"}
|
package/dist/{connector/input/ProcessInput.js → file-generators/types/GenerateInputSchema.js}
RENAMED
|
@@ -23,11 +23,10 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
26
|
+
exports.generateInputSchema = void 0;
|
|
27
27
|
const lodash_1 = require("lodash");
|
|
28
28
|
const O = __importStar(require("fp-ts/Option"));
|
|
29
|
-
const
|
|
30
|
-
const TransformInput_1 = require("./TransformInput");
|
|
29
|
+
const openapi_schema_to_json_schema_1 = require("@openapi-contrib/openapi-schema-to-json-schema");
|
|
31
30
|
const mergeRequired = (params, body) => {
|
|
32
31
|
if ((0, lodash_1.isArray)(body.required) && (0, lodash_1.isArray)(params.required)) {
|
|
33
32
|
return [...body.required, ...params.required];
|
|
@@ -40,6 +39,31 @@ const mergeParamsAndBody = (params, body) => ({
|
|
|
40
39
|
required: mergeRequired(params, body),
|
|
41
40
|
additionalProperties: false,
|
|
42
41
|
});
|
|
42
|
+
const transformInput = (parameters) => {
|
|
43
|
+
const transformedParameters = {};
|
|
44
|
+
const requiredParameters = [];
|
|
45
|
+
parameters.forEach((parameter) => {
|
|
46
|
+
const parameterWithJsdocAnnotation = {
|
|
47
|
+
name: parameter.name,
|
|
48
|
+
description: `@description ${parameter.description}`,
|
|
49
|
+
required: parameter.required,
|
|
50
|
+
schema: {
|
|
51
|
+
type: parameter.schema.type,
|
|
52
|
+
format: O.toNullable(parameter.schema.format) || undefined,
|
|
53
|
+
},
|
|
54
|
+
};
|
|
55
|
+
transformedParameters[parameter.name] = Object.assign(Object.assign({}, (0, openapi_schema_to_json_schema_1.fromParameter)(parameterWithJsdocAnnotation)), { in: parameter.in });
|
|
56
|
+
if (parameter.required === true) {
|
|
57
|
+
requiredParameters.push(parameter.name);
|
|
58
|
+
}
|
|
59
|
+
});
|
|
60
|
+
return {
|
|
61
|
+
type: 'object',
|
|
62
|
+
properties: Object.assign({}, transformedParameters),
|
|
63
|
+
required: [...requiredParameters],
|
|
64
|
+
additionalProperties: false,
|
|
65
|
+
};
|
|
66
|
+
};
|
|
43
67
|
const getApplicationJsonMediaType = (content) => {
|
|
44
68
|
// TODO: we should support any value here, but there may also be more than 1 media type so we need to iterate through
|
|
45
69
|
// and combine all the schemas within into a single set of inputs
|
|
@@ -50,17 +74,17 @@ const getApplicationJsonMediaType = (content) => {
|
|
|
50
74
|
const mediaTypes = Object.keys(content);
|
|
51
75
|
throw new Error(`Unsupported media type: ${mediaTypes}`);
|
|
52
76
|
};
|
|
53
|
-
const
|
|
77
|
+
const generateInputSchema = (endpoint) => {
|
|
54
78
|
const parameters = O.toNullable(endpoint.parameters);
|
|
55
79
|
const requestBody = O.toNullable(endpoint.requestBody);
|
|
56
80
|
if (parameters && !requestBody) {
|
|
57
|
-
return
|
|
81
|
+
return transformInput(parameters);
|
|
58
82
|
}
|
|
59
83
|
if (requestBody && !parameters) {
|
|
60
84
|
return getApplicationJsonMediaType(requestBody.content).schema;
|
|
61
85
|
}
|
|
62
86
|
if (requestBody && parameters) {
|
|
63
|
-
const params =
|
|
87
|
+
const params = transformInput(parameters);
|
|
64
88
|
const body = getApplicationJsonMediaType(requestBody.content).schema;
|
|
65
89
|
return mergeParamsAndBody(params, body);
|
|
66
90
|
}
|
|
@@ -71,11 +95,4 @@ const extractInput = (endpoint) => {
|
|
|
71
95
|
additionalProperties: false,
|
|
72
96
|
};
|
|
73
97
|
};
|
|
74
|
-
|
|
75
|
-
const input = extractInput(endpoint);
|
|
76
|
-
return (0, GenerateInput_1.generateInput)({
|
|
77
|
-
operationNameCamelCase: endpoint.operationId,
|
|
78
|
-
parameters: input,
|
|
79
|
-
});
|
|
80
|
-
};
|
|
81
|
-
exports.processInput = processInput;
|
|
98
|
+
exports.generateInputSchema = generateInputSchema;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateInputSchema.test.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateInputSchema.test.ts"],"names":[],"mappings":""}
|