@trayio/tray-openapi 2.3.0 → 2.5.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/GenerateHander.test.js +42 -24
- package/dist/GenerateHandler.d.ts +2 -1
- package/dist/GenerateHandler.d.ts.map +1 -1
- package/dist/GenerateHandler.js +27 -3
- package/dist/OpenApiCodecs.d.ts +3 -0
- package/dist/OpenApiCodecs.d.ts.map +1 -0
- package/dist/OpenApiCodecs.js +6 -0
- package/dist/OpenApiSchemaImporter.d.ts +13 -0
- package/dist/OpenApiSchemaImporter.d.ts.map +1 -0
- package/dist/OpenApiSchemaImporter.js +81 -0
- package/dist/OpenApiSchemaImporter.test.d.ts +2 -0
- package/dist/OpenApiSchemaImporter.test.d.ts.map +1 -0
- package/dist/OpenApiSchemaImporter.test.js +21 -0
- package/dist/OpenApiTypeDescriptors.d.ts +59 -0
- package/dist/OpenApiTypeDescriptors.d.ts.map +1 -0
- package/dist/OpenApiTypeDescriptors.js +80 -0
- package/dist/connector/JsonSchemaToTypescriptOptions.d.ts +9 -0
- package/dist/connector/JsonSchemaToTypescriptOptions.d.ts.map +1 -0
- package/dist/connector/JsonSchemaToTypescriptOptions.js +11 -0
- package/dist/connector/input/GenerateInput.d.ts +8 -0
- package/dist/connector/input/GenerateInput.d.ts.map +1 -0
- package/dist/connector/input/GenerateInput.js +8 -0
- package/dist/connector/input/GenerateInput.test.d.ts +2 -0
- package/dist/connector/input/GenerateInput.test.d.ts.map +1 -0
- package/dist/connector/input/GenerateInput.test.js +133 -0
- package/dist/connector/input/ProcessInput.d.ts +4 -0
- package/dist/connector/input/ProcessInput.d.ts.map +1 -0
- package/dist/connector/input/ProcessInput.js +81 -0
- package/dist/connector/input/ProcessInput.test.d.ts +2 -0
- package/dist/connector/input/ProcessInput.test.d.ts.map +1 -0
- package/dist/connector/input/ProcessInput.test.js +227 -0
- package/dist/connector/input/TransformInput.d.ts +4 -0
- package/dist/connector/input/TransformInput.d.ts.map +1 -0
- package/dist/connector/input/TransformInput.js +54 -0
- package/dist/connector/input/TransformInput.test.d.ts +2 -0
- package/dist/connector/input/TransformInput.test.d.ts.map +1 -0
- package/dist/connector/input/TransformInput.test.js +75 -0
- package/dist/single-get-openapi.json +78 -0
- package/dist/templates/connector-template.zip +0 -0
- package/package.json +6 -2
|
@@ -0,0 +1,133 @@
|
|
|
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
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
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"}
|
|
@@ -0,0 +1,81 @@
|
|
|
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.processInput = void 0;
|
|
27
|
+
const lodash_1 = require("lodash");
|
|
28
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
29
|
+
const GenerateInput_1 = require("./GenerateInput");
|
|
30
|
+
const TransformInput_1 = require("./TransformInput");
|
|
31
|
+
const mergeRequired = (params, body) => {
|
|
32
|
+
if ((0, lodash_1.isArray)(body.required) && (0, lodash_1.isArray)(params.required)) {
|
|
33
|
+
return [...body.required, ...params.required];
|
|
34
|
+
}
|
|
35
|
+
return [];
|
|
36
|
+
};
|
|
37
|
+
const mergeParamsAndBody = (params, body) => ({
|
|
38
|
+
type: 'object',
|
|
39
|
+
properties: Object.assign(Object.assign({}, body.properties), params.properties),
|
|
40
|
+
required: mergeRequired(params, body),
|
|
41
|
+
additionalProperties: false,
|
|
42
|
+
});
|
|
43
|
+
const getApplicationJsonMediaType = (content) => {
|
|
44
|
+
// TODO: we should support any value here, but there may also be more than 1 media type so we need to iterate through
|
|
45
|
+
// and combine all the schemas within into a single set of inputs
|
|
46
|
+
const mediaTypeApplicationJson = Object.keys(content).find((mediaType) => /^application\/.*json$/.test(mediaType));
|
|
47
|
+
if (mediaTypeApplicationJson) {
|
|
48
|
+
return content[mediaTypeApplicationJson];
|
|
49
|
+
}
|
|
50
|
+
const mediaTypes = Object.keys(content);
|
|
51
|
+
throw new Error(`Unsupported media type: ${mediaTypes}`);
|
|
52
|
+
};
|
|
53
|
+
const extractInput = (endpoint) => {
|
|
54
|
+
const parameters = O.toNullable(endpoint.parameters);
|
|
55
|
+
const requestBody = O.toNullable(endpoint.requestBody);
|
|
56
|
+
if (parameters && !requestBody) {
|
|
57
|
+
return (0, TransformInput_1.transformInput)(parameters);
|
|
58
|
+
}
|
|
59
|
+
if (requestBody && !parameters) {
|
|
60
|
+
return getApplicationJsonMediaType(requestBody.content).schema;
|
|
61
|
+
}
|
|
62
|
+
if (requestBody && parameters) {
|
|
63
|
+
const params = (0, TransformInput_1.transformInput)(parameters);
|
|
64
|
+
const body = getApplicationJsonMediaType(requestBody.content).schema;
|
|
65
|
+
return mergeParamsAndBody(params, body);
|
|
66
|
+
}
|
|
67
|
+
return {
|
|
68
|
+
type: 'object',
|
|
69
|
+
properties: {},
|
|
70
|
+
required: [],
|
|
71
|
+
additionalProperties: false,
|
|
72
|
+
};
|
|
73
|
+
};
|
|
74
|
+
const processInput = (endpoint) => {
|
|
75
|
+
const input = extractInput(endpoint);
|
|
76
|
+
return (0, GenerateInput_1.generateInput)({
|
|
77
|
+
operationNameCamelCase: endpoint.operationId,
|
|
78
|
+
parameters: input,
|
|
79
|
+
});
|
|
80
|
+
};
|
|
81
|
+
exports.processInput = processInput;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"ProcessInput.test.d.ts","sourceRoot":"","sources":["../../../src/connector/input/ProcessInput.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,227 @@
|
|
|
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 O = __importStar(require("fp-ts/Option"));
|
|
37
|
+
const ProcessInput_1 = require("./ProcessInput");
|
|
38
|
+
describe('Input: ProcessInput', () => {
|
|
39
|
+
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
|
+
const endpoint = {
|
|
41
|
+
operationId: 'getPost',
|
|
42
|
+
description: '',
|
|
43
|
+
tags: [],
|
|
44
|
+
parameters: O.some([
|
|
45
|
+
{
|
|
46
|
+
name: 'id',
|
|
47
|
+
in: 'path',
|
|
48
|
+
required: true,
|
|
49
|
+
description: 'The user id.',
|
|
50
|
+
schema: {
|
|
51
|
+
type: 'integer',
|
|
52
|
+
format: O.some('int64'),
|
|
53
|
+
},
|
|
54
|
+
},
|
|
55
|
+
]),
|
|
56
|
+
requestBody: O.none,
|
|
57
|
+
};
|
|
58
|
+
const processedInput = (0, ProcessInput_1.processInput)(endpoint);
|
|
59
|
+
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
60
|
+
throw new Error('Should have been right');
|
|
61
|
+
})(processedInput)();
|
|
62
|
+
const expectedInputFile = `export interface GetPostInput {
|
|
63
|
+
/**
|
|
64
|
+
* @description The user id.
|
|
65
|
+
*/
|
|
66
|
+
id: number;
|
|
67
|
+
}
|
|
68
|
+
`;
|
|
69
|
+
expect(generatedInputFile).toEqual(expectedInputFile);
|
|
70
|
+
}));
|
|
71
|
+
it('it should process an endpoint with body parameters and generate input.ts file contents', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
72
|
+
const endpoint = {
|
|
73
|
+
operationId: 'createPost',
|
|
74
|
+
description: 'Create a new post',
|
|
75
|
+
tags: [],
|
|
76
|
+
parameters: O.none,
|
|
77
|
+
requestBody: O.some({
|
|
78
|
+
content: {
|
|
79
|
+
'application/json': {
|
|
80
|
+
schema: {
|
|
81
|
+
type: 'object',
|
|
82
|
+
required: ['id', 'userId', 'title', 'body'],
|
|
83
|
+
properties: {
|
|
84
|
+
id: {
|
|
85
|
+
type: 'integer',
|
|
86
|
+
},
|
|
87
|
+
userId: {
|
|
88
|
+
type: 'integer',
|
|
89
|
+
},
|
|
90
|
+
title: {
|
|
91
|
+
type: 'string',
|
|
92
|
+
},
|
|
93
|
+
body: {
|
|
94
|
+
type: 'string',
|
|
95
|
+
},
|
|
96
|
+
},
|
|
97
|
+
additionalProperties: false,
|
|
98
|
+
},
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
required: true,
|
|
102
|
+
}),
|
|
103
|
+
};
|
|
104
|
+
const processedInput = (0, ProcessInput_1.processInput)(endpoint);
|
|
105
|
+
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
106
|
+
throw new Error('Should have been right');
|
|
107
|
+
})(processedInput)();
|
|
108
|
+
const expectedInputFile = `export interface CreatePostInput {
|
|
109
|
+
id: number;
|
|
110
|
+
userId: number;
|
|
111
|
+
title: string;
|
|
112
|
+
body: string;
|
|
113
|
+
}
|
|
114
|
+
`;
|
|
115
|
+
expect(generatedInputFile).toEqual(expectedInputFile);
|
|
116
|
+
}));
|
|
117
|
+
it('it should process an endpoint with path, query string and body parameters and generate input.ts file contents', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
118
|
+
const endpoint = {
|
|
119
|
+
operationId: 'getPost',
|
|
120
|
+
description: '',
|
|
121
|
+
tags: [],
|
|
122
|
+
parameters: O.some([
|
|
123
|
+
{
|
|
124
|
+
name: 'id',
|
|
125
|
+
in: 'path',
|
|
126
|
+
required: true,
|
|
127
|
+
description: 'The user id.',
|
|
128
|
+
schema: {
|
|
129
|
+
type: 'integer',
|
|
130
|
+
format: O.some('int64'),
|
|
131
|
+
},
|
|
132
|
+
},
|
|
133
|
+
]),
|
|
134
|
+
requestBody: O.some({
|
|
135
|
+
content: {
|
|
136
|
+
'application/json': {
|
|
137
|
+
schema: {
|
|
138
|
+
type: 'object',
|
|
139
|
+
required: ['id', 'userId', 'title', 'body'],
|
|
140
|
+
properties: {
|
|
141
|
+
userId: {
|
|
142
|
+
type: 'integer',
|
|
143
|
+
},
|
|
144
|
+
title: {
|
|
145
|
+
type: 'string',
|
|
146
|
+
},
|
|
147
|
+
body: {
|
|
148
|
+
type: 'string',
|
|
149
|
+
},
|
|
150
|
+
},
|
|
151
|
+
additionalProperties: false,
|
|
152
|
+
},
|
|
153
|
+
},
|
|
154
|
+
},
|
|
155
|
+
required: true,
|
|
156
|
+
}),
|
|
157
|
+
};
|
|
158
|
+
const processedInput = (0, ProcessInput_1.processInput)(endpoint);
|
|
159
|
+
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
160
|
+
throw new Error('Should have been right');
|
|
161
|
+
})(processedInput)();
|
|
162
|
+
const expectedInputFile = `export interface GetPostInput {
|
|
163
|
+
userId: number;
|
|
164
|
+
title: string;
|
|
165
|
+
body: string;
|
|
166
|
+
/**
|
|
167
|
+
* @description The user id.
|
|
168
|
+
*/
|
|
169
|
+
id: number;
|
|
170
|
+
}
|
|
171
|
+
`;
|
|
172
|
+
expect(generatedInputFile).toEqual(expectedInputFile);
|
|
173
|
+
}));
|
|
174
|
+
it('it should process an endpoint with no parameters and generate empty input.ts file contents', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
175
|
+
const endpoint = {
|
|
176
|
+
operationId: 'getPosts',
|
|
177
|
+
description: '',
|
|
178
|
+
tags: [],
|
|
179
|
+
parameters: O.none,
|
|
180
|
+
requestBody: O.none,
|
|
181
|
+
};
|
|
182
|
+
const processedInput = (0, ProcessInput_1.processInput)(endpoint);
|
|
183
|
+
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
184
|
+
throw new Error('Should have been right');
|
|
185
|
+
})(processedInput)();
|
|
186
|
+
const expectedInputFile = `export interface GetPostsInput {}
|
|
187
|
+
`;
|
|
188
|
+
expect(generatedInputFile).toEqual(expectedInputFile);
|
|
189
|
+
}));
|
|
190
|
+
it('it should throw an exception when finding an unsupported media type', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
191
|
+
const endpoint = {
|
|
192
|
+
operationId: 'createPost',
|
|
193
|
+
description: '',
|
|
194
|
+
tags: [],
|
|
195
|
+
parameters: O.none,
|
|
196
|
+
requestBody: O.some({
|
|
197
|
+
content: {
|
|
198
|
+
'unsupported-media-type': {
|
|
199
|
+
schema: {
|
|
200
|
+
type: 'object',
|
|
201
|
+
required: ['id', 'userId', 'title', 'body'],
|
|
202
|
+
properties: {
|
|
203
|
+
id: {
|
|
204
|
+
type: 'integer',
|
|
205
|
+
},
|
|
206
|
+
userId: {
|
|
207
|
+
type: 'integer',
|
|
208
|
+
},
|
|
209
|
+
title: {
|
|
210
|
+
type: 'string',
|
|
211
|
+
},
|
|
212
|
+
body: {
|
|
213
|
+
type: 'string',
|
|
214
|
+
},
|
|
215
|
+
},
|
|
216
|
+
additionalProperties: false,
|
|
217
|
+
},
|
|
218
|
+
},
|
|
219
|
+
},
|
|
220
|
+
required: true,
|
|
221
|
+
}),
|
|
222
|
+
};
|
|
223
|
+
yield expect(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
224
|
+
(0, ProcessInput_1.processInput)(endpoint);
|
|
225
|
+
})).rejects.toThrow('Unsupported media type: unsupported-media-type');
|
|
226
|
+
}));
|
|
227
|
+
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransformInput.d.ts","sourceRoot":"","sources":["../../../src/connector/input/TransformInput.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,WAAW,EAAE,MAAM,aAAa,CAAC;AAG1C,OAAO,EAAE,SAAS,EAAE,MAAM,8BAA8B,CAAC;AAEzD,eAAO,MAAM,cAAc,eAAgB,SAAS,EAAE,KAAG,WA4BxD,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.transformInput = void 0;
|
|
27
|
+
const openapi_schema_to_json_schema_1 = require("@openapi-contrib/openapi-schema-to-json-schema");
|
|
28
|
+
const O = __importStar(require("fp-ts/Option"));
|
|
29
|
+
const transformInput = (parameters) => {
|
|
30
|
+
const transformedParameters = {};
|
|
31
|
+
const requiredParameters = [];
|
|
32
|
+
parameters.forEach((parameter) => {
|
|
33
|
+
const paramterWithJsdocAnnotation = {
|
|
34
|
+
name: parameter.name,
|
|
35
|
+
description: `@description ${parameter.description}`,
|
|
36
|
+
required: parameter.required,
|
|
37
|
+
schema: {
|
|
38
|
+
type: parameter.schema.type,
|
|
39
|
+
format: O.toNullable(parameter.schema.format) || undefined,
|
|
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
|
+
};
|
|
53
|
+
};
|
|
54
|
+
exports.transformInput = transformInput;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"TransformInput.test.d.ts","sourceRoot":"","sources":["../../../src/connector/input/TransformInput.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,75 @@
|
|
|
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 TransformInput_1 = require("./TransformInput");
|
|
28
|
+
describe('Input: TransformInput', () => {
|
|
29
|
+
it('it should transform open api spec path and query parameters into JSON schema', () => {
|
|
30
|
+
const openApiSpecParameters = [
|
|
31
|
+
{
|
|
32
|
+
name: 'id',
|
|
33
|
+
in: 'path',
|
|
34
|
+
required: true,
|
|
35
|
+
description: 'The user id.',
|
|
36
|
+
schema: {
|
|
37
|
+
type: 'integer',
|
|
38
|
+
format: O.some('int64'),
|
|
39
|
+
},
|
|
40
|
+
},
|
|
41
|
+
{
|
|
42
|
+
name: 'filter',
|
|
43
|
+
in: 'query',
|
|
44
|
+
required: false,
|
|
45
|
+
description: 'The type to filter on.',
|
|
46
|
+
schema: {
|
|
47
|
+
type: 'string',
|
|
48
|
+
format: O.none,
|
|
49
|
+
},
|
|
50
|
+
},
|
|
51
|
+
];
|
|
52
|
+
const generatedJsonSchema = (0, TransformInput_1.transformInput)(openApiSpecParameters);
|
|
53
|
+
const expectedJsonSchema = {
|
|
54
|
+
type: 'object',
|
|
55
|
+
properties: {
|
|
56
|
+
id: {
|
|
57
|
+
type: 'integer',
|
|
58
|
+
$schema: 'http://json-schema.org/draft-04/schema#',
|
|
59
|
+
description: '@description The user id.',
|
|
60
|
+
format: 'int64',
|
|
61
|
+
maximum: 9223372036854776000,
|
|
62
|
+
minimum: -9223372036854776000,
|
|
63
|
+
},
|
|
64
|
+
filter: {
|
|
65
|
+
type: 'string',
|
|
66
|
+
$schema: 'http://json-schema.org/draft-04/schema#',
|
|
67
|
+
description: '@description The type to filter on.',
|
|
68
|
+
},
|
|
69
|
+
},
|
|
70
|
+
required: ['id'],
|
|
71
|
+
additionalProperties: false,
|
|
72
|
+
};
|
|
73
|
+
expect(generatedJsonSchema).toEqual(expectedJsonSchema);
|
|
74
|
+
});
|
|
75
|
+
});
|