@trapi/swagger 1.0.0-alpha.11 → 1.0.0-alpha.12
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/config/index.d.ts +2 -2
- package/dist/config/index.js +24 -24
- package/dist/config/type.d.ts +82 -82
- package/dist/config/type.js +8 -8
- package/dist/config/utils.d.ts +2 -2
- package/dist/config/utils.js +53 -53
- package/dist/constants.d.ts +14 -14
- package/dist/constants.js +26 -26
- package/dist/generator/abstract.d.ts +34 -34
- package/dist/generator/abstract.js +251 -251
- package/dist/generator/index.d.ts +4 -4
- package/dist/generator/index.js +26 -26
- package/dist/generator/module.d.ts +13 -13
- package/dist/generator/module.js +34 -34
- package/dist/generator/v2/index.d.ts +1 -1
- package/dist/generator/v2/index.js +23 -23
- package/dist/generator/v2/module.d.ts +24 -24
- package/dist/generator/v2/module.js +516 -516
- package/dist/generator/v3/index.d.ts +1 -1
- package/dist/generator/v3/index.js +23 -23
- package/dist/generator/v3/module.d.ts +29 -29
- package/dist/generator/v3/module.js +498 -498
- package/dist/index.d.ts +7 -7
- package/dist/index.js +29 -29
- package/dist/metadata.d.ts +3 -3
- package/dist/metadata.js +13 -13
- package/dist/schema/constants.d.ts +27 -27
- package/dist/schema/constants.js +39 -39
- package/dist/schema/index.d.ts +4 -4
- package/dist/schema/index.js +26 -26
- package/dist/schema/type.d.ts +138 -138
- package/dist/schema/type.js +8 -8
- package/dist/schema/v2/constants.d.ts +7 -7
- package/dist/schema/v2/constants.js +17 -17
- package/dist/schema/v2/index.d.ts +2 -2
- package/dist/schema/v2/index.js +24 -24
- package/dist/schema/v2/type.d.ts +115 -115
- package/dist/schema/v2/type.js +8 -8
- package/dist/schema/v3/constants.d.ts +6 -6
- package/dist/schema/v3/constants.js +16 -16
- package/dist/schema/v3/index.d.ts +2 -2
- package/dist/schema/v3/index.js +24 -24
- package/dist/schema/v3/type.d.ts +158 -158
- package/dist/schema/v3/type.js +8 -8
- package/dist/type.d.ts +48 -48
- package/dist/type.js +8 -8
- package/dist/utils/character.d.ts +2 -2
- package/dist/utils/character.js +20 -20
- package/dist/utils/index.d.ts +4 -4
- package/dist/utils/index.js +26 -26
- package/dist/utils/object.d.ts +1 -1
- package/dist/utils/object.js +14 -14
- package/dist/utils/path.d.ts +1 -1
- package/dist/utils/path.js +20 -20
- package/dist/utils/value.d.ts +1 -1
- package/dist/utils/value.js +25 -25
- package/package.json +4 -4
|
@@ -1,252 +1,252 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2021-2023.
|
|
4
|
-
* Author Peter Placzek (tada5hi)
|
|
5
|
-
* For the full copyright and license information,
|
|
6
|
-
* view the LICENSE file that was distributed with this source code.
|
|
7
|
-
*/
|
|
8
|
-
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
-
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
-
};
|
|
11
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
-
exports.AbstractSpecGenerator = void 0;
|
|
13
|
-
const metadata_1 = require("@trapi/metadata");
|
|
14
|
-
const node_path_1 = __importDefault(require("node:path"));
|
|
15
|
-
const node_fs_1 = __importDefault(require("node:fs"));
|
|
16
|
-
const smob_1 = require("smob");
|
|
17
|
-
const yamljs_1 = __importDefault(require("yamljs"));
|
|
18
|
-
const config_1 = require("../config");
|
|
19
|
-
const schema_1 = require("../schema");
|
|
20
|
-
class AbstractSpecGenerator {
|
|
21
|
-
constructor(metadata, config) {
|
|
22
|
-
this.metadata = metadata;
|
|
23
|
-
this.config = (0, config_1.buildOptions)(config);
|
|
24
|
-
}
|
|
25
|
-
async save() {
|
|
26
|
-
if (!this.config.output) {
|
|
27
|
-
return;
|
|
28
|
-
}
|
|
29
|
-
if (typeof this.spec === 'undefined') {
|
|
30
|
-
throw new Error('The spec has not been build yet...');
|
|
31
|
-
}
|
|
32
|
-
try {
|
|
33
|
-
await node_fs_1.default.promises.access(this.config.outputDirectory, node_fs_1.default.constants.R_OK | node_fs_1.default.constants.O_DIRECTORY);
|
|
34
|
-
}
|
|
35
|
-
catch (e) {
|
|
36
|
-
await node_fs_1.default.promises.mkdir(this.config.outputDirectory, { recursive: true });
|
|
37
|
-
}
|
|
38
|
-
const data = [
|
|
39
|
-
{
|
|
40
|
-
path: node_path_1.default.join(this.config.outputDirectory, `${this.config.outputFileName}.json`),
|
|
41
|
-
name: `${this.config.outputFileName}.json`,
|
|
42
|
-
content: JSON.stringify(this.spec, null, 4),
|
|
43
|
-
},
|
|
44
|
-
];
|
|
45
|
-
if (this.config.yaml) {
|
|
46
|
-
data.push({
|
|
47
|
-
path: node_path_1.default.join(this.config.outputDirectory, `${this.config.outputFileName}.yaml`),
|
|
48
|
-
name: `${this.config.outputFileName}.yaml`,
|
|
49
|
-
content: yamljs_1.default.stringify(this.spec, 1000),
|
|
50
|
-
});
|
|
51
|
-
}
|
|
52
|
-
const promises = [];
|
|
53
|
-
for (let i = 0; i < data.length; i++) {
|
|
54
|
-
promises.push(node_fs_1.default.promises.writeFile(data[i].path, data[i].content, { encoding: 'utf-8' }));
|
|
55
|
-
}
|
|
56
|
-
await Promise.all(promises);
|
|
57
|
-
}
|
|
58
|
-
buildInfo() {
|
|
59
|
-
const info = {
|
|
60
|
-
title: this.config.name || 'Documentation',
|
|
61
|
-
version: this.config.version || '1.0.0',
|
|
62
|
-
};
|
|
63
|
-
if (this.config.description) {
|
|
64
|
-
info.description = this.config.description;
|
|
65
|
-
}
|
|
66
|
-
if (this.config.license) {
|
|
67
|
-
info.license = { name: this.config.license };
|
|
68
|
-
}
|
|
69
|
-
return info;
|
|
70
|
-
}
|
|
71
|
-
getSchemaForType(type) {
|
|
72
|
-
if ((0, metadata_1.isVoidType)(type) || (0, metadata_1.isUndefinedType)(type)) {
|
|
73
|
-
return {};
|
|
74
|
-
}
|
|
75
|
-
if ((0, metadata_1.isReferenceType)(type)) {
|
|
76
|
-
return this.getSchemaForReferenceType(type);
|
|
77
|
-
}
|
|
78
|
-
if ((0, metadata_1.isPrimitiveType)(type)) {
|
|
79
|
-
return this.getSchemaForPrimitiveType(type);
|
|
80
|
-
}
|
|
81
|
-
if ((0, metadata_1.isArrayType)(type)) {
|
|
82
|
-
return this.getSchemaForArrayType(type);
|
|
83
|
-
}
|
|
84
|
-
if ((0, metadata_1.isEnumType)(type)) {
|
|
85
|
-
return this.getSchemaForEnumType(type);
|
|
86
|
-
}
|
|
87
|
-
if ((0, metadata_1.isUnionType)(type)) {
|
|
88
|
-
return this.getSchemaForUnionType(type);
|
|
89
|
-
}
|
|
90
|
-
if ((0, metadata_1.isIntersectionType)(type)) {
|
|
91
|
-
return this.getSchemaForIntersectionType(type);
|
|
92
|
-
}
|
|
93
|
-
if ((0, metadata_1.isNestedObjectLiteralType)(type)) {
|
|
94
|
-
return this.getSchemaForObjectLiteralType(type);
|
|
95
|
-
}
|
|
96
|
-
return {};
|
|
97
|
-
}
|
|
98
|
-
getSchemaForPrimitiveType(type) {
|
|
99
|
-
const PrimitiveSwaggerTypeMap = {
|
|
100
|
-
any: {
|
|
101
|
-
additionalProperties: true,
|
|
102
|
-
},
|
|
103
|
-
binary: { type: schema_1.DataTypeName.STRING, format: schema_1.DataFormatName.BINARY },
|
|
104
|
-
boolean: { type: schema_1.DataTypeName.BOOLEAN },
|
|
105
|
-
buffer: { type: schema_1.DataTypeName.STRING, format: schema_1.DataFormatName.BYTE },
|
|
106
|
-
byte: { type: schema_1.DataTypeName.STRING, format: schema_1.DataFormatName.BYTE },
|
|
107
|
-
date: { type: schema_1.DataTypeName.STRING, format: schema_1.DataFormatName.DATE },
|
|
108
|
-
datetime: { type: schema_1.DataTypeName.STRING, format: schema_1.DataFormatName.DATE_TIME },
|
|
109
|
-
double: { type: schema_1.DataTypeName.NUMBER, format: schema_1.DataFormatName.DOUBLE },
|
|
110
|
-
file: { type: schema_1.DataTypeName.STRING, format: schema_1.DataFormatName.BINARY },
|
|
111
|
-
float: { type: schema_1.DataTypeName.NUMBER, format: schema_1.DataFormatName.FLOAT },
|
|
112
|
-
integer: { type: schema_1.DataTypeName.INTEGER, format: schema_1.DataFormatName.INT_32 },
|
|
113
|
-
long: { type: schema_1.DataTypeName.INTEGER, format: schema_1.DataFormatName.INT_64 },
|
|
114
|
-
object: {
|
|
115
|
-
type: schema_1.DataTypeName.OBJECT,
|
|
116
|
-
additionalProperties: true,
|
|
117
|
-
},
|
|
118
|
-
string: { type: schema_1.DataTypeName.STRING },
|
|
119
|
-
};
|
|
120
|
-
return PrimitiveSwaggerTypeMap[type.typeName] || { type: schema_1.DataTypeName.OBJECT };
|
|
121
|
-
}
|
|
122
|
-
getSchemaForArrayType(arrayType) {
|
|
123
|
-
return {
|
|
124
|
-
type: schema_1.DataTypeName.ARRAY,
|
|
125
|
-
items: this.getSchemaForType(arrayType.elementType),
|
|
126
|
-
};
|
|
127
|
-
}
|
|
128
|
-
getSchemaForObjectLiteralType(objectLiteral) {
|
|
129
|
-
const properties = this.buildProperties(objectLiteral.properties);
|
|
130
|
-
const additionalProperties = objectLiteral.additionalProperties &&
|
|
131
|
-
this.getSchemaForType(objectLiteral.additionalProperties);
|
|
132
|
-
const required = objectLiteral.properties
|
|
133
|
-
.filter((prop) => prop.required && !this.isUndefinedProperty(prop))
|
|
134
|
-
.map((prop) => prop.name);
|
|
135
|
-
// An empty list required: [] is not valid.
|
|
136
|
-
// If all properties are optional, do not specify the required keyword.
|
|
137
|
-
return {
|
|
138
|
-
properties,
|
|
139
|
-
...(additionalProperties && { additionalProperties }),
|
|
140
|
-
...(required && required.length && { required }),
|
|
141
|
-
type: schema_1.DataTypeName.OBJECT,
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
buildSchemasForReferenceTypes(extendFn) {
|
|
145
|
-
const output = {};
|
|
146
|
-
const keys = Object.keys(this.metadata.referenceTypes);
|
|
147
|
-
for (let i = 0; i < keys.length; i++) {
|
|
148
|
-
const referenceType = this.metadata.referenceTypes[keys[i]];
|
|
149
|
-
switch (referenceType.typeName) {
|
|
150
|
-
case metadata_1.TypeName.REF_ALIAS: {
|
|
151
|
-
output[referenceType.refName] = this.buildSchemaForRefAlias(referenceType);
|
|
152
|
-
break;
|
|
153
|
-
}
|
|
154
|
-
case metadata_1.TypeName.REF_ENUM: {
|
|
155
|
-
output[referenceType.refName] = this.buildSchemaForRefEnum(referenceType);
|
|
156
|
-
break;
|
|
157
|
-
}
|
|
158
|
-
case metadata_1.TypeName.REF_OBJECT: {
|
|
159
|
-
output[referenceType.refName] = this.buildSchemaForRefObject(referenceType);
|
|
160
|
-
break;
|
|
161
|
-
}
|
|
162
|
-
}
|
|
163
|
-
if (typeof extendFn === 'function') {
|
|
164
|
-
extendFn(output[referenceType.refName], referenceType);
|
|
165
|
-
}
|
|
166
|
-
}
|
|
167
|
-
return output;
|
|
168
|
-
}
|
|
169
|
-
// ----------------------------------------------------------------
|
|
170
|
-
isUndefinedProperty(input) {
|
|
171
|
-
return (0, metadata_1.isUndefinedType)(input.type) ||
|
|
172
|
-
((0, metadata_1.isUnionType)(input.type) && input.type.members.some((el) => (0, metadata_1.isUndefinedType)(el)));
|
|
173
|
-
}
|
|
174
|
-
determineTypesUsedInEnum(anEnum) {
|
|
175
|
-
const set = new Set();
|
|
176
|
-
for (let i = 0; i < anEnum.length; i++) {
|
|
177
|
-
if (anEnum[i] === null) {
|
|
178
|
-
continue;
|
|
179
|
-
}
|
|
180
|
-
set.add(typeof anEnum[i]);
|
|
181
|
-
}
|
|
182
|
-
return Array.from(set);
|
|
183
|
-
}
|
|
184
|
-
decideEnumType(input) {
|
|
185
|
-
const types = this.determineTypesUsedInEnum(input);
|
|
186
|
-
if (types.length === 1) {
|
|
187
|
-
const value = types[0];
|
|
188
|
-
if (value === 'string' ||
|
|
189
|
-
value === 'number' ||
|
|
190
|
-
value === 'boolean') {
|
|
191
|
-
return value;
|
|
192
|
-
}
|
|
193
|
-
throw new Error(`Enums can only have string or number values, but type "${types[0] || 'unknown'}" given.`);
|
|
194
|
-
}
|
|
195
|
-
for (let i = 0; i < types.length; i++) {
|
|
196
|
-
const type = types[i];
|
|
197
|
-
if (type !== 'string' &&
|
|
198
|
-
type !== 'number' &&
|
|
199
|
-
type !== 'boolean') {
|
|
200
|
-
const values = types.join(',');
|
|
201
|
-
throw new Error(`Enums can only have string or number values, but types ${values} given.`);
|
|
202
|
-
}
|
|
203
|
-
}
|
|
204
|
-
return 'string';
|
|
205
|
-
}
|
|
206
|
-
getOperationId(name) {
|
|
207
|
-
return name.charAt(0).toUpperCase() + name.substring(1);
|
|
208
|
-
}
|
|
209
|
-
groupParameters(items) {
|
|
210
|
-
const output = {};
|
|
211
|
-
for (let i = 0; i < items.length; i++) {
|
|
212
|
-
if (typeof output[items[i].in] === 'undefined') {
|
|
213
|
-
output[items[i].in] = [];
|
|
214
|
-
}
|
|
215
|
-
output[items[i].in].push(items[i]);
|
|
216
|
-
}
|
|
217
|
-
return output;
|
|
218
|
-
}
|
|
219
|
-
transformExtensions(input) {
|
|
220
|
-
if (!input) {
|
|
221
|
-
return {};
|
|
222
|
-
}
|
|
223
|
-
const output = {};
|
|
224
|
-
for (let i = 0; i < input.length; i++) {
|
|
225
|
-
const extension = input[i];
|
|
226
|
-
if (!extension.key.startsWith('x-')) {
|
|
227
|
-
extension.key = `x-${extension.key}`;
|
|
228
|
-
}
|
|
229
|
-
output[extension.key] = extension.value;
|
|
230
|
-
}
|
|
231
|
-
return output;
|
|
232
|
-
}
|
|
233
|
-
transformValidators(input) {
|
|
234
|
-
if (!(0, smob_1.isObject)(input)) {
|
|
235
|
-
return {};
|
|
236
|
-
}
|
|
237
|
-
const keys = Object.keys(input);
|
|
238
|
-
const output = {};
|
|
239
|
-
for (let i = 0; i < keys.length; i++) {
|
|
240
|
-
const key = keys[i];
|
|
241
|
-
if (key.startsWith('is') ||
|
|
242
|
-
key === metadata_1.ValidatorName.MIN_DATE ||
|
|
243
|
-
key === metadata_1.ValidatorName.MAX_DATE) {
|
|
244
|
-
continue;
|
|
245
|
-
}
|
|
246
|
-
output[key] = input[key].value;
|
|
247
|
-
}
|
|
248
|
-
return output;
|
|
249
|
-
}
|
|
250
|
-
}
|
|
251
|
-
exports.AbstractSpecGenerator = AbstractSpecGenerator;
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2021-2023.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
var __importDefault = (this && this.__importDefault) || function (mod) {
|
|
9
|
+
return (mod && mod.__esModule) ? mod : { "default": mod };
|
|
10
|
+
};
|
|
11
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
12
|
+
exports.AbstractSpecGenerator = void 0;
|
|
13
|
+
const metadata_1 = require("@trapi/metadata");
|
|
14
|
+
const node_path_1 = __importDefault(require("node:path"));
|
|
15
|
+
const node_fs_1 = __importDefault(require("node:fs"));
|
|
16
|
+
const smob_1 = require("smob");
|
|
17
|
+
const yamljs_1 = __importDefault(require("yamljs"));
|
|
18
|
+
const config_1 = require("../config");
|
|
19
|
+
const schema_1 = require("../schema");
|
|
20
|
+
class AbstractSpecGenerator {
|
|
21
|
+
constructor(metadata, config) {
|
|
22
|
+
this.metadata = metadata;
|
|
23
|
+
this.config = (0, config_1.buildOptions)(config);
|
|
24
|
+
}
|
|
25
|
+
async save() {
|
|
26
|
+
if (!this.config.output) {
|
|
27
|
+
return;
|
|
28
|
+
}
|
|
29
|
+
if (typeof this.spec === 'undefined') {
|
|
30
|
+
throw new Error('The spec has not been build yet...');
|
|
31
|
+
}
|
|
32
|
+
try {
|
|
33
|
+
await node_fs_1.default.promises.access(this.config.outputDirectory, node_fs_1.default.constants.R_OK | node_fs_1.default.constants.O_DIRECTORY);
|
|
34
|
+
}
|
|
35
|
+
catch (e) {
|
|
36
|
+
await node_fs_1.default.promises.mkdir(this.config.outputDirectory, { recursive: true });
|
|
37
|
+
}
|
|
38
|
+
const data = [
|
|
39
|
+
{
|
|
40
|
+
path: node_path_1.default.join(this.config.outputDirectory, `${this.config.outputFileName}.json`),
|
|
41
|
+
name: `${this.config.outputFileName}.json`,
|
|
42
|
+
content: JSON.stringify(this.spec, null, 4),
|
|
43
|
+
},
|
|
44
|
+
];
|
|
45
|
+
if (this.config.yaml) {
|
|
46
|
+
data.push({
|
|
47
|
+
path: node_path_1.default.join(this.config.outputDirectory, `${this.config.outputFileName}.yaml`),
|
|
48
|
+
name: `${this.config.outputFileName}.yaml`,
|
|
49
|
+
content: yamljs_1.default.stringify(this.spec, 1000),
|
|
50
|
+
});
|
|
51
|
+
}
|
|
52
|
+
const promises = [];
|
|
53
|
+
for (let i = 0; i < data.length; i++) {
|
|
54
|
+
promises.push(node_fs_1.default.promises.writeFile(data[i].path, data[i].content, { encoding: 'utf-8' }));
|
|
55
|
+
}
|
|
56
|
+
await Promise.all(promises);
|
|
57
|
+
}
|
|
58
|
+
buildInfo() {
|
|
59
|
+
const info = {
|
|
60
|
+
title: this.config.name || 'Documentation',
|
|
61
|
+
version: this.config.version || '1.0.0',
|
|
62
|
+
};
|
|
63
|
+
if (this.config.description) {
|
|
64
|
+
info.description = this.config.description;
|
|
65
|
+
}
|
|
66
|
+
if (this.config.license) {
|
|
67
|
+
info.license = { name: this.config.license };
|
|
68
|
+
}
|
|
69
|
+
return info;
|
|
70
|
+
}
|
|
71
|
+
getSchemaForType(type) {
|
|
72
|
+
if ((0, metadata_1.isVoidType)(type) || (0, metadata_1.isUndefinedType)(type)) {
|
|
73
|
+
return {};
|
|
74
|
+
}
|
|
75
|
+
if ((0, metadata_1.isReferenceType)(type)) {
|
|
76
|
+
return this.getSchemaForReferenceType(type);
|
|
77
|
+
}
|
|
78
|
+
if ((0, metadata_1.isPrimitiveType)(type)) {
|
|
79
|
+
return this.getSchemaForPrimitiveType(type);
|
|
80
|
+
}
|
|
81
|
+
if ((0, metadata_1.isArrayType)(type)) {
|
|
82
|
+
return this.getSchemaForArrayType(type);
|
|
83
|
+
}
|
|
84
|
+
if ((0, metadata_1.isEnumType)(type)) {
|
|
85
|
+
return this.getSchemaForEnumType(type);
|
|
86
|
+
}
|
|
87
|
+
if ((0, metadata_1.isUnionType)(type)) {
|
|
88
|
+
return this.getSchemaForUnionType(type);
|
|
89
|
+
}
|
|
90
|
+
if ((0, metadata_1.isIntersectionType)(type)) {
|
|
91
|
+
return this.getSchemaForIntersectionType(type);
|
|
92
|
+
}
|
|
93
|
+
if ((0, metadata_1.isNestedObjectLiteralType)(type)) {
|
|
94
|
+
return this.getSchemaForObjectLiteralType(type);
|
|
95
|
+
}
|
|
96
|
+
return {};
|
|
97
|
+
}
|
|
98
|
+
getSchemaForPrimitiveType(type) {
|
|
99
|
+
const PrimitiveSwaggerTypeMap = {
|
|
100
|
+
any: {
|
|
101
|
+
additionalProperties: true,
|
|
102
|
+
},
|
|
103
|
+
binary: { type: schema_1.DataTypeName.STRING, format: schema_1.DataFormatName.BINARY },
|
|
104
|
+
boolean: { type: schema_1.DataTypeName.BOOLEAN },
|
|
105
|
+
buffer: { type: schema_1.DataTypeName.STRING, format: schema_1.DataFormatName.BYTE },
|
|
106
|
+
byte: { type: schema_1.DataTypeName.STRING, format: schema_1.DataFormatName.BYTE },
|
|
107
|
+
date: { type: schema_1.DataTypeName.STRING, format: schema_1.DataFormatName.DATE },
|
|
108
|
+
datetime: { type: schema_1.DataTypeName.STRING, format: schema_1.DataFormatName.DATE_TIME },
|
|
109
|
+
double: { type: schema_1.DataTypeName.NUMBER, format: schema_1.DataFormatName.DOUBLE },
|
|
110
|
+
file: { type: schema_1.DataTypeName.STRING, format: schema_1.DataFormatName.BINARY },
|
|
111
|
+
float: { type: schema_1.DataTypeName.NUMBER, format: schema_1.DataFormatName.FLOAT },
|
|
112
|
+
integer: { type: schema_1.DataTypeName.INTEGER, format: schema_1.DataFormatName.INT_32 },
|
|
113
|
+
long: { type: schema_1.DataTypeName.INTEGER, format: schema_1.DataFormatName.INT_64 },
|
|
114
|
+
object: {
|
|
115
|
+
type: schema_1.DataTypeName.OBJECT,
|
|
116
|
+
additionalProperties: true,
|
|
117
|
+
},
|
|
118
|
+
string: { type: schema_1.DataTypeName.STRING },
|
|
119
|
+
};
|
|
120
|
+
return PrimitiveSwaggerTypeMap[type.typeName] || { type: schema_1.DataTypeName.OBJECT };
|
|
121
|
+
}
|
|
122
|
+
getSchemaForArrayType(arrayType) {
|
|
123
|
+
return {
|
|
124
|
+
type: schema_1.DataTypeName.ARRAY,
|
|
125
|
+
items: this.getSchemaForType(arrayType.elementType),
|
|
126
|
+
};
|
|
127
|
+
}
|
|
128
|
+
getSchemaForObjectLiteralType(objectLiteral) {
|
|
129
|
+
const properties = this.buildProperties(objectLiteral.properties);
|
|
130
|
+
const additionalProperties = objectLiteral.additionalProperties &&
|
|
131
|
+
this.getSchemaForType(objectLiteral.additionalProperties);
|
|
132
|
+
const required = objectLiteral.properties
|
|
133
|
+
.filter((prop) => prop.required && !this.isUndefinedProperty(prop))
|
|
134
|
+
.map((prop) => prop.name);
|
|
135
|
+
// An empty list required: [] is not valid.
|
|
136
|
+
// If all properties are optional, do not specify the required keyword.
|
|
137
|
+
return {
|
|
138
|
+
properties,
|
|
139
|
+
...(additionalProperties && { additionalProperties }),
|
|
140
|
+
...(required && required.length && { required }),
|
|
141
|
+
type: schema_1.DataTypeName.OBJECT,
|
|
142
|
+
};
|
|
143
|
+
}
|
|
144
|
+
buildSchemasForReferenceTypes(extendFn) {
|
|
145
|
+
const output = {};
|
|
146
|
+
const keys = Object.keys(this.metadata.referenceTypes);
|
|
147
|
+
for (let i = 0; i < keys.length; i++) {
|
|
148
|
+
const referenceType = this.metadata.referenceTypes[keys[i]];
|
|
149
|
+
switch (referenceType.typeName) {
|
|
150
|
+
case metadata_1.TypeName.REF_ALIAS: {
|
|
151
|
+
output[referenceType.refName] = this.buildSchemaForRefAlias(referenceType);
|
|
152
|
+
break;
|
|
153
|
+
}
|
|
154
|
+
case metadata_1.TypeName.REF_ENUM: {
|
|
155
|
+
output[referenceType.refName] = this.buildSchemaForRefEnum(referenceType);
|
|
156
|
+
break;
|
|
157
|
+
}
|
|
158
|
+
case metadata_1.TypeName.REF_OBJECT: {
|
|
159
|
+
output[referenceType.refName] = this.buildSchemaForRefObject(referenceType);
|
|
160
|
+
break;
|
|
161
|
+
}
|
|
162
|
+
}
|
|
163
|
+
if (typeof extendFn === 'function') {
|
|
164
|
+
extendFn(output[referenceType.refName], referenceType);
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
return output;
|
|
168
|
+
}
|
|
169
|
+
// ----------------------------------------------------------------
|
|
170
|
+
isUndefinedProperty(input) {
|
|
171
|
+
return (0, metadata_1.isUndefinedType)(input.type) ||
|
|
172
|
+
((0, metadata_1.isUnionType)(input.type) && input.type.members.some((el) => (0, metadata_1.isUndefinedType)(el)));
|
|
173
|
+
}
|
|
174
|
+
determineTypesUsedInEnum(anEnum) {
|
|
175
|
+
const set = new Set();
|
|
176
|
+
for (let i = 0; i < anEnum.length; i++) {
|
|
177
|
+
if (anEnum[i] === null) {
|
|
178
|
+
continue;
|
|
179
|
+
}
|
|
180
|
+
set.add(typeof anEnum[i]);
|
|
181
|
+
}
|
|
182
|
+
return Array.from(set);
|
|
183
|
+
}
|
|
184
|
+
decideEnumType(input) {
|
|
185
|
+
const types = this.determineTypesUsedInEnum(input);
|
|
186
|
+
if (types.length === 1) {
|
|
187
|
+
const value = types[0];
|
|
188
|
+
if (value === 'string' ||
|
|
189
|
+
value === 'number' ||
|
|
190
|
+
value === 'boolean') {
|
|
191
|
+
return value;
|
|
192
|
+
}
|
|
193
|
+
throw new Error(`Enums can only have string or number values, but type "${types[0] || 'unknown'}" given.`);
|
|
194
|
+
}
|
|
195
|
+
for (let i = 0; i < types.length; i++) {
|
|
196
|
+
const type = types[i];
|
|
197
|
+
if (type !== 'string' &&
|
|
198
|
+
type !== 'number' &&
|
|
199
|
+
type !== 'boolean') {
|
|
200
|
+
const values = types.join(',');
|
|
201
|
+
throw new Error(`Enums can only have string or number values, but types ${values} given.`);
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
return 'string';
|
|
205
|
+
}
|
|
206
|
+
getOperationId(name) {
|
|
207
|
+
return name.charAt(0).toUpperCase() + name.substring(1);
|
|
208
|
+
}
|
|
209
|
+
groupParameters(items) {
|
|
210
|
+
const output = {};
|
|
211
|
+
for (let i = 0; i < items.length; i++) {
|
|
212
|
+
if (typeof output[items[i].in] === 'undefined') {
|
|
213
|
+
output[items[i].in] = [];
|
|
214
|
+
}
|
|
215
|
+
output[items[i].in].push(items[i]);
|
|
216
|
+
}
|
|
217
|
+
return output;
|
|
218
|
+
}
|
|
219
|
+
transformExtensions(input) {
|
|
220
|
+
if (!input) {
|
|
221
|
+
return {};
|
|
222
|
+
}
|
|
223
|
+
const output = {};
|
|
224
|
+
for (let i = 0; i < input.length; i++) {
|
|
225
|
+
const extension = input[i];
|
|
226
|
+
if (!extension.key.startsWith('x-')) {
|
|
227
|
+
extension.key = `x-${extension.key}`;
|
|
228
|
+
}
|
|
229
|
+
output[extension.key] = extension.value;
|
|
230
|
+
}
|
|
231
|
+
return output;
|
|
232
|
+
}
|
|
233
|
+
transformValidators(input) {
|
|
234
|
+
if (!(0, smob_1.isObject)(input)) {
|
|
235
|
+
return {};
|
|
236
|
+
}
|
|
237
|
+
const keys = Object.keys(input);
|
|
238
|
+
const output = {};
|
|
239
|
+
for (let i = 0; i < keys.length; i++) {
|
|
240
|
+
const key = keys[i];
|
|
241
|
+
if (key.startsWith('is') ||
|
|
242
|
+
key === metadata_1.ValidatorName.MIN_DATE ||
|
|
243
|
+
key === metadata_1.ValidatorName.MAX_DATE) {
|
|
244
|
+
continue;
|
|
245
|
+
}
|
|
246
|
+
output[key] = input[key].value;
|
|
247
|
+
}
|
|
248
|
+
return output;
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
exports.AbstractSpecGenerator = AbstractSpecGenerator;
|
|
252
252
|
//# sourceMappingURL=abstract.js.map
|
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
export * from './v2';
|
|
2
|
-
export * from './v3';
|
|
3
|
-
export * from './abstract';
|
|
4
|
-
export * from './module';
|
|
1
|
+
export * from './v2';
|
|
2
|
+
export * from './v3';
|
|
3
|
+
export * from './abstract';
|
|
4
|
+
export * from './module';
|
|
5
5
|
//# sourceMappingURL=index.d.ts.map
|
package/dist/generator/index.js
CHANGED
|
@@ -1,27 +1,27 @@
|
|
|
1
|
-
"use strict";
|
|
2
|
-
/*
|
|
3
|
-
* Copyright (c) 2023.
|
|
4
|
-
* Author Peter Placzek (tada5hi)
|
|
5
|
-
* For the full copyright and license information,
|
|
6
|
-
* view the LICENSE file that was distributed with this source code.
|
|
7
|
-
*/
|
|
8
|
-
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
-
if (k2 === undefined) k2 = k;
|
|
10
|
-
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
-
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
-
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
-
}
|
|
14
|
-
Object.defineProperty(o, k2, desc);
|
|
15
|
-
}) : (function(o, m, k, k2) {
|
|
16
|
-
if (k2 === undefined) k2 = k;
|
|
17
|
-
o[k2] = m[k];
|
|
18
|
-
}));
|
|
19
|
-
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
-
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
-
};
|
|
22
|
-
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
-
__exportStar(require("./v2"), exports);
|
|
24
|
-
__exportStar(require("./v3"), exports);
|
|
25
|
-
__exportStar(require("./abstract"), exports);
|
|
26
|
-
__exportStar(require("./module"), exports);
|
|
1
|
+
"use strict";
|
|
2
|
+
/*
|
|
3
|
+
* Copyright (c) 2023.
|
|
4
|
+
* Author Peter Placzek (tada5hi)
|
|
5
|
+
* For the full copyright and license information,
|
|
6
|
+
* view the LICENSE file that was distributed with this source code.
|
|
7
|
+
*/
|
|
8
|
+
var __createBinding = (this && this.__createBinding) || (Object.create ? (function(o, m, k, k2) {
|
|
9
|
+
if (k2 === undefined) k2 = k;
|
|
10
|
+
var desc = Object.getOwnPropertyDescriptor(m, k);
|
|
11
|
+
if (!desc || ("get" in desc ? !m.__esModule : desc.writable || desc.configurable)) {
|
|
12
|
+
desc = { enumerable: true, get: function() { return m[k]; } };
|
|
13
|
+
}
|
|
14
|
+
Object.defineProperty(o, k2, desc);
|
|
15
|
+
}) : (function(o, m, k, k2) {
|
|
16
|
+
if (k2 === undefined) k2 = k;
|
|
17
|
+
o[k2] = m[k];
|
|
18
|
+
}));
|
|
19
|
+
var __exportStar = (this && this.__exportStar) || function(m, exports) {
|
|
20
|
+
for (var p in m) if (p !== "default" && !Object.prototype.hasOwnProperty.call(exports, p)) __createBinding(exports, m, p);
|
|
21
|
+
};
|
|
22
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
23
|
+
__exportStar(require("./v2"), exports);
|
|
24
|
+
__exportStar(require("./v3"), exports);
|
|
25
|
+
__exportStar(require("./abstract"), exports);
|
|
26
|
+
__exportStar(require("./module"), exports);
|
|
27
27
|
//# sourceMappingURL=index.js.map
|
|
@@ -1,14 +1,14 @@
|
|
|
1
|
-
import type { TsConfig } from '@trapi/metadata';
|
|
2
|
-
import type { OptionsInput } from '../config';
|
|
3
|
-
import { Version } from '../constants';
|
|
4
|
-
import type { SpecV2, SpecV3 } from '../schema';
|
|
5
|
-
export declare function buildMetadata(options: OptionsInput, tsConfig?: TsConfig | string): Promise<import("@trapi/metadata").Metadata>;
|
|
6
|
-
export type DocumentationGenerationContext<V extends `${Version}`> = {
|
|
7
|
-
version: V;
|
|
8
|
-
options: OptionsInput;
|
|
9
|
-
tsConfig?: TsConfig | string;
|
|
10
|
-
};
|
|
11
|
-
type OutputSpec<V extends `${Version}`> = V extends `${Version.V2}` ? SpecV2 : SpecV3;
|
|
12
|
-
export declare function generate<V extends `${Version}`>(context: DocumentationGenerationContext<V>): Promise<OutputSpec<V>>;
|
|
13
|
-
export {};
|
|
1
|
+
import type { TsConfig } from '@trapi/metadata';
|
|
2
|
+
import type { OptionsInput } from '../config';
|
|
3
|
+
import { Version } from '../constants';
|
|
4
|
+
import type { SpecV2, SpecV3 } from '../schema';
|
|
5
|
+
export declare function buildMetadata(options: OptionsInput, tsConfig?: TsConfig | string): Promise<import("@trapi/metadata").Metadata>;
|
|
6
|
+
export type DocumentationGenerationContext<V extends `${Version}`> = {
|
|
7
|
+
version: V;
|
|
8
|
+
options: OptionsInput;
|
|
9
|
+
tsConfig?: TsConfig | string;
|
|
10
|
+
};
|
|
11
|
+
type OutputSpec<V extends `${Version}`> = V extends `${Version.V2}` ? SpecV2 : SpecV3;
|
|
12
|
+
export declare function generate<V extends `${Version}`>(context: DocumentationGenerationContext<V>): Promise<OutputSpec<V>>;
|
|
13
|
+
export {};
|
|
14
14
|
//# sourceMappingURL=module.d.ts.map
|