@trayio/tray-openapi 2.7.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.
Files changed (71) hide show
  1. package/dist/OpenApiSchemaImporter.d.ts +1 -1
  2. package/dist/OpenApiSchemaImporter.d.ts.map +1 -1
  3. package/dist/OpenApiSchemaImporter.js +43 -28
  4. package/dist/OpenApiSchemaImporter.test.js +12 -3
  5. package/dist/OpenApiTypeDescriptors.d.ts +10 -5
  6. package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
  7. package/dist/OpenApiTypeDescriptors.js +10 -1
  8. package/dist/ResolveOptionValues.d.ts +3 -0
  9. package/dist/ResolveOptionValues.d.ts.map +1 -0
  10. package/dist/{connector/input/TransformInput.js → ResolveOptionValues.js} +16 -27
  11. package/dist/ResolveOptionValues.test.d.ts +2 -0
  12. package/dist/ResolveOptionValues.test.d.ts.map +1 -0
  13. package/dist/ResolveOptionValues.test.js +91 -0
  14. package/dist/{GenerateHandler.d.ts → file-generators/GenerateHandler.d.ts} +2 -7
  15. package/dist/file-generators/GenerateHandler.d.ts.map +1 -0
  16. package/dist/{GenerateHandler.js → file-generators/GenerateHandler.js} +53 -16
  17. package/dist/file-generators/GenerateHandler.test.d.ts +2 -0
  18. package/dist/file-generators/GenerateHandler.test.d.ts.map +1 -0
  19. package/dist/{GenerateHander.test.js → file-generators/GenerateHandler.test.js} +119 -33
  20. package/dist/{GenerateHandlerTest.d.ts → file-generators/GenerateHandlerTest.d.ts} +2 -4
  21. package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -0
  22. package/dist/{GenerateHandlerTest.js → file-generators/GenerateHandlerTest.js} +5 -16
  23. package/dist/file-generators/GenerateHandlerTest.test.d.ts.map +1 -0
  24. package/dist/{GenerateHandlerTest.test.js → file-generators/GenerateHandlerTest.test.js} +47 -34
  25. package/dist/file-generators/GenerateOperationJson.d.ts +4 -0
  26. package/dist/file-generators/GenerateOperationJson.d.ts.map +1 -0
  27. package/dist/file-generators/GenerateOperationJson.js +43 -0
  28. package/dist/file-generators/GenerateOperationJson.test.d.ts +2 -0
  29. package/dist/file-generators/GenerateOperationJson.test.d.ts.map +1 -0
  30. package/dist/file-generators/GenerateOperationJson.test.js +77 -0
  31. package/dist/file-generators/types/GenerateInputSchema.d.ts +4 -0
  32. package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -0
  33. package/dist/{connector/input/ProcessInput.js → file-generators/types/GenerateInputSchema.js} +31 -14
  34. package/dist/file-generators/types/GenerateInputSchema.test.d.ts +2 -0
  35. package/dist/file-generators/types/GenerateInputSchema.test.d.ts.map +1 -0
  36. package/dist/{connector/input/ProcessInput.test.js → file-generators/types/GenerateInputSchema.test.js} +25 -14
  37. package/dist/file-generators/types/GenerateInputTypes.d.ts +4 -0
  38. package/dist/file-generators/types/GenerateInputTypes.d.ts.map +1 -0
  39. package/dist/file-generators/types/GenerateInputTypes.js +39 -0
  40. package/dist/file-generators/types/GenerateOutput.d.ts +9 -0
  41. package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -0
  42. package/dist/file-generators/types/GenerateOutput.js +54 -0
  43. package/dist/file-generators/types/GenerateOutput.test.d.ts +2 -0
  44. package/dist/file-generators/types/GenerateOutput.test.d.ts.map +1 -0
  45. package/dist/file-generators/types/GenerateOutput.test.js +197 -0
  46. package/dist/file-generators/types/JsonSchemaToTypescriptOptions.d.ts.map +1 -0
  47. package/package.json +4 -2
  48. package/dist/GenerateHander.test.d.ts +0 -2
  49. package/dist/GenerateHander.test.d.ts.map +0 -1
  50. package/dist/GenerateHandler.d.ts.map +0 -1
  51. package/dist/GenerateHandlerTest.d.ts.map +0 -1
  52. package/dist/GenerateHandlerTest.test.d.ts.map +0 -1
  53. package/dist/connector/JsonSchemaToTypescriptOptions.d.ts.map +0 -1
  54. package/dist/connector/input/GenerateInput.d.ts +0 -8
  55. package/dist/connector/input/GenerateInput.d.ts.map +0 -1
  56. package/dist/connector/input/GenerateInput.js +0 -8
  57. package/dist/connector/input/GenerateInput.test.d.ts +0 -2
  58. package/dist/connector/input/GenerateInput.test.d.ts.map +0 -1
  59. package/dist/connector/input/GenerateInput.test.js +0 -133
  60. package/dist/connector/input/ProcessInput.d.ts +0 -4
  61. package/dist/connector/input/ProcessInput.d.ts.map +0 -1
  62. package/dist/connector/input/ProcessInput.test.d.ts +0 -2
  63. package/dist/connector/input/ProcessInput.test.d.ts.map +0 -1
  64. package/dist/connector/input/TransformInput.d.ts +0 -4
  65. package/dist/connector/input/TransformInput.d.ts.map +0 -1
  66. package/dist/connector/input/TransformInput.test.d.ts +0 -2
  67. package/dist/connector/input/TransformInput.test.d.ts.map +0 -1
  68. package/dist/connector/input/TransformInput.test.js +0 -75
  69. /package/dist/{GenerateHandlerTest.test.d.ts → file-generators/GenerateHandlerTest.test.d.ts} +0 -0
  70. /package/dist/{connector → file-generators/types}/JsonSchemaToTypescriptOptions.d.ts +0 -0
  71. /package/dist/{connector → file-generators/types}/JsonSchemaToTypescriptOptions.js +0 -0
@@ -25,13 +25,13 @@ var __importStar = (this && this.__importStar) || function (mod) {
25
25
  Object.defineProperty(exports, "__esModule", { value: true });
26
26
  const E = __importStar(require("fp-ts/Either"));
27
27
  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: [], path: 'photos' }, input));
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
29
  describe('GenerateHandler', () => {
30
- it('it should generate a handler', () => {
30
+ it('it should generate a handler with no inputs', () => {
31
31
  const payload = getGenerateHandlerInput({});
32
32
  const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
33
33
  expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
34
- import { OpenApiTest } from "../OpenApiTest";
34
+ import { OpenApiTestAuth } from "../OpenApiTestAuth";
35
35
  import { GetPhotoInput } from "./input";
36
36
  import { GetPhotoOutput } from "./output";
37
37
 
@@ -43,17 +43,25 @@ describe('GenerateHandler', () => {
43
43
  handler.usingHttp((http) =>
44
44
  http
45
45
  .get("https://jsonplaceholder.typicode.com/photos")
46
- .handleRequest((ctx, input, request) => request)
47
- .handleResponse((response) => response.parseWithBodyAsJson())
46
+ .handleRequest((ctx, input, request) => request.withoutBody())
47
+ .handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
48
48
  )
49
49
  );`)).toEqual(generatedHandler);
50
50
  });
51
51
  it('it should generate a handler with a path parameter', () => {
52
- const input = [{ type: 'string', name: 'photoId', in: 'path' }];
53
- const payload = getGenerateHandlerInput({ input });
52
+ const input = {
53
+ type: 'object',
54
+ properties: { photoId: { type: 'string', in: 'path' } },
55
+ required: ['photoId'],
56
+ additionalProperties: false,
57
+ };
58
+ const payload = getGenerateHandlerInput({
59
+ input,
60
+ path: '/photos/{photoId}',
61
+ });
54
62
  const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
55
63
  expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
56
- import { OpenApiTest } from "../OpenApiTest";
64
+ import { OpenApiTestAuth } from "../OpenApiTestAuth";
57
65
  import { GetPhotoInput } from "./input";
58
66
  import { GetPhotoOutput } from "./output";
59
67
 
@@ -65,17 +73,22 @@ describe('GenerateHandler', () => {
65
73
  handler.usingHttp((http) =>
66
74
  http
67
75
  .get("https://jsonplaceholder.typicode.com/photos/:photoId")
68
- .handleRequest((ctx, input, request) => request.addPathParameter("photoId", input.photoId))
69
- .handleResponse((response) => response.parseWithBodyAsJson())
76
+ .handleRequest((ctx, input, request) => request.addPathParameter("photoId", input.photoId).withoutBody())
77
+ .handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
70
78
  )
71
79
  );`)).toEqual(generatedHandler);
72
80
  });
73
81
  it('it should generate a handler with a body input as json', () => {
74
- const input = [{ type: 'object', name: 'payload', in: 'body' }];
82
+ const input = {
83
+ type: 'object',
84
+ properties: { photoId: { type: 'string', in: 'body' } },
85
+ required: ['photoId'],
86
+ additionalProperties: false,
87
+ };
75
88
  const payload = getGenerateHandlerInput({ input });
76
89
  const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
77
90
  expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
78
- import { OpenApiTest } from "../OpenApiTest";
91
+ import { OpenApiTestAuth } from "../OpenApiTestAuth";
79
92
  import { GetPhotoInput } from "./input";
80
93
  import { GetPhotoOutput } from "./output";
81
94
 
@@ -87,17 +100,22 @@ describe('GenerateHandler', () => {
87
100
  handler.usingHttp((http) =>
88
101
  http
89
102
  .get("https://jsonplaceholder.typicode.com/photos")
90
- .handleRequest((ctx, input, request) => request.withBodyAsJson(input))
91
- .handleResponse((response) => response.parseWithBodyAsJson())
103
+ .handleRequest((ctx, input, request) => request.withBodyAsJson({ photoId: input.photoId }))
104
+ .handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
92
105
  )
93
106
  );`)).toEqual(generatedHandler);
94
107
  });
95
108
  it('it should generate a handler with a query string input', () => {
96
- const input = [{ type: 'string', name: 'id', in: 'query' }];
109
+ const input = {
110
+ type: 'object',
111
+ properties: { id: { type: 'string', in: 'query' } },
112
+ required: ['id'],
113
+ additionalProperties: false,
114
+ };
97
115
  const payload = getGenerateHandlerInput({ input });
98
116
  const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
99
117
  expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
100
- import { OpenApiTest } from "../OpenApiTest";
118
+ import { OpenApiTestAuth } from "../OpenApiTestAuth";
101
119
  import { GetPhotoInput } from "./input";
102
120
  import { GetPhotoOutput } from "./output";
103
121
 
@@ -109,19 +127,22 @@ describe('GenerateHandler', () => {
109
127
  handler.usingHttp((http) =>
110
128
  http
111
129
  .get("https://jsonplaceholder.typicode.com/photos")
112
- .handleRequest((ctx, input, request) => request.addQueryString("id", input.id))
113
- .handleResponse((response) => response.parseWithBodyAsJson())
130
+ .handleRequest((ctx, input, request) => request.addQueryString("id", input.id).withoutBody())
131
+ .handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
114
132
  )
115
133
  );`)).toEqual(generatedHandler);
116
134
  });
117
135
  it('it should generate a handler with a header input', () => {
118
- const input = [
119
- { type: 'string', name: 'Content-Type', in: 'header' },
120
- ];
136
+ const input = {
137
+ type: 'object',
138
+ properties: { 'Content-Type': { type: 'string', in: 'header' } },
139
+ required: ['photoId'],
140
+ additionalProperties: false,
141
+ };
121
142
  const payload = getGenerateHandlerInput({ input });
122
143
  const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
123
144
  expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
124
- import { OpenApiTest } from "../OpenApiTest";
145
+ import { OpenApiTestAuth } from "../OpenApiTestAuth";
125
146
  import { GetPhotoInput } from "./input";
126
147
  import { GetPhotoOutput } from "./output";
127
148
 
@@ -133,21 +154,56 @@ describe('GenerateHandler', () => {
133
154
  handler.usingHttp((http) =>
134
155
  http
135
156
  .get("https://jsonplaceholder.typicode.com/photos")
136
- .handleRequest((ctx, input, request) => request.addHeader("Content-Type", input.Content-Type))
137
- .handleResponse((response) => response.parseWithBodyAsJson())
157
+ .handleRequest((ctx, input, request) => request.addHeader("Content-Type", input.Content-Type).withoutBody())
158
+ .handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
138
159
  )
139
160
  );`)).toEqual(generatedHandler);
140
161
  });
141
- it('it should generate a handler with a query string and path param input', () => {
142
- const input = [
143
- { type: 'string', name: 'id', in: 'query' },
144
- { type: 'string', name: 'photoId', in: 'path' },
145
- { type: 'string', name: 'commentId', in: 'path' },
146
- ];
162
+ it('it should generate a handler and transform number type to string for input', () => {
163
+ const input = {
164
+ type: 'object',
165
+ properties: { 'Content-Type': { type: 'integer', in: 'header' } },
166
+ required: ['photoId'],
167
+ additionalProperties: false,
168
+ };
147
169
  const payload = getGenerateHandlerInput({ input });
148
170
  const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
149
171
  expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
150
- import { OpenApiTest } from "../OpenApiTest";
172
+ import { OpenApiTestAuth } from "../OpenApiTestAuth";
173
+ import { GetPhotoInput } from "./input";
174
+ import { GetPhotoOutput } from "./output";
175
+
176
+ export const getPhotoHandler = OperationHandlerSetup.configureHandler<
177
+ OpenApiTestAuth,
178
+ GetPhotoInput,
179
+ GetPhotoOutput
180
+ >((handler) =>
181
+ handler.usingHttp((http) =>
182
+ http
183
+ .get("https://jsonplaceholder.typicode.com/photos")
184
+ .handleRequest((ctx, input, request) => request.addHeader("Content-Type", input.Content-Type.toString()).withoutBody())
185
+ .handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
186
+ )
187
+ );`)).toEqual(generatedHandler);
188
+ });
189
+ it('it should generate a handler with a query string and path param input', () => {
190
+ 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,
199
+ };
200
+ const payload = getGenerateHandlerInput({
201
+ input,
202
+ path: '/photos/{photoId}/{commentId}',
203
+ });
204
+ const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
205
+ expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
206
+ import { OpenApiTestAuth } from "../OpenApiTestAuth";
151
207
  import { GetPhotoInput } from "./input";
152
208
  import { GetPhotoOutput } from "./output";
153
209
 
@@ -159,8 +215,38 @@ describe('GenerateHandler', () => {
159
215
  handler.usingHttp((http) =>
160
216
  http
161
217
  .get("https://jsonplaceholder.typicode.com/photos/:photoId/:commentId")
162
- .handleRequest((ctx, input, request) => request.addQueryString("id", input.id).addPathParameter("photoId", input.photoId).addPathParameter("commentId", input.commentId))
163
- .handleResponse((response) => response.parseWithBodyAsJson())
218
+ .handleRequest((ctx, input, request) => request.addQueryString("id", input.id).addPathParameter("photoId", input.photoId).addPathParameter("commentId", input.commentId).withoutBody())
219
+ .handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
220
+ )
221
+ );`)).toEqual(generatedHandler);
222
+ });
223
+ it('it should generate a handler with a query string and body param input', () => {
224
+ 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,
232
+ };
233
+ const payload = getGenerateHandlerInput({ input });
234
+ const generatedHandler = (0, GenerateHandler_1.generateHandler)(payload);
235
+ expect(E.right(`import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
236
+ import { OpenApiTestAuth } from "../OpenApiTestAuth";
237
+ import { GetPhotoInput } from "./input";
238
+ import { GetPhotoOutput } from "./output";
239
+
240
+ export const getPhotoHandler = OperationHandlerSetup.configureHandler<
241
+ OpenApiTestAuth,
242
+ GetPhotoInput,
243
+ GetPhotoOutput
244
+ >((handler) =>
245
+ handler.usingHttp((http) =>
246
+ http
247
+ .get("https://jsonplaceholder.typicode.com/photos")
248
+ .handleRequest((ctx, input, request) => request.addQueryString("id", input.id).withBodyAsJson({ photoId: input.photoId }))
249
+ .handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
164
250
  )
165
251
  );`)).toEqual(generatedHandler);
166
252
  });
@@ -1,11 +1,9 @@
1
1
  import { JSONSchema4 } from 'json-schema';
2
2
  import * as E from 'fp-ts/Either';
3
- type Prop = Record<string, JSONSchema4>;
4
3
  export type GenerateHandlerTestInput = {
5
4
  operationNameCamelCase: string;
6
- input: Prop[];
7
- output: Prop[];
5
+ input: JSONSchema4;
6
+ output: JSONSchema4;
8
7
  };
9
8
  export declare const generateHandlerTest: ({ operationNameCamelCase, input, output, }: GenerateHandlerTestInput) => E.Either<Error, string>;
10
- export {};
11
9
  //# sourceMappingURL=GenerateHandlerTest.d.ts.map
@@ -0,0 +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"}
@@ -37,28 +37,17 @@ const getDefaultValue = (prop) => {
37
37
  case 'array':
38
38
  return prop.items ? `[${getDefaultValue(prop.items)}]` : '[]';
39
39
  case 'object':
40
- return prop.properties
41
- ? handleInput(convertPropertiesToPropArray(prop.properties))
42
- : '{}';
40
+ return prop.properties ? handleInput(prop.properties) : '{}';
43
41
  default:
44
42
  return `'test_value'`;
45
43
  }
46
44
  };
47
- const convertPropertiesToPropArray = (properties) => Object.entries(properties).map(([name, schema]) => ({
48
- [name]: schema,
49
- }));
50
45
  const handleInput = (inputs) => {
51
- const populatedTestInputs = inputs.map((prop) => {
52
- const propName = Object.keys(prop)[0];
53
- return `${propName}: ${getDefaultValue(prop[propName])}`;
54
- });
46
+ const populatedTestInputs = Object.entries(inputs).map(([key, prop]) => `${key}: ${getDefaultValue(prop)}`);
55
47
  return `{ ${populatedTestInputs.join(', ')} }`;
56
48
  };
57
49
  const handleOutput = (outputs) => {
58
- const expectations = outputs.map((prop) => {
59
- const propName = Object.keys(prop)[0];
60
- return `expect(outputValue.${propName}).toEqual(${getDefaultValue(prop[propName])});`;
61
- });
50
+ const expectations = Object.entries(outputs).map(([key, prop]) => `expect(outputValue.${key}).toEqual(${getDefaultValue(prop)});`);
62
51
  return expectations.join('\n');
63
52
  };
64
53
  const generateHandlerTest = ({ operationNameCamelCase, input, output, }) => E.tryCatch(() => `import { OperationHandlerTestSetup } from '@trayio/cdk-dsl/connector/operation/OperationHandlerTest';
@@ -73,12 +62,12 @@ const generateHandlerTest = ({ operationNameCamelCase, input, output, }) => E.tr
73
62
  .testCase('should ${operationNameCamelCase}', (testCase) =>
74
63
  testCase
75
64
  .givenNothing()
76
- .when(() => (${handleInput(input)}))
65
+ .when(() => (${input.properties ? handleInput(input.properties) : `{}`}))
77
66
  .then(({ output }) => {
78
67
  // console.log(output);
79
68
  const outputValue =
80
69
  OperationHandlerResult.getSuccessfulValueOrFail(output);
81
- ${handleOutput(output)}
70
+ ${handleOutput(output.properties || {})}
82
71
  })
83
72
  .finallyDoNothing()
84
73
  )
@@ -0,0 +1 @@
1
+ {"version":3,"file":"GenerateHandlerTest.test.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandlerTest.test.ts"],"names":[],"mappings":""}
@@ -29,30 +29,34 @@ describe('GenerateHandlerTest', () => {
29
29
  it('should generate a handler test with inputs and outputs', () => {
30
30
  const input = {
31
31
  operationNameCamelCase: 'getItem',
32
- input: [
33
- {
32
+ input: {
33
+ type: 'object',
34
+ properties: {
34
35
  id: {
35
36
  type: 'integer',
37
+ format: 'int64',
36
38
  },
37
- },
38
- {
39
39
  name: {
40
40
  type: 'string',
41
41
  },
42
42
  },
43
- ],
44
- output: [
45
- {
43
+ required: ['id', 'name'],
44
+ additionalProperties: false,
45
+ },
46
+ output: {
47
+ type: 'object',
48
+ properties: {
46
49
  id: {
47
50
  type: 'integer',
51
+ format: 'int64',
48
52
  },
49
- },
50
- {
51
53
  name: {
52
54
  type: 'string',
53
55
  },
54
56
  },
55
- ],
57
+ required: ['id'],
58
+ additionalProperties: false,
59
+ },
56
60
  };
57
61
  const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
58
62
  if (E.isLeft(result)) {
@@ -87,14 +91,17 @@ describe('GenerateHandlerTest', () => {
87
91
  it('should generate a handler test with empty inputs', () => {
88
92
  const input = {
89
93
  operationNameCamelCase: 'getItem',
90
- input: [],
91
- output: [
92
- {
94
+ input: {},
95
+ output: {
96
+ type: 'object',
97
+ properties: {
93
98
  success: {
94
99
  type: 'boolean',
95
100
  },
96
101
  },
97
- ],
102
+ required: ['success'],
103
+ additionalProperties: false,
104
+ },
98
105
  };
99
106
  const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
100
107
  if (E.isLeft(result)) {
@@ -128,8 +135,9 @@ describe('GenerateHandlerTest', () => {
128
135
  it('should generate a handler test with a basic object input and output type', () => {
129
136
  const input = {
130
137
  operationNameCamelCase: 'createPerson',
131
- input: [
132
- {
138
+ input: {
139
+ type: 'object',
140
+ properties: {
133
141
  metadata: {
134
142
  type: 'object',
135
143
  properties: {
@@ -142,9 +150,10 @@ describe('GenerateHandlerTest', () => {
142
150
  },
143
151
  },
144
152
  },
145
- ],
146
- output: [
147
- {
153
+ },
154
+ output: {
155
+ type: 'object',
156
+ properties: {
148
157
  parents: {
149
158
  type: 'object',
150
159
  properties: {
@@ -154,7 +163,7 @@ describe('GenerateHandlerTest', () => {
154
163
  },
155
164
  },
156
165
  },
157
- ],
166
+ },
158
167
  };
159
168
  const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
160
169
  if (E.isLeft(result)) {
@@ -188,8 +197,9 @@ describe('GenerateHandlerTest', () => {
188
197
  it('should generate a handler test with a basic array input and output type', () => {
189
198
  const input = {
190
199
  operationNameCamelCase: 'listItems',
191
- input: [
192
- {
200
+ input: {
201
+ type: 'object',
202
+ properties: {
193
203
  ids: {
194
204
  type: 'array',
195
205
  items: {
@@ -197,9 +207,10 @@ describe('GenerateHandlerTest', () => {
197
207
  },
198
208
  },
199
209
  },
200
- ],
201
- output: [
202
- {
210
+ },
211
+ output: {
212
+ type: 'object',
213
+ properties: {
203
214
  parents: {
204
215
  type: 'array',
205
216
  items: {
@@ -207,7 +218,7 @@ describe('GenerateHandlerTest', () => {
207
218
  },
208
219
  },
209
220
  },
210
- ],
221
+ },
211
222
  };
212
223
  const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
213
224
  if (E.isLeft(result)) {
@@ -241,9 +252,10 @@ describe('GenerateHandlerTest', () => {
241
252
  it('should generate a handler test with a complex object output type', () => {
242
253
  const input = {
243
254
  operationNameCamelCase: 'listItems',
244
- input: [],
245
- output: [
246
- {
255
+ input: {},
256
+ output: {
257
+ type: 'object',
258
+ properties: {
247
259
  parents: {
248
260
  type: 'object',
249
261
  properties: {
@@ -259,7 +271,7 @@ describe('GenerateHandlerTest', () => {
259
271
  },
260
272
  },
261
273
  },
262
- ],
274
+ },
263
275
  };
264
276
  const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
265
277
  if (E.isLeft(result)) {
@@ -293,9 +305,10 @@ describe('GenerateHandlerTest', () => {
293
305
  it('should generate a handler test with a complex array output type', () => {
294
306
  const input = {
295
307
  operationNameCamelCase: 'listItems',
296
- input: [],
297
- output: [
298
- {
308
+ input: {},
309
+ output: {
310
+ type: 'object',
311
+ properties: {
299
312
  parents: {
300
313
  type: 'array',
301
314
  items: {
@@ -308,7 +321,7 @@ describe('GenerateHandlerTest', () => {
308
321
  },
309
322
  },
310
323
  },
311
- ],
324
+ },
312
325
  };
313
326
  const result = (0, GenerateHandlerTest_1.generateHandlerTest)(input);
314
327
  if (E.isLeft(result)) {
@@ -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,2 @@
1
+ export {};
2
+ //# sourceMappingURL=GenerateOperationJson.test.d.ts.map
@@ -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,4 @@
1
+ import { JSONSchema4 } from 'json-schema';
2
+ import { Path } from '../../OpenApiTypeDescriptors';
3
+ export declare const generateInputSchema: (endpoint: Path) => JSONSchema4;
4
+ //# sourceMappingURL=GenerateInputSchema.d.ts.map
@@ -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"}