@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
|
@@ -34,8 +34,9 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
34
34
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
35
35
|
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
36
36
|
const O = __importStar(require("fp-ts/Option"));
|
|
37
|
-
const
|
|
38
|
-
|
|
37
|
+
const GenerateInputSchema_1 = require("./GenerateInputSchema");
|
|
38
|
+
const GenerateInputTypes_1 = require("./GenerateInputTypes");
|
|
39
|
+
describe('GenerateInputSchema', () => {
|
|
39
40
|
it('it should process an endpoint with path and query string parameters and generate input.ts file contents', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
41
|
const endpoint = {
|
|
41
42
|
operationId: 'getPost',
|
|
@@ -51,14 +52,17 @@ describe('Input: ProcessInput', () => {
|
|
|
51
52
|
type: 'integer',
|
|
52
53
|
format: O.some('int64'),
|
|
53
54
|
},
|
|
55
|
+
additionalProperties: O.none,
|
|
54
56
|
},
|
|
55
57
|
]),
|
|
56
58
|
requestBody: O.none,
|
|
59
|
+
responses: O.none,
|
|
57
60
|
};
|
|
58
|
-
const
|
|
61
|
+
const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
|
|
62
|
+
const inputTypes = (0, GenerateInputTypes_1.generateInputTypes)(endpoint.operationId, inputSchema);
|
|
59
63
|
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
60
64
|
throw new Error('Should have been right');
|
|
61
|
-
})(
|
|
65
|
+
})(inputTypes)();
|
|
62
66
|
const expectedInputFile = `export interface GetPostInput {
|
|
63
67
|
/**
|
|
64
68
|
* @description The user id.
|
|
@@ -94,17 +98,19 @@ describe('Input: ProcessInput', () => {
|
|
|
94
98
|
type: 'string',
|
|
95
99
|
},
|
|
96
100
|
},
|
|
97
|
-
additionalProperties: false,
|
|
101
|
+
additionalProperties: O.some(false),
|
|
98
102
|
},
|
|
99
103
|
},
|
|
100
104
|
},
|
|
101
105
|
required: true,
|
|
102
106
|
}),
|
|
107
|
+
responses: O.none,
|
|
103
108
|
};
|
|
104
|
-
const
|
|
109
|
+
const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
|
|
110
|
+
const inputTypes = (0, GenerateInputTypes_1.generateInputTypes)(endpoint.operationId, inputSchema);
|
|
105
111
|
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
106
112
|
throw new Error('Should have been right');
|
|
107
|
-
})(
|
|
113
|
+
})(inputTypes)();
|
|
108
114
|
const expectedInputFile = `export interface CreatePostInput {
|
|
109
115
|
id: number;
|
|
110
116
|
userId: number;
|
|
@@ -148,17 +154,19 @@ describe('Input: ProcessInput', () => {
|
|
|
148
154
|
type: 'string',
|
|
149
155
|
},
|
|
150
156
|
},
|
|
151
|
-
additionalProperties: false,
|
|
157
|
+
additionalProperties: O.some(false),
|
|
152
158
|
},
|
|
153
159
|
},
|
|
154
160
|
},
|
|
155
161
|
required: true,
|
|
156
162
|
}),
|
|
163
|
+
responses: O.none,
|
|
157
164
|
};
|
|
158
|
-
const
|
|
165
|
+
const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
|
|
166
|
+
const inputTypes = (0, GenerateInputTypes_1.generateInputTypes)(endpoint.operationId, inputSchema);
|
|
159
167
|
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
160
168
|
throw new Error('Should have been right');
|
|
161
|
-
})(
|
|
169
|
+
})(inputTypes)();
|
|
162
170
|
const expectedInputFile = `export interface GetPostInput {
|
|
163
171
|
userId: number;
|
|
164
172
|
title: string;
|
|
@@ -178,11 +186,13 @@ describe('Input: ProcessInput', () => {
|
|
|
178
186
|
tags: [],
|
|
179
187
|
parameters: O.none,
|
|
180
188
|
requestBody: O.none,
|
|
189
|
+
responses: O.none,
|
|
181
190
|
};
|
|
182
|
-
const
|
|
191
|
+
const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
|
|
192
|
+
const inputTypes = (0, GenerateInputTypes_1.generateInputTypes)(endpoint.operationId, inputSchema);
|
|
183
193
|
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
184
194
|
throw new Error('Should have been right');
|
|
185
|
-
})(
|
|
195
|
+
})(inputTypes)();
|
|
186
196
|
const expectedInputFile = `export interface GetPostsInput {}
|
|
187
197
|
`;
|
|
188
198
|
expect(generatedInputFile).toEqual(expectedInputFile);
|
|
@@ -213,15 +223,16 @@ describe('Input: ProcessInput', () => {
|
|
|
213
223
|
type: 'string',
|
|
214
224
|
},
|
|
215
225
|
},
|
|
216
|
-
additionalProperties: false,
|
|
226
|
+
additionalProperties: O.some(false),
|
|
217
227
|
},
|
|
218
228
|
},
|
|
219
229
|
},
|
|
220
230
|
required: true,
|
|
221
231
|
}),
|
|
232
|
+
responses: O.none,
|
|
222
233
|
};
|
|
223
234
|
yield expect(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
224
|
-
(0,
|
|
235
|
+
(0, GenerateInputSchema_1.generateInputSchema)(endpoint);
|
|
225
236
|
})).rejects.toThrow('Unsupported media type: unsupported-media-type');
|
|
226
237
|
}));
|
|
227
238
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateInputTypes.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateInputTypes.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAKvC,eAAO,MAAM,kBAAkB,2BACN,MAAM,cAClB,WAAW,KACrB,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAiB7B,CAAC"}
|
|
@@ -0,0 +1,39 @@
|
|
|
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.generateInputTypes = void 0;
|
|
27
|
+
const json_schema_to_typescript_1 = require("json-schema-to-typescript");
|
|
28
|
+
const TaskEither_1 = require("fp-ts/TaskEither");
|
|
29
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
30
|
+
const JsonSchemaToTypescriptOptions_1 = require("./JsonSchemaToTypescriptOptions");
|
|
31
|
+
const ResolveOptionValues_1 = require("../../ResolveOptionValues");
|
|
32
|
+
const generateInputTypes = (operationNameCamelCase, parameters) => {
|
|
33
|
+
const resolver = (0, ResolveOptionValues_1.resolveOptionValues)(parameters);
|
|
34
|
+
const resolvedParameters = E.getOrElse((error) => {
|
|
35
|
+
throw new Error(`${error}`);
|
|
36
|
+
})(resolver);
|
|
37
|
+
return (0, TaskEither_1.tryCatch)(() => (0, json_schema_to_typescript_1.compile)(resolvedParameters, `${operationNameCamelCase}Input`, JsonSchemaToTypescriptOptions_1.JsonSchemaToTypescriptOptions), (reason) => new Error(`${reason}`));
|
|
38
|
+
};
|
|
39
|
+
exports.generateInputTypes = generateInputTypes;
|
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { JSONSchema4 } from 'json-schema';
|
|
2
|
+
import * as TE from 'fp-ts/TaskEither';
|
|
3
|
+
import * as E from 'fp-ts/Either';
|
|
4
|
+
import * as O from 'fp-ts/Option';
|
|
5
|
+
import { Responses, Response, MediaType } from '../../OpenApiTypeDescriptors';
|
|
6
|
+
export declare const getApplicationJsonMediaType: (successResponse: Response) => E.Either<Error, MediaType>;
|
|
7
|
+
export declare const generateOutputSchema: (responses: O.Option<Responses>) => TE.TaskEither<Error, JSONSchema4>;
|
|
8
|
+
export declare const generateOutputTypes: (operationNameCamelCase: string, outputSchema: JSONSchema4) => TE.TaskEither<Error, string>;
|
|
9
|
+
//# sourceMappingURL=GenerateOutput.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateOutput.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateOutput.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAC1C,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AACvC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAClC,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAGlC,OAAO,EAAE,SAAS,EAAE,QAAQ,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAsB9E,eAAO,MAAM,2BAA2B,oBACtB,QAAQ,KACvB,EAAE,MAAM,CAAC,KAAK,EAAE,SAAS,CAgB1B,CAAC;AAEH,eAAO,MAAM,oBAAoB,cACrB,EAAE,MAAM,CAAC,SAAS,CAAC,KAC5B,GAAG,UAAU,CAAC,KAAK,EAAE,WAAW,CAcjC,CAAC;AAEH,eAAO,MAAM,mBAAmB,2BACP,MAAM,gBAChB,WAAW,KACvB,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAS5B,CAAC"}
|
|
@@ -0,0 +1,54 @@
|
|
|
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.generateOutputTypes = exports.generateOutputSchema = exports.getApplicationJsonMediaType = void 0;
|
|
27
|
+
const json_schema_to_typescript_1 = require("json-schema-to-typescript");
|
|
28
|
+
const TE = __importStar(require("fp-ts/TaskEither"));
|
|
29
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
30
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
31
|
+
const function_1 = require("fp-ts/function");
|
|
32
|
+
const JsonSchemaToTypescriptOptions_1 = require("./JsonSchemaToTypescriptOptions");
|
|
33
|
+
const ResolveOptionValues_1 = require("../../ResolveOptionValues");
|
|
34
|
+
const get2XXResponse = (responses) => O.fold(() => TE.left(new Error('No responses found')), (someResponses) => {
|
|
35
|
+
const statusCode2XX = Object.keys(someResponses).find((statusCode) => /^2\d{2}$/.test(statusCode));
|
|
36
|
+
if (statusCode2XX) {
|
|
37
|
+
return TE.right(someResponses[statusCode2XX]);
|
|
38
|
+
}
|
|
39
|
+
const responseCodes = Object.keys(someResponses);
|
|
40
|
+
return TE.left(new Error(`Unsupported success response code: ${responseCodes}`));
|
|
41
|
+
})(responses);
|
|
42
|
+
const getApplicationJsonMediaType = (successResponse) => (0, function_1.pipe)(O.fold(() => E.left(new Error('No success response content found')), (content) => E.right(content))(successResponse.content), E.chain((content) => {
|
|
43
|
+
const mediaTypeApplicationJson = Object.keys(content).find((mediaType) => /^application\/.*json.*$/.test(mediaType));
|
|
44
|
+
if (mediaTypeApplicationJson) {
|
|
45
|
+
return E.right(content[mediaTypeApplicationJson]);
|
|
46
|
+
}
|
|
47
|
+
const mediaTypes = Object.keys(content);
|
|
48
|
+
return E.left(new Error(`Unsupported media type: ${mediaTypes}`));
|
|
49
|
+
}));
|
|
50
|
+
exports.getApplicationJsonMediaType = getApplicationJsonMediaType;
|
|
51
|
+
const generateOutputSchema = (responses) => (0, function_1.pipe)(get2XXResponse(responses), TE.chain((successResponse) => TE.fromEither((0, exports.getApplicationJsonMediaType)(successResponse))), TE.chain((applicationJson) => TE.fromEither((0, ResolveOptionValues_1.resolveOptionValues)(applicationJson.schema))));
|
|
52
|
+
exports.generateOutputSchema = generateOutputSchema;
|
|
53
|
+
const generateOutputTypes = (operationNameCamelCase, outputSchema) => TE.tryCatch(() => (0, json_schema_to_typescript_1.compile)(outputSchema, `${operationNameCamelCase}Output`, JsonSchemaToTypescriptOptions_1.JsonSchemaToTypescriptOptions), (error) => new Error(`Failed to generate output types: ${error}`));
|
|
54
|
+
exports.generateOutputTypes = generateOutputTypes;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateOutput.test.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateOutput.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,197 @@
|
|
|
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 TE = __importStar(require("fp-ts/TaskEither"));
|
|
36
|
+
const E = __importStar(require("fp-ts/Either"));
|
|
37
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
38
|
+
const GenerateOutput_1 = require("./GenerateOutput");
|
|
39
|
+
const generateOutputFileContents = (responses) => __awaiter(void 0, void 0, void 0, function* () {
|
|
40
|
+
const operationNameCamelCase = 'CreatePost';
|
|
41
|
+
const generatedOutputSchema = yield (0, GenerateOutput_1.generateOutputSchema)(responses)();
|
|
42
|
+
if (E.isLeft(generatedOutputSchema)) {
|
|
43
|
+
throw new Error('Should have been right');
|
|
44
|
+
}
|
|
45
|
+
const generatedOutputTypes = (0, GenerateOutput_1.generateOutputTypes)(operationNameCamelCase, generatedOutputSchema.right);
|
|
46
|
+
return TE.getOrElse((error) => {
|
|
47
|
+
throw new Error('Should have been right');
|
|
48
|
+
})(generatedOutputTypes)();
|
|
49
|
+
});
|
|
50
|
+
describe('Generate output: ', () => {
|
|
51
|
+
it('it should generate output.ts file contents for a response code 200 content json', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
52
|
+
const responses = O.some({
|
|
53
|
+
'200': {
|
|
54
|
+
description: 'A post was created',
|
|
55
|
+
content: O.some({
|
|
56
|
+
'application/json': {
|
|
57
|
+
schema: {
|
|
58
|
+
type: 'object',
|
|
59
|
+
required: ['id', 'userId', 'title', 'body'],
|
|
60
|
+
properties: {
|
|
61
|
+
id: {
|
|
62
|
+
type: 'integer',
|
|
63
|
+
},
|
|
64
|
+
userId: {
|
|
65
|
+
type: 'integer',
|
|
66
|
+
},
|
|
67
|
+
title: {
|
|
68
|
+
type: 'string',
|
|
69
|
+
},
|
|
70
|
+
body: {
|
|
71
|
+
type: 'string',
|
|
72
|
+
},
|
|
73
|
+
},
|
|
74
|
+
additionalProperties: O.some(false),
|
|
75
|
+
},
|
|
76
|
+
},
|
|
77
|
+
}),
|
|
78
|
+
},
|
|
79
|
+
});
|
|
80
|
+
const generatedOutputFileContents = yield generateOutputFileContents(responses);
|
|
81
|
+
const expectedOutputFileContents = `export interface CreatePostOutput {
|
|
82
|
+
id: number;
|
|
83
|
+
userId: number;
|
|
84
|
+
title: string;
|
|
85
|
+
body: string;
|
|
86
|
+
}
|
|
87
|
+
`;
|
|
88
|
+
expect(generatedOutputFileContents).toEqual(expectedOutputFileContents);
|
|
89
|
+
}));
|
|
90
|
+
it('it should generate output.ts file contents for a response code 201 content json', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
91
|
+
const responses = O.some({
|
|
92
|
+
'201': {
|
|
93
|
+
description: 'A post was created',
|
|
94
|
+
content: O.some({
|
|
95
|
+
'application/json': {
|
|
96
|
+
schema: {
|
|
97
|
+
type: 'object',
|
|
98
|
+
required: ['id', 'userId', 'title', 'body'],
|
|
99
|
+
properties: {
|
|
100
|
+
id: {
|
|
101
|
+
type: 'integer',
|
|
102
|
+
},
|
|
103
|
+
userId: {
|
|
104
|
+
type: 'integer',
|
|
105
|
+
},
|
|
106
|
+
title: {
|
|
107
|
+
type: 'string',
|
|
108
|
+
},
|
|
109
|
+
body: {
|
|
110
|
+
type: 'string',
|
|
111
|
+
},
|
|
112
|
+
},
|
|
113
|
+
additionalProperties: O.some(false),
|
|
114
|
+
},
|
|
115
|
+
},
|
|
116
|
+
}),
|
|
117
|
+
},
|
|
118
|
+
});
|
|
119
|
+
const generatedOutputFileContents = yield generateOutputFileContents(responses);
|
|
120
|
+
const expectedOutputFileContents = `export interface CreatePostOutput {
|
|
121
|
+
id: number;
|
|
122
|
+
userId: number;
|
|
123
|
+
title: string;
|
|
124
|
+
body: string;
|
|
125
|
+
}
|
|
126
|
+
`;
|
|
127
|
+
expect(generatedOutputFileContents).toEqual(expectedOutputFileContents);
|
|
128
|
+
}));
|
|
129
|
+
it('it should extract different json media types: application/vnd.tableau.analyticsextensions.v1.ServerSettings+json', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
130
|
+
const response = {
|
|
131
|
+
description: 'A post was created',
|
|
132
|
+
content: O.some({
|
|
133
|
+
'application/vnd.tableau.analyticsextensions.v1.ServerSettings+json': {
|
|
134
|
+
schema: {
|
|
135
|
+
type: 'object',
|
|
136
|
+
properties: {
|
|
137
|
+
id: {
|
|
138
|
+
type: 'integer',
|
|
139
|
+
},
|
|
140
|
+
},
|
|
141
|
+
additionalProperties: O.some(false),
|
|
142
|
+
},
|
|
143
|
+
},
|
|
144
|
+
}),
|
|
145
|
+
};
|
|
146
|
+
const applicationJson = (0, GenerateOutput_1.getApplicationJsonMediaType)(response);
|
|
147
|
+
const actualApplicationJson = E.getOrElse((error) => {
|
|
148
|
+
throw new Error('Should have been right');
|
|
149
|
+
})(applicationJson);
|
|
150
|
+
const expectedApplicationJson = {
|
|
151
|
+
schema: {
|
|
152
|
+
type: 'object',
|
|
153
|
+
properties: {
|
|
154
|
+
id: {
|
|
155
|
+
type: 'integer',
|
|
156
|
+
},
|
|
157
|
+
},
|
|
158
|
+
additionalProperties: O.some(false),
|
|
159
|
+
},
|
|
160
|
+
};
|
|
161
|
+
expect(actualApplicationJson).toEqual(expectedApplicationJson);
|
|
162
|
+
}));
|
|
163
|
+
it('it should extract different json media types: application/json; charset=utf-8', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
164
|
+
const response = {
|
|
165
|
+
description: 'A post was created',
|
|
166
|
+
content: O.some({
|
|
167
|
+
'application/json; charset=utf-8': {
|
|
168
|
+
schema: {
|
|
169
|
+
type: 'object',
|
|
170
|
+
properties: {
|
|
171
|
+
id: {
|
|
172
|
+
type: 'integer',
|
|
173
|
+
},
|
|
174
|
+
},
|
|
175
|
+
additionalProperties: O.some(false),
|
|
176
|
+
},
|
|
177
|
+
},
|
|
178
|
+
}),
|
|
179
|
+
};
|
|
180
|
+
const applicationJson = (0, GenerateOutput_1.getApplicationJsonMediaType)(response);
|
|
181
|
+
const actualApplicationJson = E.getOrElse((error) => {
|
|
182
|
+
throw new Error('Should have been right');
|
|
183
|
+
})(applicationJson);
|
|
184
|
+
const expectedApplicationJson = {
|
|
185
|
+
schema: {
|
|
186
|
+
type: 'object',
|
|
187
|
+
properties: {
|
|
188
|
+
id: {
|
|
189
|
+
type: 'integer',
|
|
190
|
+
},
|
|
191
|
+
},
|
|
192
|
+
additionalProperties: O.some(false),
|
|
193
|
+
},
|
|
194
|
+
};
|
|
195
|
+
expect(actualApplicationJson).toEqual(expectedApplicationJson);
|
|
196
|
+
}));
|
|
197
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"JsonSchemaToTypescriptOptions.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/JsonSchemaToTypescriptOptions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B;;;;;;;CAOzC,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@trayio/tray-openapi",
|
|
3
|
-
"version": "2.
|
|
3
|
+
"version": "2.8.0",
|
|
4
4
|
"description": "Creating CDK Projects from OpenAPI 3.0 Schemas",
|
|
5
5
|
"exports": {
|
|
6
6
|
"./*": "./dist/*.js"
|
|
@@ -23,6 +23,8 @@
|
|
|
23
23
|
],
|
|
24
24
|
"dependencies": {
|
|
25
25
|
"@openapi-contrib/openapi-schema-to-json-schema": "5.1.0",
|
|
26
|
-
"json-
|
|
26
|
+
"@stoplight/json-ref-resolver": "3.1.6",
|
|
27
|
+
"json-schema-to-typescript": "13.1.1",
|
|
28
|
+
"json-to-typescript": "1.0.1"
|
|
27
29
|
}
|
|
28
30
|
}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateHander.test.d.ts","sourceRoot":"","sources":["../src/GenerateHander.test.ts"],"names":[],"mappings":""}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateHandler.d.ts","sourceRoot":"","sources":["../src/GenerateHandler.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,CAAC,MAAM,cAAc,CAAC;AAElC,KAAK,WAAW,GAAG,MAAM,GAAG,OAAO,GAAG,MAAM,GAAG,QAAQ,CAAC;AAExD,KAAK,iBAAiB,GAAG,KAAK,GAAG,MAAM,GAAG,KAAK,GAAG,OAAO,GAAG,QAAQ,CAAC;AAErE,KAAK,KAAK,GAAG;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,EAAE,EAAE,WAAW,CAAC;CAChB,CAAC;AAEF,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,KAAK,EAAE,CAAC;CACf,CAAC;AAyCF,eAAO,MAAM,eAAe,oHAQzB,oBAAoB,KAAG,EAAE,MAAM,CAAC,KAAK,EAAE,MAAM,CAoB9C,CAAC"}
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"JsonSchemaToTypescriptOptions.d.ts","sourceRoot":"","sources":["../../src/connector/JsonSchemaToTypescriptOptions.ts"],"names":[],"mappings":"AAAA,eAAO,MAAM,6BAA6B;;;;;;;CAOzC,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
import { JSONSchema4 } from 'json-schema';
|
|
2
|
-
import * as TE from 'fp-ts/TaskEither';
|
|
3
|
-
export type GenerateInputParams = {
|
|
4
|
-
operationNameCamelCase: string;
|
|
5
|
-
parameters: JSONSchema4;
|
|
6
|
-
};
|
|
7
|
-
export declare const generateInput: ({ operationNameCamelCase, parameters, }: GenerateInputParams) => TE.TaskEither<Error, string>;
|
|
8
|
-
//# sourceMappingURL=GenerateInput.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateInput.d.ts","sourceRoot":"","sources":["../../../src/connector/input/GenerateInput.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAE1C,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAGvC,MAAM,MAAM,mBAAmB,GAAG;IACjC,sBAAsB,EAAE,MAAM,CAAC;IAC/B,UAAU,EAAE,WAAW,CAAC;CACxB,CAAC;AAEF,eAAO,MAAM,aAAa,4CAGvB,mBAAmB,KAAG,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CASlD,CAAC"}
|
|
@@ -1,8 +0,0 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.generateInput = void 0;
|
|
4
|
-
const json_schema_to_typescript_1 = require("json-schema-to-typescript");
|
|
5
|
-
const TaskEither_1 = require("fp-ts/TaskEither");
|
|
6
|
-
const JsonSchemaToTypescriptOptions_1 = require("../JsonSchemaToTypescriptOptions");
|
|
7
|
-
const generateInput = ({ operationNameCamelCase, parameters, }) => (0, TaskEither_1.tryCatch)(() => (0, json_schema_to_typescript_1.compile)(parameters, `${operationNameCamelCase}Input`, JsonSchemaToTypescriptOptions_1.JsonSchemaToTypescriptOptions), (reason) => new Error(`${reason}`));
|
|
8
|
-
exports.generateInput = generateInput;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateInput.test.d.ts","sourceRoot":"","sources":["../../../src/connector/input/GenerateInput.test.ts"],"names":[],"mappings":""}
|
|
@@ -1,133 +0,0 @@
|
|
|
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 TE = __importStar(require("fp-ts/TaskEither"));
|
|
36
|
-
const GenerateInput_1 = require("./GenerateInput");
|
|
37
|
-
describe('Input: GenerateInput', () => {
|
|
38
|
-
it('it should generate input.ts file contents when given JSON schema path and query params', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
39
|
-
const operationNameCamelCase = 'getPost';
|
|
40
|
-
const parameters = {
|
|
41
|
-
type: 'object',
|
|
42
|
-
properties: {
|
|
43
|
-
id: {
|
|
44
|
-
type: 'integer',
|
|
45
|
-
},
|
|
46
|
-
filter: {
|
|
47
|
-
type: 'string',
|
|
48
|
-
},
|
|
49
|
-
},
|
|
50
|
-
required: ['id'],
|
|
51
|
-
additionalProperties: false,
|
|
52
|
-
};
|
|
53
|
-
const generatedInput = (0, GenerateInput_1.generateInput)({
|
|
54
|
-
operationNameCamelCase,
|
|
55
|
-
parameters,
|
|
56
|
-
});
|
|
57
|
-
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
58
|
-
throw new Error('Should have been right');
|
|
59
|
-
})(generatedInput)();
|
|
60
|
-
const expected = `export interface GetPostInput {
|
|
61
|
-
id: number;
|
|
62
|
-
filter?: string;
|
|
63
|
-
}
|
|
64
|
-
`;
|
|
65
|
-
expect(generatedInputFile).toEqual(expected);
|
|
66
|
-
}));
|
|
67
|
-
it('it should generate input.ts file contents when given JSON schema optional path and query params', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
68
|
-
const operationNameCamelCase = 'getPost';
|
|
69
|
-
const parameters = {
|
|
70
|
-
type: 'object',
|
|
71
|
-
properties: {
|
|
72
|
-
id: {
|
|
73
|
-
type: 'integer',
|
|
74
|
-
},
|
|
75
|
-
filter: {
|
|
76
|
-
type: 'string',
|
|
77
|
-
},
|
|
78
|
-
},
|
|
79
|
-
required: [],
|
|
80
|
-
additionalProperties: false,
|
|
81
|
-
};
|
|
82
|
-
const generatedInput = (0, GenerateInput_1.generateInput)({
|
|
83
|
-
operationNameCamelCase,
|
|
84
|
-
parameters,
|
|
85
|
-
});
|
|
86
|
-
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
87
|
-
throw new Error('Should have been right');
|
|
88
|
-
})(generatedInput)();
|
|
89
|
-
const expected = `export interface GetPostInput {
|
|
90
|
-
id?: number;
|
|
91
|
-
filter?: string;
|
|
92
|
-
}
|
|
93
|
-
`;
|
|
94
|
-
expect(generatedInputFile).toEqual(expected);
|
|
95
|
-
}));
|
|
96
|
-
it('it should generate input.ts file contents when given JSON schema body params', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
97
|
-
const operationNameCamelCase = 'createPost';
|
|
98
|
-
const parameters = {
|
|
99
|
-
type: 'object',
|
|
100
|
-
required: ['id', 'userId', 'title', 'body'],
|
|
101
|
-
properties: {
|
|
102
|
-
id: {
|
|
103
|
-
type: 'integer',
|
|
104
|
-
},
|
|
105
|
-
userId: {
|
|
106
|
-
type: 'integer',
|
|
107
|
-
},
|
|
108
|
-
title: {
|
|
109
|
-
type: 'string',
|
|
110
|
-
},
|
|
111
|
-
body: {
|
|
112
|
-
type: 'string',
|
|
113
|
-
},
|
|
114
|
-
},
|
|
115
|
-
additionalProperties: false,
|
|
116
|
-
};
|
|
117
|
-
const generatedInput = (0, GenerateInput_1.generateInput)({
|
|
118
|
-
operationNameCamelCase,
|
|
119
|
-
parameters,
|
|
120
|
-
});
|
|
121
|
-
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
122
|
-
throw new Error('Should have been right');
|
|
123
|
-
})(generatedInput)();
|
|
124
|
-
const expected = `export interface CreatePostInput {
|
|
125
|
-
id: number;
|
|
126
|
-
userId: number;
|
|
127
|
-
title: string;
|
|
128
|
-
body: string;
|
|
129
|
-
}
|
|
130
|
-
`;
|
|
131
|
-
expect(generatedInputFile).toEqual(expected);
|
|
132
|
-
}));
|
|
133
|
-
});
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"ProcessInput.d.ts","sourceRoot":"","sources":["../../../src/connector/input/ProcessInput.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIvC,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AA2DpD,eAAO,MAAM,YAAY,aAAc,IAAI,KAAG,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAMxE,CAAC"}
|