@typia/utils 12.0.0-dev.20260307-2 → 12.0.0-dev.20260310

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.
Files changed (103) hide show
  1. package/README.md +2 -2
  2. package/lib/http/internal/HttpLlmApplicationComposer.js +1 -0
  3. package/lib/http/internal/HttpLlmApplicationComposer.js.map +1 -1
  4. package/lib/http/internal/HttpLlmApplicationComposer.mjs +1 -0
  5. package/lib/http/internal/HttpLlmApplicationComposer.mjs.map +1 -1
  6. package/lib/utils/LlmJson.d.ts +3 -3
  7. package/lib/utils/LlmJson.js +2 -2
  8. package/lib/utils/LlmJson.js.map +1 -1
  9. package/lib/utils/LlmJson.mjs +2 -2
  10. package/lib/utils/LlmJson.mjs.map +1 -1
  11. package/lib/utils/internal/coerceLlmArguments.js +17 -1
  12. package/lib/utils/internal/coerceLlmArguments.js.map +1 -1
  13. package/lib/utils/internal/coerceLlmArguments.mjs +17 -1
  14. package/lib/utils/internal/coerceLlmArguments.mjs.map +1 -1
  15. package/lib/utils/internal/parseLenientJson.js +236 -96
  16. package/lib/utils/internal/parseLenientJson.js.map +1 -1
  17. package/lib/utils/internal/parseLenientJson.mjs +236 -96
  18. package/lib/utils/internal/parseLenientJson.mjs.map +1 -1
  19. package/lib/utils/internal/stringifyValidationFailure.js +17 -15
  20. package/lib/utils/internal/stringifyValidationFailure.js.map +1 -1
  21. package/lib/utils/internal/stringifyValidationFailure.mjs +17 -15
  22. package/lib/utils/internal/stringifyValidationFailure.mjs.map +1 -1
  23. package/package.json +2 -2
  24. package/src/converters/LlmSchemaConverter.ts +647 -647
  25. package/src/converters/OpenApiConverter.ts +285 -285
  26. package/src/converters/index.ts +5 -5
  27. package/src/converters/internal/LlmDescriptionInverter.ts +178 -178
  28. package/src/converters/internal/LlmParametersComposer.ts +52 -52
  29. package/src/converters/internal/OpenApiConstraintShifter.ts +154 -154
  30. package/src/converters/internal/OpenApiExclusiveEmender.ts +46 -46
  31. package/src/converters/internal/OpenApiV3Downgrader.ts +355 -355
  32. package/src/converters/internal/OpenApiV3Upgrader.ts +470 -470
  33. package/src/converters/internal/OpenApiV3_1Upgrader.ts +685 -685
  34. package/src/converters/internal/SwaggerV2Downgrader.ts +424 -424
  35. package/src/converters/internal/SwaggerV2Upgrader.ts +523 -523
  36. package/src/http/HttpError.ts +107 -107
  37. package/src/http/HttpLlm.ts +167 -167
  38. package/src/http/HttpMigration.ts +92 -92
  39. package/src/http/index.ts +3 -3
  40. package/src/http/internal/HttpLlmApplicationComposer.ts +361 -360
  41. package/src/http/internal/HttpLlmFunctionFetcher.ts +37 -37
  42. package/src/http/internal/HttpMigrateApplicationComposer.ts +56 -56
  43. package/src/http/internal/HttpMigrateRouteAccessor.ts +135 -135
  44. package/src/http/internal/HttpMigrateRouteComposer.ts +505 -505
  45. package/src/http/internal/HttpMigrateRouteFetcher.ts +203 -203
  46. package/src/index.ts +4 -4
  47. package/src/utils/ArrayUtil.ts +42 -42
  48. package/src/utils/LlmJson.ts +141 -141
  49. package/src/utils/MapUtil.ts +15 -15
  50. package/src/utils/NamingConvention.ts +205 -205
  51. package/src/utils/Singleton.ts +17 -17
  52. package/src/utils/StringUtil.ts +14 -14
  53. package/src/utils/dedent.ts +57 -57
  54. package/src/utils/index.ts +8 -8
  55. package/src/utils/internal/EndpointUtil.ts +44 -44
  56. package/src/utils/internal/JsonDescriptor.ts +70 -70
  57. package/src/utils/internal/OpenApiTypeCheckerBase.ts +822 -822
  58. package/src/utils/internal/coerceLlmArguments.ts +314 -297
  59. package/src/utils/internal/parseLenientJson.ts +894 -731
  60. package/src/utils/internal/stringifyValidationFailure.ts +415 -411
  61. package/src/validators/LlmTypeChecker.ts +402 -402
  62. package/src/validators/OpenApiTypeChecker.ts +297 -297
  63. package/src/validators/OpenApiV3TypeChecker.ts +70 -70
  64. package/src/validators/OpenApiV3_1TypeChecker.ts +86 -86
  65. package/src/validators/OpenApiValidator.ts +94 -94
  66. package/src/validators/SwaggerV2TypeChecker.ts +71 -71
  67. package/src/validators/functional/_isBigintString.ts +8 -8
  68. package/src/validators/functional/_isFormatByte.ts +7 -7
  69. package/src/validators/functional/_isFormatDate.ts +3 -3
  70. package/src/validators/functional/_isFormatDateTime.ts +4 -4
  71. package/src/validators/functional/_isFormatDuration.ts +4 -4
  72. package/src/validators/functional/_isFormatEmail.ts +4 -4
  73. package/src/validators/functional/_isFormatHostname.ts +4 -4
  74. package/src/validators/functional/_isFormatIdnEmail.ts +4 -4
  75. package/src/validators/functional/_isFormatIdnHostname.ts +4 -4
  76. package/src/validators/functional/_isFormatIpv4.ts +4 -4
  77. package/src/validators/functional/_isFormatIpv6.ts +4 -4
  78. package/src/validators/functional/_isFormatIri.ts +3 -3
  79. package/src/validators/functional/_isFormatIriReference.ts +4 -4
  80. package/src/validators/functional/_isFormatJsonPointer.ts +3 -3
  81. package/src/validators/functional/_isFormatPassword.ts +1 -1
  82. package/src/validators/functional/_isFormatRegex.ts +8 -8
  83. package/src/validators/functional/_isFormatRelativeJsonPointer.ts +4 -4
  84. package/src/validators/functional/_isFormatTime.ts +4 -4
  85. package/src/validators/functional/_isFormatUri.ts +6 -6
  86. package/src/validators/functional/_isFormatUriReference.ts +5 -5
  87. package/src/validators/functional/_isFormatUriTemplate.ts +4 -4
  88. package/src/validators/functional/_isFormatUrl.ts +4 -4
  89. package/src/validators/functional/_isFormatUuid.ts +3 -3
  90. package/src/validators/functional/_isUniqueItems.ts +159 -159
  91. package/src/validators/index.ts +14 -14
  92. package/src/validators/internal/IOpenApiValidatorContext.ts +17 -17
  93. package/src/validators/internal/OpenApiArrayValidator.ts +49 -49
  94. package/src/validators/internal/OpenApiBooleanValidator.ts +11 -11
  95. package/src/validators/internal/OpenApiConstantValidator.ts +11 -11
  96. package/src/validators/internal/OpenApiIntegerValidator.ts +49 -49
  97. package/src/validators/internal/OpenApiNumberValidator.ts +48 -48
  98. package/src/validators/internal/OpenApiObjectValidator.ts +83 -83
  99. package/src/validators/internal/OpenApiOneOfValidator.ts +309 -309
  100. package/src/validators/internal/OpenApiSchemaNamingRule.ts +124 -124
  101. package/src/validators/internal/OpenApiStationValidator.ts +115 -115
  102. package/src/validators/internal/OpenApiStringValidator.ts +88 -88
  103. package/src/validators/internal/OpenApiTupleValidator.ts +55 -55
@@ -1,285 +1,285 @@
1
- import { OpenApi, OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@typia/interface";
2
-
3
- import { OpenApiV3Downgrader } from "./internal/OpenApiV3Downgrader";
4
- import { OpenApiV3Upgrader } from "./internal/OpenApiV3Upgrader";
5
- import { OpenApiV3_1Upgrader } from "./internal/OpenApiV3_1Upgrader";
6
- import { SwaggerV2Downgrader } from "./internal/SwaggerV2Downgrader";
7
- import { SwaggerV2Upgrader } from "./internal/SwaggerV2Upgrader";
8
-
9
- /**
10
- * OpenAPI version converter.
11
- *
12
- * `OpenApiConverter` converts between different OpenAPI specification versions:
13
- * Swagger v2.0, OpenAPI v3.0, OpenAPI v3.1, and typia's emended {@link OpenApi}
14
- * format. Also converts individual components (schemas, operations, paths).
15
- *
16
- * Upgrade path (to emended v3.1):
17
- *
18
- * - Swagger v2.0 → emended v3.1
19
- * - OpenAPI v3.0 → emended v3.1
20
- * - OpenAPI v3.1 → emended v3.1
21
- *
22
- * Downgrade path (from emended v3.1):
23
- *
24
- * - Emended v3.1 → Swagger v2.0
25
- * - Emended v3.1 → OpenAPI v3.0
26
- *
27
- * The emended format normalizes ambiguous expressions: dereferences `$ref`,
28
- * merges `allOf`, converts `nullable` to union types, etc.
29
- *
30
- * @author Jeongho Nam - https://github.com/samchon
31
- */
32
- export namespace OpenApiConverter {
33
- /* -----------------------------------------------------------
34
- DOCUMENTS
35
- ----------------------------------------------------------- */
36
- /**
37
- * Upgrade document to typia's emended OpenAPI v3.1 format.
38
- *
39
- * @param document Source document (Swagger v2.0, OpenAPI v3.0/v3.1)
40
- * @returns Emended OpenAPI v3.1 document
41
- */
42
- export function upgradeDocument(
43
- document:
44
- | SwaggerV2.IDocument
45
- | OpenApiV3.IDocument
46
- | OpenApiV3_1.IDocument
47
- | OpenApi.IDocument,
48
- ): OpenApi.IDocument {
49
- if (isUpgraded(document)) return document;
50
- else if (is_v31(document)) return OpenApiV3_1Upgrader.convert(document);
51
- else if (is_v30(document)) return OpenApiV3Upgrader.convert(document);
52
- else if (is_v20(document)) return SwaggerV2Upgrader.convert(document);
53
- document satisfies never;
54
- throw new Error("Invalid OpenAPI document");
55
- }
56
-
57
- /**
58
- * Downgrade document to Swagger v2.0 format.
59
- *
60
- * @param document Source emended OpenAPI document
61
- * @param version Target version "2.0"
62
- * @returns Swagger v2.0 document
63
- */
64
- export function downgradeDocument(
65
- document: OpenApi.IDocument,
66
- version: "2.0",
67
- ): SwaggerV2.IDocument;
68
-
69
- /**
70
- * Downgrade document to OpenAPI v3.0 format.
71
- *
72
- * @param document Source emended OpenAPI document
73
- * @param version Target version "3.0"
74
- * @returns OpenAPI v3.0 document
75
- */
76
- export function downgradeDocument(
77
- document: OpenApi.IDocument,
78
- version: "3.0",
79
- ): OpenApiV3.IDocument;
80
-
81
- /** @internal */
82
- export function downgradeDocument(
83
- document: OpenApi.IDocument,
84
- version: "2.0" | "3.0",
85
- ): SwaggerV2.IDocument | OpenApiV3.IDocument {
86
- if (version === "2.0") return SwaggerV2Downgrader.downgrade(document);
87
- else if (version === "3.0") return OpenApiV3Downgrader.downgrade(document);
88
- version satisfies never;
89
- throw new Error("Invalid OpenAPI version");
90
- }
91
-
92
- /* -----------------------------------------------------------
93
- COMPONENTS
94
- ----------------------------------------------------------- */
95
- /**
96
- * Upgrade components to typia's emended format.
97
- *
98
- * @param input Source components (Swagger v2.0, OpenAPI v3.0/v3.1)
99
- * @returns Emended OpenAPI components
100
- */
101
- export function upgradeComponents(
102
- input:
103
- | OpenApiV3_1.IComponents
104
- | OpenApiV3.IComponents
105
- | SwaggerV2.IDocument,
106
- ): OpenApi.IComponents {
107
- if (is_v20(input)) return SwaggerV2Upgrader.convertComponents(input);
108
- return OpenApiV3_1Upgrader.convertComponents(input);
109
- }
110
-
111
- /**
112
- * Downgrade components to Swagger v2.0 definitions.
113
- *
114
- * @param input Source emended components
115
- * @param version Target version "2.0"
116
- * @returns Swagger v2.0 definitions record
117
- */
118
- export function downgradeComponents(
119
- input: OpenApi.IComponents,
120
- version: "2.0",
121
- ): Record<string, SwaggerV2.IJsonSchema>;
122
-
123
- /**
124
- * Downgrade components to OpenAPI v3.0 format.
125
- *
126
- * @param input Source emended components
127
- * @param version Target version "3.0"
128
- * @returns OpenAPI v3.0 components
129
- */
130
- export function downgradeComponents(
131
- input: OpenApi.IComponents,
132
- version: "3.0",
133
- ): OpenApiV3.IComponents;
134
-
135
- /** @internal */
136
- export function downgradeComponents(
137
- input: OpenApi.IComponents,
138
- version: "2.0" | "3.0",
139
- ): Record<string, SwaggerV2.IJsonSchema> | OpenApiV3.IComponents {
140
- if (version === "2.0")
141
- return SwaggerV2Downgrader.downgradeComponents(input).downgraded;
142
- return OpenApiV3Downgrader.downgradeComponents(input).downgraded;
143
- }
144
-
145
- /* -----------------------------------------------------------
146
- SCHEMAS
147
- ----------------------------------------------------------- */
148
- /**
149
- * Upgrade Swagger v2.0 schema to emended format.
150
- *
151
- * @param props.definitions Swagger v2.0 definitions
152
- * @param props.schema Schema to upgrade
153
- * @returns Emended JSON schema
154
- */
155
- export function upgradeSchema(props: {
156
- definitions: Record<string, SwaggerV2.IJsonSchema>;
157
- schema: SwaggerV2.IJsonSchema;
158
- }): OpenApi.IJsonSchema;
159
-
160
- /**
161
- * Upgrade OpenAPI v3.0 schema to emended format.
162
- *
163
- * @param props.components OpenAPI v3.0 components
164
- * @param props.schema Schema to upgrade
165
- * @returns Emended JSON schema
166
- */
167
- export function upgradeSchema(props: {
168
- components: OpenApiV3.IComponents;
169
- schema: OpenApiV3.IJsonSchema;
170
- }): OpenApi.IJsonSchema;
171
-
172
- /**
173
- * Upgrade OpenAPI v3.1 schema to emended format.
174
- *
175
- * @param props.components OpenAPI v3.1 components
176
- * @param props.schema Schema to upgrade
177
- * @returns Emended JSON schema
178
- */
179
- export function upgradeSchema(props: {
180
- components: OpenApiV3_1.IComponents;
181
- schema: OpenApiV3_1.IJsonSchema;
182
- }): OpenApi.IJsonSchema;
183
-
184
- /** @internal */
185
- export function upgradeSchema(
186
- props:
187
- | {
188
- definitions: Record<string, SwaggerV2.IJsonSchema>;
189
- schema: SwaggerV2.IJsonSchema;
190
- }
191
- | {
192
- components: OpenApiV3.IComponents;
193
- schema: OpenApiV3.IJsonSchema;
194
- }
195
- | {
196
- components: OpenApiV3_1.IComponents;
197
- schema: OpenApiV3_1.IJsonSchema;
198
- },
199
- ): OpenApi.IJsonSchema {
200
- if ("definitions" in props)
201
- return SwaggerV2Upgrader.convertSchema(props.definitions)(props.schema);
202
- return OpenApiV3_1Upgrader.convertSchema(props.components)(props.schema);
203
- }
204
-
205
- /**
206
- * Downgrade schema to Swagger v2.0 format.
207
- *
208
- * @param props.components Source emended components
209
- * @param props.schema Schema to downgrade
210
- * @param props.version Target version "2.0"
211
- * @param props.downgraded Target definitions record (mutated)
212
- * @returns Swagger v2.0 schema
213
- */
214
- export function downgradeSchema(props: {
215
- components: OpenApi.IComponents;
216
- schema: OpenApi.IJsonSchema;
217
- version: "2.0";
218
- downgraded: Record<string, SwaggerV2.IJsonSchema>;
219
- }): SwaggerV2.IJsonSchema;
220
-
221
- /**
222
- * Downgrade schema to OpenAPI v3.0 format.
223
- *
224
- * @param props.components Source emended components
225
- * @param props.schema Schema to downgrade
226
- * @param props.version Target version "3.0"
227
- * @param props.downgraded Target components (mutated)
228
- * @returns OpenAPI v3.0 schema
229
- */
230
- export function downgradeSchema(props: {
231
- components: OpenApi.IComponents;
232
- schema: OpenApi.IJsonSchema;
233
- version: "3.0";
234
- downgraded: OpenApiV3.IComponents;
235
- }): OpenApiV3.IJsonSchema;
236
-
237
- /** @internal */
238
- export function downgradeSchema<Version extends "2.0" | "3.0">(props: {
239
- components: OpenApi.IComponents;
240
- schema: OpenApi.IJsonSchema;
241
- version: Version;
242
- downgraded: Version extends "2.0"
243
- ? Record<string, SwaggerV2.IJsonSchema>
244
- : OpenApiV3.IComponents;
245
- }): OpenApiV3.IJsonSchema | SwaggerV2.IJsonSchema {
246
- if (props.version === "2.0")
247
- return SwaggerV2Downgrader.downgradeSchema({
248
- original: props.components,
249
- downgraded: props.downgraded as Record<string, SwaggerV2.IJsonSchema>,
250
- })(props.schema);
251
- return OpenApiV3Downgrader.downgradeSchema({
252
- original: props.components,
253
- downgraded: props.downgraded,
254
- })(props.schema);
255
- }
256
- }
257
-
258
- const is_v20 = (input: unknown): input is SwaggerV2.IDocument =>
259
- typeof input === "object" &&
260
- input !== null &&
261
- "swagger" in input &&
262
- typeof input.swagger === "string" &&
263
- input.swagger.startsWith("2.0");
264
-
265
- const is_v30 = (input: unknown): input is OpenApiV3.IDocument =>
266
- typeof input === "object" &&
267
- input !== null &&
268
- "openapi" in input &&
269
- typeof input.openapi === "string" &&
270
- input.openapi.startsWith("3.0");
271
-
272
- const is_v31 = (input: unknown): input is OpenApiV3_1.IDocument =>
273
- typeof input === "object" &&
274
- input !== null &&
275
- "openapi" in input &&
276
- typeof input.openapi === "string" &&
277
- input.openapi.startsWith("3.1");
278
-
279
- const isUpgraded = (input: unknown): input is OpenApi.IDocument =>
280
- typeof input === "object" &&
281
- input !== null &&
282
- "openapi" in input &&
283
- typeof input.openapi === "string" &&
284
- input.openapi.startsWith("3.1") &&
285
- (input as OpenApi.IDocument)["x-samchon-emended-v4"] === true;
1
+ import { OpenApi, OpenApiV3, OpenApiV3_1, SwaggerV2 } from "@typia/interface";
2
+
3
+ import { OpenApiV3Downgrader } from "./internal/OpenApiV3Downgrader";
4
+ import { OpenApiV3Upgrader } from "./internal/OpenApiV3Upgrader";
5
+ import { OpenApiV3_1Upgrader } from "./internal/OpenApiV3_1Upgrader";
6
+ import { SwaggerV2Downgrader } from "./internal/SwaggerV2Downgrader";
7
+ import { SwaggerV2Upgrader } from "./internal/SwaggerV2Upgrader";
8
+
9
+ /**
10
+ * OpenAPI version converter.
11
+ *
12
+ * `OpenApiConverter` converts between different OpenAPI specification versions:
13
+ * Swagger v2.0, OpenAPI v3.0, OpenAPI v3.1, and typia's emended {@link OpenApi}
14
+ * format. Also converts individual components (schemas, operations, paths).
15
+ *
16
+ * Upgrade path (to emended v3.1):
17
+ *
18
+ * - Swagger v2.0 → emended v3.1
19
+ * - OpenAPI v3.0 → emended v3.1
20
+ * - OpenAPI v3.1 → emended v3.1
21
+ *
22
+ * Downgrade path (from emended v3.1):
23
+ *
24
+ * - Emended v3.1 → Swagger v2.0
25
+ * - Emended v3.1 → OpenAPI v3.0
26
+ *
27
+ * The emended format normalizes ambiguous expressions: dereferences `$ref`,
28
+ * merges `allOf`, converts `nullable` to union types, etc.
29
+ *
30
+ * @author Jeongho Nam - https://github.com/samchon
31
+ */
32
+ export namespace OpenApiConverter {
33
+ /* -----------------------------------------------------------
34
+ DOCUMENTS
35
+ ----------------------------------------------------------- */
36
+ /**
37
+ * Upgrade document to typia's emended OpenAPI v3.1 format.
38
+ *
39
+ * @param document Source document (Swagger v2.0, OpenAPI v3.0/v3.1)
40
+ * @returns Emended OpenAPI v3.1 document
41
+ */
42
+ export function upgradeDocument(
43
+ document:
44
+ | SwaggerV2.IDocument
45
+ | OpenApiV3.IDocument
46
+ | OpenApiV3_1.IDocument
47
+ | OpenApi.IDocument,
48
+ ): OpenApi.IDocument {
49
+ if (isUpgraded(document)) return document;
50
+ else if (is_v31(document)) return OpenApiV3_1Upgrader.convert(document);
51
+ else if (is_v30(document)) return OpenApiV3Upgrader.convert(document);
52
+ else if (is_v20(document)) return SwaggerV2Upgrader.convert(document);
53
+ document satisfies never;
54
+ throw new Error("Invalid OpenAPI document");
55
+ }
56
+
57
+ /**
58
+ * Downgrade document to Swagger v2.0 format.
59
+ *
60
+ * @param document Source emended OpenAPI document
61
+ * @param version Target version "2.0"
62
+ * @returns Swagger v2.0 document
63
+ */
64
+ export function downgradeDocument(
65
+ document: OpenApi.IDocument,
66
+ version: "2.0",
67
+ ): SwaggerV2.IDocument;
68
+
69
+ /**
70
+ * Downgrade document to OpenAPI v3.0 format.
71
+ *
72
+ * @param document Source emended OpenAPI document
73
+ * @param version Target version "3.0"
74
+ * @returns OpenAPI v3.0 document
75
+ */
76
+ export function downgradeDocument(
77
+ document: OpenApi.IDocument,
78
+ version: "3.0",
79
+ ): OpenApiV3.IDocument;
80
+
81
+ /** @internal */
82
+ export function downgradeDocument(
83
+ document: OpenApi.IDocument,
84
+ version: "2.0" | "3.0",
85
+ ): SwaggerV2.IDocument | OpenApiV3.IDocument {
86
+ if (version === "2.0") return SwaggerV2Downgrader.downgrade(document);
87
+ else if (version === "3.0") return OpenApiV3Downgrader.downgrade(document);
88
+ version satisfies never;
89
+ throw new Error("Invalid OpenAPI version");
90
+ }
91
+
92
+ /* -----------------------------------------------------------
93
+ COMPONENTS
94
+ ----------------------------------------------------------- */
95
+ /**
96
+ * Upgrade components to typia's emended format.
97
+ *
98
+ * @param input Source components (Swagger v2.0, OpenAPI v3.0/v3.1)
99
+ * @returns Emended OpenAPI components
100
+ */
101
+ export function upgradeComponents(
102
+ input:
103
+ | OpenApiV3_1.IComponents
104
+ | OpenApiV3.IComponents
105
+ | SwaggerV2.IDocument,
106
+ ): OpenApi.IComponents {
107
+ if (is_v20(input)) return SwaggerV2Upgrader.convertComponents(input);
108
+ return OpenApiV3_1Upgrader.convertComponents(input);
109
+ }
110
+
111
+ /**
112
+ * Downgrade components to Swagger v2.0 definitions.
113
+ *
114
+ * @param input Source emended components
115
+ * @param version Target version "2.0"
116
+ * @returns Swagger v2.0 definitions record
117
+ */
118
+ export function downgradeComponents(
119
+ input: OpenApi.IComponents,
120
+ version: "2.0",
121
+ ): Record<string, SwaggerV2.IJsonSchema>;
122
+
123
+ /**
124
+ * Downgrade components to OpenAPI v3.0 format.
125
+ *
126
+ * @param input Source emended components
127
+ * @param version Target version "3.0"
128
+ * @returns OpenAPI v3.0 components
129
+ */
130
+ export function downgradeComponents(
131
+ input: OpenApi.IComponents,
132
+ version: "3.0",
133
+ ): OpenApiV3.IComponents;
134
+
135
+ /** @internal */
136
+ export function downgradeComponents(
137
+ input: OpenApi.IComponents,
138
+ version: "2.0" | "3.0",
139
+ ): Record<string, SwaggerV2.IJsonSchema> | OpenApiV3.IComponents {
140
+ if (version === "2.0")
141
+ return SwaggerV2Downgrader.downgradeComponents(input).downgraded;
142
+ return OpenApiV3Downgrader.downgradeComponents(input).downgraded;
143
+ }
144
+
145
+ /* -----------------------------------------------------------
146
+ SCHEMAS
147
+ ----------------------------------------------------------- */
148
+ /**
149
+ * Upgrade Swagger v2.0 schema to emended format.
150
+ *
151
+ * @param props.definitions Swagger v2.0 definitions
152
+ * @param props.schema Schema to upgrade
153
+ * @returns Emended JSON schema
154
+ */
155
+ export function upgradeSchema(props: {
156
+ definitions: Record<string, SwaggerV2.IJsonSchema>;
157
+ schema: SwaggerV2.IJsonSchema;
158
+ }): OpenApi.IJsonSchema;
159
+
160
+ /**
161
+ * Upgrade OpenAPI v3.0 schema to emended format.
162
+ *
163
+ * @param props.components OpenAPI v3.0 components
164
+ * @param props.schema Schema to upgrade
165
+ * @returns Emended JSON schema
166
+ */
167
+ export function upgradeSchema(props: {
168
+ components: OpenApiV3.IComponents;
169
+ schema: OpenApiV3.IJsonSchema;
170
+ }): OpenApi.IJsonSchema;
171
+
172
+ /**
173
+ * Upgrade OpenAPI v3.1 schema to emended format.
174
+ *
175
+ * @param props.components OpenAPI v3.1 components
176
+ * @param props.schema Schema to upgrade
177
+ * @returns Emended JSON schema
178
+ */
179
+ export function upgradeSchema(props: {
180
+ components: OpenApiV3_1.IComponents;
181
+ schema: OpenApiV3_1.IJsonSchema;
182
+ }): OpenApi.IJsonSchema;
183
+
184
+ /** @internal */
185
+ export function upgradeSchema(
186
+ props:
187
+ | {
188
+ definitions: Record<string, SwaggerV2.IJsonSchema>;
189
+ schema: SwaggerV2.IJsonSchema;
190
+ }
191
+ | {
192
+ components: OpenApiV3.IComponents;
193
+ schema: OpenApiV3.IJsonSchema;
194
+ }
195
+ | {
196
+ components: OpenApiV3_1.IComponents;
197
+ schema: OpenApiV3_1.IJsonSchema;
198
+ },
199
+ ): OpenApi.IJsonSchema {
200
+ if ("definitions" in props)
201
+ return SwaggerV2Upgrader.convertSchema(props.definitions)(props.schema);
202
+ return OpenApiV3_1Upgrader.convertSchema(props.components)(props.schema);
203
+ }
204
+
205
+ /**
206
+ * Downgrade schema to Swagger v2.0 format.
207
+ *
208
+ * @param props.components Source emended components
209
+ * @param props.schema Schema to downgrade
210
+ * @param props.version Target version "2.0"
211
+ * @param props.downgraded Target definitions record (mutated)
212
+ * @returns Swagger v2.0 schema
213
+ */
214
+ export function downgradeSchema(props: {
215
+ components: OpenApi.IComponents;
216
+ schema: OpenApi.IJsonSchema;
217
+ version: "2.0";
218
+ downgraded: Record<string, SwaggerV2.IJsonSchema>;
219
+ }): SwaggerV2.IJsonSchema;
220
+
221
+ /**
222
+ * Downgrade schema to OpenAPI v3.0 format.
223
+ *
224
+ * @param props.components Source emended components
225
+ * @param props.schema Schema to downgrade
226
+ * @param props.version Target version "3.0"
227
+ * @param props.downgraded Target components (mutated)
228
+ * @returns OpenAPI v3.0 schema
229
+ */
230
+ export function downgradeSchema(props: {
231
+ components: OpenApi.IComponents;
232
+ schema: OpenApi.IJsonSchema;
233
+ version: "3.0";
234
+ downgraded: OpenApiV3.IComponents;
235
+ }): OpenApiV3.IJsonSchema;
236
+
237
+ /** @internal */
238
+ export function downgradeSchema<Version extends "2.0" | "3.0">(props: {
239
+ components: OpenApi.IComponents;
240
+ schema: OpenApi.IJsonSchema;
241
+ version: Version;
242
+ downgraded: Version extends "2.0"
243
+ ? Record<string, SwaggerV2.IJsonSchema>
244
+ : OpenApiV3.IComponents;
245
+ }): OpenApiV3.IJsonSchema | SwaggerV2.IJsonSchema {
246
+ if (props.version === "2.0")
247
+ return SwaggerV2Downgrader.downgradeSchema({
248
+ original: props.components,
249
+ downgraded: props.downgraded as Record<string, SwaggerV2.IJsonSchema>,
250
+ })(props.schema);
251
+ return OpenApiV3Downgrader.downgradeSchema({
252
+ original: props.components,
253
+ downgraded: props.downgraded,
254
+ })(props.schema);
255
+ }
256
+ }
257
+
258
+ const is_v20 = (input: unknown): input is SwaggerV2.IDocument =>
259
+ typeof input === "object" &&
260
+ input !== null &&
261
+ "swagger" in input &&
262
+ typeof input.swagger === "string" &&
263
+ input.swagger.startsWith("2.0");
264
+
265
+ const is_v30 = (input: unknown): input is OpenApiV3.IDocument =>
266
+ typeof input === "object" &&
267
+ input !== null &&
268
+ "openapi" in input &&
269
+ typeof input.openapi === "string" &&
270
+ input.openapi.startsWith("3.0");
271
+
272
+ const is_v31 = (input: unknown): input is OpenApiV3_1.IDocument =>
273
+ typeof input === "object" &&
274
+ input !== null &&
275
+ "openapi" in input &&
276
+ typeof input.openapi === "string" &&
277
+ input.openapi.startsWith("3.1");
278
+
279
+ const isUpgraded = (input: unknown): input is OpenApi.IDocument =>
280
+ typeof input === "object" &&
281
+ input !== null &&
282
+ "openapi" in input &&
283
+ typeof input.openapi === "string" &&
284
+ input.openapi.startsWith("3.1") &&
285
+ (input as OpenApi.IDocument)["x-samchon-emended-v4"] === true;
@@ -1,5 +1,5 @@
1
- export * from "./LlmSchemaConverter";
2
- export * from "./OpenApiConverter";
3
-
4
- /** @internal */
5
- export * from "./internal/OpenApiExclusiveEmender";
1
+ export * from "./LlmSchemaConverter";
2
+ export * from "./OpenApiConverter";
3
+
4
+ /** @internal */
5
+ export * from "./internal/OpenApiExclusiveEmender";