@nestia/migrate 0.10.0 → 0.11.1
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/lib/MigrateApplication.d.ts +3 -1
- package/lib/MigrateApplication.js +1558 -1601
- package/lib/MigrateApplication.js.map +1 -1
- package/lib/bundles/NEST_TEMPLATE.js +1 -1
- package/lib/internal/MigrateCommander.js +1 -1
- package/lib/internal/MigrateCommander.js.map +1 -1
- package/lib/structures/ISwaggerV20.d.ts +8 -0
- package/lib/structures/ISwaggerV20.js +3 -0
- package/lib/structures/ISwaggerV20.js.map +1 -0
- package/lib/structures/ISwaggerV31.d.ts +9 -0
- package/lib/structures/ISwaggerV31.js +3 -0
- package/lib/structures/ISwaggerV31.js.map +1 -0
- package/lib/utils/OpenApiConverter.d.ts +7 -0
- package/lib/utils/OpenApiConverter.js +3132 -0
- package/lib/utils/OpenApiConverter.js.map +1 -0
- package/lib/utils/openapi-down-convert/RefVisitor.d.ts +57 -0
- package/lib/utils/openapi-down-convert/RefVisitor.js +100 -0
- package/lib/utils/openapi-down-convert/RefVisitor.js.map +1 -0
- package/lib/utils/openapi-down-convert/converter.d.ts +138 -0
- package/lib/utils/openapi-down-convert/converter.js +431 -0
- package/lib/utils/openapi-down-convert/converter.js.map +1 -0
- package/package.json +11 -7
- package/src/MigrateApplication.ts +17 -8
- package/src/internal/MigrateCommander.ts +1 -1
- package/src/structures/ISwagger.ts +23 -23
- package/src/structures/ISwaggerV20.ts +10 -0
- package/src/structures/ISwaggerV31.ts +10 -0
- package/src/utils/OpenApiConverter.ts +19 -0
- package/src/utils/openapi-down-convert/RefVisitor.ts +139 -0
- package/src/utils/openapi-down-convert/converter.ts +527 -0
- package/lib/utils/SwaggerExplorer.d.ts +0 -0
- package/lib/utils/SwaggerExplorer.js +0 -2
- package/lib/utils/SwaggerExplorer.js.map +0 -1
@@ -0,0 +1,431 @@
|
|
1
|
+
"use strict";
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
3
|
+
exports.Converter = void 0;
|
4
|
+
/** OpenAPI Down Converted - convert an OAS document from OAS 3.1 to OAS 3.0 */
|
5
|
+
const RefVisitor_1 = require("./RefVisitor");
|
6
|
+
class Converter {
|
7
|
+
/**
|
8
|
+
* Construct a new Converter
|
9
|
+
* @throws Error if the scopeDescriptionFile (if specified) cannot be read or parsed as YAML/JSON
|
10
|
+
*/
|
11
|
+
constructor(openapiDocument, options) {
|
12
|
+
this.verbose = false;
|
13
|
+
this.deleteExampleWithId = false;
|
14
|
+
this.allOfTransform = false;
|
15
|
+
this.scopeDescriptions = undefined;
|
16
|
+
this.convertSchemaComments = false;
|
17
|
+
this.returnCode = 0;
|
18
|
+
this.openapi30 = Converter.deepClone(openapiDocument);
|
19
|
+
this.verbose = Boolean(options === null || options === void 0 ? void 0 : options.verbose);
|
20
|
+
this.deleteExampleWithId = Boolean(options === null || options === void 0 ? void 0 : options.deleteExampleWithId);
|
21
|
+
this.allOfTransform = Boolean(options === null || options === void 0 ? void 0 : options.allOfTransform);
|
22
|
+
this.authorizationUrl =
|
23
|
+
(options === null || options === void 0 ? void 0 : options.authorizationUrl) || "https://www.example.com/oauth2/authorize";
|
24
|
+
this.tokenUrl = (options === null || options === void 0 ? void 0 : options.tokenUrl) || "https://www.example.com/oauth2/token";
|
25
|
+
this.loadScopeDescriptions(options === null || options === void 0 ? void 0 : options.scopeDescriptionFile);
|
26
|
+
this.convertSchemaComments = !!(options === null || options === void 0 ? void 0 : options.convertSchemaComments);
|
27
|
+
}
|
28
|
+
/** Load the scopes.yaml file and save in this.scopeDescriptions
|
29
|
+
* @throws Error if the file cannot be read or parsed as YAML/JSON
|
30
|
+
*/
|
31
|
+
loadScopeDescriptions(scopeDescriptionFile) {
|
32
|
+
if (!scopeDescriptionFile) {
|
33
|
+
return;
|
34
|
+
}
|
35
|
+
}
|
36
|
+
/**
|
37
|
+
* Log a message to console.warn stream if verbose is true
|
38
|
+
* @param message parameters for console.warn
|
39
|
+
*/
|
40
|
+
log(...message) {
|
41
|
+
if (this.verbose) {
|
42
|
+
this.warn(...message);
|
43
|
+
}
|
44
|
+
}
|
45
|
+
/**
|
46
|
+
* Log a message to console.warn stream. Prefix the message string with `Warning: `
|
47
|
+
* if it does not already have that text.
|
48
|
+
* @param message parameters for console.warn
|
49
|
+
*/
|
50
|
+
warn(...message) {
|
51
|
+
if (!message[0].startsWith("Warning")) {
|
52
|
+
message[0] = `Warning: ${message[0]}`;
|
53
|
+
}
|
54
|
+
console.warn(...message);
|
55
|
+
}
|
56
|
+
/**
|
57
|
+
* Log an error message to `console.error` stream. Prefix the message string with `Error: `
|
58
|
+
* if it does not already start with `'Error'`. Increments the `returnCode`, causing
|
59
|
+
* the CLI to throw an Error when done.
|
60
|
+
* @param message parameters for `console.error`
|
61
|
+
*/
|
62
|
+
error(...message) {
|
63
|
+
if (!message[0].startsWith("Error")) {
|
64
|
+
message[0] = `Error: ${message[0]}`;
|
65
|
+
}
|
66
|
+
this.returnCode++;
|
67
|
+
console.error(...message);
|
68
|
+
}
|
69
|
+
/**
|
70
|
+
* Convert the OpenAPI document to 3.0
|
71
|
+
* @returns the converted document. The input is not modified.
|
72
|
+
*/
|
73
|
+
convert() {
|
74
|
+
this.log("Converting from OpenAPI 3.1 to 3.0");
|
75
|
+
this.openapi30.openapi = "3.0.3";
|
76
|
+
this.removeLicenseIdentifier();
|
77
|
+
this.convertSchemaRef();
|
78
|
+
this.simplifyNonSchemaRef();
|
79
|
+
if (this.scopeDescriptions) {
|
80
|
+
this.convertSecuritySchemes();
|
81
|
+
}
|
82
|
+
this.convertJsonSchemaExamples();
|
83
|
+
this.convertJsonSchemaContentEncoding();
|
84
|
+
this.convertJsonSchemaContentMediaType();
|
85
|
+
this.convertConstToEnum();
|
86
|
+
this.convertNullableTypeArray();
|
87
|
+
this.removeWebhooksObject();
|
88
|
+
this.removeUnsupportedSchemaKeywords();
|
89
|
+
if (this.convertSchemaComments) {
|
90
|
+
this.renameSchema$comment();
|
91
|
+
}
|
92
|
+
else {
|
93
|
+
this.deleteSchema$comment();
|
94
|
+
}
|
95
|
+
if (this.returnCode > 0) {
|
96
|
+
throw new Error("Cannot down convert this OpenAPI definition.");
|
97
|
+
}
|
98
|
+
return this.openapi30;
|
99
|
+
}
|
100
|
+
/**
|
101
|
+
* OpenAPI 3.1 uses JSON Schema 2020-12 which allows schema `examples`;
|
102
|
+
* OpenAPI 3.0 uses JSON Scheme Draft 7 which only allows `example`.
|
103
|
+
* Replace all `examples` with `example`, using `examples[0]`
|
104
|
+
*/
|
105
|
+
convertJsonSchemaExamples() {
|
106
|
+
const schemaVisitor = (schema) => {
|
107
|
+
for (const key in schema) {
|
108
|
+
const subSchema = schema[key];
|
109
|
+
if (subSchema !== null && typeof subSchema === "object") {
|
110
|
+
if (key === "examples") {
|
111
|
+
const examples = schema["examples"];
|
112
|
+
if (Array.isArray(examples) && examples.length > 0) {
|
113
|
+
delete schema["examples"];
|
114
|
+
const first = examples[0];
|
115
|
+
if (this.deleteExampleWithId &&
|
116
|
+
first != null &&
|
117
|
+
typeof first === "object" &&
|
118
|
+
first.hasOwnProperty("id")) {
|
119
|
+
this.log(`Deleted schema example with \`id\` property:\n${this.json(examples)}`);
|
120
|
+
}
|
121
|
+
else {
|
122
|
+
schema["example"] = first;
|
123
|
+
this.log(`Replaces examples with examples[0]. Old examples:\n${this.json(examples)}`);
|
124
|
+
}
|
125
|
+
// TODO: Add an else here to check example for `id` and delete the example if this.deleteExampleWithId
|
126
|
+
// We've put most of those in `examples` so this is probably not needed, but it would be more robust.
|
127
|
+
}
|
128
|
+
}
|
129
|
+
else {
|
130
|
+
schema[key] = (0, RefVisitor_1.walkObject)(subSchema, schemaVisitor);
|
131
|
+
}
|
132
|
+
}
|
133
|
+
}
|
134
|
+
return schema;
|
135
|
+
};
|
136
|
+
(0, RefVisitor_1.visitSchemaObjects)(this.openapi30, schemaVisitor);
|
137
|
+
}
|
138
|
+
walkNestedSchemaObjects(schema, schemaVisitor) {
|
139
|
+
for (const key in schema) {
|
140
|
+
const subSchema = schema[key];
|
141
|
+
if (subSchema !== null && typeof subSchema === "object") {
|
142
|
+
schema[key] = (0, RefVisitor_1.walkObject)(subSchema, schemaVisitor);
|
143
|
+
}
|
144
|
+
}
|
145
|
+
return schema;
|
146
|
+
}
|
147
|
+
/**
|
148
|
+
* OpenAPI 3.1 uses JSON Schema 2020-12 which allows `const`
|
149
|
+
* OpenAPI 3.0 uses JSON Scheme Draft 7 which only allows `enum`.
|
150
|
+
* Replace all `const: value` with `enum: [ value ]`
|
151
|
+
*/
|
152
|
+
convertConstToEnum() {
|
153
|
+
const schemaVisitor = (schema) => {
|
154
|
+
if (schema["const"]) {
|
155
|
+
const constant = schema["const"];
|
156
|
+
delete schema["const"];
|
157
|
+
schema["enum"] = [constant];
|
158
|
+
this.log(`Converted const: ${constant} to enum`);
|
159
|
+
}
|
160
|
+
return this.walkNestedSchemaObjects(schema, schemaVisitor);
|
161
|
+
};
|
162
|
+
(0, RefVisitor_1.visitSchemaObjects)(this.openapi30, schemaVisitor);
|
163
|
+
}
|
164
|
+
/**
|
165
|
+
* Convert 2-element type arrays containing 'null' to
|
166
|
+
* string type and `nullable: true`
|
167
|
+
*/
|
168
|
+
convertNullableTypeArray() {
|
169
|
+
const schemaVisitor = (schema) => {
|
170
|
+
if (schema.hasOwnProperty("type")) {
|
171
|
+
const schemaType = schema["type"];
|
172
|
+
if (Array.isArray(schemaType) &&
|
173
|
+
schemaType.length === 2 &&
|
174
|
+
schemaType.includes("null")) {
|
175
|
+
const nonNull = schemaType.filter((_) => _ !== "null")[0];
|
176
|
+
schema["type"] = nonNull;
|
177
|
+
schema["nullable"] = true;
|
178
|
+
this.log(`Converted schema type array to nullable`);
|
179
|
+
}
|
180
|
+
}
|
181
|
+
return this.walkNestedSchemaObjects(schema, schemaVisitor);
|
182
|
+
};
|
183
|
+
(0, RefVisitor_1.visitSchemaObjects)(this.openapi30, schemaVisitor);
|
184
|
+
}
|
185
|
+
removeWebhooksObject() {
|
186
|
+
if (Object.hasOwnProperty.call(this.openapi30, "webhooks")) {
|
187
|
+
this.log(`Deleted webhooks object`);
|
188
|
+
delete this.openapi30["webhooks"];
|
189
|
+
}
|
190
|
+
}
|
191
|
+
removeUnsupportedSchemaKeywords() {
|
192
|
+
const keywordsToRemove = [
|
193
|
+
"$id",
|
194
|
+
"$schema",
|
195
|
+
"unevaluatedProperties",
|
196
|
+
"contentMediaType",
|
197
|
+
"patternProperties",
|
198
|
+
];
|
199
|
+
const schemaVisitor = (schema) => {
|
200
|
+
keywordsToRemove.forEach((key) => {
|
201
|
+
if (schema.hasOwnProperty(key)) {
|
202
|
+
delete schema[key];
|
203
|
+
this.log(`Removed unsupported schema keyword ${key}`);
|
204
|
+
}
|
205
|
+
});
|
206
|
+
return this.walkNestedSchemaObjects(schema, schemaVisitor);
|
207
|
+
};
|
208
|
+
(0, RefVisitor_1.visitSchemaObjects)(this.openapi30, schemaVisitor);
|
209
|
+
}
|
210
|
+
renameSchema$comment() {
|
211
|
+
const schemaVisitor = (schema) => {
|
212
|
+
if (schema.hasOwnProperty("$comment")) {
|
213
|
+
schema["x-comment"] = schema["$comment"];
|
214
|
+
delete schema["$comment"];
|
215
|
+
this.log(`schema $comment renamed to x-comment`);
|
216
|
+
}
|
217
|
+
return this.walkNestedSchemaObjects(schema, schemaVisitor);
|
218
|
+
};
|
219
|
+
(0, RefVisitor_1.visitSchemaObjects)(this.openapi30, schemaVisitor);
|
220
|
+
}
|
221
|
+
deleteSchema$comment() {
|
222
|
+
const schemaVisitor = (schema) => {
|
223
|
+
if (schema.hasOwnProperty("$comment")) {
|
224
|
+
const comment = schema["$comment"];
|
225
|
+
delete schema["$comment"];
|
226
|
+
this.log(`schema $comment deleted: ${comment}`);
|
227
|
+
}
|
228
|
+
return this.walkNestedSchemaObjects(schema, schemaVisitor);
|
229
|
+
};
|
230
|
+
(0, RefVisitor_1.visitSchemaObjects)(this.openapi30, schemaVisitor);
|
231
|
+
}
|
232
|
+
/**
|
233
|
+
* Convert
|
234
|
+
* ```
|
235
|
+
* contentMediaType: 'application/octet-stream'
|
236
|
+
* ```
|
237
|
+
* to
|
238
|
+
* ```
|
239
|
+
* format: binary
|
240
|
+
* ```
|
241
|
+
* in `type: string` schemas.
|
242
|
+
* Warn if schema has a `format` already and it is not `binary`.
|
243
|
+
*/
|
244
|
+
convertJsonSchemaContentMediaType() {
|
245
|
+
const schemaVisitor = (schema) => {
|
246
|
+
if (schema.hasOwnProperty("type") &&
|
247
|
+
schema["type"] === "string" &&
|
248
|
+
schema.hasOwnProperty("contentMediaType") &&
|
249
|
+
schema["contentMediaType"] === "application/octet-stream") {
|
250
|
+
if (schema.hasOwnProperty("format")) {
|
251
|
+
if (schema["format"] === "binary") {
|
252
|
+
this.log(`Deleted schema contentMediaType: application/octet-stream (leaving format: binary)`);
|
253
|
+
delete schema["contentMediaType"];
|
254
|
+
}
|
255
|
+
else {
|
256
|
+
this.error(`Unable to down-convert schema with contentMediaType: application/octet-stream to format: binary because the schema already has a format (${schema["format"]})`);
|
257
|
+
}
|
258
|
+
}
|
259
|
+
else {
|
260
|
+
delete schema["contentMediaType"];
|
261
|
+
schema["format"] = "binary";
|
262
|
+
this.log(`Converted schema contentMediaType: application/octet-stream to format: binary`);
|
263
|
+
}
|
264
|
+
}
|
265
|
+
return this.walkNestedSchemaObjects(schema, schemaVisitor);
|
266
|
+
};
|
267
|
+
(0, RefVisitor_1.visitSchemaObjects)(this.openapi30, schemaVisitor);
|
268
|
+
}
|
269
|
+
/**
|
270
|
+
* Convert
|
271
|
+
* ```
|
272
|
+
* contentEncoding: base64
|
273
|
+
* ```
|
274
|
+
* to
|
275
|
+
* ```
|
276
|
+
* format: byte
|
277
|
+
* ```
|
278
|
+
* in `type: string` schemas. It is an error if the schema has a `format` already
|
279
|
+
* and it is not `byte`.
|
280
|
+
*/
|
281
|
+
convertJsonSchemaContentEncoding() {
|
282
|
+
const schemaVisitor = (schema) => {
|
283
|
+
if (schema.hasOwnProperty("type") &&
|
284
|
+
schema["type"] === "string" &&
|
285
|
+
schema.hasOwnProperty("contentEncoding")) {
|
286
|
+
if (schema["contentEncoding"] === "base64") {
|
287
|
+
if (schema.hasOwnProperty("format")) {
|
288
|
+
if (schema["format"] === "byte") {
|
289
|
+
this.log(`Deleted schema contentEncoding: base64 (leaving format: byte)`);
|
290
|
+
delete schema["contentEncoding"];
|
291
|
+
}
|
292
|
+
else {
|
293
|
+
this.error(`Unable to down-convert schema contentEncoding: base64 to format: byte because the schema already has a format (${schema["format"]})`);
|
294
|
+
}
|
295
|
+
}
|
296
|
+
else {
|
297
|
+
delete schema["contentEncoding"];
|
298
|
+
schema["format"] = "byte";
|
299
|
+
this.log(`Converted schema: 'contentEncoding: base64' to 'format: byte'`);
|
300
|
+
}
|
301
|
+
}
|
302
|
+
else {
|
303
|
+
this.error(`Unable to down-convert contentEncoding: ${schema["contentEncoding"]}`);
|
304
|
+
}
|
305
|
+
}
|
306
|
+
return this.walkNestedSchemaObjects(schema, schemaVisitor);
|
307
|
+
};
|
308
|
+
(0, RefVisitor_1.visitSchemaObjects)(this.openapi30, schemaVisitor);
|
309
|
+
}
|
310
|
+
json(x) {
|
311
|
+
return JSON.stringify(x, null, 2);
|
312
|
+
}
|
313
|
+
/**
|
314
|
+
* OpenAPI 3.1 defines a new `openIdConnect` security scheme.
|
315
|
+
* Down-convert the scheme to `oauth2` / authorization code flow.
|
316
|
+
* Collect all the scopes used in any security requirements within
|
317
|
+
* operations and add them to the scheme. Also define the
|
318
|
+
* URLs to the `authorizationUrl` and `tokenUrl` of `oauth2`.
|
319
|
+
*/
|
320
|
+
convertSecuritySchemes() {
|
321
|
+
var _a, _b, _c;
|
322
|
+
const oauth2Scopes = (schemeName) => {
|
323
|
+
var _a, _b;
|
324
|
+
const scopes = {};
|
325
|
+
const paths = (_b = (_a = this.openapi30) === null || _a === void 0 ? void 0 : _a.paths) !== null && _b !== void 0 ? _b : {};
|
326
|
+
for (const path in paths) {
|
327
|
+
for (const op in paths[path]) {
|
328
|
+
if (op === "parameters") {
|
329
|
+
continue;
|
330
|
+
}
|
331
|
+
const operation = paths[path][op];
|
332
|
+
const sec = operation === null || operation === void 0 ? void 0 : operation.security;
|
333
|
+
sec.forEach((s) => {
|
334
|
+
const requirement = s === null || s === void 0 ? void 0 : s[schemeName];
|
335
|
+
if (requirement) {
|
336
|
+
requirement.forEach((scope) => {
|
337
|
+
var _a, _b;
|
338
|
+
scopes[scope] =
|
339
|
+
(_b = (_a = this.scopeDescriptions) === null || _a === void 0 ? void 0 : _a[scope]) !== null && _b !== void 0 ? _b : `TODO: describe the '${scope}' scope`;
|
340
|
+
});
|
341
|
+
}
|
342
|
+
});
|
343
|
+
}
|
344
|
+
}
|
345
|
+
return scopes;
|
346
|
+
};
|
347
|
+
const schemes = (_c = (_b = (_a = this.openapi30) === null || _a === void 0 ? void 0 : _a.components) === null || _b === void 0 ? void 0 : _b["securitySchemes"]) !== null && _c !== void 0 ? _c : {};
|
348
|
+
for (const schemeName in schemes) {
|
349
|
+
const scheme = schemes[schemeName];
|
350
|
+
const type = scheme.type;
|
351
|
+
if (type === "openIdConnect") {
|
352
|
+
this.log(`Converting openIdConnect security scheme to oauth2/authorizationCode`);
|
353
|
+
scheme.type = "oauth2";
|
354
|
+
const openIdConnectUrl = scheme.openIdConnectUrl;
|
355
|
+
scheme.description = `OAuth2 Authorization Code Flow. The client may
|
356
|
+
GET the OpenID Connect configuration JSON from \`${openIdConnectUrl}\`
|
357
|
+
to get the correct \`authorizationUrl\` and \`tokenUrl\`.`;
|
358
|
+
delete scheme.openIdConnectUrl;
|
359
|
+
const scopes = oauth2Scopes(schemeName);
|
360
|
+
scheme.flows = {
|
361
|
+
authorizationCode: {
|
362
|
+
// TODO: add options for these URLs
|
363
|
+
authorizationUrl: this.authorizationUrl,
|
364
|
+
tokenUrl: this.tokenUrl,
|
365
|
+
scopes: scopes,
|
366
|
+
},
|
367
|
+
};
|
368
|
+
}
|
369
|
+
}
|
370
|
+
}
|
371
|
+
/**
|
372
|
+
* Find remaining OpenAPI 3.0 [Reference Objects](https://github.com/OAI/OpenAPI-Specification/blob/main/versions/3.1.0.md#referenceObject)
|
373
|
+
* and down convert them to [JSON Reference](https://tools.ietf.org/html/draft-pbryan-zyp-json-ref-03) objects
|
374
|
+
* with _only_ a `$ref` property.
|
375
|
+
*/
|
376
|
+
simplifyNonSchemaRef() {
|
377
|
+
(0, RefVisitor_1.visitRefObjects)(this.openapi30, (node) => {
|
378
|
+
if (Object.keys(node).length === 1) {
|
379
|
+
return node;
|
380
|
+
}
|
381
|
+
else {
|
382
|
+
this.log(`Down convert reference object to JSON Reference:\n${JSON.stringify(node, null, 3)}`);
|
383
|
+
Object.keys(node)
|
384
|
+
.filter((key) => key !== "$ref")
|
385
|
+
.forEach((key) => delete node[key]);
|
386
|
+
return node;
|
387
|
+
}
|
388
|
+
});
|
389
|
+
}
|
390
|
+
removeLicenseIdentifier() {
|
391
|
+
var _a, _b, _c;
|
392
|
+
if ((_c = (_b = (_a = this.openapi30) === null || _a === void 0 ? void 0 : _a["info"]) === null || _b === void 0 ? void 0 : _b["license"]) === null || _c === void 0 ? void 0 : _c["identifier"]) {
|
393
|
+
this.log(`Removed info.license.identifier: ${this.openapi30["info"]["license"]["identifier"]}`);
|
394
|
+
delete this.openapi30["info"]["license"]["identifier"];
|
395
|
+
}
|
396
|
+
}
|
397
|
+
// This transformation ends up breaking openapi-generator
|
398
|
+
// SDK gen (typescript-axios, typescript-angular)
|
399
|
+
// so it is disabled unless the `allOfTransform` option is `true`.
|
400
|
+
convertSchemaRef() {
|
401
|
+
/**
|
402
|
+
* In a JSON Schema, replace `{ blah blah, $ref: "uri"}`
|
403
|
+
* with `{ blah blah, allOf: [ $ref: "uri" ]}`
|
404
|
+
* @param object an object that may contain JSON schemas (directly
|
405
|
+
* or in sub-objects)
|
406
|
+
*/
|
407
|
+
const simplifyRefObjectsInSchemas = (object) => {
|
408
|
+
return (0, RefVisitor_1.visitRefObjects)(object, (node) => {
|
409
|
+
if (Object.keys(node).length === 1) {
|
410
|
+
return node;
|
411
|
+
}
|
412
|
+
else {
|
413
|
+
this.log(`Converting JSON Schema $ref ${this.json(node)} to allOf: [ $ref ]`);
|
414
|
+
node["allOf"] = [{ $ref: node.$ref }];
|
415
|
+
delete node.$ref;
|
416
|
+
return node;
|
417
|
+
}
|
418
|
+
});
|
419
|
+
};
|
420
|
+
if (this.allOfTransform) {
|
421
|
+
(0, RefVisitor_1.visitSchemaObjects)(this.openapi30, (schema) => {
|
422
|
+
return simplifyRefObjectsInSchemas(schema);
|
423
|
+
});
|
424
|
+
}
|
425
|
+
}
|
426
|
+
static deepClone(obj) {
|
427
|
+
return JSON.parse(JSON.stringify(obj)); // kinda simple way to clone, but it works...
|
428
|
+
}
|
429
|
+
}
|
430
|
+
exports.Converter = Converter;
|
431
|
+
//# sourceMappingURL=converter.js.map
|
@@ -0,0 +1 @@
|
|
1
|
+
{"version":3,"file":"converter.js","sourceRoot":"","sources":["../../../src/utils/openapi-down-convert/converter.ts"],"names":[],"mappings":";;;AAAA,+EAA+E;AAC/E,6CAOsB;AAyCtB,MAAa,SAAS;IAYpB;;;OAGG;IACH,YAAY,eAAuB,EAAE,OAA0B;QAdvD,YAAO,GAAG,KAAK,CAAC;QAChB,wBAAmB,GAAG,KAAK,CAAC;QAC5B,mBAAc,GAAG,KAAK,CAAC;QAIvB,sBAAiB,GAAG,SAAS,CAAC;QAC9B,0BAAqB,GAAG,KAAK,CAAC;QAC9B,eAAU,GAAG,CAAC,CAAC;QAOrB,IAAI,CAAC,SAAS,GAAG,SAAS,CAAC,SAAS,CAAC,eAAe,CAAa,CAAC;QAClE,IAAI,CAAC,OAAO,GAAG,OAAO,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,OAAO,CAAC,CAAC;QACzC,IAAI,CAAC,mBAAmB,GAAG,OAAO,CAAC,OAAO,aAAP,OAAO,uBAAP,OAAO,CAAE,mBAAmB,CAAC,CAAC;QACjE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AO,IAAA,4BAAe,EAAC,MAAM,EAAE,CAAC,IAAS,EAAY,EAAE;gBACrD,IAAI,MAAM,CAAC,IAAI,CAAC,IAAI,CAAC,CAAC,MAAM,KAAK,CAAC,EAAE,CAAC;oBACnC,OAAO,IAAI,CAAC;gBACd,CAAC;qBAAM,CAAC;oBACN,IAAI,CAAC,GAAG,CACN,+BAA+B,IAAI,CAAC,IAAI,CAAC,IAAI,CAAC,qBAAqB,CACpE,CAAC;oBACF,IAAI,CAAC,OAAO,CAAC,GAAG,CAAC,EAAE,IAAI,EAAE,IAAI,CAAC,IAAI,EAAE,CAAC,CAAC;oBACtC,OAAO,IAAI,CAAC,IAAI,CAAC;oBACjB,OAAO,IAAI,CAAC;gBACd,CAAC;YACH,CAAC,CAAC,CAAC;QACL,CAAC,CAAC;QAEF,IAAI,IAAI,CAAC,cAAc,EAAE,CAAC;YACxB,IAAA,+BAAkB,EAChB,IAAI,CAAC,SAAS,EACd,CAAC,MAAoB,EAAgB,EAAE;gBACrC,OAAO,2BAA2B,CAAC,MAAM,CAAC,CAAC;YAC7C,CAAC,CACF,CAAC;QACJ,CAAC;IACH,CAAC;IAEM,MAAM,CAAC,SAAS,CAAC,GAAW;QACjC,OAAO,IAAI,CAAC,KAAK,CAAC,IAAI,CAAC,SAAS,CAAC,GAAG,CAAC,CAAC,CAAC,CAAC,6CAA6C;IACvF,CAAC;CACF;AA7dD,8BA6dC"}
|
package/package.json
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
{
|
2
2
|
"name": "@nestia/migrate",
|
3
|
-
"version": "0.
|
3
|
+
"version": "0.11.1",
|
4
4
|
"description": "Migration program from swagger to NestJS",
|
5
5
|
"main": "lib/index.js",
|
6
6
|
"typings": "lib/index.d.ts",
|
@@ -34,17 +34,18 @@
|
|
34
34
|
},
|
35
35
|
"homepage": "https://nestia.io",
|
36
36
|
"devDependencies": {
|
37
|
-
"@nestia/core": "^2.
|
37
|
+
"@nestia/core": "^2.6.0",
|
38
38
|
"@nestia/e2e": "^0.4.1",
|
39
|
-
"@nestia/fetcher": "^2.
|
40
|
-
"@nestjs/common": "^10.3.
|
41
|
-
"@nestjs/core": "^10.3.
|
42
|
-
"@nestjs/platform-express": "^10.3.
|
43
|
-
"@nestjs/platform-fastify": "^10.3.
|
39
|
+
"@nestia/fetcher": "^2.6.0",
|
40
|
+
"@nestjs/common": "^10.3.5",
|
41
|
+
"@nestjs/core": "^10.3.5",
|
42
|
+
"@nestjs/platform-express": "^10.3.5",
|
43
|
+
"@nestjs/platform-fastify": "^10.3.5",
|
44
44
|
"@trivago/prettier-plugin-sort-imports": "^4.3.0",
|
45
45
|
"@types/express": "^4.17.21",
|
46
46
|
"@types/inquirer": "^9.0.7",
|
47
47
|
"@types/node": "^20.3.3",
|
48
|
+
"@types/swagger2openapi": "^7.0.4",
|
48
49
|
"dotenv": "^16.3.1",
|
49
50
|
"dotenv-expand": "^10.0.0",
|
50
51
|
"rimraf": "^5.0.1",
|
@@ -55,9 +56,12 @@
|
|
55
56
|
"typescript-transform-paths": "^3.4.6"
|
56
57
|
},
|
57
58
|
"dependencies": {
|
59
|
+
"@apiture/openapi-down-convert": "^0.13.0",
|
58
60
|
"commander": "10.0.0",
|
59
61
|
"inquirer": "8.2.5",
|
62
|
+
"openapi-types": "^12.1.3",
|
60
63
|
"prettier": "^3.2.5",
|
64
|
+
"swagger2openapi": "^7.0.8",
|
61
65
|
"tstl": "^2.5.13",
|
62
66
|
"typescript": "^5.4.2",
|
63
67
|
"typia": "^5.5.7"
|
@@ -10,19 +10,28 @@ import { MigrateNestProgrammer } from "./programmers/MigrateNestProgrammer";
|
|
10
10
|
import { IMigrateFile } from "./structures/IMigrateFile";
|
11
11
|
import { IMigrateProgram } from "./structures/IMigrateProgram";
|
12
12
|
import { ISwagger } from "./structures/ISwagger";
|
13
|
+
import { ISwaggerV20 } from "./structures/ISwaggerV20";
|
14
|
+
import { ISwaggerV31 } from "./structures/ISwaggerV31";
|
15
|
+
import { OpenApiConverter } from "./utils/OpenApiConverter";
|
13
16
|
|
14
17
|
export class MigrateApplication {
|
15
18
|
private constructor(public readonly swagger: ISwagger) {}
|
16
19
|
|
17
|
-
public static create(
|
20
|
+
public static async create(
|
21
|
+
swagger: ISwagger | ISwaggerV20 | ISwaggerV31,
|
22
|
+
): Promise<IValidation<MigrateApplication>> {
|
23
|
+
swagger = typia.is<ISwaggerV20.IVersion>(swagger)
|
24
|
+
? await OpenApiConverter.v2_0(swagger)
|
25
|
+
: typia.is<ISwaggerV31.IVersion>(swagger)
|
26
|
+
? OpenApiConverter.v3_1(swagger)
|
27
|
+
: swagger;
|
18
28
|
const result = typia.validate<ISwagger>(swagger);
|
19
|
-
if (result.success)
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
return result;
|
29
|
+
if (result.success === false) return result;
|
30
|
+
return {
|
31
|
+
success: true,
|
32
|
+
data: new MigrateApplication(swagger),
|
33
|
+
errors: [],
|
34
|
+
};
|
26
35
|
}
|
27
36
|
|
28
37
|
public nest(config: MigrateApplication.IConfig): MigrateApplication.IOutput {
|
@@ -35,7 +35,7 @@ export namespace MigrateCommander {
|
|
35
35
|
})();
|
36
36
|
|
37
37
|
const result: IValidation<MigrateApplication> =
|
38
|
-
MigrateApplication.create(swagger);
|
38
|
+
await MigrateApplication.create(swagger);
|
39
39
|
if (result.success === false) {
|
40
40
|
console.log(result.errors);
|
41
41
|
throw new Error(
|
@@ -1,23 +1,23 @@
|
|
1
|
-
import { ISwaggerComponents } from "./ISwaggerComponents";
|
2
|
-
import { ISwaggerInfo } from "./ISwaggerInfo";
|
3
|
-
import { ISwaggerRoute } from "./ISwaggerRoute";
|
4
|
-
|
5
|
-
export interface ISwagger {
|
6
|
-
openapi: `3.0.${number}`;
|
7
|
-
info: ISwaggerInfo;
|
8
|
-
servers: ISwagger.IServer[];
|
9
|
-
|
10
|
-
components: ISwaggerComponents;
|
11
|
-
paths: Record<string, ISwagger.IPath>;
|
12
|
-
security?: Record<string, string[]>[];
|
13
|
-
}
|
14
|
-
export namespace ISwagger {
|
15
|
-
export interface IServer {
|
16
|
-
url: string;
|
17
|
-
description?: string;
|
18
|
-
}
|
19
|
-
export type IPath = Record<
|
20
|
-
"get" | "post" | "patch" | "put" | "delete",
|
21
|
-
ISwaggerRoute | undefined
|
22
|
-
>;
|
23
|
-
}
|
1
|
+
import { ISwaggerComponents } from "./ISwaggerComponents";
|
2
|
+
import { ISwaggerInfo } from "./ISwaggerInfo";
|
3
|
+
import { ISwaggerRoute } from "./ISwaggerRoute";
|
4
|
+
|
5
|
+
export interface ISwagger {
|
6
|
+
openapi: `3.0.${number}`;
|
7
|
+
info: ISwaggerInfo;
|
8
|
+
servers: ISwagger.IServer[];
|
9
|
+
|
10
|
+
components: ISwaggerComponents;
|
11
|
+
paths: Record<string, ISwagger.IPath>;
|
12
|
+
security?: Record<string, string[]>[];
|
13
|
+
}
|
14
|
+
export namespace ISwagger {
|
15
|
+
export interface IServer {
|
16
|
+
url: string;
|
17
|
+
description?: string;
|
18
|
+
}
|
19
|
+
export type IPath = Record<
|
20
|
+
"get" | "post" | "patch" | "put" | "delete",
|
21
|
+
ISwaggerRoute | undefined
|
22
|
+
>;
|
23
|
+
}
|
@@ -0,0 +1,19 @@
|
|
1
|
+
import V2_0Converter from "swagger2openapi";
|
2
|
+
import typia from "typia";
|
3
|
+
|
4
|
+
import { ISwagger } from "../structures/ISwagger";
|
5
|
+
import { ISwaggerV20 } from "../structures/ISwaggerV20";
|
6
|
+
import { ISwaggerV31 } from "../structures/ISwaggerV31";
|
7
|
+
import { Converter as V3_1Converter } from "./openapi-down-convert/converter";
|
8
|
+
|
9
|
+
export namespace OpenApiConverter {
|
10
|
+
export const v2_0 = async (swagger: ISwaggerV20): Promise<ISwagger> => {
|
11
|
+
const output = await V2_0Converter.convertObj(swagger, {});
|
12
|
+
return typia.assert<ISwagger>(output.openapi);
|
13
|
+
};
|
14
|
+
|
15
|
+
export const v3_1 = (swagger: ISwaggerV31): ISwagger => {
|
16
|
+
const converter = new V3_1Converter(swagger);
|
17
|
+
return typia.assert<ISwagger>(converter.convert() as ISwagger);
|
18
|
+
};
|
19
|
+
}
|