@trayio/tray-openapi 5.34.0 → 5.35.0-unstable.fd7158a
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/OpenApiCodecs.d.ts +207 -4
- package/dist/OpenApiCodecs.d.ts.map +1 -1
- package/dist/OpenApiCodecs.js +3 -3
- package/dist/OpenApiSchemaImporter.d.ts +2 -2
- package/dist/OpenApiSchemaImporter.d.ts.map +1 -1
- package/dist/OpenApiSchemaImporter.js +33 -55
- package/dist/OpenApiSchemaImporter.unit.test.js +24 -13
- package/dist/OpenApiSchemaTransformer.d.ts +2 -2
- package/dist/OpenApiSchemaTransformer.d.ts.map +1 -1
- package/dist/OpenApiSchemaTransformer.js +2 -25
- package/dist/OpenApiSchemaTransformer.unit.test.js +30 -44
- package/dist/OpenApiTypeDescriptors.d.ts +389 -32
- package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
- package/dist/OpenApiTypeDescriptors.js +80 -109
- package/dist/file-generators/GenerateHandler.d.ts +2 -2
- package/dist/file-generators/GenerateHandler.d.ts.map +1 -1
- package/dist/file-generators/GenerateHandler.js +75 -78
- package/dist/file-generators/GenerateHandler.unit.test.js +73 -97
- package/dist/file-generators/GenerateHandlerTest.d.ts +2 -2
- package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -1
- package/dist/file-generators/GenerateHandlerTest.js +69 -76
- package/dist/file-generators/GenerateHandlerTest.unit.test.js +206 -230
- package/dist/file-generators/GenerateOperationJson.d.ts +2 -2
- package/dist/file-generators/GenerateOperationJson.d.ts.map +1 -1
- package/dist/file-generators/GenerateOperationJson.js +4 -29
- package/dist/file-generators/GenerateOperationJson.unit.test.js +25 -49
- package/dist/file-generators/SchemaGenerator.d.ts.map +1 -1
- package/dist/file-generators/SchemaGenerator.js +14 -37
- package/dist/file-generators/types/GenerateInputSchema.d.ts +2 -2
- package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateInputSchema.js +88 -95
- package/dist/file-generators/types/GenerateInputSchema.test.js +60 -91
- package/dist/file-generators/types/GenerateInputType.test.js +143 -169
- package/dist/file-generators/types/GenerateInputTypes.d.ts +2 -2
- package/dist/file-generators/types/GenerateInputTypes.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateInputTypes.js +7 -28
- package/dist/file-generators/types/GenerateOutput.d.ts +4 -6
- package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateOutput.js +46 -57
- package/dist/file-generators/types/GenerateOutput.test.js +35 -62
- package/package.json +6 -8
package/dist/OpenApiCodecs.d.ts
CHANGED
|
@@ -1,5 +1,208 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
1
|
+
export declare const openApiSpecCodec: import("@trayio/commons/dist/codec/Codec").Codec<{
|
|
2
|
+
readonly openapi: string;
|
|
3
|
+
readonly info: {
|
|
4
|
+
readonly title: string;
|
|
5
|
+
readonly description: string;
|
|
6
|
+
readonly version: string;
|
|
7
|
+
};
|
|
8
|
+
readonly servers: {
|
|
9
|
+
readonly url: string;
|
|
10
|
+
}[];
|
|
11
|
+
readonly paths: {
|
|
12
|
+
[x: string]: {
|
|
13
|
+
readonly get?: {
|
|
14
|
+
readonly description: import("effect/Option").Option<string>;
|
|
15
|
+
readonly summary: import("effect/Option").Option<string>;
|
|
16
|
+
readonly tags: import("effect/Option").Option<string[]>;
|
|
17
|
+
readonly operationId: string;
|
|
18
|
+
readonly parameters: import("effect/Option").Option<{
|
|
19
|
+
readonly required: import("effect/Option").Option<boolean>;
|
|
20
|
+
readonly in: string;
|
|
21
|
+
readonly schema: import("./OpenApiTypeDescriptors").SchemaObject;
|
|
22
|
+
readonly description: import("effect/Option").Option<string>;
|
|
23
|
+
readonly name: string;
|
|
24
|
+
}[]>;
|
|
25
|
+
readonly requestBody: import("effect/Option").Option<{
|
|
26
|
+
readonly content: {
|
|
27
|
+
[x: string]: {
|
|
28
|
+
readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
|
|
29
|
+
};
|
|
30
|
+
};
|
|
31
|
+
}>;
|
|
32
|
+
readonly responses: import("effect/Option").Option<{
|
|
33
|
+
[x: string]: {
|
|
34
|
+
readonly content: import("effect/Option").Option<{
|
|
35
|
+
[x: string]: {
|
|
36
|
+
readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
|
|
37
|
+
};
|
|
38
|
+
}>;
|
|
39
|
+
readonly description: string;
|
|
40
|
+
};
|
|
41
|
+
}>;
|
|
42
|
+
} | undefined;
|
|
43
|
+
readonly post?: {
|
|
44
|
+
readonly description: import("effect/Option").Option<string>;
|
|
45
|
+
readonly summary: import("effect/Option").Option<string>;
|
|
46
|
+
readonly tags: import("effect/Option").Option<string[]>;
|
|
47
|
+
readonly operationId: string;
|
|
48
|
+
readonly parameters: import("effect/Option").Option<{
|
|
49
|
+
readonly required: import("effect/Option").Option<boolean>;
|
|
50
|
+
readonly in: string;
|
|
51
|
+
readonly schema: import("./OpenApiTypeDescriptors").SchemaObject;
|
|
52
|
+
readonly description: import("effect/Option").Option<string>;
|
|
53
|
+
readonly name: string;
|
|
54
|
+
}[]>;
|
|
55
|
+
readonly requestBody: import("effect/Option").Option<{
|
|
56
|
+
readonly content: {
|
|
57
|
+
[x: string]: {
|
|
58
|
+
readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
|
|
59
|
+
};
|
|
60
|
+
};
|
|
61
|
+
}>;
|
|
62
|
+
readonly responses: import("effect/Option").Option<{
|
|
63
|
+
[x: string]: {
|
|
64
|
+
readonly content: import("effect/Option").Option<{
|
|
65
|
+
[x: string]: {
|
|
66
|
+
readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
|
|
67
|
+
};
|
|
68
|
+
}>;
|
|
69
|
+
readonly description: string;
|
|
70
|
+
};
|
|
71
|
+
}>;
|
|
72
|
+
} | undefined;
|
|
73
|
+
readonly put?: {
|
|
74
|
+
readonly description: import("effect/Option").Option<string>;
|
|
75
|
+
readonly summary: import("effect/Option").Option<string>;
|
|
76
|
+
readonly tags: import("effect/Option").Option<string[]>;
|
|
77
|
+
readonly operationId: string;
|
|
78
|
+
readonly parameters: import("effect/Option").Option<{
|
|
79
|
+
readonly required: import("effect/Option").Option<boolean>;
|
|
80
|
+
readonly in: string;
|
|
81
|
+
readonly schema: import("./OpenApiTypeDescriptors").SchemaObject;
|
|
82
|
+
readonly description: import("effect/Option").Option<string>;
|
|
83
|
+
readonly name: string;
|
|
84
|
+
}[]>;
|
|
85
|
+
readonly requestBody: import("effect/Option").Option<{
|
|
86
|
+
readonly content: {
|
|
87
|
+
[x: string]: {
|
|
88
|
+
readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
|
|
89
|
+
};
|
|
90
|
+
};
|
|
91
|
+
}>;
|
|
92
|
+
readonly responses: import("effect/Option").Option<{
|
|
93
|
+
[x: string]: {
|
|
94
|
+
readonly content: import("effect/Option").Option<{
|
|
95
|
+
[x: string]: {
|
|
96
|
+
readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
|
|
97
|
+
};
|
|
98
|
+
}>;
|
|
99
|
+
readonly description: string;
|
|
100
|
+
};
|
|
101
|
+
}>;
|
|
102
|
+
} | undefined;
|
|
103
|
+
readonly patch?: {
|
|
104
|
+
readonly description: import("effect/Option").Option<string>;
|
|
105
|
+
readonly summary: import("effect/Option").Option<string>;
|
|
106
|
+
readonly tags: import("effect/Option").Option<string[]>;
|
|
107
|
+
readonly operationId: string;
|
|
108
|
+
readonly parameters: import("effect/Option").Option<{
|
|
109
|
+
readonly required: import("effect/Option").Option<boolean>;
|
|
110
|
+
readonly in: string;
|
|
111
|
+
readonly schema: import("./OpenApiTypeDescriptors").SchemaObject;
|
|
112
|
+
readonly description: import("effect/Option").Option<string>;
|
|
113
|
+
readonly name: string;
|
|
114
|
+
}[]>;
|
|
115
|
+
readonly requestBody: import("effect/Option").Option<{
|
|
116
|
+
readonly content: {
|
|
117
|
+
[x: string]: {
|
|
118
|
+
readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
|
|
119
|
+
};
|
|
120
|
+
};
|
|
121
|
+
}>;
|
|
122
|
+
readonly responses: import("effect/Option").Option<{
|
|
123
|
+
[x: string]: {
|
|
124
|
+
readonly content: import("effect/Option").Option<{
|
|
125
|
+
[x: string]: {
|
|
126
|
+
readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
|
|
127
|
+
};
|
|
128
|
+
}>;
|
|
129
|
+
readonly description: string;
|
|
130
|
+
};
|
|
131
|
+
}>;
|
|
132
|
+
} | undefined;
|
|
133
|
+
readonly delete?: {
|
|
134
|
+
readonly description: import("effect/Option").Option<string>;
|
|
135
|
+
readonly summary: import("effect/Option").Option<string>;
|
|
136
|
+
readonly tags: import("effect/Option").Option<string[]>;
|
|
137
|
+
readonly operationId: string;
|
|
138
|
+
readonly parameters: import("effect/Option").Option<{
|
|
139
|
+
readonly required: import("effect/Option").Option<boolean>;
|
|
140
|
+
readonly in: string;
|
|
141
|
+
readonly schema: import("./OpenApiTypeDescriptors").SchemaObject;
|
|
142
|
+
readonly description: import("effect/Option").Option<string>;
|
|
143
|
+
readonly name: string;
|
|
144
|
+
}[]>;
|
|
145
|
+
readonly requestBody: import("effect/Option").Option<{
|
|
146
|
+
readonly content: {
|
|
147
|
+
[x: string]: {
|
|
148
|
+
readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
|
|
149
|
+
};
|
|
150
|
+
};
|
|
151
|
+
}>;
|
|
152
|
+
readonly responses: import("effect/Option").Option<{
|
|
153
|
+
[x: string]: {
|
|
154
|
+
readonly content: import("effect/Option").Option<{
|
|
155
|
+
[x: string]: {
|
|
156
|
+
readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
|
|
157
|
+
};
|
|
158
|
+
}>;
|
|
159
|
+
readonly description: string;
|
|
160
|
+
};
|
|
161
|
+
}>;
|
|
162
|
+
} | undefined;
|
|
163
|
+
};
|
|
164
|
+
};
|
|
165
|
+
readonly components: {
|
|
166
|
+
readonly schemas: import("effect/Option").Option<{
|
|
167
|
+
[x: string]: import("./OpenApiTypeDescriptors").SchemaObject;
|
|
168
|
+
}>;
|
|
169
|
+
};
|
|
170
|
+
}>;
|
|
171
|
+
export declare const pathCodec: import("@trayio/commons/dist/codec/Codec").Codec<{
|
|
172
|
+
readonly description: import("effect/Option").Option<string>;
|
|
173
|
+
readonly summary: import("effect/Option").Option<string>;
|
|
174
|
+
readonly tags: import("effect/Option").Option<string[]>;
|
|
175
|
+
readonly operationId: string;
|
|
176
|
+
readonly parameters: import("effect/Option").Option<{
|
|
177
|
+
readonly required: import("effect/Option").Option<boolean>;
|
|
178
|
+
readonly in: string;
|
|
179
|
+
readonly schema: import("./OpenApiTypeDescriptors").SchemaObject;
|
|
180
|
+
readonly description: import("effect/Option").Option<string>;
|
|
181
|
+
readonly name: string;
|
|
182
|
+
}[]>;
|
|
183
|
+
readonly requestBody: import("effect/Option").Option<{
|
|
184
|
+
readonly content: {
|
|
185
|
+
[x: string]: {
|
|
186
|
+
readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
|
|
187
|
+
};
|
|
188
|
+
};
|
|
189
|
+
}>;
|
|
190
|
+
readonly responses: import("effect/Option").Option<{
|
|
191
|
+
[x: string]: {
|
|
192
|
+
readonly content: import("effect/Option").Option<{
|
|
193
|
+
[x: string]: {
|
|
194
|
+
readonly schema: import("effect/Option").Option<import("./OpenApiTypeDescriptors").SchemaObject>;
|
|
195
|
+
};
|
|
196
|
+
}>;
|
|
197
|
+
readonly description: string;
|
|
198
|
+
};
|
|
199
|
+
}>;
|
|
200
|
+
}>;
|
|
201
|
+
export declare const parameterSchemaCodec: import("@trayio/commons/dist/codec/Codec").Codec<{
|
|
202
|
+
readonly required: import("effect/Option").Option<boolean>;
|
|
203
|
+
readonly in: string;
|
|
204
|
+
readonly schema: import("./OpenApiTypeDescriptors").SchemaObject;
|
|
205
|
+
readonly description: import("effect/Option").Option<string>;
|
|
206
|
+
readonly name: string;
|
|
207
|
+
}>;
|
|
5
208
|
//# sourceMappingURL=OpenApiCodecs.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenApiCodecs.d.ts","sourceRoot":"","sources":["../src/OpenApiCodecs.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"OpenApiCodecs.d.ts","sourceRoot":"","sources":["../src/OpenApiCodecs.ts"],"names":[],"mappings":"AAUA,eAAO,MAAM,gBAAgB;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAA0C,CAAC;AAExE,eAAO,MAAM,SAAS;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAA8C,CAAC;AAErE,eAAO,MAAM,oBAAoB;;;;;;EAA8C,CAAC"}
|
package/dist/OpenApiCodecs.js
CHANGED
|
@@ -3,6 +3,6 @@ Object.defineProperty(exports, "__esModule", { value: true });
|
|
|
3
3
|
exports.parameterSchemaCodec = exports.pathCodec = exports.openApiSpecCodec = void 0;
|
|
4
4
|
const TypeCodec_1 = require("@trayio/commons/codec/TypeCodec");
|
|
5
5
|
const OpenApiTypeDescriptors_1 = require("./OpenApiTypeDescriptors");
|
|
6
|
-
exports.openApiSpecCodec = TypeCodec_1.TypeCodec.
|
|
7
|
-
exports.pathCodec = TypeCodec_1.TypeCodec.
|
|
8
|
-
exports.parameterSchemaCodec = TypeCodec_1.TypeCodec.
|
|
6
|
+
exports.openApiSpecCodec = TypeCodec_1.TypeCodec.fromSchema(OpenApiTypeDescriptors_1.openApiSpecSchema);
|
|
7
|
+
exports.pathCodec = TypeCodec_1.TypeCodec.fromSchema(OpenApiTypeDescriptors_1.openApiSpecPathSchema);
|
|
8
|
+
exports.parameterSchemaCodec = TypeCodec_1.TypeCodec.fromSchema(OpenApiTypeDescriptors_1.parameterSchemaSchema);
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Effect } from 'effect';
|
|
2
2
|
import { FileStorage } from '@trayio/commons/file/File';
|
|
3
3
|
import { Generator } from '@trayio/generator/generator/Generator';
|
|
4
4
|
import { BuildConnectorResponse } from './OpenApiTypeDescriptors';
|
|
@@ -6,7 +6,7 @@ export declare class OpenApiSchemaImporter {
|
|
|
6
6
|
private generator;
|
|
7
7
|
private fileStorage;
|
|
8
8
|
constructor(generator: Generator, fileStorage: FileStorage);
|
|
9
|
-
buildConnector(openApiSpecPath: string, connectorName: string):
|
|
9
|
+
buildConnector(openApiSpecPath: string, connectorName: string): Effect.Effect<BuildConnectorResponse, Error>;
|
|
10
10
|
private generateOperationFromPath;
|
|
11
11
|
private decodeOperation;
|
|
12
12
|
private getOpenApiSpec;
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenApiSchemaImporter.d.ts","sourceRoot":"","sources":["../src/OpenApiSchemaImporter.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"OpenApiSchemaImporter.d.ts","sourceRoot":"","sources":["../src/OpenApiSchemaImporter.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAwB,MAAM,QAAQ,CAAC;AAItD,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,MAAM,CAAC,MAAM,CAAC,sBAAsB,EAAE,KAAK,CAAC;IAsD/C,OAAO,CAAC,yBAAyB;IAuDjC,OAAO,CAAC,eAAe;IAgBvB,OAAO,CAAC,cAAc;IAkCtB,OAAO,CAAC,oCAAoC;IA+F5C,OAAO,CAAC,0BAA0B;IAwBlC,OAAO,CAAC,0BAA0B;CAclC"}
|
|
@@ -1,35 +1,7 @@
|
|
|
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
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.OpenApiSchemaImporter = void 0;
|
|
27
|
-
const
|
|
28
|
-
const E = __importStar(require("fp-ts/Either"));
|
|
29
|
-
const O = __importStar(require("fp-ts/Option"));
|
|
30
|
-
const function_1 = require("fp-ts/function");
|
|
31
|
-
const Array_1 = require("fp-ts/Array");
|
|
32
|
-
const Apply_1 = require("fp-ts/Apply");
|
|
4
|
+
const effect_1 = require("effect");
|
|
33
5
|
const json_ref_resolver_1 = require("@stoplight/json-ref-resolver");
|
|
34
6
|
const StringExtensions_1 = require("@trayio/commons/string/StringExtensions");
|
|
35
7
|
const lodash_1 = require("lodash");
|
|
@@ -51,18 +23,18 @@ class OpenApiSchemaImporter {
|
|
|
51
23
|
this.fileStorage = fileStorage;
|
|
52
24
|
}
|
|
53
25
|
buildConnector(openApiSpecPath, connectorName) {
|
|
54
|
-
return (0,
|
|
26
|
+
return (0, effect_1.pipe)(this.generateConnectorDirectory(connectorName), effect_1.Effect.bindTo('connectorPath'), effect_1.Effect.bind('openApiSpec', () => this.getOpenApiSpec(openApiSpecPath)), effect_1.Effect.bind('paths', ({ openApiSpec }) => {
|
|
55
27
|
if (openApiSpec.paths === undefined) {
|
|
56
|
-
return
|
|
28
|
+
return effect_1.Effect.fail(new Error('OpenAPI spec does not contain any paths'));
|
|
57
29
|
}
|
|
58
|
-
return
|
|
30
|
+
return effect_1.Effect.succeed(Object.keys(openApiSpec.paths).map((path) => ({
|
|
59
31
|
path,
|
|
60
32
|
routes: Object.keys(openApiSpec.paths[path]).map((route) => ({
|
|
61
33
|
method: route,
|
|
62
34
|
path: openApiSpec.paths[path][route],
|
|
63
35
|
})),
|
|
64
36
|
})));
|
|
65
|
-
}),
|
|
37
|
+
}), effect_1.Effect.flatMap(({ openApiSpec, connectorPath, paths }) => effect_1.Effect.forEach((path) => this.generateOperationFromPath(path, connectorPath, openApiSpec.servers[0].url, connectorName))(paths)), effect_1.Effect.map((operation) => {
|
|
66
38
|
const flatOperations = operation.flat();
|
|
67
39
|
const buildConnectorResponse = flatOperations.reduce((acc, curr) => {
|
|
68
40
|
if (curr.tag === 'error') {
|
|
@@ -80,11 +52,11 @@ class OpenApiSchemaImporter {
|
|
|
80
52
|
}));
|
|
81
53
|
}
|
|
82
54
|
generateOperationFromPath(path, connectorPath, baseUrl, connectorName) {
|
|
83
|
-
return (0,
|
|
55
|
+
return (0, effect_1.pipe)(effect_1.Effect.forEach((route) => (0, effect_1.pipe)(this.decodeOperation(route.path, path.path, route.method), effect_1.Effect.bindTo('decodedPath'), effect_1.Effect.flatMap(({ decodedPath }) => (0, effect_1.pipe)(this.generateOperationDirectory(connectorPath, decodedPath.operationId), effect_1.Effect.map((operationDirectory) => ({ operationDirectory })), effect_1.Effect.bind('inputs', () => (0, GenerateInputSchema_1.generateInputSchema)(decodedPath)), effect_1.Effect.bind('outputs', () => (0, GenerateOutput_1.generateOutputSchema)(decodedPath.responses)), effect_1.Effect.bind('decodedPath', () => effect_1.Effect.succeed(decodedPath)))), effect_1.Effect.flatMap(({ inputs, outputs, decodedPath }) => this.generateHandlerFilesAndOperationJson(route.method, decodedPath, `${connectorPath}/src/${(0, lodash_1.snakeCase)(decodedPath.operationId)}`, baseUrl, path.path, connectorName, inputs, outputs)), effect_1.Effect.map(() => ({
|
|
84
56
|
tag: 'success',
|
|
85
57
|
httpMethod: route.method,
|
|
86
58
|
path: path.path,
|
|
87
|
-
})),
|
|
59
|
+
})), effect_1.Effect.catchAll((error) => effect_1.Effect.succeed({
|
|
88
60
|
tag: 'error',
|
|
89
61
|
httpMethod: route.method,
|
|
90
62
|
path: path.path,
|
|
@@ -92,14 +64,20 @@ class OpenApiSchemaImporter {
|
|
|
92
64
|
}))))(path.routes));
|
|
93
65
|
}
|
|
94
66
|
decodeOperation(path, httpPath, method) {
|
|
95
|
-
return (0,
|
|
67
|
+
return (0, effect_1.pipe)(OpenApiCodecs_1.pathCodec.decode(path), effect_1.Effect.mapError((error) => new Error(`Failed to decode httpPath: ${httpPath} and method: ${method} : ${error}`)));
|
|
96
68
|
}
|
|
97
69
|
getOpenApiSpec(openApiSpecPath) {
|
|
98
|
-
return (0,
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
70
|
+
return (0, effect_1.pipe)(this.fileStorage.read(openApiSpecPath), effect_1.Effect.flatMap((openApiSpec) => BufferExtensions_1.BufferExtensions.readableToArrayBuffer(openApiSpec.content)), effect_1.Effect.flatMap((openApiSpec) => effect_1.Either.try({
|
|
71
|
+
try: () => JSON.parse(Buffer.from(openApiSpec).toString('utf-8')),
|
|
72
|
+
catch: (error) => new Error(`Failed to parse OpenAPI spec as JSON from path ${openApiSpecPath}: ${error}`),
|
|
73
|
+
})), effect_1.Effect.flatMap((openApiSpec) => effect_1.Effect.tryPromise({
|
|
74
|
+
try: () => {
|
|
75
|
+
const resolver = new json_ref_resolver_1.Resolver({});
|
|
76
|
+
const resolvedOpenApiSpec = resolver.resolve(openApiSpec, {});
|
|
77
|
+
return resolvedOpenApiSpec;
|
|
78
|
+
},
|
|
79
|
+
catch: (reason) => new Error(`Failed to resolve references in schema: ${reason}`),
|
|
80
|
+
})), effect_1.Effect.flatMap((openApiSpec) => (0, OpenApiSchemaTransformer_1.mergePathLevelParamsIntoHttpMethod)(openApiSpec.result)));
|
|
103
81
|
}
|
|
104
82
|
generateHandlerFilesAndOperationJson(method, path, operationPath, baseUrl, httpPath, connectorName, input, output) {
|
|
105
83
|
const writeFile = (content, fileName) => this.fileStorage.write({
|
|
@@ -109,11 +87,11 @@ class OpenApiSchemaImporter {
|
|
|
109
87
|
key: `${operationPath}/${fileName}`,
|
|
110
88
|
metadata: { name: fileName },
|
|
111
89
|
},
|
|
112
|
-
},
|
|
90
|
+
}, effect_1.Option.none());
|
|
113
91
|
const operationName = path.operationId;
|
|
114
|
-
const handleFileCreationError = (error, fileName) => (0,
|
|
92
|
+
const handleFileCreationError = (error, fileName) => (0, effect_1.pipe)(writeFile('', fileName), effect_1.Effect.mapError(() => error));
|
|
115
93
|
const operationFileGenerationTasks = {
|
|
116
|
-
handler: (0,
|
|
94
|
+
handler: (0, effect_1.pipe)((0, GenerateHandler_1.generateHandler)({
|
|
117
95
|
connectorNamePascalCase: StringExtensions_1.StringExtensions.pascalCase(connectorName),
|
|
118
96
|
operationNameCamelCase: (0, lodash_1.camelCase)(operationName),
|
|
119
97
|
operationNamePascalCase: StringExtensions_1.StringExtensions.pascalCase(operationName),
|
|
@@ -121,30 +99,30 @@ class OpenApiSchemaImporter {
|
|
|
121
99
|
baseUrl,
|
|
122
100
|
httpPath,
|
|
123
101
|
input,
|
|
124
|
-
})
|
|
102
|
+
}),
|
|
125
103
|
// TODO: Why does this throw unhelpful errors?
|
|
126
|
-
|
|
127
|
-
handlerTest: (0,
|
|
104
|
+
effect_1.Effect.flatMap((handlerInput) => writeFile(handlerInput, 'handler.ts')), effect_1.Effect.catchAll((error) => handleFileCreationError(error, 'handler.ts'))),
|
|
105
|
+
handlerTest: (0, effect_1.pipe)((0, GenerateHandlerTest_1.generateHandlerTest)({
|
|
128
106
|
operationNameCamelCase: (0, lodash_1.camelCase)(operationName),
|
|
129
107
|
input,
|
|
130
108
|
output,
|
|
131
|
-
})
|
|
132
|
-
generateOutputType: (0,
|
|
133
|
-
generateInputType: (0,
|
|
134
|
-
operationJson: (0,
|
|
109
|
+
}), effect_1.Effect.flatMap((handlerInput) => writeFile(handlerInput, 'handler.test.ts')), effect_1.Effect.catchAll((error) => handleFileCreationError(error, 'handler.test.ts'))),
|
|
110
|
+
generateOutputType: (0, effect_1.pipe)((0, GenerateOutput_1.generateOutputTypes)(operationName, output), effect_1.Effect.flatMap((outputType) => writeFile(outputType, 'output.ts')), effect_1.Effect.catchAll((error) => handleFileCreationError(error, 'output.ts'))),
|
|
111
|
+
generateInputType: (0, effect_1.pipe)((0, GenerateInputTypes_1.generateInputTypes)(operationName, input), effect_1.Effect.flatMap((inputType) => writeFile(inputType, 'input.ts')), effect_1.Effect.catchAll((error) => handleFileCreationError(error, 'input.ts'))),
|
|
112
|
+
operationJson: (0, effect_1.pipe)((0, GenerateOperationJson_1.generateOperationJson)(operationName, path), effect_1.Effect.flatMap((operationJson) => writeFile(operationJson, 'operation.json')), effect_1.Effect.catchAll((error) => handleFileCreationError(error, 'operation.json'))),
|
|
135
113
|
};
|
|
136
|
-
return (0,
|
|
114
|
+
return (0, effect_1.pipe)(effect_1.Effect.all(operationFileGenerationTasks, { concurrency: 'unbounded' }), effect_1.Effect.mapError((error) => new Error(`Failed to generate files for operation: ${operationName}: ${error}`)), effect_1.Effect.map(() => undefined));
|
|
137
115
|
}
|
|
138
116
|
generateConnectorDirectory(connectorName) {
|
|
139
|
-
return (0,
|
|
117
|
+
return (0, effect_1.pipe)(effect_1.Effect.succeed({
|
|
140
118
|
connectorNameTitleCase: StringExtensions_1.StringExtensions.titleCase(connectorName),
|
|
141
119
|
connectorNameKebabCase: (0, lodash_1.kebabCase)(connectorName),
|
|
142
120
|
connectorNamePascalCase: StringExtensions_1.StringExtensions.pascalCase(connectorName),
|
|
143
121
|
connectorNameCamelCase: (0, lodash_1.camelCase)(connectorName),
|
|
144
|
-
}),
|
|
122
|
+
}), effect_1.Effect.flatMap((parameters) => this.generator.generate(`${__dirname}/templates/connector-template.zip`, process.cwd(), parameters)), effect_1.Effect.map(() => `/${(0, lodash_1.kebabCase)(connectorName)}`), effect_1.Effect.mapError((error) => new Error(`Failed to generate connector directory: ${error}`)));
|
|
145
123
|
}
|
|
146
124
|
generateOperationDirectory(connectorPath, operationName) {
|
|
147
|
-
return (0,
|
|
125
|
+
return (0, effect_1.pipe)(effect_1.Effect.mapError(this.fileStorage.createDirectory(`${connectorPath}/src/${(0, lodash_1.snakeCase)(operationName)}`), (error) => new Error(`Failed to create operation directory: ${error}`)), effect_1.Effect.map(() => `${connectorPath}/src/${(0, lodash_1.snakeCase)(operationName)}`));
|
|
148
126
|
}
|
|
149
127
|
}
|
|
150
128
|
exports.OpenApiSchemaImporter = OpenApiSchemaImporter;
|
|
@@ -15,18 +15,28 @@ var __setModuleDefault = (this && this.__setModuleDefault) || (Object.create ? (
|
|
|
15
15
|
}) : function(o, v) {
|
|
16
16
|
o["default"] = v;
|
|
17
17
|
});
|
|
18
|
-
var __importStar = (this && this.__importStar) || function (
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
};
|
|
18
|
+
var __importStar = (this && this.__importStar) || (function () {
|
|
19
|
+
var ownKeys = function(o) {
|
|
20
|
+
ownKeys = Object.getOwnPropertyNames || function (o) {
|
|
21
|
+
var ar = [];
|
|
22
|
+
for (var k in o) if (Object.prototype.hasOwnProperty.call(o, k)) ar[ar.length] = k;
|
|
23
|
+
return ar;
|
|
24
|
+
};
|
|
25
|
+
return ownKeys(o);
|
|
26
|
+
};
|
|
27
|
+
return function (mod) {
|
|
28
|
+
if (mod && mod.__esModule) return mod;
|
|
29
|
+
var result = {};
|
|
30
|
+
if (mod != null) for (var k = ownKeys(mod), i = 0; i < k.length; i++) if (k[i] !== "default") __createBinding(result, mod, k[i]);
|
|
31
|
+
__setModuleDefault(result, mod);
|
|
32
|
+
return result;
|
|
33
|
+
};
|
|
34
|
+
})();
|
|
25
35
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
36
|
+
const effect_1 = require("effect");
|
|
26
37
|
const NodeFsGenerator_1 = require("@trayio/generator/generator/NodeFsGenerator");
|
|
27
38
|
const FakeFileStorage_1 = require("@trayio/commons/file/FakeFileStorage");
|
|
28
39
|
const stream_1 = require("stream");
|
|
29
|
-
const E = __importStar(require("fp-ts/Either"));
|
|
30
40
|
const fs = __importStar(require("fs-extra"));
|
|
31
41
|
const OpenApiSchemaImporter_1 = require("./OpenApiSchemaImporter");
|
|
32
42
|
const openApiSpec = __importStar(require("./test-openapi-spec.json"));
|
|
@@ -37,15 +47,16 @@ describe('openApiSchemaImporter', () => {
|
|
|
37
47
|
let result;
|
|
38
48
|
const spec = 'test-openapi-spec.json';
|
|
39
49
|
beforeAll(async () => {
|
|
40
|
-
|
|
50
|
+
// Effects are lazy: the write only happens when it is run (the fp-ts version wrote eagerly on construction).
|
|
51
|
+
await effect_1.Effect.runPromise(fileStorage.write({
|
|
41
52
|
reference: {
|
|
42
53
|
_tag: 'FileDescriptor',
|
|
43
54
|
key: `${__dirname}/${spec}`,
|
|
44
55
|
metadata: { name: spec },
|
|
45
56
|
},
|
|
46
57
|
content: stream_1.Readable.from(Buffer.from(JSON.stringify(openApiSpec))),
|
|
47
|
-
});
|
|
48
|
-
result = await openApiSchemaImporter.buildConnector(`${__dirname}/${spec}`, 'testConnector')
|
|
58
|
+
}));
|
|
59
|
+
result = await effect_1.Effect.runPromise(effect_1.Effect.either(openApiSchemaImporter.buildConnector(`${__dirname}/${spec}`, 'testConnector')));
|
|
49
60
|
});
|
|
50
61
|
afterAll(async () => {
|
|
51
62
|
await fs.rm(`${process.cwd()}/test-connector/`, {
|
|
@@ -54,10 +65,10 @@ describe('openApiSchemaImporter', () => {
|
|
|
54
65
|
});
|
|
55
66
|
});
|
|
56
67
|
it('should import successfully', () => {
|
|
57
|
-
const buildConnectorResponse =
|
|
68
|
+
const buildConnectorResponse = effect_1.Either.getOrElse(result, (error) => {
|
|
58
69
|
console.error(error);
|
|
59
70
|
throw new Error('Should have been right');
|
|
60
|
-
})
|
|
71
|
+
});
|
|
61
72
|
console.log(buildConnectorResponse);
|
|
62
73
|
console.log(fileStorage.files);
|
|
63
74
|
expect(buildConnectorResponse.successes.length).toEqual(1);
|
|
@@ -1,9 +1,9 @@
|
|
|
1
|
-
import
|
|
1
|
+
import { Either } from 'effect';
|
|
2
2
|
import { BaseOpenApiSpec } from './OpenApiTypeDescriptors';
|
|
3
3
|
export declare const isObject: (value: unknown) => value is Record<string, unknown>;
|
|
4
4
|
export declare const isObjectWithParameters: (value: unknown) => value is Record<string, unknown> & {
|
|
5
5
|
parameters: unknown[];
|
|
6
6
|
};
|
|
7
7
|
export declare const getMergedParameters: (pathValue: Record<string, unknown>, httpMethodValue: Record<string, unknown>) => unknown[];
|
|
8
|
-
export declare const mergePathLevelParamsIntoHttpMethod: (openApiSpec: BaseOpenApiSpec) =>
|
|
8
|
+
export declare const mergePathLevelParamsIntoHttpMethod: (openApiSpec: BaseOpenApiSpec) => Either.Either<BaseOpenApiSpec, Error>;
|
|
9
9
|
//# sourceMappingURL=OpenApiSchemaTransformer.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"OpenApiSchemaTransformer.d.ts","sourceRoot":"","sources":["../src/OpenApiSchemaTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,
|
|
1
|
+
{"version":3,"file":"OpenApiSchemaTransformer.d.ts","sourceRoot":"","sources":["../src/OpenApiSchemaTransformer.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,MAAM,EAAE,MAAM,QAAQ,CAAC;AAChC,OAAO,EAAE,eAAe,EAAE,MAAM,0BAA0B,CAAC;AAE3D,eAAO,MAAM,QAAQ,GAAI,OAAO,OAAO,KAAG,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAC7B,CAAC;AAE7C,eAAO,MAAM,sBAAsB,GAClC,OAAO,OAAO,KACZ,KAAK,IAAI,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,GAAG;IAAE,UAAU,EAAE,OAAO,EAAE,CAAA;CACpB,CAAC;AAE1C,eAAO,MAAM,mBAAmB,GAC/B,WAAW,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,EAClC,iBAAiB,MAAM,CAAC,MAAM,EAAE,OAAO,CAAC,KACtC,OAAO,EAcT,CAAC;AAEF,eAAO,MAAM,kCAAkC,GAC9C,aAAa,eAAe,KAC1B,MAAM,CAAC,MAAM,CAAC,eAAe,EAAE,KAAK,CAkCtC,CAAC"}
|
|
@@ -1,30 +1,7 @@
|
|
|
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
|
-
};
|
|
25
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
26
3
|
exports.mergePathLevelParamsIntoHttpMethod = exports.getMergedParameters = exports.isObjectWithParameters = exports.isObject = void 0;
|
|
27
|
-
const
|
|
4
|
+
const effect_1 = require("effect");
|
|
28
5
|
const isObject = (value) => typeof value === 'object' && value !== null;
|
|
29
6
|
exports.isObject = isObject;
|
|
30
7
|
const isObjectWithParameters = (value) => (0, exports.isObject)(value) && 'parameters' in value;
|
|
@@ -63,6 +40,6 @@ const mergePathLevelParamsIntoHttpMethod = (openApiSpec) => {
|
|
|
63
40
|
pathAcc[pathName] = updatedPathValue;
|
|
64
41
|
return pathAcc;
|
|
65
42
|
}, {});
|
|
66
|
-
return
|
|
43
|
+
return effect_1.Either.right({ ...openApiSpec, paths });
|
|
67
44
|
};
|
|
68
45
|
exports.mergePathLevelParamsIntoHttpMethod = mergePathLevelParamsIntoHttpMethod;
|