@trayio/tray-openapi 2.6.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.
- package/dist/OpenApiSchemaImporter.d.ts +4 -2
- package/dist/OpenApiSchemaImporter.d.ts.map +1 -1
- package/dist/OpenApiSchemaImporter.js +49 -22
- package/dist/OpenApiSchemaImporter.test.js +58 -4
- package/dist/OpenApiTypeDescriptors.d.ts +10 -5
- package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
- package/dist/OpenApiTypeDescriptors.js +11 -1
- package/dist/ResolveOptionValues.d.ts +3 -0
- package/dist/ResolveOptionValues.d.ts.map +1 -0
- package/dist/{connector/input/TransformInput.js → ResolveOptionValues.js} +16 -27
- package/dist/ResolveOptionValues.test.d.ts +2 -0
- package/dist/ResolveOptionValues.test.d.ts.map +1 -0
- package/dist/ResolveOptionValues.test.js +91 -0
- package/dist/{GenerateHandler.d.ts → file-generators/GenerateHandler.d.ts} +2 -7
- package/dist/file-generators/GenerateHandler.d.ts.map +1 -0
- package/dist/{GenerateHandler.js → file-generators/GenerateHandler.js} +53 -16
- package/dist/file-generators/GenerateHandler.test.d.ts +2 -0
- package/dist/file-generators/GenerateHandler.test.d.ts.map +1 -0
- package/dist/{GenerateHander.test.js → file-generators/GenerateHandler.test.js} +119 -33
- package/dist/file-generators/GenerateHandlerTest.d.ts +9 -0
- package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -0
- package/dist/file-generators/GenerateHandlerTest.js +76 -0
- package/dist/file-generators/GenerateHandlerTest.test.d.ts +2 -0
- package/dist/file-generators/GenerateHandlerTest.test.d.ts.map +1 -0
- package/dist/file-generators/GenerateHandlerTest.test.js +355 -0
- package/dist/file-generators/GenerateOperationJson.d.ts +4 -0
- package/dist/file-generators/GenerateOperationJson.d.ts.map +1 -0
- package/dist/file-generators/GenerateOperationJson.js +43 -0
- package/dist/file-generators/GenerateOperationJson.test.d.ts +2 -0
- package/dist/file-generators/GenerateOperationJson.test.d.ts.map +1 -0
- package/dist/file-generators/GenerateOperationJson.test.js +77 -0
- package/dist/file-generators/types/GenerateInputSchema.d.ts +4 -0
- package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -0
- package/dist/{connector/input/ProcessInput.js → file-generators/types/GenerateInputSchema.js} +31 -14
- package/dist/file-generators/types/GenerateInputSchema.test.d.ts +2 -0
- package/dist/file-generators/types/GenerateInputSchema.test.d.ts.map +1 -0
- package/dist/{connector/input/ProcessInput.test.js → file-generators/types/GenerateInputSchema.test.js} +25 -14
- package/dist/file-generators/types/GenerateInputTypes.d.ts +4 -0
- package/dist/file-generators/types/GenerateInputTypes.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateInputTypes.js +39 -0
- package/dist/file-generators/types/GenerateOutput.d.ts +9 -0
- package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateOutput.js +54 -0
- package/dist/file-generators/types/GenerateOutput.test.d.ts +2 -0
- package/dist/file-generators/types/GenerateOutput.test.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateOutput.test.js +197 -0
- package/dist/file-generators/types/JsonSchemaToTypescriptOptions.d.ts.map +1 -0
- package/package.json +4 -2
- package/dist/GenerateHander.test.d.ts +0 -2
- package/dist/GenerateHander.test.d.ts.map +0 -1
- package/dist/GenerateHandler.d.ts.map +0 -1
- package/dist/connector/JsonSchemaToTypescriptOptions.d.ts.map +0 -1
- package/dist/connector/input/GenerateInput.d.ts +0 -8
- package/dist/connector/input/GenerateInput.d.ts.map +0 -1
- package/dist/connector/input/GenerateInput.js +0 -8
- package/dist/connector/input/GenerateInput.test.d.ts +0 -2
- package/dist/connector/input/GenerateInput.test.d.ts.map +0 -1
- package/dist/connector/input/GenerateInput.test.js +0 -133
- package/dist/connector/input/ProcessInput.d.ts +0 -4
- package/dist/connector/input/ProcessInput.d.ts.map +0 -1
- package/dist/connector/input/ProcessInput.test.d.ts +0 -2
- package/dist/connector/input/ProcessInput.test.d.ts.map +0 -1
- package/dist/connector/input/TransformInput.d.ts +0 -4
- package/dist/connector/input/TransformInput.d.ts.map +0 -1
- package/dist/connector/input/TransformInput.test.d.ts +0 -2
- package/dist/connector/input/TransformInput.test.d.ts.map +0 -1
- package/dist/connector/input/TransformInput.test.js +0 -75
- /package/dist/{connector → file-generators/types}/JsonSchemaToTypescriptOptions.d.ts +0 -0
- /package/dist/{connector → file-generators/types}/JsonSchemaToTypescriptOptions.js +0 -0
|
@@ -1,12 +1,14 @@
|
|
|
1
1
|
import * as TE from 'fp-ts/TaskEither';
|
|
2
|
+
import { FileStorage } from '@trayio/commons/file/File';
|
|
2
3
|
import { Generator } from '@trayio/generator/generator/Generator';
|
|
3
4
|
export declare class OpenApiSchemaImporter {
|
|
4
5
|
private generator;
|
|
5
|
-
|
|
6
|
+
private fileStorage;
|
|
7
|
+
constructor(generator: Generator, fileStorage: FileStorage);
|
|
6
8
|
buildConnector(openApiSpecPath: string, connectorName: string): TE.TaskEither<Error, undefined>;
|
|
7
9
|
private generateOperationFromPath;
|
|
8
10
|
private getOpenApiSpec;
|
|
9
|
-
private
|
|
11
|
+
private generateHandlerFilesAndOperationJson;
|
|
10
12
|
private generateConnectorDirectory;
|
|
11
13
|
private generateOperationDirectory;
|
|
12
14
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenApiSchemaImporter.d.ts","sourceRoot":"","sources":["../src/OpenApiSchemaImporter.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OpenApiSchemaImporter.d.ts","sourceRoot":"","sources":["../src/OpenApiSchemaImporter.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAQvC,OAAO,EAAE,WAAW,EAAE,MAAM,2BAA2B,CAAC;AACxD,OAAO,EAAE,SAAS,EAAE,MAAM,uCAAuC,CAAC;AAwBlE,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,SAAS,CAAC;IAgClC,OAAO,CAAC,yBAAyB;IAmCjC,OAAO,CAAC,cAAc;IAoCtB,OAAO,CAAC,oCAAoC;IAuE5C,OAAO,CAAC,0BAA0B;IAwBlC,OAAO,CAAC,0BAA0B;CAclC"}
|
|
@@ -27,44 +27,71 @@ exports.OpenApiSchemaImporter = void 0;
|
|
|
27
27
|
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
28
28
|
const E = __importStar(require("fp-ts/Either"));
|
|
29
29
|
const function_1 = require("fp-ts/function");
|
|
30
|
-
const fse = __importStar(require("fs-extra"));
|
|
31
30
|
const Array_1 = require("fp-ts/Array");
|
|
31
|
+
const Apply_1 = require("fp-ts/Apply");
|
|
32
|
+
const json_ref_resolver_1 = require("@stoplight/json-ref-resolver");
|
|
32
33
|
const StringExtensions_1 = require("@trayio/commons/string/StringExtensions");
|
|
33
34
|
const lodash_1 = require("lodash");
|
|
34
|
-
const
|
|
35
|
+
const stream_1 = require("stream");
|
|
36
|
+
const BufferExtensions_1 = require("@trayio/commons/buffer/BufferExtensions");
|
|
35
37
|
const OpenApiCodecs_1 = require("./OpenApiCodecs");
|
|
36
|
-
const GenerateHandler_1 = require("./GenerateHandler");
|
|
38
|
+
const GenerateHandler_1 = require("./file-generators/GenerateHandler");
|
|
39
|
+
const GenerateOutput_1 = require("./file-generators/types/GenerateOutput");
|
|
40
|
+
const GenerateInputTypes_1 = require("./file-generators/types/GenerateInputTypes");
|
|
41
|
+
const GenerateHandlerTest_1 = require("./file-generators/GenerateHandlerTest");
|
|
42
|
+
const GenerateOperationJson_1 = require("./file-generators/GenerateOperationJson");
|
|
43
|
+
const GenerateInputSchema_1 = require("./file-generators/types/GenerateInputSchema");
|
|
37
44
|
class OpenApiSchemaImporter {
|
|
38
|
-
constructor(generator) {
|
|
45
|
+
constructor(generator, fileStorage) {
|
|
39
46
|
this.generator = generator;
|
|
47
|
+
this.fileStorage = fileStorage;
|
|
40
48
|
}
|
|
41
49
|
buildConnector(openApiSpecPath, connectorName) {
|
|
42
|
-
return (0, function_1.pipe)(this.generateConnectorDirectory(connectorName), TE.bindTo('connectorPath'), TE.bind('openApiSpec', () =>
|
|
50
|
+
return (0, function_1.pipe)(this.generateConnectorDirectory(connectorName), TE.bindTo('connectorPath'), TE.bind('openApiSpec', () => this.getOpenApiSpec(openApiSpecPath)), TE.bind('paths', ({ openApiSpec }) => TE.right(Object.keys(openApiSpec.paths).map((path) => ({
|
|
43
51
|
path,
|
|
44
52
|
routes: Object.keys(openApiSpec.paths[path]).map((route) => ({
|
|
45
53
|
method: route,
|
|
46
54
|
path: openApiSpec.paths[path][route],
|
|
47
55
|
})),
|
|
48
|
-
})))), TE.
|
|
56
|
+
})))), TE.chain(({ openApiSpec, connectorPath, paths }) => (0, Array_1.traverse)(TE.ApplicativeSeq)((path) => this.generateOperationFromPath(path, connectorPath, openApiSpec.servers[0].url, connectorName))(paths)), TE.map(() => undefined));
|
|
49
57
|
}
|
|
50
58
|
generateOperationFromPath(path, connectorPath, baseUrl, connectorName) {
|
|
51
|
-
return (0, function_1.pipe)((0, Array_1.traverse)(
|
|
59
|
+
return (0, function_1.pipe)((0, Array_1.traverse)(TE.ApplicativeSeq)((route) => (0, function_1.pipe)(this.generateOperationDirectory(connectorPath, route.path.operationId), TE.bind('inputs', () => TE.right((0, GenerateInputSchema_1.generateInputSchema)(route.path))), TE.bind('outputs', () => (0, GenerateOutput_1.generateOutputSchema)(route.path.responses)), TE.chain(({ inputs, outputs }) => this.generateHandlerFilesAndOperationJson(route, `${connectorPath}/src/${(0, lodash_1.kebabCase)(route.path.operationId)}`, baseUrl, path.path, connectorName, inputs, outputs))))(path.routes), TE.map(() => undefined));
|
|
52
60
|
}
|
|
53
61
|
getOpenApiSpec(openApiSpecPath) {
|
|
54
|
-
return (0, function_1.pipe)(
|
|
62
|
+
return (0, function_1.pipe)(this.fileStorage.read(openApiSpecPath), TE.chain((openApiSpec) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(openApiSpec.content)), TE.chain((openApiSpec) => TE.fromEither(E.tryCatch(() => JSON.parse(Buffer.from(openApiSpec).toString('utf-8')), (error) => new Error(`Failed to parse OpenAPI spec as JSON from path ${openApiSpecPath}: ${error}`)))), TE.chain((openApiSpec) => TE.tryCatch(() => {
|
|
63
|
+
const resolver = new json_ref_resolver_1.Resolver({});
|
|
64
|
+
const resolvedOpenApiSpec = resolver.resolve(openApiSpec, {});
|
|
65
|
+
return resolvedOpenApiSpec;
|
|
66
|
+
}, (reason) => new Error(`Failed to resolve references in schema: ${reason}`))), TE.chain((openApiSpec) => TE.fromEither(OpenApiCodecs_1.openApiSpecCodec.decode(openApiSpec.result))));
|
|
55
67
|
}
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
+
generateHandlerFilesAndOperationJson(route, operationPath, baseUrl, path, connectorName, input, output) {
|
|
69
|
+
const { method, path: { operationId: operationName, description }, } = route;
|
|
70
|
+
const writeFile = (content, fileName) => this.fileStorage.write({
|
|
71
|
+
content: stream_1.Readable.from(content),
|
|
72
|
+
key: `${operationPath}/${fileName}`,
|
|
73
|
+
metadata: { name: fileName },
|
|
74
|
+
});
|
|
75
|
+
const operationFileGenerationTasks = {
|
|
76
|
+
handler: (0, function_1.pipe)(TE.fromEither((0, GenerateHandler_1.generateHandler)({
|
|
77
|
+
connectorNamePascalCase: StringExtensions_1.StringExtensions.pascalCase(connectorName),
|
|
78
|
+
operationNameCamelCase: (0, lodash_1.camelCase)(operationName),
|
|
79
|
+
operationNamePascalCase: StringExtensions_1.StringExtensions.pascalCase(operationName),
|
|
80
|
+
httpMethod: method,
|
|
81
|
+
baseUrl,
|
|
82
|
+
path,
|
|
83
|
+
input,
|
|
84
|
+
})), TE.chain((handlerInput) => writeFile(handlerInput, 'handler.ts'))),
|
|
85
|
+
handlerTest: (0, function_1.pipe)(TE.fromEither((0, GenerateHandlerTest_1.generateHandlerTest)({
|
|
86
|
+
operationNameCamelCase: (0, lodash_1.camelCase)(operationName),
|
|
87
|
+
input,
|
|
88
|
+
output,
|
|
89
|
+
})), TE.chain((handlerInput) => writeFile(handlerInput, 'handler.test.ts'))),
|
|
90
|
+
generateOutputType: (0, function_1.pipe)((0, GenerateOutput_1.generateOutputTypes)(operationName, output), TE.chain((outputType) => writeFile(outputType, 'output.ts'))),
|
|
91
|
+
generateInputType: (0, function_1.pipe)((0, GenerateInputTypes_1.generateInputTypes)(operationName, input), TE.chain((inputType) => writeFile(inputType, 'input.ts'))),
|
|
92
|
+
operationJson: (0, GenerateOperationJson_1.generateOperationJson)(this.fileStorage, operationPath, operationName, (0, lodash_1.kebabCase)(operationName), description),
|
|
93
|
+
};
|
|
94
|
+
return (0, function_1.pipe)((0, Apply_1.sequenceS)(TE.ApplicativePar)(operationFileGenerationTasks), TE.mapLeft((error) => new Error(`Failed to generate files for operation: ${error}`)), TE.map(() => undefined));
|
|
68
95
|
}
|
|
69
96
|
generateConnectorDirectory(connectorName) {
|
|
70
97
|
return (0, function_1.pipe)(TE.right({
|
|
@@ -72,10 +99,10 @@ class OpenApiSchemaImporter {
|
|
|
72
99
|
connectorNameKebabCase: (0, lodash_1.kebabCase)(connectorName),
|
|
73
100
|
connectorNamePascalCase: StringExtensions_1.StringExtensions.pascalCase(connectorName),
|
|
74
101
|
connectorNameCamelCase: (0, lodash_1.camelCase)(connectorName),
|
|
75
|
-
}), TE.chain((parameters) => this.generator.generate(`${__dirname}/templates/connector-template.zip`, `${process.cwd()}/test`, parameters)), TE.map(() =>
|
|
102
|
+
}), TE.chain((parameters) => this.generator.generate(`${__dirname}/templates/connector-template.zip`, `${process.cwd()}/test`, parameters)), TE.map(() => `/test/${(0, lodash_1.kebabCase)(connectorName)}`), TE.mapLeft((error) => new Error(`Failed to generate connector directory: ${error}`)));
|
|
76
103
|
}
|
|
77
104
|
generateOperationDirectory(connectorPath, operationName) {
|
|
78
|
-
return (0, function_1.pipe)(
|
|
105
|
+
return (0, function_1.pipe)(TE.tryCatch(this.fileStorage.createDirectory(`${connectorPath}/src/${(0, lodash_1.kebabCase)(operationName)}`), (error) => new Error(`Failed to create operation directory: ${error}`)), TE.map(() => `${connectorPath}/src/${(0, lodash_1.kebabCase)(operationName)}`));
|
|
79
106
|
}
|
|
80
107
|
}
|
|
81
108
|
exports.OpenApiSchemaImporter = OpenApiSchemaImporter;
|
|
@@ -1,4 +1,27 @@
|
|
|
1
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
|
+
};
|
|
2
25
|
var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, generator) {
|
|
3
26
|
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
|
|
4
27
|
return new (P || (P = Promise))(function (resolve, reject) {
|
|
@@ -10,12 +33,43 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
10
33
|
};
|
|
11
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
35
|
const NodeFsGenerator_1 = require("@trayio/generator/generator/NodeFsGenerator");
|
|
36
|
+
const FakeFileStorage_1 = require("@trayio/commons/file/FakeFileStorage");
|
|
37
|
+
const stream_1 = require("stream");
|
|
38
|
+
const fs = __importStar(require("fs-extra"));
|
|
13
39
|
const OpenApiSchemaImporter_1 = require("./OpenApiSchemaImporter");
|
|
40
|
+
const openApiSpec = __importStar(require("./single-get-openapi.json"));
|
|
14
41
|
describe('openApiSchemaImporter', () => {
|
|
15
42
|
const generator = new NodeFsGenerator_1.NodeFsGenerator();
|
|
16
|
-
const
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
43
|
+
const fileStorage = new FakeFileStorage_1.FakeFileStorage();
|
|
44
|
+
const openApiSchemaImporter = new OpenApiSchemaImporter_1.OpenApiSchemaImporter(generator, fileStorage);
|
|
45
|
+
let result;
|
|
46
|
+
beforeAll(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
47
|
+
fileStorage.write({
|
|
48
|
+
key: `${__dirname}/single-get-openapi.json`,
|
|
49
|
+
metadata: { name: 'single-get-openapi.json' },
|
|
50
|
+
content: stream_1.Readable.from(Buffer.from(JSON.stringify(openApiSpec))),
|
|
51
|
+
});
|
|
52
|
+
result = yield openApiSchemaImporter.buildConnector(`${__dirname}/single-get-openapi.json`, 'testConnector')();
|
|
53
|
+
}));
|
|
54
|
+
afterAll(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
55
|
+
yield fs.rm(`${process.cwd()}/test/`, { recursive: true, force: true });
|
|
20
56
|
}));
|
|
57
|
+
it('should import successfully', () => {
|
|
58
|
+
expect(result._tag).toEqual('Right');
|
|
59
|
+
});
|
|
60
|
+
it('should generate a operation handler', () => {
|
|
61
|
+
expect(fileStorage.files.has(`/test/test-connector/src/get-post/handler.ts`)).toEqual(true);
|
|
62
|
+
});
|
|
63
|
+
it('should generate an operation handler test', () => {
|
|
64
|
+
expect(fileStorage.files.has(`/test/test-connector/src/get-post/handler.test.ts`)).toEqual(true);
|
|
65
|
+
});
|
|
66
|
+
it('should generate an operation.json', () => {
|
|
67
|
+
expect(fileStorage.files.has(`/test/test-connector/src/get-post/operation.json`)).toEqual(true);
|
|
68
|
+
});
|
|
69
|
+
it('should generate an output.ts', () => {
|
|
70
|
+
expect(fileStorage.files.has(`/test/test-connector/src/get-post/output.ts`)).toEqual(true);
|
|
71
|
+
});
|
|
72
|
+
it('should generate a operation directory', () => {
|
|
73
|
+
expect(fileStorage.files.has(`/test/test-connector/src/get-post`)).toEqual(true);
|
|
74
|
+
});
|
|
21
75
|
});
|
|
@@ -6,6 +6,7 @@ export type Path = {
|
|
|
6
6
|
operationId: string;
|
|
7
7
|
parameters: O.Option<Parameter[]>;
|
|
8
8
|
requestBody: O.Option<RequestBody>;
|
|
9
|
+
responses: O.Option<Responses>;
|
|
9
10
|
};
|
|
10
11
|
export type Parameter = {
|
|
11
12
|
name: string;
|
|
@@ -20,22 +21,26 @@ export type Parameter = {
|
|
|
20
21
|
export type RequestBody = {
|
|
21
22
|
content: Record<string, MediaType>;
|
|
22
23
|
};
|
|
23
|
-
type MediaType = {
|
|
24
|
+
export type MediaType = {
|
|
24
25
|
schema: ArraySchema | ObjectSchema;
|
|
25
26
|
};
|
|
27
|
+
export type Responses = Record<string, Response>;
|
|
28
|
+
export type Response = {
|
|
29
|
+
description: string;
|
|
30
|
+
content: O.Option<Record<string, MediaType>>;
|
|
31
|
+
};
|
|
26
32
|
export type OpenApiHttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
27
33
|
type ArraySchema = {
|
|
28
34
|
type: 'array';
|
|
29
|
-
items:
|
|
30
|
-
$ref: string;
|
|
31
|
-
};
|
|
35
|
+
items: PropertySchema;
|
|
32
36
|
};
|
|
33
37
|
type ObjectSchema = {
|
|
34
38
|
type: 'object';
|
|
35
39
|
required?: string[];
|
|
36
40
|
properties: Record<string, PropertySchema>;
|
|
41
|
+
additionalProperties: O.Option<boolean>;
|
|
37
42
|
};
|
|
38
|
-
type PropertySchema = {
|
|
43
|
+
export type PropertySchema = {
|
|
39
44
|
type: string;
|
|
40
45
|
} | ArraySchema | ObjectSchema;
|
|
41
46
|
type ComponentSchema = {
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenApiTypeDescriptors.d.ts","sourceRoot":"","sources":["../src/OpenApiTypeDescriptors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAGlC,MAAM,MAAM,IAAI,GAAG;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;IAClC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;
|
|
1
|
+
{"version":3,"file":"OpenApiTypeDescriptors.d.ts","sourceRoot":"","sources":["../src/OpenApiTypeDescriptors.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,OAAO,CAAC;AAE3B,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAGlC,MAAM,MAAM,IAAI,GAAG;IAClB,WAAW,EAAE,MAAM,CAAC;IACpB,IAAI,EAAE,MAAM,EAAE,CAAC;IACf,WAAW,EAAE,MAAM,CAAC;IACpB,UAAU,EAAE,CAAC,CAAC,MAAM,CAAC,SAAS,EAAE,CAAC,CAAC;IAClC,WAAW,EAAE,CAAC,CAAC,MAAM,CAAC,WAAW,CAAC,CAAC;IACnC,SAAS,EAAE,CAAC,CAAC,MAAM,CAAC,SAAS,CAAC,CAAC;CAC/B,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACvB,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,MAAM,CAAC;IACX,WAAW,EAAE,MAAM,CAAC;IACpB,QAAQ,EAAE,OAAO,CAAC;IAClB,MAAM,EAAE;QACP,IAAI,EAAE,MAAM,CAAC;QACb,MAAM,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,CAAC;KACzB,CAAC;CACF,CAAC;AAEF,MAAM,MAAM,WAAW,GAAG;IACzB,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG;IACvB,MAAM,EAAE,WAAW,GAAG,YAAY,CAAC;CACnC,CAAC;AAEF,MAAM,MAAM,SAAS,GAAG,MAAM,CAAC,MAAM,EAAE,QAAQ,CAAC,CAAC;AAEjD,MAAM,MAAM,QAAQ,GAAG;IACtB,WAAW,EAAE,MAAM,CAAC;IACpB,OAAO,EAAE,CAAC,CAAC,MAAM,CAAC,MAAM,CAAC,MAAM,EAAE,SAAS,CAAC,CAAC,CAAC;CAC7C,CAAC;AAEF,MAAM,MAAM,iBAAiB,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAE5E,KAAK,WAAW,GAAG;IAClB,IAAI,EAAE,OAAO,CAAC;IACd,KAAK,EAAE,cAAc,CAAC;CACtB,CAAC;AAEF,KAAK,YAAY,GAAG;IACnB,IAAI,EAAE,QAAQ,CAAC;IACf,QAAQ,CAAC,EAAE,MAAM,EAAE,CAAC;IACpB,UAAU,EAAE,MAAM,CAAC,MAAM,EAAE,cAAc,CAAC,CAAC;IAC3C,oBAAoB,EAAE,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC;CACxC,CAAC;AAEF,MAAM,MAAM,cAAc,GAAG;IAAE,IAAI,EAAE,MAAM,CAAA;CAAE,GAAG,WAAW,GAAG,YAAY,CAAC;AAE3E,KAAK,eAAe,GAAG;IAAE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,WAAW,GAAG,YAAY,CAAC,CAAA;CAAE,CAAC;AAE/E,MAAM,MAAM,aAAa,GAAG;IAC3B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE;QACL,KAAK,EAAE,MAAM,CAAC;QACd,WAAW,EAAE,MAAM,CAAC;QACpB,OAAO,EAAE,MAAM,CAAC;KAChB,CAAC;IACF,OAAO,EAAE;QACR,GAAG,EAAE,MAAM,CAAC;KACZ,EAAE,CAAC;IACJ,KAAK,EAAE,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,MAAM,CAAC,iBAAiB,EAAE,IAAI,CAAC,CAAC,CAAC,CAAC;IAChE,UAAU,EAAE,eAAe,CAAC;CAC5B,CAAC;AAqFF,eAAO,MAAM,yBAAyB,EAAE,CAAC,CAAC,IAAI,CAAC,aAAa,EAAE,OAAO,CAWpE,CAAC"}
|
|
@@ -27,12 +27,17 @@ exports.openApiSpecTypeDescriptor = void 0;
|
|
|
27
27
|
const t = __importStar(require("io-ts"));
|
|
28
28
|
const io_ts_types_1 = require("io-ts-types");
|
|
29
29
|
const TypeCodec_1 = require("@trayio/commons/codec/TypeCodec");
|
|
30
|
+
// Codecs
|
|
30
31
|
const openApiSpecPropertySchemaTypeDescriptor = t.type({ type: t.string });
|
|
31
32
|
const openApiSpecObjectSchemaTypeDescriptor = t.type({
|
|
32
33
|
type: t.literal('object'),
|
|
33
34
|
properties: t.record(t.string, openApiSpecPropertySchemaTypeDescriptor),
|
|
35
|
+
additionalProperties: (0, io_ts_types_1.optionFromNullable)(t.boolean),
|
|
36
|
+
});
|
|
37
|
+
const openApiSpecArraySchemaTypeDescriptor = t.type({
|
|
38
|
+
type: t.literal('array'),
|
|
39
|
+
items: openApiSpecPropertySchemaTypeDescriptor,
|
|
34
40
|
});
|
|
35
|
-
const openApiSpecArraySchemaTypeDescriptor = t.type({ type: t.literal('array'), items: t.any });
|
|
36
41
|
const openApiSpecMediaTypeTypeDescriptor = t.type({
|
|
37
42
|
schema: t.union([
|
|
38
43
|
openApiSpecObjectSchemaTypeDescriptor,
|
|
@@ -48,6 +53,10 @@ const openApiSpecComponentSchemaTypeDescriptor = t.type({
|
|
|
48
53
|
const openApiSpecRequestBodyTypeDescriptor = t.type({
|
|
49
54
|
content: t.record(t.string, openApiSpecMediaTypeTypeDescriptor),
|
|
50
55
|
});
|
|
56
|
+
const openApiSpecResponsesTypeDescriptor = t.record(t.string, t.type({
|
|
57
|
+
description: t.string,
|
|
58
|
+
content: (0, io_ts_types_1.optionFromNullable)(t.record(t.string, openApiSpecMediaTypeTypeDescriptor)),
|
|
59
|
+
}));
|
|
51
60
|
const openApiSpecPathTypeDescriptor = t.type({
|
|
52
61
|
description: t.string,
|
|
53
62
|
tags: t.array(t.string),
|
|
@@ -63,6 +72,7 @@ const openApiSpecPathTypeDescriptor = t.type({
|
|
|
63
72
|
}),
|
|
64
73
|
}))),
|
|
65
74
|
requestBody: (0, io_ts_types_1.optionFromNullable)(openApiSpecRequestBodyTypeDescriptor),
|
|
75
|
+
responses: (0, io_ts_types_1.optionFromNullable)(openApiSpecResponsesTypeDescriptor),
|
|
66
76
|
});
|
|
67
77
|
const httpKeys = t.keyof({
|
|
68
78
|
get: null,
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResolveOptionValues.d.ts","sourceRoot":"","sources":["../src/ResolveOptionValues.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,eAAO,MAAM,mBAAmB,UAAW,OAAO,KAAG,EAAE,MAAM,CAAC,KAAK,EAAE,OAAO,CAC/B,CAAC"}
|
|
@@ -23,32 +23,21 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
23
23
|
return result;
|
|
24
24
|
};
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
|
-
exports.
|
|
27
|
-
const
|
|
26
|
+
exports.resolveOptionValues = void 0;
|
|
27
|
+
const Option_1 = require("fp-ts/lib/Option");
|
|
28
28
|
const O = __importStar(require("fp-ts/Option"));
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
transformedParameters[parameter.name] = (0, openapi_schema_to_json_schema_1.fromParameter)(paramterWithJsdocAnnotation);
|
|
43
|
-
if (parameter.required === true) {
|
|
44
|
-
requiredParameters.push(parameter.name);
|
|
45
|
-
}
|
|
46
|
-
});
|
|
47
|
-
return {
|
|
48
|
-
type: 'object',
|
|
49
|
-
properties: Object.assign({}, transformedParameters),
|
|
50
|
-
required: [...requiredParameters],
|
|
51
|
-
additionalProperties: false,
|
|
52
|
-
};
|
|
29
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
30
|
+
const resolveOptionValues = (value) => E.right(resolveOptionValuesIfPresent(value));
|
|
31
|
+
exports.resolveOptionValues = resolveOptionValues;
|
|
32
|
+
const isObject = (value) => typeof value === 'object' && !Array.isArray(value) && value !== null;
|
|
33
|
+
const isOption = (value) => (0, Option_1.isSome)(value) || (0, Option_1.isNone)(value);
|
|
34
|
+
const resolveOptionValuesIfPresent = (value) => {
|
|
35
|
+
if (isOption(value)) {
|
|
36
|
+
return O.fold(() => undefined, (someValue) => someValue)(value);
|
|
37
|
+
}
|
|
38
|
+
if (isObject(value)) {
|
|
39
|
+
return resolveOptionFromObjectIfPresent(value);
|
|
40
|
+
}
|
|
41
|
+
return value;
|
|
53
42
|
};
|
|
54
|
-
|
|
43
|
+
const resolveOptionFromObjectIfPresent = (value) => Object.entries(value).reduce((acc, [key, propertyValue]) => (Object.assign(Object.assign({}, acc), { [key]: resolveOptionValuesIfPresent(propertyValue) })), {});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ResolveOptionValues.test.d.ts","sourceRoot":"","sources":["../src/ResolveOptionValues.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,91 @@
|
|
|
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
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
27
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
28
|
+
const ResolveOptionValues_1 = require("./ResolveOptionValues");
|
|
29
|
+
describe('ResolveOptionValues', () => {
|
|
30
|
+
it('it should resolve some options to their underlying values', () => {
|
|
31
|
+
const given = O.some('some value');
|
|
32
|
+
const resolvedOptions = (0, ResolveOptionValues_1.resolveOptionValues)(given);
|
|
33
|
+
const actual = E.getOrElse((error) => {
|
|
34
|
+
throw new Error('Should have been right');
|
|
35
|
+
})(resolvedOptions);
|
|
36
|
+
const expected = 'some value';
|
|
37
|
+
expect(actual).toEqual(expected);
|
|
38
|
+
});
|
|
39
|
+
it('it should resolve none options to undefined', () => {
|
|
40
|
+
const given = O.none;
|
|
41
|
+
const resolvedOptions = (0, ResolveOptionValues_1.resolveOptionValues)(given);
|
|
42
|
+
const actual = E.getOrElse((error) => {
|
|
43
|
+
throw new Error('Should have been right');
|
|
44
|
+
})(resolvedOptions);
|
|
45
|
+
const expected = undefined;
|
|
46
|
+
expect(actual).toEqual(expected);
|
|
47
|
+
});
|
|
48
|
+
it('it should return values unaltered that are not options', () => {
|
|
49
|
+
const given = 'some value';
|
|
50
|
+
const resolvedOptions = (0, ResolveOptionValues_1.resolveOptionValues)(given);
|
|
51
|
+
const actual = E.getOrElse((error) => {
|
|
52
|
+
throw new Error('Should have been right');
|
|
53
|
+
})(resolvedOptions);
|
|
54
|
+
const expected = 'some value';
|
|
55
|
+
expect(actual).toEqual(expected);
|
|
56
|
+
});
|
|
57
|
+
it('it should return arrays unaltered that are not options', () => {
|
|
58
|
+
const given = ['some value'];
|
|
59
|
+
const resolvedOptions = (0, ResolveOptionValues_1.resolveOptionValues)(given);
|
|
60
|
+
const actual = E.getOrElse((error) => {
|
|
61
|
+
throw new Error('Should have been right');
|
|
62
|
+
})(resolvedOptions);
|
|
63
|
+
const expected = ['some value'];
|
|
64
|
+
expect(actual).toEqual(expected);
|
|
65
|
+
});
|
|
66
|
+
it('it should resolve an object with some options to their underlying values', () => {
|
|
67
|
+
const given = {
|
|
68
|
+
property: 'some property',
|
|
69
|
+
someOptionalProperty: O.some('some value'),
|
|
70
|
+
noneOptionalProperty: O.none,
|
|
71
|
+
nestedObject: {
|
|
72
|
+
someNestedOptionalProperty: O.some('some nested value'),
|
|
73
|
+
someNestedNoneOptionalProperty: O.none,
|
|
74
|
+
},
|
|
75
|
+
};
|
|
76
|
+
const resolvedOptions = (0, ResolveOptionValues_1.resolveOptionValues)(given);
|
|
77
|
+
const actual = E.getOrElse((error) => {
|
|
78
|
+
throw new Error('Should have been right');
|
|
79
|
+
})(resolvedOptions);
|
|
80
|
+
const expected = {
|
|
81
|
+
property: 'some property',
|
|
82
|
+
someOptionalProperty: 'some value',
|
|
83
|
+
noneOptionalProperty: undefined,
|
|
84
|
+
nestedObject: {
|
|
85
|
+
someNestedOptionalProperty: 'some nested value',
|
|
86
|
+
someNestedNoneOptionalProperty: undefined,
|
|
87
|
+
},
|
|
88
|
+
};
|
|
89
|
+
expect(actual).toEqual(expected);
|
|
90
|
+
});
|
|
91
|
+
});
|
|
@@ -1,11 +1,6 @@
|
|
|
1
1
|
import * as E from 'fp-ts/Either';
|
|
2
|
-
|
|
2
|
+
import { JSONSchema4 } from 'json-schema';
|
|
3
3
|
type HandlerHttpMethod = 'get' | 'post' | 'put' | 'patch' | 'delete';
|
|
4
|
-
type Input = {
|
|
5
|
-
name: string;
|
|
6
|
-
type: string;
|
|
7
|
-
in: InputMethod;
|
|
8
|
-
};
|
|
9
4
|
export type GenerateHandlerInput = {
|
|
10
5
|
connectorNamePascalCase: string;
|
|
11
6
|
operationNamePascalCase: string;
|
|
@@ -13,7 +8,7 @@ export type GenerateHandlerInput = {
|
|
|
13
8
|
httpMethod: HandlerHttpMethod;
|
|
14
9
|
baseUrl: string;
|
|
15
10
|
path: string;
|
|
16
|
-
input:
|
|
11
|
+
input: JSONSchema4;
|
|
17
12
|
};
|
|
18
13
|
export declare const generateHandler: ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, path, input, }: GenerateHandlerInput) => E.Either<Error, string>;
|
|
19
14
|
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateHandler.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,EAAE,WAAW,EAAuB,MAAM,aAAa,CAAC;AAE/D,KAAK,iBAAiB,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE,MAAM,MAAM,oBAAoB,GAAG;IAClC,uBAAuB,EAAE,MAAM,CAAC;IAChC,uBAAuB,EAAE,MAAM,CAAC;IAChC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,UAAU,EAAE,iBAAiB,CAAC;IAC9B,OAAO,EAAE,MAAM,CAAC;IAChB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,WAAW,CAAC;CACnB,CAAC;AAyGF,eAAO,MAAM,eAAe,oHAQzB,oBAAoB,KAAG,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAoB9C,CAAC"}
|
|
@@ -25,39 +25,76 @@ var __importStar = (this && this.__importStar) || function (mod) {
|
|
|
25
25
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
26
|
exports.generateHandler = void 0;
|
|
27
27
|
const E = __importStar(require("fp-ts/Either"));
|
|
28
|
+
const getInputVariable = (name, type) => {
|
|
29
|
+
if (type === undefined) {
|
|
30
|
+
return `input.${name}`;
|
|
31
|
+
}
|
|
32
|
+
switch (type) {
|
|
33
|
+
case 'integer':
|
|
34
|
+
case 'boolean':
|
|
35
|
+
case 'number':
|
|
36
|
+
return `input.${name}.toString()`;
|
|
37
|
+
default:
|
|
38
|
+
return `input.${name}`;
|
|
39
|
+
}
|
|
40
|
+
};
|
|
28
41
|
const handleInput = (inputs) => {
|
|
29
|
-
if (
|
|
30
|
-
|
|
42
|
+
if (inputs.properties === undefined ||
|
|
43
|
+
Object.keys(inputs.properties).length === 0) {
|
|
44
|
+
return 'request.withoutBody()';
|
|
31
45
|
}
|
|
32
|
-
const
|
|
46
|
+
const inputsArray = Object.entries(inputs.properties);
|
|
47
|
+
const bodyInputs = [];
|
|
48
|
+
const handlerInput = inputsArray.map(([name, input], index) => {
|
|
33
49
|
const prefix = index === 0 ? 'request.' : '';
|
|
34
|
-
let inputMapping;
|
|
50
|
+
let inputMapping = '';
|
|
35
51
|
switch (input.in) {
|
|
36
52
|
case 'body':
|
|
37
|
-
|
|
53
|
+
bodyInputs.push(`${name}: input.${name}`);
|
|
38
54
|
break;
|
|
39
55
|
case 'path':
|
|
40
|
-
inputMapping = `addPathParameter("${
|
|
56
|
+
inputMapping = `addPathParameter("${name}", ${getInputVariable(name, input.type)})`;
|
|
41
57
|
break;
|
|
42
58
|
case 'query':
|
|
43
|
-
inputMapping = `addQueryString("${
|
|
59
|
+
inputMapping = `addQueryString("${name}", ${getInputVariable(name, input.type)})`;
|
|
44
60
|
break;
|
|
45
61
|
case 'header':
|
|
46
|
-
inputMapping = `addHeader("${
|
|
62
|
+
inputMapping = `addHeader("${name}", ${getInputVariable(name, input.type)})`;
|
|
47
63
|
break;
|
|
48
64
|
}
|
|
49
65
|
return prefix + inputMapping;
|
|
50
66
|
});
|
|
51
|
-
return handlerInput
|
|
67
|
+
return generateRequestHandlerInputs(handlerInput, bodyInputs);
|
|
52
68
|
};
|
|
53
|
-
const
|
|
54
|
-
if (
|
|
55
|
-
|
|
69
|
+
const generateRequestHandlerInputs = (inputs, bodyInputs) => {
|
|
70
|
+
if (bodyInputs.length > 0) {
|
|
71
|
+
const constructedBodyProperty = `withBodyAsJson({ ${bodyInputs.join(',')} })`;
|
|
72
|
+
if (inputs[0] === 'request.') {
|
|
73
|
+
return inputs
|
|
74
|
+
.join('.')
|
|
75
|
+
.replace('request.', `request.${constructedBodyProperty}`);
|
|
76
|
+
}
|
|
77
|
+
inputs.push(constructedBodyProperty);
|
|
78
|
+
}
|
|
79
|
+
else {
|
|
80
|
+
inputs.push('withoutBody()');
|
|
56
81
|
}
|
|
57
|
-
|
|
58
|
-
|
|
82
|
+
const cleanInput = inputs.filter((item) => item !== '');
|
|
83
|
+
return cleanInput.join('.');
|
|
84
|
+
};
|
|
85
|
+
const generatePath = (path, inputs) => {
|
|
86
|
+
if (inputs.properties === undefined) {
|
|
87
|
+
return path;
|
|
88
|
+
}
|
|
89
|
+
return Object.entries(inputs.properties).reduce((acc, [name, input]) => {
|
|
90
|
+
if (input.in === 'path') {
|
|
91
|
+
return acc.replace(`{${name}}`, `:${name}`);
|
|
92
|
+
}
|
|
93
|
+
return acc;
|
|
94
|
+
}, path);
|
|
95
|
+
};
|
|
59
96
|
const generateHandler = ({ connectorNamePascalCase, operationNamePascalCase, operationNameCamelCase, httpMethod, baseUrl, path, input, }) => E.tryCatch(() => `import { OperationHandlerSetup } from "@trayio/cdk-dsl/connector/operation/OperationHandlerSetup";
|
|
60
|
-
import { ${connectorNamePascalCase} } from "../${connectorNamePascalCase}";
|
|
97
|
+
import { ${connectorNamePascalCase}Auth } from "../${connectorNamePascalCase}Auth";
|
|
61
98
|
import { ${operationNamePascalCase}Input } from "./input";
|
|
62
99
|
import { ${operationNamePascalCase}Output } from "./output";
|
|
63
100
|
|
|
@@ -70,7 +107,7 @@ const generateHandler = ({ connectorNamePascalCase, operationNamePascalCase, ope
|
|
|
70
107
|
http
|
|
71
108
|
.${httpMethod}("${baseUrl}${generatePath(path, input)}")
|
|
72
109
|
.handleRequest((ctx, input, request) => ${handleInput(input)})
|
|
73
|
-
.handleResponse((response) => response.parseWithBodyAsJson())
|
|
110
|
+
.handleResponse((ctx, input, response) => response.parseWithBodyAsJson())
|
|
74
111
|
)
|
|
75
112
|
);`, (error) => new Error(`Failed to generate handler: ${error}`));
|
|
76
113
|
exports.generateHandler = generateHandler;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateHandler.test.d.ts","sourceRoot":"","sources":["../../src/file-generators/GenerateHandler.test.ts"],"names":[],"mappings":""}
|