@grandlinex/swagger-mate 2.0.0-alpha.3 → 2.0.0-alpha.4
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/cjs/Swagger/Client/ClientUtil.d.ts +1 -0
- package/dist/cjs/Swagger/Client/ClientUtil.js +25 -4
- package/dist/cjs/Swagger/Client/FunctionProps.js +3 -0
- package/dist/cjs/Swagger/Client/InterfaceTemplate.js +1 -1
- package/dist/cjs/Swagger/Client/SwaggerClient.js +4 -4
- package/dist/cjs/Swagger/Meta/SwaggerTypes.d.ts +2 -1
- package/dist/cjs/Swagger/Meta/SwaggerTypesStatic.d.ts +1 -1
- package/dist/cjs/Swagger/Path/ESchemaEditor.js +6 -3
- package/dist/cjs/Swagger/SwaggerUtil.js +19 -21
- package/dist/mjs/Swagger/Client/ClientUtil.d.ts +1 -0
- package/dist/mjs/Swagger/Client/ClientUtil.js +25 -4
- package/dist/mjs/Swagger/Client/FunctionProps.js +3 -0
- package/dist/mjs/Swagger/Client/InterfaceTemplate.js +1 -1
- package/dist/mjs/Swagger/Client/SwaggerClient.js +4 -4
- package/dist/mjs/Swagger/Meta/SwaggerTypes.d.ts +2 -1
- package/dist/mjs/Swagger/Meta/SwaggerTypesStatic.d.ts +1 -1
- package/dist/mjs/Swagger/Path/ESchemaEditor.js +6 -3
- package/dist/mjs/Swagger/SwaggerUtil.js +19 -21
- package/package.json +4 -4
|
@@ -118,6 +118,7 @@ function transformInterface(operation, tag, schema) {
|
|
|
118
118
|
const isRequired = schema.required && schema.required.includes(key);
|
|
119
119
|
if (!(0, SwaggerTypes_js_1.isSwaggerRef)(prop)) {
|
|
120
120
|
const nullable = prop.nullable ?? false;
|
|
121
|
+
const deprecated = prop.deprecated ?? false;
|
|
121
122
|
switch (prop.type) {
|
|
122
123
|
case 'number':
|
|
123
124
|
case 'integer':
|
|
@@ -126,14 +127,18 @@ function transformInterface(operation, tag, schema) {
|
|
|
126
127
|
type: 'number',
|
|
127
128
|
required: isRequired,
|
|
128
129
|
nullable,
|
|
130
|
+
deprecated,
|
|
129
131
|
});
|
|
130
132
|
break;
|
|
131
133
|
case 'string':
|
|
132
134
|
cur.keys.push({
|
|
133
135
|
key,
|
|
134
|
-
type:
|
|
136
|
+
type: prop.enum
|
|
137
|
+
? prop.enum.map((v) => `'${v}'`).join(' | ')
|
|
138
|
+
: 'string',
|
|
135
139
|
required: isRequired,
|
|
136
140
|
nullable,
|
|
141
|
+
deprecated,
|
|
137
142
|
});
|
|
138
143
|
break;
|
|
139
144
|
case 'boolean':
|
|
@@ -142,6 +147,7 @@ function transformInterface(operation, tag, schema) {
|
|
|
142
147
|
type: 'boolean',
|
|
143
148
|
required: isRequired,
|
|
144
149
|
nullable,
|
|
150
|
+
deprecated,
|
|
145
151
|
});
|
|
146
152
|
break;
|
|
147
153
|
case 'object':
|
|
@@ -151,6 +157,7 @@ function transformInterface(operation, tag, schema) {
|
|
|
151
157
|
type: 'any',
|
|
152
158
|
required: isRequired,
|
|
153
159
|
nullable,
|
|
160
|
+
deprecated,
|
|
154
161
|
});
|
|
155
162
|
}
|
|
156
163
|
else {
|
|
@@ -158,17 +165,28 @@ function transformInterface(operation, tag, schema) {
|
|
|
158
165
|
key,
|
|
159
166
|
type: ifName(cur.name, key),
|
|
160
167
|
required: isRequired,
|
|
168
|
+
deprecated,
|
|
161
169
|
});
|
|
162
170
|
out.push(...transformInterface(cur.name, key, prop));
|
|
163
171
|
}
|
|
164
172
|
break;
|
|
165
173
|
case 'array':
|
|
166
|
-
if (
|
|
174
|
+
if (!prop.items) {
|
|
175
|
+
cur.keys.push({
|
|
176
|
+
key,
|
|
177
|
+
type: 'unknown[]',
|
|
178
|
+
required: isRequired,
|
|
179
|
+
nullable,
|
|
180
|
+
deprecated,
|
|
181
|
+
});
|
|
182
|
+
}
|
|
183
|
+
else if ((0, SwaggerTypes_js_1.isSwaggerRef)(prop.items)) {
|
|
167
184
|
cur.keys.push({
|
|
168
185
|
key,
|
|
169
186
|
type: `${typeByRef(prop.items.$ref)}[]`,
|
|
170
187
|
required: isRequired,
|
|
171
188
|
nullable,
|
|
189
|
+
deprecated,
|
|
172
190
|
});
|
|
173
191
|
}
|
|
174
192
|
else {
|
|
@@ -177,8 +195,9 @@ function transformInterface(operation, tag, schema) {
|
|
|
177
195
|
type: `${ifName(cur.name, `${key}Element`)}[]`,
|
|
178
196
|
required: isRequired,
|
|
179
197
|
nullable,
|
|
198
|
+
deprecated,
|
|
180
199
|
});
|
|
181
|
-
out.push(...transformInterface(cur.name, key
|
|
200
|
+
out.push(...transformInterface(cur.name, `${key}Element`, prop.items));
|
|
182
201
|
}
|
|
183
202
|
break;
|
|
184
203
|
default:
|
|
@@ -226,7 +245,9 @@ function transformInterface(operation, tag, schema) {
|
|
|
226
245
|
out.push({
|
|
227
246
|
keys: [],
|
|
228
247
|
name: cur.name,
|
|
229
|
-
rawType:
|
|
248
|
+
rawType: schema.enum
|
|
249
|
+
? schema.enum.map((v) => `'${v}'`).join(' | ')
|
|
250
|
+
: 'string',
|
|
230
251
|
});
|
|
231
252
|
break;
|
|
232
253
|
case 'integer':
|
|
@@ -5,6 +5,9 @@ const ClientUtil_js_1 = require("./ClientUtil.js");
|
|
|
5
5
|
const FunctionTemplate_js_1 = require("./FunctionTemplate.js");
|
|
6
6
|
function functionProps(route, t, cur) {
|
|
7
7
|
const comments = [];
|
|
8
|
+
if (cur.deprecated) {
|
|
9
|
+
comments.push('@deprecated');
|
|
10
|
+
}
|
|
8
11
|
if (cur.description) {
|
|
9
12
|
comments.push(cur.description);
|
|
10
13
|
}
|
|
@@ -8,6 +8,6 @@ function interfaceTemplate(IF_NAME, types, rawType) {
|
|
|
8
8
|
return `export type ${IF_NAME} = ${rawType};`;
|
|
9
9
|
}
|
|
10
10
|
return `export interface ${IF_NAME} {
|
|
11
|
-
${types.map(({ key, type, required, nullable }) => `${(0, ClientUtil_js_1.S)(2)}${(0, ClientUtil_js_1.sK)(key)}${(0, ClientUtil_js_1.rq)(required)} ${(0, ClientUtil_js_1.rN)(type, nullable)};`).join('\n')}
|
|
11
|
+
${types.map(({ key, type, required, nullable, deprecated }) => `${deprecated ? `${(0, ClientUtil_js_1.S)(2)}/** @deprecated */\n` : ''}${(0, ClientUtil_js_1.S)(2)}${(0, ClientUtil_js_1.sK)(key)}${(0, ClientUtil_js_1.rq)(required)} ${(0, ClientUtil_js_1.rN)(type, nullable)};`).join('\n')}
|
|
12
12
|
}`;
|
|
13
13
|
}
|
|
@@ -56,7 +56,7 @@ function cp(path, file) {
|
|
|
56
56
|
fs.copyFileSync(dest, target);
|
|
57
57
|
}
|
|
58
58
|
else {
|
|
59
|
-
|
|
59
|
+
throw new Error(`Template file not found: ${dest}`);
|
|
60
60
|
}
|
|
61
61
|
}
|
|
62
62
|
// # undefined, undefined, undefined
|
|
@@ -130,7 +130,7 @@ function interfaceHandler(conf) {
|
|
|
130
130
|
for (const resp of keys) {
|
|
131
131
|
const cur = schema[resp];
|
|
132
132
|
if (cur) {
|
|
133
|
-
interfaceList.push(...(0, ClientUtil_js_1.transformInterface)(resp, '', cur).map((del) => (0, InterfaceTemplate_js_1.interfaceTemplate)(del.name, del.keys)));
|
|
133
|
+
interfaceList.push(...(0, ClientUtil_js_1.transformInterface)(resp, '', cur).map((del) => (0, InterfaceTemplate_js_1.interfaceTemplate)(del.name, del.keys, del.rawType)));
|
|
134
134
|
}
|
|
135
135
|
}
|
|
136
136
|
}
|
|
@@ -176,8 +176,8 @@ function createPackage(name, version) {
|
|
|
176
176
|
typescript: '5.9.2',
|
|
177
177
|
},
|
|
178
178
|
peerDependencies: {
|
|
179
|
-
'@grandlinex/base-con': '
|
|
180
|
-
axios: '>=1.
|
|
179
|
+
'@grandlinex/base-con': '2.0.0',
|
|
180
|
+
axios: '>=1.16.1',
|
|
181
181
|
'form-data': '>=4.0.5',
|
|
182
182
|
},
|
|
183
183
|
scripts: {
|
|
@@ -32,13 +32,13 @@ export interface SwaggerRPathConf {
|
|
|
32
32
|
operationId?: string;
|
|
33
33
|
requestBody?: SwaggerRPathReqBody;
|
|
34
34
|
parameters?: SwaggerRPathParameter[];
|
|
35
|
+
deprecated?: boolean;
|
|
35
36
|
}
|
|
36
37
|
export interface SwaggerRPathTypes {
|
|
37
38
|
get?: SwaggerRPathConf;
|
|
38
39
|
post?: SwaggerRPathConf;
|
|
39
40
|
patch?: SwaggerRPathConf;
|
|
40
41
|
delete?: SwaggerRPathConf;
|
|
41
|
-
update?: SwaggerRPathConf;
|
|
42
42
|
}
|
|
43
43
|
export interface SwaggerRInfoLicence {
|
|
44
44
|
name: string;
|
|
@@ -68,6 +68,7 @@ export type SSchemaElObj = {
|
|
|
68
68
|
required?: string[];
|
|
69
69
|
enum?: string[];
|
|
70
70
|
nullable?: boolean;
|
|
71
|
+
deprecated?: boolean;
|
|
71
72
|
};
|
|
72
73
|
export type SSchemaEl = SSchemaElObj | SwaggerRRef;
|
|
73
74
|
export type SwaggerContent = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type SMediaType = 'text/plain; charset=utf-8' | '
|
|
1
|
+
export type SMediaType = 'application/json' | 'application/octet-stream' | 'application/pdf' | 'application/xml' | 'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/csv' | 'text/html' | 'text/plain' | 'text/plain; charset=utf-8' | 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp';
|
|
2
2
|
export type SDataFormat = 'binary' | 'base64' | 'uuid';
|
|
3
3
|
export type SDataType = 'integer' | 'number' | 'string' | 'boolean' | 'array' | 'object';
|
|
4
4
|
export type HttpStatusTypes = '100' | '101' | '102' | '103' | '200' | '201' | '202' | '203' | '204' | '205' | '206' | '207' | '208' | '226' | '300' | '301' | '302' | '303' | '304' | '305' | '306' | '307' | '308' | '400' | '401' | '402' | '403' | '404' | '405' | '406' | '407' | '408' | '409' | '410' | '411' | '412' | '413' | '414' | '415' | '416' | '417' | '418' | '421' | '422' | '423' | '424' | '425' | '426' | '428' | '429' | '431' | '451' | '500' | '501' | '502' | '503' | '504' | '505' | '506' | '507' | '508' | '510' | '511';
|
|
@@ -69,6 +69,9 @@ class ESchemaEditor {
|
|
|
69
69
|
else {
|
|
70
70
|
this.data.properties[option.key] = option.schema;
|
|
71
71
|
}
|
|
72
|
+
if (option.required) {
|
|
73
|
+
this.data.required = [...(this.data.required || []), option.key];
|
|
74
|
+
}
|
|
72
75
|
}
|
|
73
76
|
else if (option.entity) {
|
|
74
77
|
const scheme = ESchemaEditor.fromEntity(option.entity).getSchema();
|
|
@@ -84,9 +87,9 @@ class ESchemaEditor {
|
|
|
84
87
|
else {
|
|
85
88
|
this.data.properties[option.key] = scheme;
|
|
86
89
|
}
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
+
if (option.required) {
|
|
91
|
+
this.data.required = [...(this.data.required || []), option.key];
|
|
92
|
+
}
|
|
90
93
|
}
|
|
91
94
|
}
|
|
92
95
|
return this;
|
|
@@ -95,11 +95,12 @@ class SwaggerUtil {
|
|
|
95
95
|
app.get('/spec', (req, res) => {
|
|
96
96
|
res.status(200).send(conf);
|
|
97
97
|
});
|
|
98
|
-
return new Promise((resolve) => {
|
|
98
|
+
return new Promise((resolve, reject) => {
|
|
99
99
|
const s = app.listen(port, () => {
|
|
100
100
|
this.getLogger().log(`${type} listen on http://localhost:${port}${key}#`);
|
|
101
101
|
resolve(s);
|
|
102
102
|
});
|
|
103
|
+
s.on('error', reject);
|
|
103
104
|
});
|
|
104
105
|
}
|
|
105
106
|
static metaExtractor(root, npmPackageVersion, ...path) {
|
|
@@ -203,10 +204,10 @@ class SwaggerUtil {
|
|
|
203
204
|
break;
|
|
204
205
|
case 'USE':
|
|
205
206
|
path[convertedPath] = {
|
|
206
|
-
get: conf,
|
|
207
|
-
patch: conf,
|
|
208
|
-
post: conf,
|
|
209
|
-
delete: conf,
|
|
207
|
+
get: { ...conf },
|
|
208
|
+
patch: { ...conf },
|
|
209
|
+
post: { ...conf },
|
|
210
|
+
delete: { ...conf },
|
|
210
211
|
};
|
|
211
212
|
break;
|
|
212
213
|
default:
|
|
@@ -214,13 +215,11 @@ class SwaggerUtil {
|
|
|
214
215
|
return path;
|
|
215
216
|
}
|
|
216
217
|
static merge(root, data) {
|
|
217
|
-
const out =
|
|
218
|
-
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
|
|
222
|
-
out.components = {};
|
|
223
|
-
}
|
|
218
|
+
const out = {
|
|
219
|
+
...root,
|
|
220
|
+
paths: { ...(root.paths || {}) },
|
|
221
|
+
components: { ...(root.components || {}) },
|
|
222
|
+
};
|
|
224
223
|
data.forEach(({ path, comp }) => {
|
|
225
224
|
if (path && out.paths) {
|
|
226
225
|
const keys = Object.keys(path.path);
|
|
@@ -233,11 +232,9 @@ class SwaggerUtil {
|
|
|
233
232
|
if (!out.paths[nKey]) {
|
|
234
233
|
out.paths[nKey] = {};
|
|
235
234
|
}
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
out.paths[nKey][nC] = ac[nC];
|
|
240
|
-
}
|
|
235
|
+
for (const c of comps) {
|
|
236
|
+
const nC = c;
|
|
237
|
+
out.paths[nKey][nC] = ac[nC];
|
|
241
238
|
}
|
|
242
239
|
}
|
|
243
240
|
}
|
|
@@ -254,10 +251,8 @@ class SwaggerUtil {
|
|
|
254
251
|
if (!out.components[nKey]) {
|
|
255
252
|
out.components[nKey] = {};
|
|
256
253
|
}
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
out.components[nKey][c] = ac[c];
|
|
260
|
-
}
|
|
254
|
+
for (const c of comps) {
|
|
255
|
+
out.components[nKey][c] = ac[c];
|
|
261
256
|
}
|
|
262
257
|
}
|
|
263
258
|
}
|
|
@@ -279,6 +274,9 @@ class SwaggerUtil {
|
|
|
279
274
|
if (!map.has(key)) {
|
|
280
275
|
map.set(key, obj[key]);
|
|
281
276
|
}
|
|
277
|
+
else {
|
|
278
|
+
console.warn(`mergeConfig: duplicate key "${key}" skipped`);
|
|
279
|
+
}
|
|
282
280
|
}
|
|
283
281
|
}
|
|
284
282
|
}
|
|
@@ -104,6 +104,7 @@ export function transformInterface(operation, tag, schema) {
|
|
|
104
104
|
const isRequired = schema.required && schema.required.includes(key);
|
|
105
105
|
if (!isSwaggerRef(prop)) {
|
|
106
106
|
const nullable = prop.nullable ?? false;
|
|
107
|
+
const deprecated = prop.deprecated ?? false;
|
|
107
108
|
switch (prop.type) {
|
|
108
109
|
case 'number':
|
|
109
110
|
case 'integer':
|
|
@@ -112,14 +113,18 @@ export function transformInterface(operation, tag, schema) {
|
|
|
112
113
|
type: 'number',
|
|
113
114
|
required: isRequired,
|
|
114
115
|
nullable,
|
|
116
|
+
deprecated,
|
|
115
117
|
});
|
|
116
118
|
break;
|
|
117
119
|
case 'string':
|
|
118
120
|
cur.keys.push({
|
|
119
121
|
key,
|
|
120
|
-
type:
|
|
122
|
+
type: prop.enum
|
|
123
|
+
? prop.enum.map((v) => `'${v}'`).join(' | ')
|
|
124
|
+
: 'string',
|
|
121
125
|
required: isRequired,
|
|
122
126
|
nullable,
|
|
127
|
+
deprecated,
|
|
123
128
|
});
|
|
124
129
|
break;
|
|
125
130
|
case 'boolean':
|
|
@@ -128,6 +133,7 @@ export function transformInterface(operation, tag, schema) {
|
|
|
128
133
|
type: 'boolean',
|
|
129
134
|
required: isRequired,
|
|
130
135
|
nullable,
|
|
136
|
+
deprecated,
|
|
131
137
|
});
|
|
132
138
|
break;
|
|
133
139
|
case 'object':
|
|
@@ -137,6 +143,7 @@ export function transformInterface(operation, tag, schema) {
|
|
|
137
143
|
type: 'any',
|
|
138
144
|
required: isRequired,
|
|
139
145
|
nullable,
|
|
146
|
+
deprecated,
|
|
140
147
|
});
|
|
141
148
|
}
|
|
142
149
|
else {
|
|
@@ -144,17 +151,28 @@ export function transformInterface(operation, tag, schema) {
|
|
|
144
151
|
key,
|
|
145
152
|
type: ifName(cur.name, key),
|
|
146
153
|
required: isRequired,
|
|
154
|
+
deprecated,
|
|
147
155
|
});
|
|
148
156
|
out.push(...transformInterface(cur.name, key, prop));
|
|
149
157
|
}
|
|
150
158
|
break;
|
|
151
159
|
case 'array':
|
|
152
|
-
if (
|
|
160
|
+
if (!prop.items) {
|
|
161
|
+
cur.keys.push({
|
|
162
|
+
key,
|
|
163
|
+
type: 'unknown[]',
|
|
164
|
+
required: isRequired,
|
|
165
|
+
nullable,
|
|
166
|
+
deprecated,
|
|
167
|
+
});
|
|
168
|
+
}
|
|
169
|
+
else if (isSwaggerRef(prop.items)) {
|
|
153
170
|
cur.keys.push({
|
|
154
171
|
key,
|
|
155
172
|
type: `${typeByRef(prop.items.$ref)}[]`,
|
|
156
173
|
required: isRequired,
|
|
157
174
|
nullable,
|
|
175
|
+
deprecated,
|
|
158
176
|
});
|
|
159
177
|
}
|
|
160
178
|
else {
|
|
@@ -163,8 +181,9 @@ export function transformInterface(operation, tag, schema) {
|
|
|
163
181
|
type: `${ifName(cur.name, `${key}Element`)}[]`,
|
|
164
182
|
required: isRequired,
|
|
165
183
|
nullable,
|
|
184
|
+
deprecated,
|
|
166
185
|
});
|
|
167
|
-
out.push(...transformInterface(cur.name, key
|
|
186
|
+
out.push(...transformInterface(cur.name, `${key}Element`, prop.items));
|
|
168
187
|
}
|
|
169
188
|
break;
|
|
170
189
|
default:
|
|
@@ -212,7 +231,9 @@ export function transformInterface(operation, tag, schema) {
|
|
|
212
231
|
out.push({
|
|
213
232
|
keys: [],
|
|
214
233
|
name: cur.name,
|
|
215
|
-
rawType:
|
|
234
|
+
rawType: schema.enum
|
|
235
|
+
? schema.enum.map((v) => `'${v}'`).join(' | ')
|
|
236
|
+
: 'string',
|
|
216
237
|
});
|
|
217
238
|
break;
|
|
218
239
|
case 'integer':
|
|
@@ -3,6 +3,9 @@ import { ifName, IFTag, typeByRef } from './ClientUtil.js';
|
|
|
3
3
|
import { reqBody } from './FunctionTemplate.js';
|
|
4
4
|
function functionProps(route, t, cur) {
|
|
5
5
|
const comments = [];
|
|
6
|
+
if (cur.deprecated) {
|
|
7
|
+
comments.push('@deprecated');
|
|
8
|
+
}
|
|
6
9
|
if (cur.description) {
|
|
7
10
|
comments.push(cur.description);
|
|
8
11
|
}
|
|
@@ -5,7 +5,7 @@ function interfaceTemplate(IF_NAME, types, rawType) {
|
|
|
5
5
|
return `export type ${IF_NAME} = ${rawType};`;
|
|
6
6
|
}
|
|
7
7
|
return `export interface ${IF_NAME} {
|
|
8
|
-
${types.map(({ key, type, required, nullable }) => `${S(2)}${sK(key)}${rq(required)} ${rN(type, nullable)};`).join('\n')}
|
|
8
|
+
${types.map(({ key, type, required, nullable, deprecated }) => `${deprecated ? `${S(2)}/** @deprecated */\n` : ''}${S(2)}${sK(key)}${rq(required)} ${rN(type, nullable)};`).join('\n')}
|
|
9
9
|
}`;
|
|
10
10
|
}
|
|
11
11
|
export {
|
|
@@ -18,7 +18,7 @@ function cp(path, file) {
|
|
|
18
18
|
fs.copyFileSync(dest, target);
|
|
19
19
|
}
|
|
20
20
|
else {
|
|
21
|
-
|
|
21
|
+
throw new Error(`Template file not found: ${dest}`);
|
|
22
22
|
}
|
|
23
23
|
}
|
|
24
24
|
// # undefined, undefined, undefined
|
|
@@ -92,7 +92,7 @@ function interfaceHandler(conf) {
|
|
|
92
92
|
for (const resp of keys) {
|
|
93
93
|
const cur = schema[resp];
|
|
94
94
|
if (cur) {
|
|
95
|
-
interfaceList.push(...transformInterface(resp, '', cur).map((del) => interfaceTemplate(del.name, del.keys)));
|
|
95
|
+
interfaceList.push(...transformInterface(resp, '', cur).map((del) => interfaceTemplate(del.name, del.keys, del.rawType)));
|
|
96
96
|
}
|
|
97
97
|
}
|
|
98
98
|
}
|
|
@@ -138,8 +138,8 @@ function createPackage(name, version) {
|
|
|
138
138
|
typescript: '5.9.2',
|
|
139
139
|
},
|
|
140
140
|
peerDependencies: {
|
|
141
|
-
'@grandlinex/base-con': '
|
|
142
|
-
axios: '>=1.
|
|
141
|
+
'@grandlinex/base-con': '2.0.0',
|
|
142
|
+
axios: '>=1.16.1',
|
|
143
143
|
'form-data': '>=4.0.5',
|
|
144
144
|
},
|
|
145
145
|
scripts: {
|
|
@@ -32,13 +32,13 @@ export interface SwaggerRPathConf {
|
|
|
32
32
|
operationId?: string;
|
|
33
33
|
requestBody?: SwaggerRPathReqBody;
|
|
34
34
|
parameters?: SwaggerRPathParameter[];
|
|
35
|
+
deprecated?: boolean;
|
|
35
36
|
}
|
|
36
37
|
export interface SwaggerRPathTypes {
|
|
37
38
|
get?: SwaggerRPathConf;
|
|
38
39
|
post?: SwaggerRPathConf;
|
|
39
40
|
patch?: SwaggerRPathConf;
|
|
40
41
|
delete?: SwaggerRPathConf;
|
|
41
|
-
update?: SwaggerRPathConf;
|
|
42
42
|
}
|
|
43
43
|
export interface SwaggerRInfoLicence {
|
|
44
44
|
name: string;
|
|
@@ -68,6 +68,7 @@ export type SSchemaElObj = {
|
|
|
68
68
|
required?: string[];
|
|
69
69
|
enum?: string[];
|
|
70
70
|
nullable?: boolean;
|
|
71
|
+
deprecated?: boolean;
|
|
71
72
|
};
|
|
72
73
|
export type SSchemaEl = SSchemaElObj | SwaggerRRef;
|
|
73
74
|
export type SwaggerContent = {
|
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
export type SMediaType = 'text/plain; charset=utf-8' | '
|
|
1
|
+
export type SMediaType = 'application/json' | 'application/octet-stream' | 'application/pdf' | 'application/xml' | 'application/x-www-form-urlencoded' | 'multipart/form-data' | 'text/csv' | 'text/html' | 'text/plain' | 'text/plain; charset=utf-8' | 'image/png' | 'image/jpeg' | 'image/gif' | 'image/webp';
|
|
2
2
|
export type SDataFormat = 'binary' | 'base64' | 'uuid';
|
|
3
3
|
export type SDataType = 'integer' | 'number' | 'string' | 'boolean' | 'array' | 'object';
|
|
4
4
|
export type HttpStatusTypes = '100' | '101' | '102' | '103' | '200' | '201' | '202' | '203' | '204' | '205' | '206' | '207' | '208' | '226' | '300' | '301' | '302' | '303' | '304' | '305' | '306' | '307' | '308' | '400' | '401' | '402' | '403' | '404' | '405' | '406' | '407' | '408' | '409' | '410' | '411' | '412' | '413' | '414' | '415' | '416' | '417' | '418' | '421' | '422' | '423' | '424' | '425' | '426' | '428' | '429' | '431' | '451' | '500' | '501' | '502' | '503' | '504' | '505' | '506' | '507' | '508' | '510' | '511';
|
|
@@ -66,6 +66,9 @@ export class ESchemaEditor {
|
|
|
66
66
|
else {
|
|
67
67
|
this.data.properties[option.key] = option.schema;
|
|
68
68
|
}
|
|
69
|
+
if (option.required) {
|
|
70
|
+
this.data.required = [...(this.data.required || []), option.key];
|
|
71
|
+
}
|
|
69
72
|
}
|
|
70
73
|
else if (option.entity) {
|
|
71
74
|
const scheme = ESchemaEditor.fromEntity(option.entity).getSchema();
|
|
@@ -81,9 +84,9 @@ export class ESchemaEditor {
|
|
|
81
84
|
else {
|
|
82
85
|
this.data.properties[option.key] = scheme;
|
|
83
86
|
}
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
+
if (option.required) {
|
|
88
|
+
this.data.required = [...(this.data.required || []), option.key];
|
|
89
|
+
}
|
|
87
90
|
}
|
|
88
91
|
}
|
|
89
92
|
return this;
|
|
@@ -57,11 +57,12 @@ export default class SwaggerUtil {
|
|
|
57
57
|
app.get('/spec', (req, res) => {
|
|
58
58
|
res.status(200).send(conf);
|
|
59
59
|
});
|
|
60
|
-
return new Promise((resolve) => {
|
|
60
|
+
return new Promise((resolve, reject) => {
|
|
61
61
|
const s = app.listen(port, () => {
|
|
62
62
|
this.getLogger().log(`${type} listen on http://localhost:${port}${key}#`);
|
|
63
63
|
resolve(s);
|
|
64
64
|
});
|
|
65
|
+
s.on('error', reject);
|
|
65
66
|
});
|
|
66
67
|
}
|
|
67
68
|
static metaExtractor(root, npmPackageVersion, ...path) {
|
|
@@ -165,10 +166,10 @@ export default class SwaggerUtil {
|
|
|
165
166
|
break;
|
|
166
167
|
case 'USE':
|
|
167
168
|
path[convertedPath] = {
|
|
168
|
-
get: conf,
|
|
169
|
-
patch: conf,
|
|
170
|
-
post: conf,
|
|
171
|
-
delete: conf,
|
|
169
|
+
get: { ...conf },
|
|
170
|
+
patch: { ...conf },
|
|
171
|
+
post: { ...conf },
|
|
172
|
+
delete: { ...conf },
|
|
172
173
|
};
|
|
173
174
|
break;
|
|
174
175
|
default:
|
|
@@ -176,13 +177,11 @@ export default class SwaggerUtil {
|
|
|
176
177
|
return path;
|
|
177
178
|
}
|
|
178
179
|
static merge(root, data) {
|
|
179
|
-
const out =
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
out.components = {};
|
|
185
|
-
}
|
|
180
|
+
const out = {
|
|
181
|
+
...root,
|
|
182
|
+
paths: { ...(root.paths || {}) },
|
|
183
|
+
components: { ...(root.components || {}) },
|
|
184
|
+
};
|
|
186
185
|
data.forEach(({ path, comp }) => {
|
|
187
186
|
if (path && out.paths) {
|
|
188
187
|
const keys = Object.keys(path.path);
|
|
@@ -195,11 +194,9 @@ export default class SwaggerUtil {
|
|
|
195
194
|
if (!out.paths[nKey]) {
|
|
196
195
|
out.paths[nKey] = {};
|
|
197
196
|
}
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
out.paths[nKey][nC] = ac[nC];
|
|
202
|
-
}
|
|
197
|
+
for (const c of comps) {
|
|
198
|
+
const nC = c;
|
|
199
|
+
out.paths[nKey][nC] = ac[nC];
|
|
203
200
|
}
|
|
204
201
|
}
|
|
205
202
|
}
|
|
@@ -216,10 +213,8 @@ export default class SwaggerUtil {
|
|
|
216
213
|
if (!out.components[nKey]) {
|
|
217
214
|
out.components[nKey] = {};
|
|
218
215
|
}
|
|
219
|
-
|
|
220
|
-
|
|
221
|
-
out.components[nKey][c] = ac[c];
|
|
222
|
-
}
|
|
216
|
+
for (const c of comps) {
|
|
217
|
+
out.components[nKey][c] = ac[c];
|
|
223
218
|
}
|
|
224
219
|
}
|
|
225
220
|
}
|
|
@@ -241,6 +236,9 @@ export default class SwaggerUtil {
|
|
|
241
236
|
if (!map.has(key)) {
|
|
242
237
|
map.set(key, obj[key]);
|
|
243
238
|
}
|
|
239
|
+
else {
|
|
240
|
+
console.warn(`mergeConfig: duplicate key "${key}" skipped`);
|
|
241
|
+
}
|
|
244
242
|
}
|
|
245
243
|
}
|
|
246
244
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@grandlinex/swagger-mate",
|
|
3
|
-
"version": "2.0.0-alpha.
|
|
3
|
+
"version": "2.0.0-alpha.4",
|
|
4
4
|
"type": "module",
|
|
5
5
|
"exports": {
|
|
6
6
|
".": {
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"swagger-mate-esm": "./dist/mjs/cli.js"
|
|
38
38
|
},
|
|
39
39
|
"dependencies": {
|
|
40
|
-
"@grandlinex/core": "2.0.0-alpha.
|
|
41
|
-
"@grandlinex/base-con": "
|
|
40
|
+
"@grandlinex/core": "2.0.0-alpha.4",
|
|
41
|
+
"@grandlinex/base-con": "2.0.0",
|
|
42
42
|
"js-yaml": "4.1.1",
|
|
43
43
|
"reflect-metadata": "0.2.2"
|
|
44
44
|
},
|
|
@@ -47,7 +47,7 @@
|
|
|
47
47
|
"form-data": ">=4.0.5"
|
|
48
48
|
},
|
|
49
49
|
"devDependencies": {
|
|
50
|
-
"axios": "1.
|
|
50
|
+
"axios": "1.16.1",
|
|
51
51
|
"node-fetch": "3.3.2",
|
|
52
52
|
"cross-env": "10.0.0",
|
|
53
53
|
"@types/express": "5.0.6",
|