@trayio/tray-openapi 2.11.0 → 2.12.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 (28) hide show
  1. package/README.md +39 -0
  2. package/dist/OpenApiSchemaImporter.d.ts +1 -17
  3. package/dist/OpenApiSchemaImporter.d.ts.map +1 -1
  4. package/dist/OpenApiSchemaImporter.js +5 -5
  5. package/dist/OpenApiSchemaImporter.test.js +11 -9
  6. package/dist/OpenApiSchemaTransformer.d.ts +9 -0
  7. package/dist/OpenApiSchemaTransformer.d.ts.map +1 -0
  8. package/dist/OpenApiSchemaTransformer.js +68 -0
  9. package/dist/OpenApiSchemaTransformer.test.d.ts +2 -0
  10. package/dist/OpenApiSchemaTransformer.test.d.ts.map +1 -0
  11. package/dist/OpenApiSchemaTransformer.test.js +118 -0
  12. package/dist/OpenApiTypeDescriptors.d.ts +39 -6
  13. package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
  14. package/dist/OpenApiTypeDescriptors.js +5 -11
  15. package/dist/file-generators/GenerateHandler.test.js +18 -0
  16. package/dist/file-generators/GenerateHandlerTest.test.js +33 -0
  17. package/dist/file-generators/types/GenerateInputSchema.d.ts +2 -1
  18. package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -1
  19. package/dist/file-generators/types/GenerateInputSchema.js +25 -27
  20. package/dist/file-generators/types/GenerateInputSchema.test.js +63 -9
  21. package/dist/file-generators/types/GenerateInputType.test.js +60 -13
  22. package/dist/file-generators/types/GenerateInputTypes.d.ts.map +1 -1
  23. package/dist/file-generators/types/GenerateInputTypes.js +4 -0
  24. package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -1
  25. package/dist/file-generators/types/GenerateOutput.js +5 -4
  26. package/dist/file-generators/types/GenerateOutput.test.js +10 -0
  27. package/dist/test-openapi-spec.json +159 -139
  28. package/package.json +1 -1
@@ -32,6 +32,7 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
32
32
  });
33
33
  };
34
34
  Object.defineProperty(exports, "__esModule", { value: true });
35
+ const E = __importStar(require("fp-ts/Either"));
35
36
  const TE = __importStar(require("fp-ts/TaskEither"));
36
37
  const O = __importStar(require("fp-ts/Option"));
37
38
  const GenerateInputSchema_1 = require("./GenerateInputSchema");
@@ -47,10 +48,12 @@ describe('GenerateInputType', () => {
47
48
  content: {
48
49
  'application/json': {
49
50
  schema: O.some({
51
+ title: O.none,
50
52
  type: O.some('object'),
51
53
  required: O.some(['id', 'userId', 'title', 'body']),
52
54
  properties: O.some({
53
55
  id: {
56
+ title: O.none,
54
57
  type: O.some('integer'),
55
58
  properties: O.none,
56
59
  additionalProperties: O.some(false),
@@ -62,6 +65,7 @@ describe('GenerateInputType', () => {
62
65
  in: O.none,
63
66
  },
64
67
  userId: {
68
+ title: O.none,
65
69
  type: O.some('integer'),
66
70
  properties: O.none,
67
71
  additionalProperties: O.some(false),
@@ -73,6 +77,7 @@ describe('GenerateInputType', () => {
73
77
  in: O.none,
74
78
  },
75
79
  title: {
80
+ title: O.none,
76
81
  type: O.some('string'),
77
82
  properties: O.none,
78
83
  additionalProperties: O.some(false),
@@ -84,6 +89,7 @@ describe('GenerateInputType', () => {
84
89
  in: O.none,
85
90
  },
86
91
  body: {
92
+ title: O.none,
87
93
  type: O.some('string'),
88
94
  properties: O.none,
89
95
  additionalProperties: O.some(false),
@@ -107,12 +113,16 @@ describe('GenerateInputType', () => {
107
113
  }),
108
114
  responses: O.none,
109
115
  };
110
- const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
116
+ const inputSchema = E.getOrElse(() => {
117
+ throw new Error('Should have been right');
118
+ })((0, GenerateInputSchema_1.generateInputSchema)(endpoint));
111
119
  const expectedInputSchema = {
120
+ title: O.none,
112
121
  type: O.some('object'),
113
122
  required: O.some(['id', 'userId', 'title', 'body']),
114
123
  properties: O.some({
115
124
  id: {
125
+ title: O.none,
116
126
  type: O.some('integer'),
117
127
  properties: O.none,
118
128
  additionalProperties: O.some(false),
@@ -124,6 +134,7 @@ describe('GenerateInputType', () => {
124
134
  in: O.some('body'),
125
135
  },
126
136
  userId: {
137
+ title: O.none,
127
138
  type: O.some('integer'),
128
139
  properties: O.none,
129
140
  additionalProperties: O.some(false),
@@ -135,6 +146,7 @@ describe('GenerateInputType', () => {
135
146
  in: O.some('body'),
136
147
  },
137
148
  title: {
149
+ title: O.none,
138
150
  type: O.some('string'),
139
151
  properties: O.none,
140
152
  additionalProperties: O.some(false),
@@ -146,6 +158,7 @@ describe('GenerateInputType', () => {
146
158
  in: O.some('body'),
147
159
  },
148
160
  body: {
161
+ title: O.none,
149
162
  type: O.some('string'),
150
163
  properties: O.none,
151
164
  additionalProperties: O.some(false),
@@ -175,23 +188,39 @@ describe('GenerateInputType', () => {
175
188
  {
176
189
  name: 'id',
177
190
  in: 'path',
178
- required: true,
191
+ required: O.some(true),
179
192
  description: 'The user id.',
180
193
  schema: {
181
- type: 'integer',
194
+ title: O.none,
195
+ type: O.some('integer'),
182
196
  format: O.some('int64'),
183
- items: O.none,
197
+ properties: O.none,
198
+ additionalProperties: O.some(false),
199
+ required: O.none,
200
+ allOf: O.none,
201
+ anyOf: O.none,
202
+ oneOf: O.none,
203
+ not: O.none,
204
+ in: O.none,
184
205
  },
185
206
  },
186
207
  {
187
208
  name: 'categoryId',
188
209
  in: 'path',
189
- required: false,
210
+ required: O.some(false),
190
211
  description: 'The category id.',
191
212
  schema: {
192
- type: 'integer',
213
+ title: O.none,
214
+ type: O.some('integer'),
193
215
  format: O.some('int64'),
194
- items: O.none,
216
+ properties: O.none,
217
+ additionalProperties: O.some(false),
218
+ required: O.none,
219
+ allOf: O.none,
220
+ anyOf: O.none,
221
+ oneOf: O.none,
222
+ not: O.none,
223
+ in: O.none,
195
224
  },
196
225
  },
197
226
  ]),
@@ -199,10 +228,12 @@ describe('GenerateInputType', () => {
199
228
  content: {
200
229
  'application/json': {
201
230
  schema: O.some({
231
+ title: O.none,
202
232
  type: O.some('object'),
203
233
  required: O.some(['userId', 'body']),
204
234
  properties: O.some({
205
235
  userId: {
236
+ title: O.none,
206
237
  type: O.some('integer'),
207
238
  properties: O.none,
208
239
  additionalProperties: O.some(false),
@@ -214,6 +245,7 @@ describe('GenerateInputType', () => {
214
245
  in: O.none,
215
246
  },
216
247
  title: {
248
+ title: O.none,
217
249
  type: O.some('string'),
218
250
  properties: O.none,
219
251
  required: O.none,
@@ -225,6 +257,7 @@ describe('GenerateInputType', () => {
225
257
  in: O.none,
226
258
  },
227
259
  body: {
260
+ title: O.none,
228
261
  type: O.some('string'),
229
262
  properties: O.none,
230
263
  additionalProperties: O.some(false),
@@ -248,7 +281,9 @@ describe('GenerateInputType', () => {
248
281
  }),
249
282
  responses: O.none,
250
283
  };
251
- const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
284
+ const inputSchema = E.getOrElse(() => {
285
+ throw new Error('Should have been right');
286
+ })((0, GenerateInputSchema_1.generateInputSchema)(endpoint));
252
287
  const inputTypes = (0, GenerateInputTypes_1.generateInputTypes)(endpoint.operationId, inputSchema);
253
288
  const generatedInputFile = yield TE.getOrElse((error) => {
254
289
  throw new Error('Should have been right');
@@ -278,7 +313,9 @@ describe('GenerateInputType', () => {
278
313
  requestBody: O.none,
279
314
  responses: O.none,
280
315
  };
281
- const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
316
+ const inputSchema = E.getOrElse(() => {
317
+ throw new Error('Should have been right');
318
+ })((0, GenerateInputSchema_1.generateInputSchema)(endpoint));
282
319
  const inputTypes = (0, GenerateInputTypes_1.generateInputTypes)(endpoint.operationId, inputSchema);
283
320
  const generatedInputFile = yield TE.getOrElse((error) => {
284
321
  throw new Error('Should have been right');
@@ -297,6 +334,7 @@ describe('GenerateInputType', () => {
297
334
  content: {
298
335
  'application/json': {
299
336
  schema: O.some({
337
+ title: O.none,
300
338
  type: O.some('object'),
301
339
  required: O.none,
302
340
  properties: O.none,
@@ -312,7 +350,9 @@ describe('GenerateInputType', () => {
312
350
  }),
313
351
  responses: O.none,
314
352
  };
315
- const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
353
+ const inputSchema = E.getOrElse(() => {
354
+ throw new Error('Should have been right');
355
+ })((0, GenerateInputSchema_1.generateInputSchema)(endpoint));
316
356
  const inputTypes = (0, GenerateInputTypes_1.generateInputTypes)(endpoint.operationId, inputSchema);
317
357
  const generatedInputFile = yield TE.getOrElse((error) => {
318
358
  throw new Error('Should have been right');
@@ -333,10 +373,12 @@ describe('GenerateInputType', () => {
333
373
  content: {
334
374
  'unsupported-media-type': {
335
375
  schema: O.some({
376
+ title: O.none,
336
377
  type: O.some('object'),
337
378
  required: O.some(['id', 'userId', 'title', 'body']),
338
379
  properties: O.some({
339
380
  id: {
381
+ title: O.none,
340
382
  type: O.some('integer'),
341
383
  properties: O.none,
342
384
  required: O.none,
@@ -348,6 +390,7 @@ describe('GenerateInputType', () => {
348
390
  in: O.none,
349
391
  },
350
392
  userId: {
393
+ title: O.none,
351
394
  type: O.some('integer'),
352
395
  properties: O.none,
353
396
  required: O.none,
@@ -359,6 +402,7 @@ describe('GenerateInputType', () => {
359
402
  in: O.none,
360
403
  },
361
404
  title: {
405
+ title: O.none,
362
406
  type: O.some('string'),
363
407
  properties: O.none,
364
408
  required: O.none,
@@ -370,6 +414,7 @@ describe('GenerateInputType', () => {
370
414
  in: O.none,
371
415
  },
372
416
  body: {
417
+ title: O.none,
373
418
  type: O.some('string'),
374
419
  properties: O.none,
375
420
  required: O.none,
@@ -393,8 +438,10 @@ describe('GenerateInputType', () => {
393
438
  }),
394
439
  responses: O.none,
395
440
  };
396
- yield expect(() => __awaiter(void 0, void 0, void 0, function* () {
397
- (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
398
- })).rejects.toThrow('Unsupported media type: unsupported-media-type');
441
+ const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
442
+ if (E.isRight(inputSchema)) {
443
+ throw new Error('Should have been left');
444
+ }
445
+ expect(inputSchema.left.message).toEqual('Unsupported media type: unsupported-media-type');
399
446
  }));
400
447
  });
@@ -1 +1 @@
1
- {"version":3,"file":"GenerateInputTypes.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateInputTypes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIvC,OAAO,EACN,YAAY,EAEZ,MAAM,8BAA8B,CAAC;AAWtC,eAAO,MAAM,kBAAkB,2BACN,MAAM,cAClB,YAAY,KACtB,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAY7B,CAAC"}
1
+ {"version":3,"file":"GenerateInputTypes.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateInputTypes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAKvC,OAAO,EACN,YAAY,EAEZ,MAAM,8BAA8B,CAAC;AAWtC,eAAO,MAAM,kBAAkB,2BACN,MAAM,cAClB,YAAY,KACtB,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAc7B,CAAC"}
@@ -26,6 +26,7 @@ Object.defineProperty(exports, "__esModule", { value: true });
26
26
  exports.generateInputTypes = void 0;
27
27
  const json_schema_to_typescript_1 = require("json-schema-to-typescript");
28
28
  const TE = __importStar(require("fp-ts/TaskEither"));
29
+ const O = __importStar(require("fp-ts/Option"));
29
30
  const CompositeCodec_1 = require("@trayio/commons/codec/CompositeCodec");
30
31
  const RemoveNullValuesCodec_1 = require("@trayio/commons/codec/RemoveNullValuesCodec");
31
32
  const JsonSchemaToTypescriptOptions_1 = require("./JsonSchemaToTypescriptOptions");
@@ -35,6 +36,9 @@ const encodeInputSchema = (inputSchema) => {
35
36
  return codecWithNullValueRemoval.encode(inputSchema);
36
37
  };
37
38
  const generateInputTypes = (operationNameCamelCase, parameters) => {
39
+ if (O.isSome(parameters.title)) {
40
+ parameters.title = O.none;
41
+ }
38
42
  const resolvedInputSchema = encodeInputSchema(parameters);
39
43
  return TE.tryCatch(() => (0, json_schema_to_typescript_1.compile)(resolvedInputSchema, `${operationNameCamelCase}Input`, JsonSchemaToTypescriptOptions_1.JsonSchemaToTypescriptOptions), (reason) => new Error(`${reason}`));
40
44
  };
@@ -1 +1 @@
1
- {"version":3,"file":"GenerateOutput.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateOutput.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAKlC,OAAO,EACN,SAAS,EAET,eAAe,EACf,YAAY,EAEZ,MAAM,8BAA8B,CAAC;AAuCtC,eAAO,MAAM,2BAA2B,YAC9B,OAAO,MAAM,EAAE,eAAe,CAAC,KACtC,EAAE,MAAM,CAAC,KAAK,EAAE,eAAe,CAWjC,CAAC;AAEF,eAAO,MAAM,oBAAoB,cACrB,EAAE,MAAM,CAAC,SAAS,CAAC,KAC5B,GAAG,UAAU,CAAC,KAAK,EAAE,YAAY,CAelC,CAAC;AAWH,eAAO,MAAM,mBAAmB,2BACP,MAAM,gBAChB,YAAY,KACxB,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAe7B,CAAC"}
1
+ {"version":3,"file":"GenerateOutput.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateOutput.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAKlC,OAAO,EACN,SAAS,EAET,eAAe,EACf,YAAY,EAEZ,MAAM,8BAA8B,CAAC;AAwCtC,eAAO,MAAM,2BAA2B,YAC9B,OAAO,MAAM,EAAE,eAAe,CAAC,KACtC,EAAE,MAAM,CAAC,KAAK,EAAE,eAAe,CAWjC,CAAC;AAEF,eAAO,MAAM,oBAAoB,cACrB,EAAE,MAAM,CAAC,SAAS,CAAC,KAC5B,GAAG,UAAU,CAAC,KAAK,EAAE,YAAY,CAelC,CAAC;AAWH,eAAO,MAAM,mBAAmB,2BACP,MAAM,gBAChB,YAAY,KACxB,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAgB7B,CAAC"}
@@ -42,6 +42,7 @@ const get2XXResponse = (responses) => O.fold(() => TE.left(new Error('No respons
42
42
  return TE.left(new Error(`Unsupported success response code: ${responseCodes}`));
43
43
  })(responses);
44
44
  const blankOutputSchema = () => ({
45
+ title: O.none,
45
46
  type: O.none,
46
47
  properties: O.none,
47
48
  required: O.none,
@@ -71,10 +72,10 @@ const encodeOutputSchema = (outputSchema) => {
71
72
  return codecWithNullValueRemoval.encode(outputSchema);
72
73
  };
73
74
  const generateOutputTypes = (operationNameCamelCase, outputSchema) => {
75
+ if (O.isSome(outputSchema.title)) {
76
+ outputSchema.title = O.none;
77
+ }
74
78
  const resolvedOutputSchema = encodeOutputSchema(outputSchema);
75
- return TE.tryCatch(() => (0, json_schema_to_typescript_1.compile)(resolvedOutputSchema, `${operationNameCamelCase}Output`, JsonSchemaToTypescriptOptions_1.JsonSchemaToTypescriptOptions), (error) => {
76
- console.log(JSON.stringify(resolvedOutputSchema));
77
- return new Error(`Failed to generate output types: ${error}`);
78
- });
79
+ return TE.tryCatch(() => (0, json_schema_to_typescript_1.compile)(resolvedOutputSchema, `${operationNameCamelCase}Output`, JsonSchemaToTypescriptOptions_1.JsonSchemaToTypescriptOptions), (error) => new Error(`Failed to generate output types: ${error}`));
79
80
  };
80
81
  exports.generateOutputTypes = generateOutputTypes;
@@ -55,10 +55,12 @@ describe('Generate output: ', () => {
55
55
  content: O.some({
56
56
  'application/json': {
57
57
  schema: O.some({
58
+ title: O.some('Post'),
58
59
  type: O.some('object'),
59
60
  required: O.some(['id', 'userId', 'title', 'body']),
60
61
  properties: O.some({
61
62
  id: {
63
+ title: O.none,
62
64
  type: O.some('integer'),
63
65
  properties: O.none,
64
66
  required: O.none,
@@ -70,6 +72,7 @@ describe('Generate output: ', () => {
70
72
  in: O.none,
71
73
  },
72
74
  userId: {
75
+ title: O.none,
73
76
  type: O.some('integer'),
74
77
  properties: O.none,
75
78
  required: O.none,
@@ -81,6 +84,7 @@ describe('Generate output: ', () => {
81
84
  in: O.none,
82
85
  },
83
86
  title: {
87
+ title: O.none,
84
88
  type: O.some('string'),
85
89
  properties: O.none,
86
90
  required: O.none,
@@ -92,6 +96,7 @@ describe('Generate output: ', () => {
92
96
  in: O.none,
93
97
  },
94
98
  body: {
99
+ title: O.none,
95
100
  type: O.some('string'),
96
101
  properties: O.none,
97
102
  required: O.none,
@@ -131,10 +136,12 @@ describe('Generate output: ', () => {
131
136
  content: O.some({
132
137
  'application/json': {
133
138
  schema: O.some({
139
+ title: O.none,
134
140
  type: O.some('object'),
135
141
  required: O.some(['id', 'userId', 'title', 'body']),
136
142
  properties: O.some({
137
143
  id: {
144
+ title: O.none,
138
145
  type: O.some('integer'),
139
146
  properties: O.none,
140
147
  required: O.none,
@@ -146,6 +153,7 @@ describe('Generate output: ', () => {
146
153
  in: O.none,
147
154
  },
148
155
  userId: {
156
+ title: O.none,
149
157
  type: O.some('integer'),
150
158
  properties: O.none,
151
159
  required: O.none,
@@ -157,6 +165,7 @@ describe('Generate output: ', () => {
157
165
  in: O.none,
158
166
  },
159
167
  title: {
168
+ title: O.none,
160
169
  type: O.some('string'),
161
170
  properties: O.none,
162
171
  required: O.none,
@@ -168,6 +177,7 @@ describe('Generate output: ', () => {
168
177
  in: O.none,
169
178
  },
170
179
  body: {
180
+ title: O.none,
171
181
  type: O.some('string'),
172
182
  properties: O.none,
173
183
  required: O.none,