@trayio/tray-openapi 4.15.2-unstable → 4.16.1

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.
@@ -1 +1 @@
1
- {"version":3,"file":"OpenApiSchemaImporter.d.ts","sourceRoot":"","sources":["../src/OpenApiSchemaImporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AASvC,OAAO,EAAQ,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AAGlE,OAAO,EAEN,sBAAsB,EAMtB,MAAM,0BAA0B,CAAC;AAalC,qBAAa,qBAAqB;IACrB,OAAO,CAAC,SAAS;IAAa,OAAO,CAAC,WAAW;gBAAzC,SAAS,EAAE,SAAS,EAAU,WAAW,EAAE,WAAW;IAE1E,cAAc,CACb,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,MAAM,GACnB,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,sBAAsB,CAAC;IAoD/C,OAAO,CAAC,yBAAyB;IAyDjC,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,cAAc;IAoCtB,OAAO,CAAC,oCAAoC;IAgF5C,OAAO,CAAC,0BAA0B;IAwBlC,OAAO,CAAC,0BAA0B;CAclC"}
1
+ {"version":3,"file":"OpenApiSchemaImporter.d.ts","sourceRoot":"","sources":["../src/OpenApiSchemaImporter.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AASvC,OAAO,EAAQ,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAC9D,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AAGlE,OAAO,EAEN,sBAAsB,EAMtB,MAAM,0BAA0B,CAAC;AAalC,qBAAa,qBAAqB;IACrB,OAAO,CAAC,SAAS;IAAa,OAAO,CAAC,WAAW;gBAAzC,SAAS,EAAE,SAAS,EAAU,WAAW,EAAE,WAAW;IAE1E,cAAc,CACb,eAAe,EAAE,MAAM,EACvB,aAAa,EAAE,MAAM,GACnB,EAAE,CAAC,UAAU,CAAC,KAAK,EAAE,sBAAsB,CAAC;IAoD/C,OAAO,CAAC,yBAAyB;IAyDjC,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,cAAc;IAoCtB,OAAO,CAAC,oCAAoC;IA4F5C,OAAO,CAAC,0BAA0B;IAwBlC,OAAO,CAAC,0BAA0B;CAclC"}
@@ -108,6 +108,7 @@ class OpenApiSchemaImporter {
108
108
  metadata: { name: fileName },
109
109
  }, O.none);
110
110
  const operationName = path.operationId;
111
+ const handleFileCreationError = (error, fileName) => (0, function_1.pipe)(writeFile('', fileName), TE.mapLeft(() => error));
111
112
  const operationFileGenerationTasks = {
112
113
  handler: (0, function_1.pipe)(TE.fromEither((0, GenerateHandler_1.generateHandler)({
113
114
  connectorNamePascalCase: StringExtensions_1.StringExtensions.pascalCase(connectorName),
@@ -119,15 +120,15 @@ class OpenApiSchemaImporter {
119
120
  input,
120
121
  })),
121
122
  // TODO: Why does this throw unhelpful errors?
122
- TE.chain((handlerInput) => writeFile(handlerInput, 'handler.ts'))),
123
+ TE.chain((handlerInput) => writeFile(handlerInput, 'handler.ts')), TE.mapLeft((error) => handleFileCreationError(error, 'handler.ts'))),
123
124
  handlerTest: (0, function_1.pipe)(TE.fromEither((0, GenerateHandlerTest_1.generateHandlerTest)({
124
125
  operationNameCamelCase: (0, lodash_1.camelCase)(operationName),
125
126
  input,
126
127
  output,
127
- })), TE.chain((handlerInput) => writeFile(handlerInput, 'handler.test.ts'))),
128
- generateOutputType: (0, function_1.pipe)((0, GenerateOutput_1.generateOutputTypes)(operationName, output), TE.chain((outputType) => writeFile(outputType, 'output.ts'))),
129
- generateInputType: (0, function_1.pipe)((0, GenerateInputTypes_1.generateInputTypes)(operationName, input), TE.chain((inputType) => writeFile(inputType, 'input.ts'))),
130
- operationJson: (0, GenerateOperationJson_1.generateOperationJson)(this.fileStorage, operationPath, (0, lodash_1.snakeCase)(operationName), (0, lodash_1.kebabCase)(operationName), path),
128
+ })), TE.chain((handlerInput) => writeFile(handlerInput, 'handler.test.ts')), TE.mapLeft((error) => handleFileCreationError(error, 'handler.test.ts'))),
129
+ generateOutputType: (0, function_1.pipe)((0, GenerateOutput_1.generateOutputTypes)(operationName, output), TE.chain((outputType) => writeFile(outputType, 'output.ts')), TE.mapLeft((error) => handleFileCreationError(error, 'output.ts'))),
130
+ generateInputType: (0, function_1.pipe)((0, GenerateInputTypes_1.generateInputTypes)(operationName, input), TE.chain((inputType) => writeFile(inputType, 'input.ts')), TE.mapLeft((error) => handleFileCreationError(error, 'input.ts'))),
131
+ operationJson: (0, function_1.pipe)((0, GenerateOperationJson_1.generateOperationJson)((0, lodash_1.snakeCase)(operationName), (0, lodash_1.kebabCase)(operationName), path), TE.chain((operationJson) => writeFile(operationJson, 'operation.json')), TE.mapLeft((error) => handleFileCreationError(error, 'operation.json'))),
131
132
  };
132
133
  return (0, function_1.pipe)((0, Apply_1.sequenceS)(TE.ApplicativePar)(operationFileGenerationTasks), TE.mapLeft((error) => new Error(`Failed to generate files for operation: ${operationName}: ${error}`)), TE.map(() => undefined));
133
134
  }
@@ -1,5 +1,4 @@
1
1
  import * as TE from 'fp-ts/TaskEither';
2
- import { FileStorage } from '@trayio/commons/file/File';
3
2
  import { Path } from '../OpenApiTypeDescriptors';
4
- export declare const generateOperationJson: (fileStorage: FileStorage, operationDirPath: string, operationNameSnakeCase: string, operationNameKebabCase: string, path: Path) => TE.TaskEither<Error, undefined>;
3
+ export declare const generateOperationJson: (operationNameSnakeCase: string, operationNameKebabCase: string, path: Path) => TE.TaskEither<Error, string>;
5
4
  //# sourceMappingURL=GenerateOperationJson.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"GenerateOperationJson.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateOperationJson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGvC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AAExD,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAEjD,eAAO,MAAM,qBAAqB,gBACpB,WAAW,oBACN,MAAM,0BACA,MAAM,0BACN,MAAM,QACxB,IAAI,KACR,GAAG,UAAU,CAAC,KAAK,EAAE,SAAS,CAgChC,CAAC"}
1
+ {"version":3,"file":"GenerateOperationJson.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateOperationJson.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGvC,OAAO,EAAE,IAAI,EAAE,MAAM,2BAA2B,CAAC;AAEjD,eAAO,MAAM,qBAAqB,2BACT,MAAM,0BACN,MAAM,QACxB,IAAI,KACR,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAsB7B,CAAC"}
@@ -27,17 +27,12 @@ exports.generateOperationJson = void 0;
27
27
  const TE = __importStar(require("fp-ts/TaskEither"));
28
28
  const O = __importStar(require("fp-ts/Option"));
29
29
  const function_1 = require("fp-ts/function");
30
- const stream_1 = require("stream");
31
- const generateOperationJson = (fileStorage, operationDirPath, operationNameSnakeCase, operationNameKebabCase, path) => {
30
+ const generateOperationJson = (operationNameSnakeCase, operationNameKebabCase, path) => {
32
31
  const operationDescription = O.getOrElse(() => O.getOrElse(() => '')(path.summary))(path.description);
33
32
  return (0, function_1.pipe)(operationDescription, TE.fromPredicate((description) => description.length > 0, () => new Error('Operation description is empty')), TE.map((description) => ({
34
33
  name: operationNameSnakeCase,
35
34
  title: operationNameKebabCase,
36
35
  description,
37
- })), TE.chain((operationJson) => fileStorage.write({
38
- content: stream_1.Readable.from(JSON.stringify(operationJson)),
39
- key: `${operationDirPath}/operation.json`,
40
- metadata: { name: 'operation.json' },
41
- }, O.none)), TE.mapLeft((error) => new Error(`Failed to generate operation.json for operation: ${error}`)), TE.map(() => undefined));
36
+ })), TE.map((operationJson) => JSON.stringify(operationJson, null, 2)), TE.mapLeft((error) => new Error(`Failed to generate operation.json for operation: ${error}`)));
42
37
  };
43
38
  exports.generateOperationJson = generateOperationJson;
@@ -24,39 +24,10 @@ 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 FakeFileStorage_1 = require("@trayio/commons/file/FakeFileStorage");
28
27
  const O = __importStar(require("fp-ts/Option"));
29
28
  const GenerateOperationJson_1 = require("./GenerateOperationJson");
30
29
  describe('generateOperationJson', () => {
31
- const fileStorage = new FakeFileStorage_1.FakeFileStorage();
32
- it('should generate operation.json file', async () => {
33
- const writeSpy = jest.spyOn(fileStorage, 'write');
34
- const operationDirPath = '/path/to/operation';
35
- const operationNameSnakeCase = 'get_photo';
36
- const operationNameKebabCase = 'get-photo';
37
- const path = {
38
- operationId: 'get_photo',
39
- description: O.some('Get a photo'),
40
- summary: O.none,
41
- tags: O.some([]),
42
- parameters: O.none,
43
- requestBody: O.none,
44
- responses: O.none,
45
- };
46
- const result = await (0, GenerateOperationJson_1.generateOperationJson)(fileStorage, operationDirPath, operationNameSnakeCase, operationNameKebabCase, path)();
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
- }, O.none);
55
- expect(result.right).toBeUndefined();
56
- expect(fileStorage.files.has('/path/to/operation/operation.json')).toEqual(true);
57
- });
58
30
  it('should generate correct data for operation.json', async () => {
59
- const operationDirPath = '/path/to/operation';
60
31
  const operationNameSnakeCase = 'get_photo';
61
32
  const operationNameKebabCase = 'get-photo';
62
33
  const path = {
@@ -68,22 +39,17 @@ describe('generateOperationJson', () => {
68
39
  requestBody: O.none,
69
40
  responses: O.none,
70
41
  };
71
- const result = await (0, GenerateOperationJson_1.generateOperationJson)(fileStorage, operationDirPath, operationNameSnakeCase, operationNameKebabCase, path)();
42
+ const result = await (0, GenerateOperationJson_1.generateOperationJson)(operationNameSnakeCase, operationNameKebabCase, path)();
72
43
  if (E.isLeft(result)) {
73
44
  throw new Error('expected result to be right');
74
45
  }
75
- const operationJson = fileStorage.files.get('/path/to/operation/operation.json');
76
- if (operationJson === undefined) {
77
- throw new Error('expected operationJson to be defined');
78
- }
79
- expect(operationJson.content.read()).toEqual(JSON.stringify({
46
+ expect(result.right).toEqual(JSON.stringify({
80
47
  name: 'get_photo',
81
48
  title: 'get-photo',
82
49
  description: 'Get a photo',
83
- }));
50
+ }, null, 2));
84
51
  });
85
52
  it('should generate operation.json with summary if description is not present', async () => {
86
- const operationDirPath = '/path/to/operation';
87
53
  const operationNameSnakeCase = 'get_photo';
88
54
  const operationNameKebabCase = 'get-photo';
89
55
  const path = {
@@ -95,18 +61,14 @@ describe('generateOperationJson', () => {
95
61
  requestBody: O.none,
96
62
  responses: O.none,
97
63
  };
98
- const result = await (0, GenerateOperationJson_1.generateOperationJson)(fileStorage, operationDirPath, operationNameSnakeCase, operationNameKebabCase, path)();
64
+ const result = await (0, GenerateOperationJson_1.generateOperationJson)(operationNameSnakeCase, operationNameKebabCase, path)();
99
65
  if (E.isLeft(result)) {
100
66
  throw new Error('expected result to be right');
101
67
  }
102
- const operationJson = fileStorage.files.get('/path/to/operation/operation.json');
103
- if (operationJson === undefined) {
104
- throw new Error('expected operationJson to be defined');
105
- }
106
- expect(operationJson.content.read()).toEqual(JSON.stringify({
68
+ expect(result.right).toEqual(JSON.stringify({
107
69
  name: 'get_photo',
108
70
  title: 'get-photo',
109
71
  description: 'Get a photo',
110
- }));
72
+ }, null, 2));
111
73
  });
112
74
  });
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@trayio/tray-openapi",
3
- "version": "4.15.2-unstable",
3
+ "version": "4.16.1",
4
4
  "description": "Creating CDK Projects from OpenAPI 3.0 Schemas",
5
5
  "exports": {
6
6
  "./*": "./dist/*.js"