@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.
Files changed (39) hide show
  1. package/dist/OpenApiCodecs.d.ts +3 -1
  2. package/dist/OpenApiCodecs.d.ts.map +1 -1
  3. package/dist/OpenApiCodecs.js +3 -1
  4. package/dist/OpenApiSchemaImporter.d.ts +1 -0
  5. package/dist/OpenApiSchemaImporter.d.ts.map +1 -1
  6. package/dist/OpenApiSchemaImporter.js +25 -15
  7. package/dist/OpenApiTypeDescriptors.d.ts +32 -20
  8. package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
  9. package/dist/OpenApiTypeDescriptors.js +59 -36
  10. package/dist/file-generators/GenerateHandler.d.ts +4 -4
  11. package/dist/file-generators/GenerateHandler.d.ts.map +1 -1
  12. package/dist/file-generators/GenerateHandler.js +43 -46
  13. package/dist/file-generators/GenerateHandler.test.js +194 -38
  14. package/dist/file-generators/GenerateHandlerTest.d.ts +3 -3
  15. package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -1
  16. package/dist/file-generators/GenerateHandlerTest.js +33 -21
  17. package/dist/file-generators/GenerateHandlerTest.test.js +313 -61
  18. package/dist/file-generators/GenerateOperationJson.test.js +2 -1
  19. package/dist/file-generators/types/GenerateInputSchema.d.ts +2 -3
  20. package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -1
  21. package/dist/file-generators/types/GenerateInputSchema.js +63 -28
  22. package/dist/file-generators/types/GenerateInputSchema.test.js +72 -104
  23. package/dist/file-generators/types/GenerateInputType.test.d.ts +2 -0
  24. package/dist/file-generators/types/GenerateInputType.test.d.ts.map +1 -0
  25. package/dist/file-generators/types/GenerateInputType.test.js +400 -0
  26. package/dist/file-generators/types/GenerateInputTypes.d.ts +2 -2
  27. package/dist/file-generators/types/GenerateInputTypes.d.ts.map +1 -1
  28. package/dist/file-generators/types/GenerateInputTypes.js +10 -8
  29. package/dist/file-generators/types/GenerateOutput.d.ts +4 -5
  30. package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -1
  31. package/dist/file-generators/types/GenerateOutput.js +31 -5
  32. package/dist/file-generators/types/GenerateOutput.test.js +94 -88
  33. package/package.json +1 -1
  34. package/dist/ResolveOptionValues.d.ts +0 -3
  35. package/dist/ResolveOptionValues.d.ts.map +0 -1
  36. package/dist/ResolveOptionValues.js +0 -43
  37. package/dist/ResolveOptionValues.test.d.ts +0 -2
  38. package/dist/ResolveOptionValues.test.d.ts.map +0 -1
  39. package/dist/ResolveOptionValues.test.js +0 -91
@@ -24,8 +24,19 @@ 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 GenerateHandler_1 = require("./GenerateHandler");
28
- const getGenerateHandlerInput = (input) => (Object.assign({ connectorNamePascalCase: 'OpenApiTest', operationNamePascalCase: 'GetPhoto', operationNameCamelCase: 'getPhoto', httpMethod: 'get', baseUrl: 'https://jsonplaceholder.typicode.com', input: { properties: {} }, path: '/photos' }, input));
29
+ const getGenerateHandlerInput = (input) => (Object.assign({ connectorNamePascalCase: 'OpenApiTest', operationNamePascalCase: 'GetPhoto', operationNameCamelCase: 'getPhoto', httpMethod: 'get', baseUrl: 'https://jsonplaceholder.typicode.com', input: {
30
+ properties: O.none,
31
+ additionalProperties: O.none,
32
+ required: O.none,
33
+ allOf: O.none,
34
+ oneOf: O.none,
35
+ anyOf: O.none,
36
+ not: O.none,
37
+ in: O.none,
38
+ type: O.none,
39
+ }, httpPath: '/photos' }, input));
29
40
  describe('GenerateHandler', () => {
30
41
  it('it should generate a handler with no inputs', () => {
31
42
  const payload = getGenerateHandlerInput({});
@@ -50,14 +61,31 @@ describe('GenerateHandler', () => {
50
61
  });
51
62
  it('it should generate a handler with a path parameter', () => {
52
63
  const input = {
53
- type: 'object',
54
- properties: { photoId: { type: 'string', in: 'path' } },
55
- required: ['photoId'],
56
- additionalProperties: false,
64
+ type: O.some('object'),
65
+ properties: O.some({
66
+ photoId: {
67
+ type: O.some('string'),
68
+ in: O.some('path'),
69
+ properties: O.none,
70
+ additionalProperties: O.none,
71
+ required: O.none,
72
+ allOf: O.none,
73
+ oneOf: O.none,
74
+ anyOf: O.none,
75
+ not: O.none,
76
+ },
77
+ }),
78
+ required: O.some(['photoId']),
79
+ additionalProperties: O.some(false),
80
+ allOf: O.none,
81
+ oneOf: O.none,
82
+ anyOf: O.none,
83
+ not: O.none,
84
+ in: O.none,
57
85
  };
58
86
  const payload = getGenerateHandlerInput({
59
87
  input,
60
- path: '/photos/{photoId}',
88
+ httpPath: '/photos/{photoId}',
61
89
  });
62
90
  const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
63
91
  expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
@@ -80,10 +108,27 @@ describe('GenerateHandler', () => {
80
108
  });
81
109
  it('it should generate a handler with a body input as json', () => {
82
110
  const input = {
83
- type: 'object',
84
- properties: { photoId: { type: 'string', in: 'body' } },
85
- required: ['photoId'],
86
- additionalProperties: false,
111
+ type: O.some('object'),
112
+ properties: O.some({
113
+ photoId: {
114
+ type: O.some('string'),
115
+ in: O.some('body'),
116
+ properties: O.none,
117
+ additionalProperties: O.none,
118
+ required: O.none,
119
+ allOf: O.none,
120
+ oneOf: O.none,
121
+ anyOf: O.none,
122
+ not: O.none,
123
+ },
124
+ }),
125
+ required: O.some(['photoId']),
126
+ additionalProperties: O.some(false),
127
+ allOf: O.none,
128
+ oneOf: O.none,
129
+ anyOf: O.none,
130
+ not: O.none,
131
+ in: O.none,
87
132
  };
88
133
  const payload = getGenerateHandlerInput({ input });
89
134
  const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
@@ -107,10 +152,27 @@ describe('GenerateHandler', () => {
107
152
  });
108
153
  it('it should generate a handler with a query string input', () => {
109
154
  const input = {
110
- type: 'object',
111
- properties: { id: { type: 'string', in: 'query' } },
112
- required: ['id'],
113
- additionalProperties: false,
155
+ type: O.some('object'),
156
+ properties: O.some({
157
+ id: {
158
+ type: O.some('string'),
159
+ in: O.some('query'),
160
+ properties: O.none,
161
+ additionalProperties: O.none,
162
+ required: O.none,
163
+ allOf: O.none,
164
+ oneOf: O.none,
165
+ anyOf: O.none,
166
+ not: O.none,
167
+ },
168
+ }),
169
+ required: O.some(['id']),
170
+ additionalProperties: O.some(false),
171
+ allOf: O.none,
172
+ oneOf: O.none,
173
+ anyOf: O.none,
174
+ not: O.none,
175
+ in: O.none,
114
176
  };
115
177
  const payload = getGenerateHandlerInput({ input });
116
178
  const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
@@ -134,10 +196,27 @@ describe('GenerateHandler', () => {
134
196
  });
135
197
  it('it should generate a handler with a header input', () => {
136
198
  const input = {
137
- type: 'object',
138
- properties: { 'Content-Type': { type: 'string', in: 'header' } },
139
- required: ['photoId'],
140
- additionalProperties: false,
199
+ type: O.some('object'),
200
+ properties: O.some({
201
+ 'Content-Type': {
202
+ type: O.some('string'),
203
+ in: O.some('header'),
204
+ properties: O.none,
205
+ additionalProperties: O.none,
206
+ required: O.none,
207
+ allOf: O.none,
208
+ oneOf: O.none,
209
+ anyOf: O.none,
210
+ not: O.none,
211
+ },
212
+ }),
213
+ required: O.some(['photoId']),
214
+ additionalProperties: O.some(false),
215
+ allOf: O.none,
216
+ oneOf: O.none,
217
+ anyOf: O.none,
218
+ not: O.none,
219
+ in: O.none,
141
220
  };
142
221
  const payload = getGenerateHandlerInput({ input });
143
222
  const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
@@ -161,10 +240,27 @@ describe('GenerateHandler', () => {
161
240
  });
162
241
  it('it should generate a handler and transform number type to string for input', () => {
163
242
  const input = {
164
- type: 'object',
165
- properties: { 'Content-Type': { type: 'integer', in: 'header' } },
166
- required: ['photoId'],
167
- additionalProperties: false,
243
+ type: O.some('object'),
244
+ properties: O.some({
245
+ 'Content-Type': {
246
+ type: O.some('integer'),
247
+ in: O.some('header'),
248
+ properties: O.none,
249
+ additionalProperties: O.none,
250
+ required: O.none,
251
+ allOf: O.none,
252
+ oneOf: O.none,
253
+ anyOf: O.none,
254
+ not: O.none,
255
+ },
256
+ }),
257
+ required: O.none,
258
+ additionalProperties: O.some(false),
259
+ allOf: O.none,
260
+ oneOf: O.none,
261
+ anyOf: O.none,
262
+ not: O.none,
263
+ in: O.none,
168
264
  };
169
265
  const payload = getGenerateHandlerInput({ input });
170
266
  const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
@@ -188,18 +284,53 @@ describe('GenerateHandler', () => {
188
284
  });
189
285
  it('it should generate a handler with a query string and path param input', () => {
190
286
  const input = {
191
- type: 'object',
192
- properties: {
193
- id: { type: 'string', in: 'query' },
194
- photoId: { type: 'string', in: 'path' },
195
- commentId: { type: 'string', in: 'path' },
196
- },
197
- required: ['photoId'],
198
- additionalProperties: false,
287
+ type: O.some('object'),
288
+ properties: O.some({
289
+ id: {
290
+ type: O.some('string'),
291
+ in: O.some('query'),
292
+ properties: O.none,
293
+ additionalProperties: O.none,
294
+ required: O.none,
295
+ allOf: O.none,
296
+ oneOf: O.none,
297
+ anyOf: O.none,
298
+ not: O.none,
299
+ },
300
+ photoId: {
301
+ type: O.some('string'),
302
+ in: O.some('path'),
303
+ properties: O.none,
304
+ additionalProperties: O.none,
305
+ required: O.none,
306
+ allOf: O.none,
307
+ oneOf: O.none,
308
+ anyOf: O.none,
309
+ not: O.none,
310
+ },
311
+ commentId: {
312
+ type: O.some('string'),
313
+ in: O.some('path'),
314
+ properties: O.none,
315
+ additionalProperties: O.none,
316
+ required: O.none,
317
+ allOf: O.none,
318
+ oneOf: O.none,
319
+ anyOf: O.none,
320
+ not: O.none,
321
+ },
322
+ }),
323
+ required: O.some(['photoId']),
324
+ additionalProperties: O.some(false),
325
+ allOf: O.none,
326
+ oneOf: O.none,
327
+ anyOf: O.none,
328
+ not: O.none,
329
+ in: O.none,
199
330
  };
200
331
  const payload = getGenerateHandlerInput({
201
332
  input,
202
- path: '/photos/{photoId}/{commentId}',
333
+ httpPath: '/photos/{photoId}/{commentId}',
203
334
  });
204
335
  const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
205
336
  expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
@@ -222,13 +353,38 @@ describe('GenerateHandler', () => {
222
353
  });
223
354
  it('it should generate a handler with a query string and body param input', () => {
224
355
  const input = {
225
- type: 'object',
226
- properties: {
227
- id: { type: 'string', in: 'query' },
228
- photoId: { type: 'string', in: 'body' },
229
- },
230
- required: ['id', 'photoId'],
231
- additionalProperties: false,
356
+ type: O.some('object'),
357
+ properties: O.some({
358
+ id: {
359
+ type: O.some('string'),
360
+ in: O.some('query'),
361
+ properties: O.none,
362
+ additionalProperties: O.none,
363
+ required: O.none,
364
+ allOf: O.none,
365
+ oneOf: O.none,
366
+ anyOf: O.none,
367
+ not: O.none,
368
+ },
369
+ photoId: {
370
+ type: O.some('string'),
371
+ in: O.some('body'),
372
+ properties: O.none,
373
+ additionalProperties: O.none,
374
+ required: O.none,
375
+ allOf: O.none,
376
+ oneOf: O.none,
377
+ anyOf: O.none,
378
+ not: O.none,
379
+ },
380
+ }),
381
+ required: O.some(['id', 'photoId']),
382
+ additionalProperties: O.some(false),
383
+ allOf: O.none,
384
+ oneOf: O.none,
385
+ anyOf: O.none,
386
+ not: O.none,
387
+ in: O.none,
232
388
  };
233
389
  const payload = getGenerateHandlerInput({ input });
234
390
  const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
@@ -1,9 +1,9 @@
1
- import { JSONSchema4 } from 'json-schema';
2
1
  import * as E from 'fp-ts/Either';
2
+ import { SchemaObject } from '../OpenApiTypeDescriptors';
3
3
  export type GenerateHandlerTestInput = {
4
4
  operationNameCamelCase: string;
5
- input: JSONSchema4;
6
- output: JSONSchema4;
5
+ input: SchemaObject;
6
+ output: SchemaObject;
7
7
  };
8
8
  export declare const generateHandlerTest: ({ operationNameCamelCase, input, output, }: GenerateHandlerTestInput) => E.Either<Error, string>;
9
9
  //# sourceMappingURL=GenerateHandlerTest.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GenerateHandlerTest.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandlerTest.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,MAAM,MAAM,wBAAwB,GAAG;IACtC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,KAAK,EAAE,WAAW,CAAC;IACnB,MAAM,EAAE,WAAW,CAAC;CACpB,CAAC;AAmCF,eAAO,MAAM,mBAAmB,+CAI7B,wBAAwB,KAAG,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CA6BlD,CAAC"}
1
+ {"version":3,"file":"GenerateHandlerTest.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandlerTest.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAGlC,OAAO,EAAE,YAAY,EAAE,MAAM,2BAA2B,CAAC;AAEzD,MAAM,MAAM,wBAAwB,GAAG;IACtC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,KAAK,EAAE,YAAY,CAAC;IACpB,MAAM,EAAE,YAAY,CAAC;CACrB,CAAC;AAiDF,eAAO,MAAM,mBAAmB,+CAI7B,wBAAwB,KAAG,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAqClD,CAAC"}
@@ -25,23 +25,31 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.generateHandlerTest = void 0;
27
27
  const E = __importStar(require("fp-ts/Either"));
28
+ const O = __importStar(require("fp-ts/Option"));
28
29
  const getDefaultValue = (prop) => {
29
- switch (prop.type) {
30
- case 'string':
31
- return `'test'`;
32
- case 'number':
33
- case 'integer':
34
- return 2;
35
- case 'boolean':
36
- return 'true';
37
- case 'array':
38
- return prop.items ? `[${getDefaultValue(prop.items)}]` : '[]';
39
- case 'object':
40
- return prop.properties ? handleInput(prop.properties) : '{}';
41
- default:
42
- return `'test_value'`;
30
+ if (prop.type === 'array') {
31
+ return prop.items ? `[${getDefaultValue(prop.items)}]` : '[]';
43
32
  }
33
+ return O.fold(() => `'test_value'`, (type) => {
34
+ switch (type) {
35
+ case 'string':
36
+ return `'test'`;
37
+ case 'number':
38
+ case 'integer':
39
+ return 2;
40
+ case 'boolean':
41
+ return 'true';
42
+ // case 'array':
43
+ // return prop.items ? `[${getDefaultValue(prop.items)}]` : '[]';
44
+ case 'object':
45
+ return O.fold(() => `{}`, (properties) => handleInput(properties))(prop.properties);
46
+ // return prop.properties ? handleInput(prop.properties) : '{}';
47
+ default:
48
+ return `'test_value'`;
49
+ }
50
+ })(prop.type);
44
51
  };
52
+ // TODO: make handleInput and handleOutput accept an option and do the fold inside, will make the code cleaner in the template and switch case
45
53
  const handleInput = (inputs) => {
46
54
  const populatedTestInputs = Object.entries(inputs).map(([key, prop]) => `${key}: ${getDefaultValue(prop)}`);
47
55
  return `{ ${populatedTestInputs.join(', ')} }`;
@@ -62,15 +70,19 @@ const generateHandlerTest = ({ operationNameCamelCase, input, output, }) => E.tr
62
70
  .testCase('should ${operationNameCamelCase}', (testCase) =>
63
71
  testCase
64
72
  .givenNothing()
65
- .when(() => (${input.properties ? handleInput(input.properties) : `{}`}))
73
+ .when(() => (${O.fold(() => `{}`, (properties) => handleInput(properties))(input.properties)}
74
+ ))
66
75
  .then(({ output }) => {
67
- // console.log(output);
76
+ // console.log(output);
68
77
  const outputValue =
69
- OperationHandlerResult.getSuccessfulValueOrFail(output);
70
- ${handleOutput(output.properties || {})}
78
+ OperationHandlerResult.getSuccessfulValueOrFail(output);
79
+ ${O.fold(() => `{}`, (properties) => handleOutput(properties))(output.properties)}
80
+
71
81
  })
72
82
  .finallyDoNothing()
73
- )
74
- .nothingAfterAll()
75
- );`, (e) => new Error(`Failed to generate handler test: ${e}`));
83
+ )
84
+ .nothingAfterAll()
85
+ );`, (e) => new Error(`Failed to generate handler test: ${e}`));
76
86
  exports.generateHandlerTest = generateHandlerTest;
87
+ // ${handleOutput(output.properties || {})}
88
+ // .when(() => (${O.fold(input.properties ? handleInput(input.properties) : `{}`