@trayio/tray-openapi 2.9.0 → 2.10.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/OpenApiCodecs.d.ts +3 -1
- package/dist/OpenApiCodecs.d.ts.map +1 -1
- package/dist/OpenApiCodecs.js +3 -1
- package/dist/OpenApiSchemaImporter.d.ts +1 -0
- package/dist/OpenApiSchemaImporter.d.ts.map +1 -1
- package/dist/OpenApiSchemaImporter.js +25 -15
- package/dist/OpenApiTypeDescriptors.d.ts +32 -20
- package/dist/OpenApiTypeDescriptors.d.ts.map +1 -1
- package/dist/OpenApiTypeDescriptors.js +59 -36
- package/dist/file-generators/GenerateHandler.d.ts +4 -4
- package/dist/file-generators/GenerateHandler.d.ts.map +1 -1
- package/dist/file-generators/GenerateHandler.js +43 -46
- package/dist/file-generators/GenerateHandler.test.js +194 -38
- package/dist/file-generators/GenerateHandlerTest.d.ts +3 -3
- package/dist/file-generators/GenerateHandlerTest.d.ts.map +1 -1
- package/dist/file-generators/GenerateHandlerTest.js +33 -21
- package/dist/file-generators/GenerateHandlerTest.test.js +313 -61
- package/dist/file-generators/GenerateOperationJson.test.js +2 -1
- package/dist/file-generators/types/GenerateInputSchema.d.ts +2 -3
- package/dist/file-generators/types/GenerateInputSchema.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateInputSchema.js +63 -28
- package/dist/file-generators/types/GenerateInputSchema.test.js +72 -104
- package/dist/file-generators/types/GenerateInputType.test.d.ts +2 -0
- package/dist/file-generators/types/GenerateInputType.test.d.ts.map +1 -0
- package/dist/file-generators/types/GenerateInputType.test.js +400 -0
- 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 +10 -8
- package/dist/file-generators/types/GenerateOutput.d.ts +4 -5
- package/dist/file-generators/types/GenerateOutput.d.ts.map +1 -1
- package/dist/file-generators/types/GenerateOutput.js +31 -5
- package/dist/file-generators/types/GenerateOutput.test.js +94 -88
- package/package.json +1 -1
- package/dist/ResolveOptionValues.d.ts +0 -3
- package/dist/ResolveOptionValues.d.ts.map +0 -1
- package/dist/ResolveOptionValues.js +0 -43
- package/dist/ResolveOptionValues.test.d.ts +0 -2
- package/dist/ResolveOptionValues.test.d.ts.map +0 -1
- package/dist/ResolveOptionValues.test.js +0 -91
|
@@ -41,7 +41,7 @@ describe('GenerateInputSchema', () => {
|
|
|
41
41
|
const endpoint = {
|
|
42
42
|
operationId: 'getPost',
|
|
43
43
|
description: '',
|
|
44
|
-
tags: [],
|
|
44
|
+
tags: O.some([]),
|
|
45
45
|
parameters: O.some([
|
|
46
46
|
{
|
|
47
47
|
name: 'id',
|
|
@@ -51,6 +51,7 @@ describe('GenerateInputSchema', () => {
|
|
|
51
51
|
schema: {
|
|
52
52
|
type: 'integer',
|
|
53
53
|
format: O.some('int64'),
|
|
54
|
+
items: O.none,
|
|
54
55
|
},
|
|
55
56
|
additionalProperties: O.none,
|
|
56
57
|
},
|
|
@@ -76,33 +77,69 @@ describe('GenerateInputSchema', () => {
|
|
|
76
77
|
const endpoint = {
|
|
77
78
|
operationId: 'createPost',
|
|
78
79
|
description: 'Create a new post',
|
|
79
|
-
tags: [],
|
|
80
|
+
tags: O.some([]),
|
|
80
81
|
parameters: O.none,
|
|
81
82
|
requestBody: O.some({
|
|
82
83
|
content: {
|
|
83
84
|
'application/json': {
|
|
84
|
-
schema: {
|
|
85
|
-
type: 'object',
|
|
86
|
-
required: ['id', 'userId', 'title', 'body'],
|
|
87
|
-
properties: {
|
|
85
|
+
schema: O.some({
|
|
86
|
+
type: O.some('object'),
|
|
87
|
+
required: O.some(['id', 'userId', 'title', 'body']),
|
|
88
|
+
properties: O.some({
|
|
88
89
|
id: {
|
|
89
|
-
type: 'integer',
|
|
90
|
+
type: O.some('integer'),
|
|
91
|
+
properties: O.none,
|
|
92
|
+
additionalProperties: O.some(false),
|
|
93
|
+
required: O.none,
|
|
94
|
+
allOf: O.none,
|
|
95
|
+
anyOf: O.none,
|
|
96
|
+
oneOf: O.none,
|
|
97
|
+
not: O.none,
|
|
98
|
+
in: O.none,
|
|
90
99
|
},
|
|
91
100
|
userId: {
|
|
92
|
-
type: 'integer',
|
|
101
|
+
type: O.some('integer'),
|
|
102
|
+
properties: O.none,
|
|
103
|
+
additionalProperties: O.some(false),
|
|
104
|
+
required: O.none,
|
|
105
|
+
allOf: O.none,
|
|
106
|
+
anyOf: O.none,
|
|
107
|
+
oneOf: O.none,
|
|
108
|
+
not: O.none,
|
|
109
|
+
in: O.none,
|
|
93
110
|
},
|
|
94
111
|
title: {
|
|
95
|
-
type: 'string',
|
|
112
|
+
type: O.some('string'),
|
|
113
|
+
properties: O.none,
|
|
114
|
+
additionalProperties: O.some(false),
|
|
115
|
+
required: O.none,
|
|
116
|
+
allOf: O.none,
|
|
117
|
+
anyOf: O.none,
|
|
118
|
+
oneOf: O.none,
|
|
119
|
+
not: O.none,
|
|
120
|
+
in: O.none,
|
|
96
121
|
},
|
|
97
122
|
body: {
|
|
98
|
-
type: 'string',
|
|
123
|
+
type: O.some('string'),
|
|
124
|
+
properties: O.none,
|
|
125
|
+
additionalProperties: O.some(false),
|
|
126
|
+
required: O.none,
|
|
127
|
+
allOf: O.none,
|
|
128
|
+
anyOf: O.none,
|
|
129
|
+
oneOf: O.none,
|
|
130
|
+
not: O.none,
|
|
131
|
+
in: O.none,
|
|
99
132
|
},
|
|
100
|
-
},
|
|
133
|
+
}),
|
|
101
134
|
additionalProperties: O.some(false),
|
|
102
|
-
|
|
135
|
+
allOf: O.none,
|
|
136
|
+
anyOf: O.none,
|
|
137
|
+
oneOf: O.none,
|
|
138
|
+
not: O.none,
|
|
139
|
+
in: O.none,
|
|
140
|
+
}),
|
|
103
141
|
},
|
|
104
142
|
},
|
|
105
|
-
required: true,
|
|
106
143
|
}),
|
|
107
144
|
responses: O.none,
|
|
108
145
|
};
|
|
@@ -120,46 +157,36 @@ describe('GenerateInputSchema', () => {
|
|
|
120
157
|
`;
|
|
121
158
|
expect(generatedInputFile).toEqual(expectedInputFile);
|
|
122
159
|
}));
|
|
123
|
-
it('it should process an endpoint with
|
|
160
|
+
it('it should process an endpoint with query string parameter array and generate input.ts file contents', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
124
161
|
const endpoint = {
|
|
125
162
|
operationId: 'getPost',
|
|
126
163
|
description: '',
|
|
127
|
-
tags: [],
|
|
164
|
+
tags: O.some([]),
|
|
128
165
|
parameters: O.some([
|
|
129
166
|
{
|
|
130
|
-
name: '
|
|
131
|
-
in: '
|
|
167
|
+
name: 'tags',
|
|
168
|
+
in: 'query',
|
|
132
169
|
required: true,
|
|
133
|
-
description: '
|
|
170
|
+
description: 'tags to filter by.',
|
|
134
171
|
schema: {
|
|
135
|
-
type: '
|
|
136
|
-
format: O.
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
requestBody: O.some({
|
|
141
|
-
content: {
|
|
142
|
-
'application/json': {
|
|
143
|
-
schema: {
|
|
144
|
-
type: 'object',
|
|
145
|
-
required: ['id', 'userId', 'title', 'body'],
|
|
146
|
-
properties: {
|
|
147
|
-
userId: {
|
|
148
|
-
type: 'integer',
|
|
149
|
-
},
|
|
150
|
-
title: {
|
|
151
|
-
type: 'string',
|
|
152
|
-
},
|
|
153
|
-
body: {
|
|
154
|
-
type: 'string',
|
|
155
|
-
},
|
|
156
|
-
},
|
|
172
|
+
type: 'array',
|
|
173
|
+
format: O.none,
|
|
174
|
+
items: O.some({
|
|
175
|
+
type: O.some('string'),
|
|
176
|
+
properties: O.none,
|
|
157
177
|
additionalProperties: O.some(false),
|
|
158
|
-
|
|
178
|
+
required: O.none,
|
|
179
|
+
allOf: O.none,
|
|
180
|
+
anyOf: O.none,
|
|
181
|
+
oneOf: O.none,
|
|
182
|
+
not: O.none,
|
|
183
|
+
in: O.none,
|
|
184
|
+
}),
|
|
159
185
|
},
|
|
186
|
+
additionalProperties: O.none,
|
|
160
187
|
},
|
|
161
|
-
|
|
162
|
-
|
|
188
|
+
]),
|
|
189
|
+
requestBody: O.none,
|
|
163
190
|
responses: O.none,
|
|
164
191
|
};
|
|
165
192
|
const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
|
|
@@ -168,71 +195,12 @@ describe('GenerateInputSchema', () => {
|
|
|
168
195
|
throw new Error('Should have been right');
|
|
169
196
|
})(inputTypes)();
|
|
170
197
|
const expectedInputFile = `export interface GetPostInput {
|
|
171
|
-
userId: number;
|
|
172
|
-
title: string;
|
|
173
|
-
body: string;
|
|
174
198
|
/**
|
|
175
|
-
* @description
|
|
199
|
+
* @description tags to filter by.
|
|
176
200
|
*/
|
|
177
|
-
|
|
201
|
+
tags: string[];
|
|
178
202
|
}
|
|
179
203
|
`;
|
|
180
204
|
expect(generatedInputFile).toEqual(expectedInputFile);
|
|
181
205
|
}));
|
|
182
|
-
it('it should process an endpoint with no parameters and generate empty input.ts file contents', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
183
|
-
const endpoint = {
|
|
184
|
-
operationId: 'getPosts',
|
|
185
|
-
description: '',
|
|
186
|
-
tags: [],
|
|
187
|
-
parameters: O.none,
|
|
188
|
-
requestBody: O.none,
|
|
189
|
-
responses: O.none,
|
|
190
|
-
};
|
|
191
|
-
const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
|
|
192
|
-
const inputTypes = (0, GenerateInputTypes_1.generateInputTypes)(endpoint.operationId, inputSchema);
|
|
193
|
-
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
194
|
-
throw new Error('Should have been right');
|
|
195
|
-
})(inputTypes)();
|
|
196
|
-
const expectedInputFile = `export interface GetPostsInput {}
|
|
197
|
-
`;
|
|
198
|
-
expect(generatedInputFile).toEqual(expectedInputFile);
|
|
199
|
-
}));
|
|
200
|
-
it('it should throw an exception when finding an unsupported media type', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
201
|
-
const endpoint = {
|
|
202
|
-
operationId: 'createPost',
|
|
203
|
-
description: '',
|
|
204
|
-
tags: [],
|
|
205
|
-
parameters: O.none,
|
|
206
|
-
requestBody: O.some({
|
|
207
|
-
content: {
|
|
208
|
-
'unsupported-media-type': {
|
|
209
|
-
schema: {
|
|
210
|
-
type: 'object',
|
|
211
|
-
required: ['id', 'userId', 'title', 'body'],
|
|
212
|
-
properties: {
|
|
213
|
-
id: {
|
|
214
|
-
type: 'integer',
|
|
215
|
-
},
|
|
216
|
-
userId: {
|
|
217
|
-
type: 'integer',
|
|
218
|
-
},
|
|
219
|
-
title: {
|
|
220
|
-
type: 'string',
|
|
221
|
-
},
|
|
222
|
-
body: {
|
|
223
|
-
type: 'string',
|
|
224
|
-
},
|
|
225
|
-
},
|
|
226
|
-
additionalProperties: O.some(false),
|
|
227
|
-
},
|
|
228
|
-
},
|
|
229
|
-
},
|
|
230
|
-
required: true,
|
|
231
|
-
}),
|
|
232
|
-
responses: O.none,
|
|
233
|
-
};
|
|
234
|
-
yield expect(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
235
|
-
(0, GenerateInputSchema_1.generateInputSchema)(endpoint);
|
|
236
|
-
})).rejects.toThrow('Unsupported media type: unsupported-media-type');
|
|
237
|
-
}));
|
|
238
206
|
});
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"GenerateInputType.test.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateInputType.test.ts"],"names":[],"mappings":""}
|
|
@@ -0,0 +1,400 @@
|
|
|
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 GenerateInputSchema_1 = require("./GenerateInputSchema");
|
|
38
|
+
const GenerateInputTypes_1 = require("./GenerateInputTypes");
|
|
39
|
+
describe('GenerateInputType', () => {
|
|
40
|
+
it('it should generate a schema from an endpoint with body parameters', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
41
|
+
const endpoint = {
|
|
42
|
+
operationId: 'createPost',
|
|
43
|
+
description: 'Create a new post',
|
|
44
|
+
tags: O.some([]),
|
|
45
|
+
parameters: O.none,
|
|
46
|
+
requestBody: O.some({
|
|
47
|
+
content: {
|
|
48
|
+
'application/json': {
|
|
49
|
+
schema: O.some({
|
|
50
|
+
type: O.some('object'),
|
|
51
|
+
required: O.some(['id', 'userId', 'title', 'body']),
|
|
52
|
+
properties: O.some({
|
|
53
|
+
id: {
|
|
54
|
+
type: O.some('integer'),
|
|
55
|
+
properties: O.none,
|
|
56
|
+
additionalProperties: O.some(false),
|
|
57
|
+
required: O.none,
|
|
58
|
+
allOf: O.none,
|
|
59
|
+
anyOf: O.none,
|
|
60
|
+
oneOf: O.none,
|
|
61
|
+
not: O.none,
|
|
62
|
+
in: O.none,
|
|
63
|
+
},
|
|
64
|
+
userId: {
|
|
65
|
+
type: O.some('integer'),
|
|
66
|
+
properties: O.none,
|
|
67
|
+
additionalProperties: O.some(false),
|
|
68
|
+
required: O.none,
|
|
69
|
+
allOf: O.none,
|
|
70
|
+
anyOf: O.none,
|
|
71
|
+
oneOf: O.none,
|
|
72
|
+
not: O.none,
|
|
73
|
+
in: O.none,
|
|
74
|
+
},
|
|
75
|
+
title: {
|
|
76
|
+
type: O.some('string'),
|
|
77
|
+
properties: O.none,
|
|
78
|
+
additionalProperties: O.some(false),
|
|
79
|
+
required: O.none,
|
|
80
|
+
allOf: O.none,
|
|
81
|
+
anyOf: O.none,
|
|
82
|
+
oneOf: O.none,
|
|
83
|
+
not: O.none,
|
|
84
|
+
in: O.none,
|
|
85
|
+
},
|
|
86
|
+
body: {
|
|
87
|
+
type: O.some('string'),
|
|
88
|
+
properties: O.none,
|
|
89
|
+
additionalProperties: O.some(false),
|
|
90
|
+
required: O.none,
|
|
91
|
+
allOf: O.none,
|
|
92
|
+
anyOf: O.none,
|
|
93
|
+
oneOf: O.none,
|
|
94
|
+
not: O.none,
|
|
95
|
+
in: O.none,
|
|
96
|
+
},
|
|
97
|
+
}),
|
|
98
|
+
additionalProperties: O.some(false),
|
|
99
|
+
allOf: O.none,
|
|
100
|
+
anyOf: O.none,
|
|
101
|
+
oneOf: O.none,
|
|
102
|
+
not: O.none,
|
|
103
|
+
in: O.none,
|
|
104
|
+
}),
|
|
105
|
+
},
|
|
106
|
+
},
|
|
107
|
+
}),
|
|
108
|
+
responses: O.none,
|
|
109
|
+
};
|
|
110
|
+
const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
|
|
111
|
+
const expectedInputSchema = {
|
|
112
|
+
type: O.some('object'),
|
|
113
|
+
required: O.some(['id', 'userId', 'title', 'body']),
|
|
114
|
+
properties: O.some({
|
|
115
|
+
id: {
|
|
116
|
+
type: O.some('integer'),
|
|
117
|
+
properties: O.none,
|
|
118
|
+
additionalProperties: O.some(false),
|
|
119
|
+
required: O.none,
|
|
120
|
+
allOf: O.none,
|
|
121
|
+
anyOf: O.none,
|
|
122
|
+
oneOf: O.none,
|
|
123
|
+
not: O.none,
|
|
124
|
+
in: O.some('body'),
|
|
125
|
+
},
|
|
126
|
+
userId: {
|
|
127
|
+
type: O.some('integer'),
|
|
128
|
+
properties: O.none,
|
|
129
|
+
additionalProperties: O.some(false),
|
|
130
|
+
required: O.none,
|
|
131
|
+
allOf: O.none,
|
|
132
|
+
anyOf: O.none,
|
|
133
|
+
oneOf: O.none,
|
|
134
|
+
not: O.none,
|
|
135
|
+
in: O.some('body'),
|
|
136
|
+
},
|
|
137
|
+
title: {
|
|
138
|
+
type: O.some('string'),
|
|
139
|
+
properties: O.none,
|
|
140
|
+
additionalProperties: O.some(false),
|
|
141
|
+
required: O.none,
|
|
142
|
+
allOf: O.none,
|
|
143
|
+
anyOf: O.none,
|
|
144
|
+
oneOf: O.none,
|
|
145
|
+
not: O.none,
|
|
146
|
+
in: O.some('body'),
|
|
147
|
+
},
|
|
148
|
+
body: {
|
|
149
|
+
type: O.some('string'),
|
|
150
|
+
properties: O.none,
|
|
151
|
+
additionalProperties: O.some(false),
|
|
152
|
+
required: O.none,
|
|
153
|
+
allOf: O.none,
|
|
154
|
+
anyOf: O.none,
|
|
155
|
+
oneOf: O.none,
|
|
156
|
+
not: O.none,
|
|
157
|
+
in: O.some('body'),
|
|
158
|
+
},
|
|
159
|
+
}),
|
|
160
|
+
additionalProperties: O.some(false),
|
|
161
|
+
allOf: O.none,
|
|
162
|
+
anyOf: O.none,
|
|
163
|
+
oneOf: O.none,
|
|
164
|
+
not: O.none,
|
|
165
|
+
in: O.none,
|
|
166
|
+
};
|
|
167
|
+
expect(inputSchema).toEqual(expectedInputSchema);
|
|
168
|
+
}));
|
|
169
|
+
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* () {
|
|
170
|
+
const endpoint = {
|
|
171
|
+
operationId: 'getPost',
|
|
172
|
+
description: '',
|
|
173
|
+
tags: O.some([]),
|
|
174
|
+
parameters: O.some([
|
|
175
|
+
{
|
|
176
|
+
name: 'id',
|
|
177
|
+
in: 'path',
|
|
178
|
+
required: true,
|
|
179
|
+
description: 'The user id.',
|
|
180
|
+
schema: {
|
|
181
|
+
type: 'integer',
|
|
182
|
+
format: O.some('int64'),
|
|
183
|
+
items: O.none,
|
|
184
|
+
},
|
|
185
|
+
},
|
|
186
|
+
{
|
|
187
|
+
name: 'categoryId',
|
|
188
|
+
in: 'path',
|
|
189
|
+
required: false,
|
|
190
|
+
description: 'The category id.',
|
|
191
|
+
schema: {
|
|
192
|
+
type: 'integer',
|
|
193
|
+
format: O.some('int64'),
|
|
194
|
+
items: O.none,
|
|
195
|
+
},
|
|
196
|
+
},
|
|
197
|
+
]),
|
|
198
|
+
requestBody: O.some({
|
|
199
|
+
content: {
|
|
200
|
+
'application/json': {
|
|
201
|
+
schema: O.some({
|
|
202
|
+
type: O.some('object'),
|
|
203
|
+
required: O.some(['userId', 'body']),
|
|
204
|
+
properties: O.some({
|
|
205
|
+
userId: {
|
|
206
|
+
type: O.some('integer'),
|
|
207
|
+
properties: O.none,
|
|
208
|
+
additionalProperties: O.some(false),
|
|
209
|
+
required: O.none,
|
|
210
|
+
allOf: O.none,
|
|
211
|
+
anyOf: O.none,
|
|
212
|
+
oneOf: O.none,
|
|
213
|
+
not: O.none,
|
|
214
|
+
in: O.none,
|
|
215
|
+
},
|
|
216
|
+
title: {
|
|
217
|
+
type: O.some('string'),
|
|
218
|
+
properties: O.none,
|
|
219
|
+
required: O.none,
|
|
220
|
+
additionalProperties: O.some(false),
|
|
221
|
+
allOf: O.none,
|
|
222
|
+
anyOf: O.none,
|
|
223
|
+
oneOf: O.none,
|
|
224
|
+
not: O.none,
|
|
225
|
+
in: O.none,
|
|
226
|
+
},
|
|
227
|
+
body: {
|
|
228
|
+
type: O.some('string'),
|
|
229
|
+
properties: O.none,
|
|
230
|
+
additionalProperties: O.some(false),
|
|
231
|
+
required: O.none,
|
|
232
|
+
allOf: O.none,
|
|
233
|
+
anyOf: O.none,
|
|
234
|
+
oneOf: O.none,
|
|
235
|
+
not: O.none,
|
|
236
|
+
in: O.none,
|
|
237
|
+
},
|
|
238
|
+
}),
|
|
239
|
+
additionalProperties: O.some(false),
|
|
240
|
+
allOf: O.none,
|
|
241
|
+
anyOf: O.none,
|
|
242
|
+
oneOf: O.none,
|
|
243
|
+
not: O.none,
|
|
244
|
+
in: O.none,
|
|
245
|
+
}),
|
|
246
|
+
},
|
|
247
|
+
},
|
|
248
|
+
}),
|
|
249
|
+
responses: O.none,
|
|
250
|
+
};
|
|
251
|
+
const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
|
|
252
|
+
const inputTypes = (0, GenerateInputTypes_1.generateInputTypes)(endpoint.operationId, inputSchema);
|
|
253
|
+
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
254
|
+
throw new Error('Should have been right');
|
|
255
|
+
})(inputTypes)();
|
|
256
|
+
const expectedInputFile = `export interface GetPostInput {
|
|
257
|
+
userId: number;
|
|
258
|
+
title?: string;
|
|
259
|
+
body: string;
|
|
260
|
+
/**
|
|
261
|
+
* @description The user id.
|
|
262
|
+
*/
|
|
263
|
+
id: number;
|
|
264
|
+
/**
|
|
265
|
+
* @description The category id.
|
|
266
|
+
*/
|
|
267
|
+
categoryId?: number;
|
|
268
|
+
}
|
|
269
|
+
`;
|
|
270
|
+
expect(generatedInputFile).toEqual(expectedInputFile);
|
|
271
|
+
}));
|
|
272
|
+
it('it should process an endpoint with no parameters and generate empty input.ts file contents', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
273
|
+
const endpoint = {
|
|
274
|
+
operationId: 'getPosts',
|
|
275
|
+
description: '',
|
|
276
|
+
tags: O.some([]),
|
|
277
|
+
parameters: O.none,
|
|
278
|
+
requestBody: O.none,
|
|
279
|
+
responses: O.none,
|
|
280
|
+
};
|
|
281
|
+
const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
|
|
282
|
+
const inputTypes = (0, GenerateInputTypes_1.generateInputTypes)(endpoint.operationId, inputSchema);
|
|
283
|
+
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
284
|
+
throw new Error('Should have been right');
|
|
285
|
+
})(inputTypes)();
|
|
286
|
+
const expectedInputFile = `export interface GetPostsInput {}
|
|
287
|
+
`;
|
|
288
|
+
expect(generatedInputFile).toEqual(expectedInputFile);
|
|
289
|
+
}));
|
|
290
|
+
it('it should process an endpoint with a body schema with no parameters and additionalProperties: true and generate k: string: unknown input.ts file contents', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
291
|
+
const endpoint = {
|
|
292
|
+
operationId: 'getPosts',
|
|
293
|
+
description: '',
|
|
294
|
+
tags: O.some([]),
|
|
295
|
+
parameters: O.none,
|
|
296
|
+
requestBody: O.some({
|
|
297
|
+
content: {
|
|
298
|
+
'application/json': {
|
|
299
|
+
schema: O.some({
|
|
300
|
+
type: O.some('object'),
|
|
301
|
+
required: O.none,
|
|
302
|
+
properties: O.none,
|
|
303
|
+
additionalProperties: O.some(true),
|
|
304
|
+
allOf: O.none,
|
|
305
|
+
anyOf: O.none,
|
|
306
|
+
oneOf: O.none,
|
|
307
|
+
not: O.none,
|
|
308
|
+
in: O.none,
|
|
309
|
+
}),
|
|
310
|
+
},
|
|
311
|
+
},
|
|
312
|
+
}),
|
|
313
|
+
responses: O.none,
|
|
314
|
+
};
|
|
315
|
+
const inputSchema = (0, GenerateInputSchema_1.generateInputSchema)(endpoint);
|
|
316
|
+
const inputTypes = (0, GenerateInputTypes_1.generateInputTypes)(endpoint.operationId, inputSchema);
|
|
317
|
+
const generatedInputFile = yield TE.getOrElse((error) => {
|
|
318
|
+
throw new Error('Should have been right');
|
|
319
|
+
})(inputTypes)();
|
|
320
|
+
const expectedInputFile = `export interface GetPostsInput {
|
|
321
|
+
[k: string]: unknown;
|
|
322
|
+
}
|
|
323
|
+
`;
|
|
324
|
+
expect(generatedInputFile).toEqual(expectedInputFile);
|
|
325
|
+
}));
|
|
326
|
+
it('it should throw an exception when finding an unsupported media type', () => __awaiter(void 0, void 0, void 0, function* () {
|
|
327
|
+
const endpoint = {
|
|
328
|
+
operationId: 'createPost',
|
|
329
|
+
description: '',
|
|
330
|
+
tags: O.some([]),
|
|
331
|
+
parameters: O.none,
|
|
332
|
+
requestBody: O.some({
|
|
333
|
+
content: {
|
|
334
|
+
'unsupported-media-type': {
|
|
335
|
+
schema: O.some({
|
|
336
|
+
type: O.some('object'),
|
|
337
|
+
required: O.some(['id', 'userId', 'title', 'body']),
|
|
338
|
+
properties: O.some({
|
|
339
|
+
id: {
|
|
340
|
+
type: O.some('integer'),
|
|
341
|
+
properties: O.none,
|
|
342
|
+
required: O.none,
|
|
343
|
+
additionalProperties: O.some(false),
|
|
344
|
+
allOf: O.none,
|
|
345
|
+
anyOf: O.none,
|
|
346
|
+
oneOf: O.none,
|
|
347
|
+
not: O.none,
|
|
348
|
+
in: O.none,
|
|
349
|
+
},
|
|
350
|
+
userId: {
|
|
351
|
+
type: O.some('integer'),
|
|
352
|
+
properties: O.none,
|
|
353
|
+
required: O.none,
|
|
354
|
+
additionalProperties: O.some(false),
|
|
355
|
+
allOf: O.none,
|
|
356
|
+
anyOf: O.none,
|
|
357
|
+
oneOf: O.none,
|
|
358
|
+
not: O.none,
|
|
359
|
+
in: O.none,
|
|
360
|
+
},
|
|
361
|
+
title: {
|
|
362
|
+
type: O.some('string'),
|
|
363
|
+
properties: O.none,
|
|
364
|
+
required: O.none,
|
|
365
|
+
additionalProperties: O.some(false),
|
|
366
|
+
allOf: O.none,
|
|
367
|
+
anyOf: O.none,
|
|
368
|
+
oneOf: O.none,
|
|
369
|
+
not: O.none,
|
|
370
|
+
in: O.none,
|
|
371
|
+
},
|
|
372
|
+
body: {
|
|
373
|
+
type: O.some('string'),
|
|
374
|
+
properties: O.none,
|
|
375
|
+
required: O.none,
|
|
376
|
+
additionalProperties: O.some(false),
|
|
377
|
+
allOf: O.none,
|
|
378
|
+
anyOf: O.none,
|
|
379
|
+
oneOf: O.none,
|
|
380
|
+
not: O.none,
|
|
381
|
+
in: O.none,
|
|
382
|
+
},
|
|
383
|
+
}),
|
|
384
|
+
additionalProperties: O.some(false),
|
|
385
|
+
allOf: O.none,
|
|
386
|
+
anyOf: O.none,
|
|
387
|
+
oneOf: O.none,
|
|
388
|
+
not: O.none,
|
|
389
|
+
in: O.none,
|
|
390
|
+
}),
|
|
391
|
+
},
|
|
392
|
+
},
|
|
393
|
+
}),
|
|
394
|
+
responses: O.none,
|
|
395
|
+
};
|
|
396
|
+
yield expect(() => __awaiter(void 0, void 0, void 0, function* () {
|
|
397
|
+
(0, GenerateInputSchema_1.generateInputSchema)(endpoint);
|
|
398
|
+
})).rejects.toThrow('Unsupported media type: unsupported-media-type');
|
|
399
|
+
}));
|
|
400
|
+
});
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { JSONSchema4 } from 'json-schema';
|
|
2
1
|
import * as TE from 'fp-ts/TaskEither';
|
|
3
|
-
|
|
2
|
+
import { SchemaObject } from '../../OpenApiTypeDescriptors';
|
|
3
|
+
export declare const generateInputTypes: (operationNameCamelCase: string, parameters: SchemaObject) => TE.TaskEither<Error, string>;
|
|
4
4
|
//# sourceMappingURL=GenerateInputTypes.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"GenerateInputTypes.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateInputTypes.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"GenerateInputTypes.d.ts","sourceRoot":"","sources":["../../../src/file-generators/types/GenerateInputTypes.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,MAAM,kBAAkB,CAAC;AAIvC,OAAO,EACN,YAAY,EAEZ,MAAM,8BAA8B,CAAC;AAWtC,eAAO,MAAM,kBAAkB,2BACN,MAAM,cAClB,YAAY,KACtB,GAAG,UAAU,CAAC,KAAK,EAAE,MAAM,CAY7B,CAAC"}
|