@trayio/tray-openapi 2.9.0 → 2.10.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 +3 -1
- package/dist/OpenApiCodecs.d.ts.map +1 -1
- package/dist/OpenApiCodecs.js +3 -1
- package/dist/OpenApiSchemaImporter.d.ts +1 -0
- package/dist/OpenApiSchemaImporter.d.ts.map +1 -1
- package/dist/OpenApiSchemaImporter.js +25 -15
- package/dist/OpenApiTypeDescriptors.d.ts +32 -20
- package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
- package/dist/OpenApiTypeDescriptors.js +59 -36
- package/dist/file-generators/GenerateHandler.d.ts +4 -4
- package/dist/file-generators/GenerateHandler.d.ts.map +1 -1
- package/dist/file-generators/GenerateHandler.js +43 -46
- package/dist/file-generators/GenerateHandler.test.js +194 -38
- package/dist/file-generators/GenerateHandlerTest.d.ts +3 -3
- package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -1
- package/dist/file-generators/GenerateHandlerTest.js +33 -21
- package/dist/file-generators/GenerateHandlerTest.test.js +313 -61
- package/dist/file-generators/GenerateOperationJson.test.js +2 -1
- package/dist/file-generators/types/GenerateInputSchema.d.ts +2 -3
- package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateInputSchema.js +63 -28
- package/dist/file-generators/types/GenerateInputSchema.test.js +72 -104
- package/dist/file-generators/types/GenerateInputType.test.d.ts +2 -0
- package/dist/file-generators/types/GenerateInputType.test.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateInputType.test.js +400 -0
- 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 +10 -8
- package/dist/file-generators/types/GenerateOutput.d.ts +4 -5
- package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateOutput.js +31 -5
- package/dist/file-generators/types/GenerateOutput.test.js +94 -88
- package/package.json +1 -1
- package/dist/ResolveOptionValues.d.ts +0 -3
- package/dist/ResolveOptionValues.d.ts.map +0 -1
- package/dist/ResolveOptionValues.js +0 -43
- package/dist/ResolveOptionValues.test.d.ts +0 -2
- package/dist/ResolveOptionValues.test.d.ts.map +0 -1
- package/dist/ResolveOptionValues.test.js +0 -91
|
@@ -24,38 +24,81 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
const E = __importStar(require("fp-ts/Either"));
|
|
27
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
27
28
|
const GenerateHandlerTest_1 = require("./GenerateHandlerTest");
|
|
28
29
|
describe('GenerateHandlerTest', () => {
|
|
29
30
|
it('should generate a handler test with inputs and outputs', () => {
|
|
30
31
|
const input = {
|
|
31
32
|
operationNameCamelCase: 'getItem',
|
|
32
33
|
input: {
|
|
33
|
-
type: 'object',
|
|
34
|
-
properties: {
|
|
34
|
+
type: O.some('object'),
|
|
35
|
+
properties: O.some({
|
|
35
36
|
id: {
|
|
36
|
-
type: 'integer',
|
|
37
|
+
type: O.some('integer'),
|
|
37
38
|
format: 'int64',
|
|
39
|
+
properties: O.none,
|
|
40
|
+
required: O.none,
|
|
41
|
+
additionalProperties: O.some(false),
|
|
42
|
+
allOf: O.none,
|
|
43
|
+
anyOf: O.none,
|
|
44
|
+
oneOf: O.none,
|
|
45
|
+
not: O.none,
|
|
46
|
+
in: O.none,
|
|
38
47
|
},
|
|
39
48
|
name: {
|
|
40
|
-
type: 'string',
|
|
49
|
+
type: O.some('string'),
|
|
50
|
+
properties: O.none,
|
|
51
|
+
required: O.none,
|
|
52
|
+
additionalProperties: O.some(false),
|
|
53
|
+
allOf: O.none,
|
|
54
|
+
anyOf: O.none,
|
|
55
|
+
oneOf: O.none,
|
|
56
|
+
not: O.none,
|
|
57
|
+
in: O.none,
|
|
41
58
|
},
|
|
42
|
-
},
|
|
43
|
-
required: ['id', 'name'],
|
|
44
|
-
additionalProperties: false,
|
|
59
|
+
}),
|
|
60
|
+
required: O.some(['id', 'name']),
|
|
61
|
+
additionalProperties: O.some(false),
|
|
62
|
+
allOf: O.none,
|
|
63
|
+
anyOf: O.none,
|
|
64
|
+
oneOf: O.none,
|
|
65
|
+
not: O.none,
|
|
66
|
+
in: O.none,
|
|
45
67
|
},
|
|
46
68
|
output: {
|
|
47
|
-
type: 'object',
|
|
48
|
-
properties: {
|
|
69
|
+
type: O.some('object'),
|
|
70
|
+
properties: O.some({
|
|
49
71
|
id: {
|
|
50
|
-
type: 'integer',
|
|
72
|
+
type: O.some('integer'),
|
|
51
73
|
format: 'int64',
|
|
74
|
+
properties: O.none,
|
|
75
|
+
required: O.none,
|
|
76
|
+
additionalProperties: O.some(false),
|
|
77
|
+
allOf: O.none,
|
|
78
|
+
anyOf: O.none,
|
|
79
|
+
oneOf: O.none,
|
|
80
|
+
not: O.none,
|
|
81
|
+
in: O.none,
|
|
52
82
|
},
|
|
53
83
|
name: {
|
|
54
|
-
type: 'string',
|
|
84
|
+
type: O.some('string'),
|
|
85
|
+
properties: O.none,
|
|
86
|
+
required: O.none,
|
|
87
|
+
additionalProperties: O.some(false),
|
|
88
|
+
allOf: O.none,
|
|
89
|
+
anyOf: O.none,
|
|
90
|
+
oneOf: O.none,
|
|
91
|
+
not: O.none,
|
|
92
|
+
in: O.none,
|
|
55
93
|
},
|
|
56
|
-
},
|
|
57
|
-
required: ['id'],
|
|
58
|
-
additionalProperties: false,
|
|
94
|
+
}),
|
|
95
|
+
required: O.some(['id']),
|
|
96
|
+
additionalProperties: O.some(false),
|
|
97
|
+
allOf: O.none,
|
|
98
|
+
anyOf: O.none,
|
|
99
|
+
oneOf: O.none,
|
|
100
|
+
not: O.none,
|
|
101
|
+
in: O.none,
|
|
59
102
|
},
|
|
60
103
|
};
|
|
61
104
|
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
@@ -91,16 +134,39 @@ describe('GenerateHandlerTest', () => {
|
|
|
91
134
|
it('should generate a handler test with empty inputs', () => {
|
|
92
135
|
const input = {
|
|
93
136
|
operationNameCamelCase: 'getItem',
|
|
94
|
-
input: {
|
|
137
|
+
input: {
|
|
138
|
+
type: O.none,
|
|
139
|
+
properties: O.none,
|
|
140
|
+
required: O.none,
|
|
141
|
+
additionalProperties: O.none,
|
|
142
|
+
allOf: O.none,
|
|
143
|
+
anyOf: O.none,
|
|
144
|
+
oneOf: O.none,
|
|
145
|
+
not: O.none,
|
|
146
|
+
in: O.none,
|
|
147
|
+
},
|
|
95
148
|
output: {
|
|
96
|
-
type: 'object',
|
|
97
|
-
properties: {
|
|
149
|
+
type: O.some('object'),
|
|
150
|
+
properties: O.some({
|
|
98
151
|
success: {
|
|
99
|
-
type: 'boolean',
|
|
152
|
+
type: O.some('boolean'),
|
|
153
|
+
properties: O.none,
|
|
154
|
+
required: O.none,
|
|
155
|
+
additionalProperties: O.none,
|
|
156
|
+
allOf: O.none,
|
|
157
|
+
anyOf: O.none,
|
|
158
|
+
oneOf: O.none,
|
|
159
|
+
not: O.none,
|
|
160
|
+
in: O.none,
|
|
100
161
|
},
|
|
101
|
-
},
|
|
102
|
-
required: ['success'],
|
|
103
|
-
additionalProperties: false,
|
|
162
|
+
}),
|
|
163
|
+
required: O.some(['success']),
|
|
164
|
+
additionalProperties: O.some(false),
|
|
165
|
+
allOf: O.none,
|
|
166
|
+
anyOf: O.none,
|
|
167
|
+
oneOf: O.none,
|
|
168
|
+
not: O.none,
|
|
169
|
+
in: O.none,
|
|
104
170
|
},
|
|
105
171
|
};
|
|
106
172
|
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
@@ -136,33 +202,85 @@ describe('GenerateHandlerTest', () => {
|
|
|
136
202
|
const input = {
|
|
137
203
|
operationNameCamelCase: 'createPerson',
|
|
138
204
|
input: {
|
|
139
|
-
type: 'object',
|
|
140
|
-
properties: {
|
|
205
|
+
type: O.some('object'),
|
|
206
|
+
properties: O.some({
|
|
141
207
|
metadata: {
|
|
142
|
-
type: 'object',
|
|
143
|
-
properties: {
|
|
208
|
+
type: O.some('object'),
|
|
209
|
+
properties: O.some({
|
|
144
210
|
name: {
|
|
145
|
-
type: 'string',
|
|
211
|
+
type: O.some('string'),
|
|
212
|
+
properties: O.none,
|
|
213
|
+
required: O.none,
|
|
214
|
+
additionalProperties: O.some(false),
|
|
215
|
+
allOf: O.none,
|
|
216
|
+
anyOf: O.none,
|
|
217
|
+
oneOf: O.none,
|
|
218
|
+
not: O.none,
|
|
219
|
+
in: O.none,
|
|
146
220
|
},
|
|
147
221
|
age: {
|
|
148
|
-
type: 'integer',
|
|
222
|
+
type: O.some('integer'),
|
|
223
|
+
properties: O.none,
|
|
224
|
+
required: O.none,
|
|
225
|
+
additionalProperties: O.some(false),
|
|
226
|
+
allOf: O.none,
|
|
227
|
+
anyOf: O.none,
|
|
228
|
+
oneOf: O.none,
|
|
229
|
+
not: O.none,
|
|
230
|
+
in: O.none,
|
|
149
231
|
},
|
|
150
|
-
},
|
|
232
|
+
}),
|
|
233
|
+
required: O.none,
|
|
234
|
+
additionalProperties: O.some(false),
|
|
235
|
+
allOf: O.none,
|
|
236
|
+
anyOf: O.none,
|
|
237
|
+
oneOf: O.none,
|
|
238
|
+
not: O.none,
|
|
239
|
+
in: O.none,
|
|
151
240
|
},
|
|
152
|
-
},
|
|
241
|
+
}),
|
|
242
|
+
required: O.none,
|
|
243
|
+
additionalProperties: O.some(false),
|
|
244
|
+
allOf: O.none,
|
|
245
|
+
anyOf: O.none,
|
|
246
|
+
oneOf: O.none,
|
|
247
|
+
not: O.none,
|
|
248
|
+
in: O.none,
|
|
153
249
|
},
|
|
154
250
|
output: {
|
|
155
|
-
type: 'object',
|
|
156
|
-
properties: {
|
|
251
|
+
type: O.some('object'),
|
|
252
|
+
properties: O.some({
|
|
157
253
|
parents: {
|
|
158
|
-
type: 'object',
|
|
159
|
-
properties: {
|
|
254
|
+
type: O.some('object'),
|
|
255
|
+
properties: O.some({
|
|
160
256
|
child: {
|
|
161
|
-
type: 'string',
|
|
257
|
+
type: O.some('string'),
|
|
258
|
+
properties: O.none,
|
|
259
|
+
required: O.none,
|
|
260
|
+
additionalProperties: O.some(false),
|
|
261
|
+
allOf: O.none,
|
|
262
|
+
anyOf: O.none,
|
|
263
|
+
oneOf: O.none,
|
|
264
|
+
not: O.none,
|
|
265
|
+
in: O.none,
|
|
162
266
|
},
|
|
163
|
-
},
|
|
267
|
+
}),
|
|
268
|
+
required: O.none,
|
|
269
|
+
additionalProperties: O.some(false),
|
|
270
|
+
allOf: O.none,
|
|
271
|
+
anyOf: O.none,
|
|
272
|
+
oneOf: O.none,
|
|
273
|
+
not: O.none,
|
|
274
|
+
in: O.none,
|
|
164
275
|
},
|
|
165
|
-
},
|
|
276
|
+
}),
|
|
277
|
+
required: O.none,
|
|
278
|
+
additionalProperties: O.some(false),
|
|
279
|
+
allOf: O.none,
|
|
280
|
+
anyOf: O.none,
|
|
281
|
+
oneOf: O.none,
|
|
282
|
+
not: O.none,
|
|
283
|
+
in: O.none,
|
|
166
284
|
},
|
|
167
285
|
};
|
|
168
286
|
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
@@ -198,26 +316,72 @@ describe('GenerateHandlerTest', () => {
|
|
|
198
316
|
const input = {
|
|
199
317
|
operationNameCamelCase: 'listItems',
|
|
200
318
|
input: {
|
|
201
|
-
type: 'object',
|
|
202
|
-
properties: {
|
|
319
|
+
type: O.some('object'),
|
|
320
|
+
properties: O.some({
|
|
203
321
|
ids: {
|
|
204
322
|
type: 'array',
|
|
205
323
|
items: {
|
|
206
|
-
type: 'integer',
|
|
324
|
+
type: O.some('integer'),
|
|
325
|
+
properties: O.none,
|
|
326
|
+
required: O.none,
|
|
327
|
+
additionalProperties: O.some(false),
|
|
328
|
+
allOf: O.none,
|
|
329
|
+
anyOf: O.none,
|
|
330
|
+
oneOf: O.none,
|
|
331
|
+
not: O.none,
|
|
332
|
+
in: O.none,
|
|
207
333
|
},
|
|
334
|
+
properties: O.none,
|
|
335
|
+
required: O.none,
|
|
336
|
+
additionalProperties: O.some(false),
|
|
337
|
+
allOf: O.none,
|
|
338
|
+
anyOf: O.none,
|
|
339
|
+
oneOf: O.none,
|
|
340
|
+
not: O.none,
|
|
341
|
+
in: O.none,
|
|
208
342
|
},
|
|
209
|
-
},
|
|
343
|
+
}),
|
|
344
|
+
required: O.none,
|
|
345
|
+
additionalProperties: O.some(false),
|
|
346
|
+
allOf: O.none,
|
|
347
|
+
anyOf: O.none,
|
|
348
|
+
oneOf: O.none,
|
|
349
|
+
not: O.none,
|
|
350
|
+
in: O.none,
|
|
210
351
|
},
|
|
211
352
|
output: {
|
|
212
|
-
type: 'object',
|
|
213
|
-
properties: {
|
|
353
|
+
type: O.some('object'),
|
|
354
|
+
properties: O.some({
|
|
214
355
|
parents: {
|
|
215
356
|
type: 'array',
|
|
216
357
|
items: {
|
|
217
|
-
type: 'string',
|
|
358
|
+
type: O.some('string'),
|
|
359
|
+
properties: O.none,
|
|
360
|
+
required: O.none,
|
|
361
|
+
additionalProperties: O.some(false),
|
|
362
|
+
allOf: O.none,
|
|
363
|
+
anyOf: O.none,
|
|
364
|
+
oneOf: O.none,
|
|
365
|
+
not: O.none,
|
|
366
|
+
in: O.none,
|
|
218
367
|
},
|
|
368
|
+
properties: O.none,
|
|
369
|
+
required: O.none,
|
|
370
|
+
additionalProperties: O.some(false),
|
|
371
|
+
allOf: O.none,
|
|
372
|
+
anyOf: O.none,
|
|
373
|
+
oneOf: O.none,
|
|
374
|
+
not: O.none,
|
|
375
|
+
in: O.none,
|
|
219
376
|
},
|
|
220
|
-
},
|
|
377
|
+
}),
|
|
378
|
+
required: O.none,
|
|
379
|
+
additionalProperties: O.some(false),
|
|
380
|
+
allOf: O.none,
|
|
381
|
+
anyOf: O.none,
|
|
382
|
+
oneOf: O.none,
|
|
383
|
+
not: O.none,
|
|
384
|
+
in: O.none,
|
|
221
385
|
},
|
|
222
386
|
};
|
|
223
387
|
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
@@ -252,25 +416,73 @@ describe('GenerateHandlerTest', () => {
|
|
|
252
416
|
it('should generate a handler test with a complex object output type', () => {
|
|
253
417
|
const input = {
|
|
254
418
|
operationNameCamelCase: 'listItems',
|
|
255
|
-
input: {
|
|
419
|
+
input: {
|
|
420
|
+
type: O.none,
|
|
421
|
+
properties: O.none,
|
|
422
|
+
required: O.none,
|
|
423
|
+
additionalProperties: O.none,
|
|
424
|
+
allOf: O.none,
|
|
425
|
+
anyOf: O.none,
|
|
426
|
+
oneOf: O.none,
|
|
427
|
+
not: O.none,
|
|
428
|
+
in: O.none,
|
|
429
|
+
},
|
|
256
430
|
output: {
|
|
257
|
-
type: 'object',
|
|
258
|
-
properties: {
|
|
431
|
+
type: O.some('object'),
|
|
432
|
+
properties: O.some({
|
|
259
433
|
parents: {
|
|
260
|
-
type: 'object',
|
|
261
|
-
properties: {
|
|
434
|
+
type: O.some('object'),
|
|
435
|
+
properties: O.some({
|
|
262
436
|
child: {
|
|
263
|
-
type: 'string',
|
|
437
|
+
type: O.some('string'),
|
|
438
|
+
properties: O.none,
|
|
439
|
+
required: O.none,
|
|
440
|
+
additionalProperties: O.none,
|
|
441
|
+
allOf: O.none,
|
|
442
|
+
anyOf: O.none,
|
|
443
|
+
oneOf: O.none,
|
|
444
|
+
not: O.none,
|
|
445
|
+
in: O.none,
|
|
264
446
|
},
|
|
265
447
|
valueList: {
|
|
266
448
|
type: 'array',
|
|
267
449
|
items: {
|
|
268
|
-
type: 'string',
|
|
450
|
+
type: O.some('string'),
|
|
451
|
+
properties: O.none,
|
|
452
|
+
required: O.none,
|
|
453
|
+
additionalProperties: O.none,
|
|
454
|
+
allOf: O.none,
|
|
455
|
+
anyOf: O.none,
|
|
456
|
+
oneOf: O.none,
|
|
457
|
+
not: O.none,
|
|
458
|
+
in: O.none,
|
|
269
459
|
},
|
|
460
|
+
properties: O.none,
|
|
461
|
+
required: O.none,
|
|
462
|
+
additionalProperties: O.some(false),
|
|
463
|
+
allOf: O.none,
|
|
464
|
+
anyOf: O.none,
|
|
465
|
+
oneOf: O.none,
|
|
466
|
+
not: O.none,
|
|
467
|
+
in: O.none,
|
|
270
468
|
},
|
|
271
|
-
},
|
|
469
|
+
}),
|
|
470
|
+
required: O.none,
|
|
471
|
+
additionalProperties: O.some(false),
|
|
472
|
+
allOf: O.none,
|
|
473
|
+
anyOf: O.none,
|
|
474
|
+
oneOf: O.none,
|
|
475
|
+
not: O.none,
|
|
476
|
+
in: O.none,
|
|
272
477
|
},
|
|
273
|
-
},
|
|
478
|
+
}),
|
|
479
|
+
required: O.none,
|
|
480
|
+
additionalProperties: O.some(false),
|
|
481
|
+
allOf: O.none,
|
|
482
|
+
anyOf: O.none,
|
|
483
|
+
oneOf: O.none,
|
|
484
|
+
not: O.none,
|
|
485
|
+
in: O.none,
|
|
274
486
|
},
|
|
275
487
|
};
|
|
276
488
|
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
@@ -305,22 +517,62 @@ describe('GenerateHandlerTest', () => {
|
|
|
305
517
|
it('should generate a handler test with a complex array output type', () => {
|
|
306
518
|
const input = {
|
|
307
519
|
operationNameCamelCase: 'listItems',
|
|
308
|
-
input: {
|
|
520
|
+
input: {
|
|
521
|
+
type: O.none,
|
|
522
|
+
properties: O.none,
|
|
523
|
+
required: O.none,
|
|
524
|
+
additionalProperties: O.none,
|
|
525
|
+
allOf: O.none,
|
|
526
|
+
anyOf: O.none,
|
|
527
|
+
oneOf: O.none,
|
|
528
|
+
not: O.none,
|
|
529
|
+
in: O.none,
|
|
530
|
+
},
|
|
309
531
|
output: {
|
|
310
|
-
type: 'object',
|
|
311
|
-
properties: {
|
|
532
|
+
type: O.some('object'),
|
|
533
|
+
properties: O.some({
|
|
312
534
|
parents: {
|
|
313
535
|
type: 'array',
|
|
314
536
|
items: {
|
|
315
|
-
type: 'object',
|
|
316
|
-
properties: {
|
|
537
|
+
type: O.some('object'),
|
|
538
|
+
properties: O.some({
|
|
317
539
|
child: {
|
|
318
|
-
type: 'string',
|
|
540
|
+
type: O.some('string'),
|
|
541
|
+
properties: O.none,
|
|
542
|
+
required: O.none,
|
|
543
|
+
additionalProperties: O.none,
|
|
544
|
+
allOf: O.none,
|
|
545
|
+
anyOf: O.none,
|
|
546
|
+
oneOf: O.none,
|
|
547
|
+
not: O.none,
|
|
548
|
+
in: O.none,
|
|
319
549
|
},
|
|
320
|
-
},
|
|
550
|
+
}),
|
|
551
|
+
required: O.none,
|
|
552
|
+
additionalProperties: O.none,
|
|
553
|
+
allOf: O.none,
|
|
554
|
+
anyOf: O.none,
|
|
555
|
+
oneOf: O.none,
|
|
556
|
+
not: O.none,
|
|
557
|
+
in: O.none,
|
|
321
558
|
},
|
|
559
|
+
properties: O.none,
|
|
560
|
+
required: O.none,
|
|
561
|
+
additionalProperties: O.some(false),
|
|
562
|
+
allOf: O.none,
|
|
563
|
+
anyOf: O.none,
|
|
564
|
+
oneOf: O.none,
|
|
565
|
+
not: O.none,
|
|
566
|
+
in: O.none,
|
|
322
567
|
},
|
|
323
|
-
},
|
|
568
|
+
}),
|
|
569
|
+
required: O.none,
|
|
570
|
+
additionalProperties: O.some(false),
|
|
571
|
+
allOf: O.none,
|
|
572
|
+
anyOf: O.none,
|
|
573
|
+
oneOf: O.none,
|
|
574
|
+
not: O.none,
|
|
575
|
+
in: O.none,
|
|
324
576
|
},
|
|
325
577
|
};
|
|
326
578
|
const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
|
|
@@ -34,6 +34,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
const E = __importStar(require("fp-ts/Either"));
|
|
36
36
|
const FakeFileStorage_1 = require("@trayio/commons/file/FakeFileStorage");
|
|
37
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
37
38
|
const GenerateOperationJson_1 = require("./GenerateOperationJson");
|
|
38
39
|
describe('generateOperationJson', () => {
|
|
39
40
|
const fileStorage = new FakeFileStorage_1.FakeFileStorage();
|
|
@@ -51,7 +52,7 @@ describe('generateOperationJson', () => {
|
|
|
51
52
|
content: expect.anything(),
|
|
52
53
|
key: '/path/to/operation/operation.json',
|
|
53
54
|
metadata: { name: 'operation.json' },
|
|
54
|
-
});
|
|
55
|
+
}, O.none);
|
|
55
56
|
expect(result.right).toBeUndefined();
|
|
56
57
|
expect(fileStorage.files.has('/path/to/operation/operation.json')).toEqual(true);
|
|
57
58
|
}));
|
|
@@ -1,4 +1,3 @@
|
|
|
1
|
-
import {
|
|
2
|
-
|
|
3
|
-
export declare const generateInputSchema: (endpoint: Path) => JSONSchema4;
|
|
1
|
+
import { Path, SchemaObject } from '../../OpenApiTypeDescriptors';
|
|
2
|
+
export declare const generateInputSchema: (endpoint: Path) => SchemaObject;
|
|
4
3
|
//# sourceMappingURL=GenerateInputSchema.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateInputSchema.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateInputSchema.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GenerateInputSchema.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateInputSchema.ts"],"names":[],"mappings":"AAMA,OAAO,EACN,IAAI,EAGJ,YAAY,EAEZ,MAAM,8BAA8B,CAAC;AA8HtC,eAAO,MAAM,mBAAmB,aAAc,IAAI,KAAG,YAiCpD,CAAC"}
|
|
@@ -27,72 +27,107 @@ exports.generateInputSchema = void 0;
|
|
|
27
27
|
const lodash_1 = require("lodash");
|
|
28
28
|
const O = __importStar(require("fp-ts/Option"));
|
|
29
29
|
const openapi_schema_to_json_schema_1 = require("@openapi-contrib/openapi-schema-to-json-schema");
|
|
30
|
+
const CompositeCodec_1 = require("@trayio/commons/codec/CompositeCodec");
|
|
31
|
+
const RemoveNullValuesCodec_1 = require("@trayio/commons/codec/RemoveNullValuesCodec");
|
|
32
|
+
const OpenApiCodecs_1 = require("../../OpenApiCodecs");
|
|
33
|
+
const OpenApiTypeDescriptors_1 = require("../../OpenApiTypeDescriptors");
|
|
30
34
|
const mergeRequired = (params, body) => {
|
|
31
|
-
|
|
32
|
-
|
|
35
|
+
const requiredBody = O.fold(() => [], (required) => required)(body.required);
|
|
36
|
+
const requiredParams = O.fold(() => [], (required) => required)(params.required);
|
|
37
|
+
if ((0, lodash_1.isArray)(requiredBody) && (0, lodash_1.isArray)(requiredParams)) {
|
|
38
|
+
return [...requiredBody, ...requiredParams];
|
|
33
39
|
}
|
|
34
40
|
return [];
|
|
35
41
|
};
|
|
36
42
|
const mergeParamsAndBody = (params, body) => ({
|
|
37
|
-
type: 'object',
|
|
38
|
-
properties: Object.assign(Object.assign({}, body.properties), params.properties),
|
|
39
|
-
required: mergeRequired(params, body),
|
|
40
|
-
additionalProperties: false,
|
|
43
|
+
type: O.some('object'),
|
|
44
|
+
properties: O.some(Object.assign(Object.assign({}, (O.isSome(body.properties) && body.properties.value)), (O.isSome(params.properties) && params.properties.value))),
|
|
45
|
+
required: O.some(mergeRequired(params, body)),
|
|
46
|
+
additionalProperties: O.some(false),
|
|
47
|
+
allOf: O.none,
|
|
48
|
+
anyOf: O.none,
|
|
49
|
+
oneOf: O.none,
|
|
50
|
+
not: O.none,
|
|
51
|
+
in: O.none,
|
|
41
52
|
});
|
|
42
53
|
const transformInput = (parameters) => {
|
|
43
54
|
const transformedParameters = {};
|
|
44
55
|
const requiredParameters = [];
|
|
45
56
|
parameters.forEach((parameter) => {
|
|
46
|
-
const
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
};
|
|
55
|
-
transformedParameters[parameter.name] = Object.assign(Object.assign({}, (0, openapi_schema_to_json_schema_1.fromParameter)(parameterWithJsdocAnnotation)), { in: parameter.in });
|
|
57
|
+
const codecWithNullValueRemoval = CompositeCodec_1.CompositeCodec.fromCodecs(OpenApiCodecs_1.parameterSchemaCodec, RemoveNullValuesCodec_1.RemoveNullValuesCodec.instance);
|
|
58
|
+
const parameterWithNoOptions = codecWithNullValueRemoval.encode(parameter);
|
|
59
|
+
const parameterWithJsdocAnnotation = Object.assign(Object.assign({}, parameterWithNoOptions), { description: `@description ${parameter.description}` });
|
|
60
|
+
const decodedParam = OpenApiTypeDescriptors_1.schemaObjectTypeDescriptor.decode(Object.assign(Object.assign({}, (0, openapi_schema_to_json_schema_1.fromParameter)(parameterWithJsdocAnnotation)), { in: parameter.in }));
|
|
61
|
+
if (decodedParam._tag === 'Left') {
|
|
62
|
+
throw new Error('Failed to decode params');
|
|
63
|
+
}
|
|
64
|
+
transformedParameters[parameter.name] = decodedParam.right;
|
|
56
65
|
if (parameter.required === true) {
|
|
57
66
|
requiredParameters.push(parameter.name);
|
|
58
67
|
}
|
|
59
68
|
});
|
|
60
69
|
return {
|
|
61
|
-
type: 'object',
|
|
62
|
-
properties:
|
|
63
|
-
required: [...requiredParameters],
|
|
64
|
-
additionalProperties: false,
|
|
70
|
+
type: O.some('object'),
|
|
71
|
+
properties: O.some(transformedParameters),
|
|
72
|
+
required: O.some([...requiredParameters]),
|
|
73
|
+
additionalProperties: O.some(false),
|
|
74
|
+
allOf: O.none,
|
|
75
|
+
anyOf: O.none,
|
|
76
|
+
oneOf: O.none,
|
|
77
|
+
not: O.none,
|
|
78
|
+
in: O.none,
|
|
65
79
|
};
|
|
66
80
|
};
|
|
81
|
+
/**
|
|
82
|
+
* OpenAPI spec's body params don't have an .in property, we add one in here since query, path, and header params do
|
|
83
|
+
*/
|
|
84
|
+
const appendInPropertyToBody = (body) => O.fold(() => body, (properties) => {
|
|
85
|
+
const propsWithInBody = Object.keys(properties).reduce((acc, name) => (Object.assign(Object.assign({}, acc), { [name]: Object.assign(Object.assign({}, properties[name]), { in: O.some('body') }) })), {});
|
|
86
|
+
return Object.assign(Object.assign({}, body), { properties: O.some(propsWithInBody) });
|
|
87
|
+
})(body.properties);
|
|
67
88
|
const getApplicationJsonMediaType = (content) => {
|
|
68
89
|
// TODO: we should support any value here, but there may also be more than 1 media type so we need to iterate through
|
|
69
90
|
// and combine all the schemas within into a single set of inputs
|
|
70
91
|
const mediaTypeApplicationJson = Object.keys(content).find((mediaType) => /^application\/.*json$/.test(mediaType));
|
|
92
|
+
// TODO: fold here instead of getOrElse
|
|
71
93
|
if (mediaTypeApplicationJson) {
|
|
72
|
-
return
|
|
94
|
+
return O.getOrElse(() => {
|
|
95
|
+
throw new Error('');
|
|
96
|
+
})(content[mediaTypeApplicationJson].schema);
|
|
73
97
|
}
|
|
74
98
|
const mediaTypes = Object.keys(content);
|
|
75
99
|
throw new Error(`Unsupported media type: ${mediaTypes}`);
|
|
76
100
|
};
|
|
77
101
|
const generateInputSchema = (endpoint) => {
|
|
102
|
+
// TODO: use the encode method instead of this, or fold over the values
|
|
78
103
|
const parameters = O.toNullable(endpoint.parameters);
|
|
79
104
|
const requestBody = O.toNullable(endpoint.requestBody);
|
|
80
105
|
if (parameters && !requestBody) {
|
|
81
106
|
return transformInput(parameters);
|
|
82
107
|
}
|
|
83
108
|
if (requestBody && !parameters) {
|
|
84
|
-
return getApplicationJsonMediaType(requestBody.content)
|
|
109
|
+
// TODO: update all uses to this now that getAppJsonMedia doesn't do get content within it? return getApplicationJsonMediaType(getContent(requestBody.content));
|
|
110
|
+
const body = getApplicationJsonMediaType(requestBody.content);
|
|
111
|
+
return appendInPropertyToBody(body);
|
|
112
|
+
// return getApplicationJsonMediaType(getContent(requestBody.content));
|
|
85
113
|
}
|
|
86
114
|
if (requestBody && parameters) {
|
|
87
115
|
const params = transformInput(parameters);
|
|
88
|
-
const body = getApplicationJsonMediaType(requestBody.content)
|
|
89
|
-
|
|
116
|
+
const body = getApplicationJsonMediaType(requestBody.content);
|
|
117
|
+
const bodyWithInProperty = appendInPropertyToBody(body);
|
|
118
|
+
const mergedParamsAndBody = mergeParamsAndBody(params, bodyWithInProperty);
|
|
119
|
+
return mergedParamsAndBody;
|
|
90
120
|
}
|
|
91
121
|
return {
|
|
92
|
-
type:
|
|
93
|
-
properties:
|
|
94
|
-
required:
|
|
95
|
-
additionalProperties: false,
|
|
122
|
+
type: O.none,
|
|
123
|
+
properties: O.none,
|
|
124
|
+
required: O.none,
|
|
125
|
+
additionalProperties: O.some(false),
|
|
126
|
+
allOf: O.none,
|
|
127
|
+
anyOf: O.none,
|
|
128
|
+
oneOf: O.none,
|
|
129
|
+
not: O.none,
|
|
130
|
+
in: O.none,
|
|
96
131
|
};
|
|
97
132
|
};
|
|
98
133
|
exports.generateInputSchema = generateInputSchema;
|