@typia/utils 12.0.0-dev.20260316 → 12.0.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.
@@ -1,375 +1,375 @@
1
- import {
2
- OpenApi,
3
- OpenApiV3,
4
- OpenApiV3_1,
5
- OpenApiV3_2,
6
- SwaggerV2,
7
- } from "@typia/interface";
8
-
9
- import { OpenApiV3Downgrader } from "./internal/OpenApiV3Downgrader";
10
- import { OpenApiV3Upgrader } from "./internal/OpenApiV3Upgrader";
11
- import { OpenApiV3_1Downgrader } from "./internal/OpenApiV3_1Downgrader";
12
- import { OpenApiV3_1Upgrader } from "./internal/OpenApiV3_1Upgrader";
13
- import { OpenApiV3_2Upgrader } from "./internal/OpenApiV3_2Upgrader";
14
- import { SwaggerV2Downgrader } from "./internal/SwaggerV2Downgrader";
15
- import { SwaggerV2Upgrader } from "./internal/SwaggerV2Upgrader";
16
-
17
- /**
18
- * OpenAPI version converter.
19
- *
20
- * `OpenApiConverter` converts between different OpenAPI specification versions:
21
- * Swagger v2.0, OpenAPI v3.0, OpenAPI v3.1, OpenAPI v3.2, and typia's emended
22
- * {@link OpenApi} format. Also converts individual components (schemas,
23
- * operations, paths).
24
- *
25
- * Upgrade path (to emended v3.2):
26
- *
27
- * - Swagger v2.0 → emended v3.2
28
- * - OpenAPI v3.0 → emended v3.2
29
- * - OpenAPI v3.1 → emended v3.2
30
- * - OpenAPI v3.2 → emended v3.2
31
- *
32
- * Downgrade path (from emended v3.2):
33
- *
34
- * - Emended v3.2 → Swagger v2.0
35
- * - Emended v3.2 → OpenAPI v3.0
36
- * - Emended v3.2 → OpenAPI v3.1
37
- *
38
- * The emended format normalizes ambiguous expressions: dereferences `$ref`,
39
- * merges `allOf`, converts `nullable` to union types, etc.
40
- *
41
- * @author Jeongho Nam - https://github.com/samchon
42
- */
43
- export namespace OpenApiConverter {
44
- /* -----------------------------------------------------------
45
- DOCUMENTS
46
- ----------------------------------------------------------- */
47
- /**
48
- * Upgrade document to typia's emended OpenAPI v3.2 format.
49
- *
50
- * @param document Source document (Swagger v2.0, OpenAPI v3.0/v3.1/v3.2)
51
- * @returns Emended OpenAPI v3.2 document
52
- */
53
- export function upgradeDocument(
54
- document:
55
- | SwaggerV2.IDocument
56
- | OpenApiV3.IDocument
57
- | OpenApiV3_1.IDocument
58
- | OpenApiV3_2.IDocument
59
- | OpenApi.IDocument,
60
- ): OpenApi.IDocument {
61
- if (isUpgraded(document)) return document;
62
- else if (is_v32(document)) return OpenApiV3_2Upgrader.convert(document);
63
- else if (is_v31(document)) return OpenApiV3_1Upgrader.convert(document);
64
- else if (is_v30(document)) return OpenApiV3Upgrader.convert(document);
65
- else if (is_v20(document)) return SwaggerV2Upgrader.convert(document);
66
- document satisfies never;
67
- throw new Error("Invalid OpenAPI document");
68
- }
69
-
70
- /**
71
- * Downgrade document to Swagger v2.0 format.
72
- *
73
- * @param document Source emended OpenAPI document
74
- * @param version Target version "2.0"
75
- * @returns Swagger v2.0 document
76
- */
77
- export function downgradeDocument(
78
- document: OpenApi.IDocument,
79
- version: "2.0",
80
- ): SwaggerV2.IDocument;
81
-
82
- /**
83
- * Downgrade document to OpenAPI v3.0 format.
84
- *
85
- * @param document Source emended OpenAPI document
86
- * @param version Target version "3.0"
87
- * @returns OpenAPI v3.0 document
88
- */
89
- export function downgradeDocument(
90
- document: OpenApi.IDocument,
91
- version: "3.0",
92
- ): OpenApiV3.IDocument;
93
-
94
- export function downgradeDocument(
95
- document: OpenApi.IDocument,
96
- version: "3.1",
97
- ): OpenApiV3_1.IDocument;
98
-
99
- /** @internal */
100
- export function downgradeDocument(
101
- document: OpenApi.IDocument,
102
- version: "2.0" | "3.0" | "3.1",
103
- ): SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument {
104
- if (version === "2.0") return SwaggerV2Downgrader.downgrade(document);
105
- else if (version === "3.0") return OpenApiV3Downgrader.downgrade(document);
106
- else if (version === "3.1")
107
- return OpenApiV3_1Downgrader.downgrade(document);
108
-
109
- version satisfies never;
110
- throw new Error("Invalid OpenAPI version");
111
- }
112
-
113
- /* -----------------------------------------------------------
114
- COMPONENTS
115
- ----------------------------------------------------------- */
116
- /**
117
- * Upgrade components to typia's emended format.
118
- *
119
- * @param input Source components (Swagger v2.0, OpenAPI v3.0/v3.1/v3.2)
120
- * @returns Emended OpenAPI components
121
- */
122
- export function upgradeComponents(
123
- input:
124
- | OpenApiV3_2.IComponents
125
- | OpenApiV3_1.IComponents
126
- | OpenApiV3.IComponents
127
- | SwaggerV2.IDocument,
128
- ): OpenApi.IComponents {
129
- if (is_v20(input)) return SwaggerV2Upgrader.convertComponents(input);
130
- return OpenApiV3_1Upgrader.convertComponents(input as any);
131
- }
132
-
133
- /**
134
- * Downgrade components to Swagger v2.0 definitions.
135
- *
136
- * @param input Source emended components
137
- * @param version Target version "2.0"
138
- * @returns Swagger v2.0 definitions record
139
- */
140
- export function downgradeComponents(
141
- input: OpenApi.IComponents,
142
- version: "2.0",
143
- ): Record<string, SwaggerV2.IJsonSchema>;
144
-
145
- /**
146
- * Downgrade components to OpenAPI v3.0 format.
147
- *
148
- * @param input Source emended components
149
- * @param version Target version "3.0"
150
- * @returns OpenAPI v3.0 components
151
- */
152
- export function downgradeComponents(
153
- input: OpenApi.IComponents,
154
- version: "3.0",
155
- ): OpenApiV3.IComponents;
156
-
157
- /**
158
- * Downgrade components to OpenAPI v3.1 format.
159
- *
160
- * @param input Source emended components
161
- * @param version Target version "3.1"
162
- * @returns OpenAPI v3.1 components
163
- */
164
- export function downgradeComponents(
165
- input: OpenApi.IComponents,
166
- version: "3.1",
167
- ): OpenApiV3_1.IComponents;
168
-
169
- /** @internal */
170
- export function downgradeComponents(
171
- input: OpenApi.IComponents,
172
- version: "2.0" | "3.0" | "3.1",
173
- ):
174
- | Record<string, SwaggerV2.IJsonSchema>
175
- | OpenApiV3.IComponents
176
- | OpenApiV3_1.IComponents {
177
- if (version === "2.0")
178
- return SwaggerV2Downgrader.downgradeComponents(input).downgraded;
179
- if (version === "3.1")
180
- return OpenApiV3_1Downgrader.downgradeComponents(input).downgraded;
181
- return OpenApiV3Downgrader.downgradeComponents(input).downgraded;
182
- }
183
-
184
- /* -----------------------------------------------------------
185
- SCHEMAS
186
- ----------------------------------------------------------- */
187
- /**
188
- * Upgrade Swagger v2.0 schema to emended format.
189
- *
190
- * @param props.definitions Swagger v2.0 definitions
191
- * @param props.schema Schema to upgrade
192
- * @returns Emended JSON schema
193
- */
194
- export function upgradeSchema(props: {
195
- definitions: Record<string, SwaggerV2.IJsonSchema>;
196
- schema: SwaggerV2.IJsonSchema;
197
- }): OpenApi.IJsonSchema;
198
-
199
- /**
200
- * Upgrade OpenAPI v3.0 schema to emended format.
201
- *
202
- * @param props.components OpenAPI v3.0 components
203
- * @param props.schema Schema to upgrade
204
- * @returns Emended JSON schema
205
- */
206
- export function upgradeSchema(props: {
207
- components: OpenApiV3.IComponents;
208
- schema: OpenApiV3.IJsonSchema;
209
- }): OpenApi.IJsonSchema;
210
-
211
- /**
212
- * Upgrade OpenAPI v3.1 schema to emended format.
213
- *
214
- * @param props.components OpenAPI v3.1 components
215
- * @param props.schema Schema to upgrade
216
- * @returns Emended JSON schema
217
- */
218
- export function upgradeSchema(props: {
219
- components: OpenApiV3_1.IComponents;
220
- schema: OpenApiV3_1.IJsonSchema;
221
- }): OpenApi.IJsonSchema;
222
-
223
- /**
224
- * Upgrade OpenAPI v3.2 schema to emended format.
225
- *
226
- * @param props.components OpenAPI v3.2 components
227
- * @param props.schema Schema to upgrade
228
- * @returns Emended JSON schema
229
- */
230
- export function upgradeSchema(props: {
231
- components: OpenApiV3_2.IComponents;
232
- schema: OpenApiV3_2.IJsonSchema;
233
- }): OpenApi.IJsonSchema;
234
-
235
- /** @internal */
236
- export function upgradeSchema(
237
- props:
238
- | {
239
- definitions: Record<string, SwaggerV2.IJsonSchema>;
240
- schema: SwaggerV2.IJsonSchema;
241
- }
242
- | {
243
- components: OpenApiV3.IComponents;
244
- schema: OpenApiV3.IJsonSchema;
245
- }
246
- | {
247
- components: OpenApiV3_1.IComponents;
248
- schema: OpenApiV3_1.IJsonSchema;
249
- }
250
- | {
251
- components: OpenApiV3_2.IComponents;
252
- schema: OpenApiV3_2.IJsonSchema;
253
- },
254
- ): OpenApi.IJsonSchema {
255
- if ("definitions" in props)
256
- return SwaggerV2Upgrader.convertSchema(props.definitions)(props.schema);
257
- return OpenApiV3_1Upgrader.convertSchema(props.components as any)(
258
- props.schema as any,
259
- );
260
- }
261
-
262
- /**
263
- * Downgrade schema to Swagger v2.0 format.
264
- *
265
- * @param props.components Source emended components
266
- * @param props.schema Schema to downgrade
267
- * @param props.version Target version "2.0"
268
- * @param props.downgraded Target definitions record (mutated)
269
- * @returns Swagger v2.0 schema
270
- */
271
- export function downgradeSchema(props: {
272
- components: OpenApi.IComponents;
273
- schema: OpenApi.IJsonSchema;
274
- version: "2.0";
275
- downgraded: Record<string, SwaggerV2.IJsonSchema>;
276
- }): SwaggerV2.IJsonSchema;
277
-
278
- /**
279
- * Downgrade schema to OpenAPI v3.0 format.
280
- *
281
- * @param props.components Source emended components
282
- * @param props.schema Schema to downgrade
283
- * @param props.version Target version "3.0"
284
- * @param props.downgraded Target components (mutated)
285
- * @returns OpenAPI v3.0 schema
286
- */
287
- export function downgradeSchema(props: {
288
- components: OpenApi.IComponents;
289
- schema: OpenApi.IJsonSchema;
290
- version: "3.0";
291
- downgraded: OpenApiV3.IComponents;
292
- }): OpenApiV3.IJsonSchema;
293
-
294
- /**
295
- * Downgrade schema to OpenAPI v3.1 format.
296
- *
297
- * @param props.components Source emended components
298
- * @param props.schema Schema to downgrade
299
- * @param props.version Target version "3.1"
300
- * @param props.downgraded Target components (mutated)
301
- * @returns OpenAPI v3.1 schema
302
- */
303
- export function downgradeSchema(props: {
304
- components: OpenApi.IComponents;
305
- schema: OpenApi.IJsonSchema;
306
- version: "3.1";
307
- downgraded: OpenApiV3_1.IComponents;
308
- }): OpenApiV3_1.IJsonSchema;
309
-
310
- /** @internal */
311
- export function downgradeSchema<Version extends "2.0" | "3.0" | "3.1">(props: {
312
- components: OpenApi.IComponents;
313
- schema: OpenApi.IJsonSchema;
314
- version: Version;
315
- downgraded: Version extends "2.0"
316
- ? Record<string, SwaggerV2.IJsonSchema>
317
- : Version extends "3.1"
318
- ? OpenApiV3_1.IComponents
319
- : OpenApiV3.IComponents;
320
- }):
321
- | OpenApiV3.IJsonSchema
322
- | OpenApiV3_1.IJsonSchema
323
- | SwaggerV2.IJsonSchema {
324
- if (props.version === "2.0")
325
- return SwaggerV2Downgrader.downgradeSchema({
326
- original: props.components,
327
- downgraded: props.downgraded as Record<string, SwaggerV2.IJsonSchema>,
328
- })(props.schema);
329
- if (props.version === "3.1")
330
- return OpenApiV3_1Downgrader.downgradeSchema({
331
- original: props.components,
332
- downgraded: props.downgraded as OpenApiV3_1.IComponents,
333
- })(props.schema);
334
- return OpenApiV3Downgrader.downgradeSchema({
335
- original: props.components,
336
- downgraded: props.downgraded as OpenApiV3.IComponents,
337
- })(props.schema);
338
- }
339
- }
340
-
341
- const is_v20 = (input: unknown): input is SwaggerV2.IDocument =>
342
- typeof input === "object" &&
343
- input !== null &&
344
- "swagger" in input &&
345
- typeof input.swagger === "string" &&
346
- input.swagger.startsWith("2.0");
347
-
348
- const is_v30 = (input: unknown): input is OpenApiV3.IDocument =>
349
- typeof input === "object" &&
350
- input !== null &&
351
- "openapi" in input &&
352
- typeof input.openapi === "string" &&
353
- input.openapi.startsWith("3.0");
354
-
355
- const is_v31 = (input: unknown): input is OpenApiV3_1.IDocument =>
356
- typeof input === "object" &&
357
- input !== null &&
358
- "openapi" in input &&
359
- typeof input.openapi === "string" &&
360
- input.openapi.startsWith("3.1");
361
-
362
- const is_v32 = (input: unknown): input is OpenApiV3_2.IDocument =>
363
- typeof input === "object" &&
364
- input !== null &&
365
- "openapi" in input &&
366
- typeof input.openapi === "string" &&
367
- input.openapi.startsWith("3.2");
368
-
369
- const isUpgraded = (input: unknown): input is OpenApi.IDocument =>
370
- typeof input === "object" &&
371
- input !== null &&
372
- "openapi" in input &&
373
- typeof input.openapi === "string" &&
374
- input.openapi.startsWith("3.2") &&
375
- (input as OpenApi.IDocument)["x-typia-emended-v12"] === true;
1
+ import {
2
+ OpenApi,
3
+ OpenApiV3,
4
+ OpenApiV3_1,
5
+ OpenApiV3_2,
6
+ SwaggerV2,
7
+ } from "@typia/interface";
8
+
9
+ import { OpenApiV3Downgrader } from "./internal/OpenApiV3Downgrader";
10
+ import { OpenApiV3Upgrader } from "./internal/OpenApiV3Upgrader";
11
+ import { OpenApiV3_1Downgrader } from "./internal/OpenApiV3_1Downgrader";
12
+ import { OpenApiV3_1Upgrader } from "./internal/OpenApiV3_1Upgrader";
13
+ import { OpenApiV3_2Upgrader } from "./internal/OpenApiV3_2Upgrader";
14
+ import { SwaggerV2Downgrader } from "./internal/SwaggerV2Downgrader";
15
+ import { SwaggerV2Upgrader } from "./internal/SwaggerV2Upgrader";
16
+
17
+ /**
18
+ * OpenAPI version converter.
19
+ *
20
+ * `OpenApiConverter` converts between different OpenAPI specification versions:
21
+ * Swagger v2.0, OpenAPI v3.0, OpenAPI v3.1, OpenAPI v3.2, and typia's emended
22
+ * {@link OpenApi} format. Also converts individual components (schemas,
23
+ * operations, paths).
24
+ *
25
+ * Upgrade path (to emended v3.2):
26
+ *
27
+ * - Swagger v2.0 → emended v3.2
28
+ * - OpenAPI v3.0 → emended v3.2
29
+ * - OpenAPI v3.1 → emended v3.2
30
+ * - OpenAPI v3.2 → emended v3.2
31
+ *
32
+ * Downgrade path (from emended v3.2):
33
+ *
34
+ * - Emended v3.2 → Swagger v2.0
35
+ * - Emended v3.2 → OpenAPI v3.0
36
+ * - Emended v3.2 → OpenAPI v3.1
37
+ *
38
+ * The emended format normalizes ambiguous expressions: dereferences `$ref`,
39
+ * merges `allOf`, converts `nullable` to union types, etc.
40
+ *
41
+ * @author Jeongho Nam - https://github.com/samchon
42
+ */
43
+ export namespace OpenApiConverter {
44
+ /* -----------------------------------------------------------
45
+ DOCUMENTS
46
+ ----------------------------------------------------------- */
47
+ /**
48
+ * Upgrade document to typia's emended OpenAPI v3.2 format.
49
+ *
50
+ * @param document Source document (Swagger v2.0, OpenAPI v3.0/v3.1/v3.2)
51
+ * @returns Emended OpenAPI v3.2 document
52
+ */
53
+ export function upgradeDocument(
54
+ document:
55
+ | SwaggerV2.IDocument
56
+ | OpenApiV3.IDocument
57
+ | OpenApiV3_1.IDocument
58
+ | OpenApiV3_2.IDocument
59
+ | OpenApi.IDocument,
60
+ ): OpenApi.IDocument {
61
+ if (isUpgraded(document)) return document;
62
+ else if (is_v32(document)) return OpenApiV3_2Upgrader.convert(document);
63
+ else if (is_v31(document)) return OpenApiV3_1Upgrader.convert(document);
64
+ else if (is_v30(document)) return OpenApiV3Upgrader.convert(document);
65
+ else if (is_v20(document)) return SwaggerV2Upgrader.convert(document);
66
+ document satisfies never;
67
+ throw new Error("Invalid OpenAPI document");
68
+ }
69
+
70
+ /**
71
+ * Downgrade document to Swagger v2.0 format.
72
+ *
73
+ * @param document Source emended OpenAPI document
74
+ * @param version Target version "2.0"
75
+ * @returns Swagger v2.0 document
76
+ */
77
+ export function downgradeDocument(
78
+ document: OpenApi.IDocument,
79
+ version: "2.0",
80
+ ): SwaggerV2.IDocument;
81
+
82
+ /**
83
+ * Downgrade document to OpenAPI v3.0 format.
84
+ *
85
+ * @param document Source emended OpenAPI document
86
+ * @param version Target version "3.0"
87
+ * @returns OpenAPI v3.0 document
88
+ */
89
+ export function downgradeDocument(
90
+ document: OpenApi.IDocument,
91
+ version: "3.0",
92
+ ): OpenApiV3.IDocument;
93
+
94
+ export function downgradeDocument(
95
+ document: OpenApi.IDocument,
96
+ version: "3.1",
97
+ ): OpenApiV3_1.IDocument;
98
+
99
+ /** @internal */
100
+ export function downgradeDocument(
101
+ document: OpenApi.IDocument,
102
+ version: "2.0" | "3.0" | "3.1",
103
+ ): SwaggerV2.IDocument | OpenApiV3.IDocument | OpenApiV3_1.IDocument {
104
+ if (version === "2.0") return SwaggerV2Downgrader.downgrade(document);
105
+ else if (version === "3.0") return OpenApiV3Downgrader.downgrade(document);
106
+ else if (version === "3.1")
107
+ return OpenApiV3_1Downgrader.downgrade(document);
108
+
109
+ version satisfies never;
110
+ throw new Error("Invalid OpenAPI version");
111
+ }
112
+
113
+ /* -----------------------------------------------------------
114
+ COMPONENTS
115
+ ----------------------------------------------------------- */
116
+ /**
117
+ * Upgrade components to typia's emended format.
118
+ *
119
+ * @param input Source components (Swagger v2.0, OpenAPI v3.0/v3.1/v3.2)
120
+ * @returns Emended OpenAPI components
121
+ */
122
+ export function upgradeComponents(
123
+ input:
124
+ | OpenApiV3_2.IComponents
125
+ | OpenApiV3_1.IComponents
126
+ | OpenApiV3.IComponents
127
+ | SwaggerV2.IDocument,
128
+ ): OpenApi.IComponents {
129
+ if (is_v20(input)) return SwaggerV2Upgrader.convertComponents(input);
130
+ return OpenApiV3_1Upgrader.convertComponents(input as any);
131
+ }
132
+
133
+ /**
134
+ * Downgrade components to Swagger v2.0 definitions.
135
+ *
136
+ * @param input Source emended components
137
+ * @param version Target version "2.0"
138
+ * @returns Swagger v2.0 definitions record
139
+ */
140
+ export function downgradeComponents(
141
+ input: OpenApi.IComponents,
142
+ version: "2.0",
143
+ ): Record<string, SwaggerV2.IJsonSchema>;
144
+
145
+ /**
146
+ * Downgrade components to OpenAPI v3.0 format.
147
+ *
148
+ * @param input Source emended components
149
+ * @param version Target version "3.0"
150
+ * @returns OpenAPI v3.0 components
151
+ */
152
+ export function downgradeComponents(
153
+ input: OpenApi.IComponents,
154
+ version: "3.0",
155
+ ): OpenApiV3.IComponents;
156
+
157
+ /**
158
+ * Downgrade components to OpenAPI v3.1 format.
159
+ *
160
+ * @param input Source emended components
161
+ * @param version Target version "3.1"
162
+ * @returns OpenAPI v3.1 components
163
+ */
164
+ export function downgradeComponents(
165
+ input: OpenApi.IComponents,
166
+ version: "3.1",
167
+ ): OpenApiV3_1.IComponents;
168
+
169
+ /** @internal */
170
+ export function downgradeComponents(
171
+ input: OpenApi.IComponents,
172
+ version: "2.0" | "3.0" | "3.1",
173
+ ):
174
+ | Record<string, SwaggerV2.IJsonSchema>
175
+ | OpenApiV3.IComponents
176
+ | OpenApiV3_1.IComponents {
177
+ if (version === "2.0")
178
+ return SwaggerV2Downgrader.downgradeComponents(input).downgraded;
179
+ if (version === "3.1")
180
+ return OpenApiV3_1Downgrader.downgradeComponents(input).downgraded;
181
+ return OpenApiV3Downgrader.downgradeComponents(input).downgraded;
182
+ }
183
+
184
+ /* -----------------------------------------------------------
185
+ SCHEMAS
186
+ ----------------------------------------------------------- */
187
+ /**
188
+ * Upgrade Swagger v2.0 schema to emended format.
189
+ *
190
+ * @param props.definitions Swagger v2.0 definitions
191
+ * @param props.schema Schema to upgrade
192
+ * @returns Emended JSON schema
193
+ */
194
+ export function upgradeSchema(props: {
195
+ definitions: Record<string, SwaggerV2.IJsonSchema>;
196
+ schema: SwaggerV2.IJsonSchema;
197
+ }): OpenApi.IJsonSchema;
198
+
199
+ /**
200
+ * Upgrade OpenAPI v3.0 schema to emended format.
201
+ *
202
+ * @param props.components OpenAPI v3.0 components
203
+ * @param props.schema Schema to upgrade
204
+ * @returns Emended JSON schema
205
+ */
206
+ export function upgradeSchema(props: {
207
+ components: OpenApiV3.IComponents;
208
+ schema: OpenApiV3.IJsonSchema;
209
+ }): OpenApi.IJsonSchema;
210
+
211
+ /**
212
+ * Upgrade OpenAPI v3.1 schema to emended format.
213
+ *
214
+ * @param props.components OpenAPI v3.1 components
215
+ * @param props.schema Schema to upgrade
216
+ * @returns Emended JSON schema
217
+ */
218
+ export function upgradeSchema(props: {
219
+ components: OpenApiV3_1.IComponents;
220
+ schema: OpenApiV3_1.IJsonSchema;
221
+ }): OpenApi.IJsonSchema;
222
+
223
+ /**
224
+ * Upgrade OpenAPI v3.2 schema to emended format.
225
+ *
226
+ * @param props.components OpenAPI v3.2 components
227
+ * @param props.schema Schema to upgrade
228
+ * @returns Emended JSON schema
229
+ */
230
+ export function upgradeSchema(props: {
231
+ components: OpenApiV3_2.IComponents;
232
+ schema: OpenApiV3_2.IJsonSchema;
233
+ }): OpenApi.IJsonSchema;
234
+
235
+ /** @internal */
236
+ export function upgradeSchema(
237
+ props:
238
+ | {
239
+ definitions: Record<string, SwaggerV2.IJsonSchema>;
240
+ schema: SwaggerV2.IJsonSchema;
241
+ }
242
+ | {
243
+ components: OpenApiV3.IComponents;
244
+ schema: OpenApiV3.IJsonSchema;
245
+ }
246
+ | {
247
+ components: OpenApiV3_1.IComponents;
248
+ schema: OpenApiV3_1.IJsonSchema;
249
+ }
250
+ | {
251
+ components: OpenApiV3_2.IComponents;
252
+ schema: OpenApiV3_2.IJsonSchema;
253
+ },
254
+ ): OpenApi.IJsonSchema {
255
+ if ("definitions" in props)
256
+ return SwaggerV2Upgrader.convertSchema(props.definitions)(props.schema);
257
+ return OpenApiV3_1Upgrader.convertSchema(props.components as any)(
258
+ props.schema as any,
259
+ );
260
+ }
261
+
262
+ /**
263
+ * Downgrade schema to Swagger v2.0 format.
264
+ *
265
+ * @param props.components Source emended components
266
+ * @param props.schema Schema to downgrade
267
+ * @param props.version Target version "2.0"
268
+ * @param props.downgraded Target definitions record (mutated)
269
+ * @returns Swagger v2.0 schema
270
+ */
271
+ export function downgradeSchema(props: {
272
+ components: OpenApi.IComponents;
273
+ schema: OpenApi.IJsonSchema;
274
+ version: "2.0";
275
+ downgraded: Record<string, SwaggerV2.IJsonSchema>;
276
+ }): SwaggerV2.IJsonSchema;
277
+
278
+ /**
279
+ * Downgrade schema to OpenAPI v3.0 format.
280
+ *
281
+ * @param props.components Source emended components
282
+ * @param props.schema Schema to downgrade
283
+ * @param props.version Target version "3.0"
284
+ * @param props.downgraded Target components (mutated)
285
+ * @returns OpenAPI v3.0 schema
286
+ */
287
+ export function downgradeSchema(props: {
288
+ components: OpenApi.IComponents;
289
+ schema: OpenApi.IJsonSchema;
290
+ version: "3.0";
291
+ downgraded: OpenApiV3.IComponents;
292
+ }): OpenApiV3.IJsonSchema;
293
+
294
+ /**
295
+ * Downgrade schema to OpenAPI v3.1 format.
296
+ *
297
+ * @param props.components Source emended components
298
+ * @param props.schema Schema to downgrade
299
+ * @param props.version Target version "3.1"
300
+ * @param props.downgraded Target components (mutated)
301
+ * @returns OpenAPI v3.1 schema
302
+ */
303
+ export function downgradeSchema(props: {
304
+ components: OpenApi.IComponents;
305
+ schema: OpenApi.IJsonSchema;
306
+ version: "3.1";
307
+ downgraded: OpenApiV3_1.IComponents;
308
+ }): OpenApiV3_1.IJsonSchema;
309
+
310
+ /** @internal */
311
+ export function downgradeSchema<Version extends "2.0" | "3.0" | "3.1">(props: {
312
+ components: OpenApi.IComponents;
313
+ schema: OpenApi.IJsonSchema;
314
+ version: Version;
315
+ downgraded: Version extends "2.0"
316
+ ? Record<string, SwaggerV2.IJsonSchema>
317
+ : Version extends "3.1"
318
+ ? OpenApiV3_1.IComponents
319
+ : OpenApiV3.IComponents;
320
+ }):
321
+ | OpenApiV3.IJsonSchema
322
+ | OpenApiV3_1.IJsonSchema
323
+ | SwaggerV2.IJsonSchema {
324
+ if (props.version === "2.0")
325
+ return SwaggerV2Downgrader.downgradeSchema({
326
+ original: props.components,
327
+ downgraded: props.downgraded as Record<string, SwaggerV2.IJsonSchema>,
328
+ })(props.schema);
329
+ if (props.version === "3.1")
330
+ return OpenApiV3_1Downgrader.downgradeSchema({
331
+ original: props.components,
332
+ downgraded: props.downgraded as OpenApiV3_1.IComponents,
333
+ })(props.schema);
334
+ return OpenApiV3Downgrader.downgradeSchema({
335
+ original: props.components,
336
+ downgraded: props.downgraded as OpenApiV3.IComponents,
337
+ })(props.schema);
338
+ }
339
+ }
340
+
341
+ const is_v20 = (input: unknown): input is SwaggerV2.IDocument =>
342
+ typeof input === "object" &&
343
+ input !== null &&
344
+ "swagger" in input &&
345
+ typeof input.swagger === "string" &&
346
+ input.swagger.startsWith("2.0");
347
+
348
+ const is_v30 = (input: unknown): input is OpenApiV3.IDocument =>
349
+ typeof input === "object" &&
350
+ input !== null &&
351
+ "openapi" in input &&
352
+ typeof input.openapi === "string" &&
353
+ input.openapi.startsWith("3.0");
354
+
355
+ const is_v31 = (input: unknown): input is OpenApiV3_1.IDocument =>
356
+ typeof input === "object" &&
357
+ input !== null &&
358
+ "openapi" in input &&
359
+ typeof input.openapi === "string" &&
360
+ input.openapi.startsWith("3.1");
361
+
362
+ const is_v32 = (input: unknown): input is OpenApiV3_2.IDocument =>
363
+ typeof input === "object" &&
364
+ input !== null &&
365
+ "openapi" in input &&
366
+ typeof input.openapi === "string" &&
367
+ input.openapi.startsWith("3.2");
368
+
369
+ const isUpgraded = (input: unknown): input is OpenApi.IDocument =>
370
+ typeof input === "object" &&
371
+ input !== null &&
372
+ "openapi" in input &&
373
+ typeof input.openapi === "string" &&
374
+ input.openapi.startsWith("3.2") &&
375
+ (input as OpenApi.IDocument)["x-typia-emended-v12"] === true;