@scalar/openapi-upgrader 0.1.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.
Files changed (44) hide show
  1. package/CHANGELOG.md +12 -0
  2. package/LICENSE +21 -0
  3. package/README.md +121 -0
  4. package/dist/2.0-to-3.0/index.d.ts +2 -0
  5. package/dist/2.0-to-3.0/index.d.ts.map +1 -0
  6. package/dist/2.0-to-3.0/index.js +5 -0
  7. package/dist/2.0-to-3.0/index.js.map +7 -0
  8. package/dist/2.0-to-3.0/upgrade-from-two-to-three.d.ts +9 -0
  9. package/dist/2.0-to-3.0/upgrade-from-two-to-three.d.ts.map +1 -0
  10. package/dist/2.0-to-3.0/upgrade-from-two-to-three.js +389 -0
  11. package/dist/2.0-to-3.0/upgrade-from-two-to-three.js.map +7 -0
  12. package/dist/3.0-to-3.1/index.d.ts +2 -0
  13. package/dist/3.0-to-3.1/index.d.ts.map +1 -0
  14. package/dist/3.0-to-3.1/index.js +5 -0
  15. package/dist/3.0-to-3.1/index.js.map +7 -0
  16. package/dist/3.0-to-3.1/upgrade-from-three-to-three-one.d.ts +31 -0
  17. package/dist/3.0-to-3.1/upgrade-from-three-to-three-one.d.ts.map +1 -0
  18. package/dist/3.0-to-3.1/upgrade-from-three-to-three-one.js +119 -0
  19. package/dist/3.0-to-3.1/upgrade-from-three-to-three-one.js.map +7 -0
  20. package/dist/3.1-to-3.2/index.d.ts +2 -0
  21. package/dist/3.1-to-3.2/index.d.ts.map +1 -0
  22. package/dist/3.1-to-3.2/index.js +5 -0
  23. package/dist/3.1-to-3.2/index.js.map +7 -0
  24. package/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.d.ts +8 -0
  25. package/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.d.ts.map +1 -0
  26. package/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.js +45 -0
  27. package/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.js.map +7 -0
  28. package/dist/helpers/traverse.d.ts +6 -0
  29. package/dist/helpers/traverse.d.ts.map +1 -0
  30. package/dist/helpers/traverse.js +25 -0
  31. package/dist/helpers/traverse.js.map +7 -0
  32. package/dist/index.d.ts +2 -0
  33. package/dist/index.d.ts.map +1 -0
  34. package/dist/index.js +5 -0
  35. package/dist/index.js.map +7 -0
  36. package/dist/upgrade.bench.d.ts +2 -0
  37. package/dist/upgrade.bench.d.ts.map +1 -0
  38. package/dist/upgrade.bench.js +31 -0
  39. package/dist/upgrade.bench.js.map +7 -0
  40. package/dist/upgrade.d.ts +27 -0
  41. package/dist/upgrade.d.ts.map +1 -0
  42. package/dist/upgrade.js +22 -0
  43. package/dist/upgrade.js.map +7 -0
  44. package/package.json +73 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,12 @@
1
+ # @scalar/openapi-upgrader
2
+
3
+ ## 0.1.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 6221e4a: hello world :)
8
+ - 02085ef: feat: add OpenAPI 3.1 > 3.2 upgrader (not enabled by default)
9
+
10
+ ### Patch Changes
11
+
12
+ - 2d612e4: fix: consumed media types are not deleted for non-existing body parameter and referenced parameter is added empty schema object
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2023-present Scalar
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,121 @@
1
+ # Scalar OpenAPI Upgrader
2
+
3
+ [![Version](https://img.shields.io/npm/v/@scalar/openapi-upgrader)](https://www.npmjs.com/package/@scalar/openapi-upgrader)
4
+ [![Downloads](https://img.shields.io/npm/dm/@scalar/openapi-upgrader)](https://www.npmjs.com/package/@scalar/openapi-upgrader)
5
+ [![License](https://img.shields.io/npm/l/@scalar/openapi-upgrader)](https://www.npmjs.com/package/@scalar/openapi-upgrader)
6
+ [![Discord](https://img.shields.io/discord/1135330207960678410?style=flat&color=5865F2)](https://discord.gg/scalar)
7
+
8
+ Upgrade all your OpenAPI documents to the latest and greatest version
9
+
10
+ ## Installation
11
+
12
+ ```bash
13
+ npm add @scalar/openapi-upgrader
14
+ ```
15
+
16
+ ## Usage
17
+
18
+ ```ts
19
+ import { upgrade } from '@scalar/openapi-upgrader'
20
+
21
+ const document = upgrade({
22
+ swagger: '2.0',
23
+ info: {
24
+ title: 'Hello World',
25
+ version: '1.0.0',
26
+ },
27
+ paths: {},
28
+ })
29
+
30
+ console.log(document.openapi)
31
+ // Output: 3.1.1
32
+ ```
33
+
34
+ ### Experimental: Upgrade to OpenAPI 3.2
35
+
36
+ ```ts
37
+ import { upgrade } from '@scalar/openapi-upgrader'
38
+
39
+ const OPENAPI_DOCUMENT = {
40
+ swagger: '2.0',
41
+ info: {
42
+ title: 'Hello World',
43
+ version: '1.0.0',
44
+ },
45
+ paths: {},
46
+ }
47
+
48
+ // We need to explicitly pass '3.2' to upgrade to OpenAPI 3.2
49
+ const document = upgrade(OPENAPI_DOCUMENT, '3.2')
50
+
51
+ console.log(document.openapi)
52
+ // Output: 3.2.0
53
+ ```
54
+
55
+ ### CLI
56
+
57
+ ```bash
58
+ npx @scalar/cli document upgrade swagger.json --output openapi.json
59
+ ```
60
+
61
+ ### From Swagger 2.0 to OpenAPI 3.0
62
+
63
+ ```ts
64
+ import { upgradeFromTwoToThree } from '@scalar/openapi-upgrader/2.0-to-3.0'
65
+
66
+ const document = upgradeFromTwoToThree({
67
+ swagger: '2.0',
68
+ info: {
69
+ title: 'Hello World',
70
+ version: '1.0.0',
71
+ },
72
+ paths: {},
73
+ })
74
+
75
+ console.log(document.openapi)
76
+ // Output: 3.0.4
77
+ ```
78
+
79
+ ### From OpenAPI 3.0 to OpenAPI 3.1
80
+
81
+ ```ts
82
+ import { upgradeFromThreeToThreeOne } from '@scalar/openapi-upgrader/3.0-to-3.1'
83
+
84
+ const document = upgradeFromThreeToThreeOne({
85
+ openapi: '3.0.0',
86
+ info: {
87
+ title: 'Hello World',
88
+ version: '1.0.0',
89
+ },
90
+ paths: {},
91
+ })
92
+
93
+ console.log(document.openapi)
94
+ // Output: 3.1.1
95
+ ```
96
+
97
+ ### From OpenAPI 3.1 to OpenAPI 3.2
98
+
99
+ ```ts
100
+ import { upgradeFromThreeOneToThreeTwo } from '@scalar/openapi-upgrader/3.1-to-3.2'
101
+
102
+ const document = upgradeFromThreeOneToThreeTwo({
103
+ openapi: '3.1.0',
104
+ info: {
105
+ title: 'Hello World',
106
+ version: '1.0.0',
107
+ },
108
+ paths: {},
109
+ })
110
+
111
+ console.log(document.openapi)
112
+ // Output: 3.2.0
113
+ ```
114
+
115
+ ## Community
116
+
117
+ We are API nerds. You too? Let's chat on Discord: <https://discord.gg/scalar>
118
+
119
+ ## License
120
+
121
+ The source code in this repository is licensed under [MIT](https://github.com/scalar/scalar/blob/main/LICENSE).
@@ -0,0 +1,2 @@
1
+ export { upgradeFromTwoToThree } from './upgrade-from-two-to-three.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/2.0-to-3.0/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,qBAAqB,EAAE,MAAM,6BAA6B,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { upgradeFromTwoToThree } from "./upgrade-from-two-to-three.js";
2
+ export {
3
+ upgradeFromTwoToThree
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/2.0-to-3.0/index.ts"],
4
+ "sourcesContent": ["export { upgradeFromTwoToThree } from './upgrade-from-two-to-three'\n"],
5
+ "mappings": "AAAA,SAAS,6BAA6B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,9 @@
1
+ import type { OpenAPIV3 } from '@scalar/openapi-types';
2
+ import type { UnknownObject } from '@scalar/types/utils';
3
+ /**
4
+ * Upgrade Swagger 2.0 to OpenAPI 3.0
5
+ *
6
+ * https://swagger.io/blog/news/whats-new-in-openapi-3-0/
7
+ */
8
+ export declare function upgradeFromTwoToThree(originalSpecification: UnknownObject): UnknownObject | OpenAPIV3.Document<{}>;
9
+ //# sourceMappingURL=upgrade-from-two-to-three.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade-from-two-to-three.d.ts","sourceRoot":"","sources":["../../src/2.0-to-3.0/upgrade-from-two-to-three.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAa,SAAS,EAAE,MAAM,uBAAuB,CAAA;AACjE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAoBxD;;;;GAIG;AACH,wBAAgB,qBAAqB,CAAC,qBAAqB,EAAE,aAAa,0CAySzE"}
@@ -0,0 +1,389 @@
1
+ import { traverse } from "../helpers/traverse.js";
2
+ const upgradeFlow = (flow) => {
3
+ switch (flow) {
4
+ case "application":
5
+ return "clientCredentials";
6
+ case "accessCode":
7
+ return "authorizationCode";
8
+ case "implicit":
9
+ return "implicit";
10
+ case "password":
11
+ return "password";
12
+ default:
13
+ return flow;
14
+ }
15
+ };
16
+ function upgradeFromTwoToThree(originalSpecification) {
17
+ let document = originalSpecification;
18
+ if (document !== null && typeof document === "object" && typeof document.swagger === "string" && document.swagger?.startsWith("2.0")) {
19
+ document.openapi = "3.0.4";
20
+ delete document.swagger;
21
+ } else {
22
+ return document;
23
+ }
24
+ if (document.host) {
25
+ const schemes = Array.isArray(document.schemes) && document.schemes?.length ? document.schemes : ["http"];
26
+ document.servers = schemes.map((scheme) => ({
27
+ url: `${scheme}://${document.host}${document.basePath ?? ""}`
28
+ }));
29
+ delete document.basePath;
30
+ delete document.schemes;
31
+ delete document.host;
32
+ } else if (document.basePath) {
33
+ document.servers = [{ url: document.basePath }];
34
+ delete document.basePath;
35
+ }
36
+ if (document.definitions) {
37
+ document.components = Object.assign({}, document.components, {
38
+ schemas: document.definitions
39
+ });
40
+ delete document.definitions;
41
+ document = traverse(document, (schema) => {
42
+ if (typeof schema.$ref === "string" && schema.$ref.startsWith("#/definitions/")) {
43
+ schema.$ref = schema.$ref.replace(/^#\/definitions\//, "#/components/schemas/");
44
+ }
45
+ return schema;
46
+ });
47
+ }
48
+ document = traverse(document, (schema) => {
49
+ if (schema.type === "file") {
50
+ schema.type = "string";
51
+ schema.format = "binary";
52
+ }
53
+ return schema;
54
+ });
55
+ if (Object.hasOwn(document, "parameters")) {
56
+ document = traverse(document, (schema) => {
57
+ if (typeof schema.$ref === "string" && schema.$ref.startsWith("#/parameters/")) {
58
+ const schemaName = schema.$ref.split("/")[2];
59
+ if (!schemaName) {
60
+ return schema;
61
+ }
62
+ const param = document.parameters && typeof document.parameters === "object" && schemaName in document.parameters ? document.parameters[schemaName] : void 0;
63
+ if (param && typeof param === "object" && "in" in param && (param.in === "body" || param.in === "formData")) {
64
+ schema.$ref = schema.$ref.replace(/^#\/parameters\//, "#/components/requestBodies/");
65
+ } else {
66
+ schema.$ref = schema.$ref.replace(/^#\/parameters\//, "#/components/parameters/");
67
+ }
68
+ }
69
+ return schema;
70
+ });
71
+ document.components ??= {};
72
+ const params = {};
73
+ const bodyParams = {};
74
+ const parameters = document.parameters && typeof document.parameters === "object" ? document.parameters : {};
75
+ for (const [name, param] of Object.entries(parameters)) {
76
+ if (param && typeof param === "object" && "in" in param) {
77
+ if (param.in === "body") {
78
+ bodyParams[name] = migrateBodyParameter(
79
+ param,
80
+ document.consumes ?? ["application/json"]
81
+ );
82
+ } else if (param.in === "formData") {
83
+ bodyParams[name] = migrateFormDataParameter([param]);
84
+ } else {
85
+ params[name] = transformParameterObject(param);
86
+ }
87
+ }
88
+ }
89
+ if (Object.keys(params).length > 0) {
90
+ ;
91
+ document.components.parameters = params;
92
+ }
93
+ if (Object.keys(bodyParams).length > 0) {
94
+ ;
95
+ document.components.requestBodies = bodyParams;
96
+ }
97
+ delete document.parameters;
98
+ }
99
+ if (typeof document.paths === "object") {
100
+ for (const path in document.paths) {
101
+ if (Object.hasOwn(document.paths, path)) {
102
+ const pathItem = document.paths && typeof document.paths === "object" && path in document.paths ? document.paths[path] : void 0;
103
+ if (!pathItem || typeof pathItem !== "object") {
104
+ continue;
105
+ }
106
+ let requestBodyObject;
107
+ for (const methodOrParameters in pathItem) {
108
+ if (methodOrParameters === "parameters" && Object.hasOwn(pathItem, methodOrParameters)) {
109
+ const pathItemParameters = migrateParameters(
110
+ pathItem.parameters,
111
+ document.consumes ?? ["application/json"]
112
+ );
113
+ pathItem.parameters = pathItemParameters.parameters;
114
+ requestBodyObject = pathItemParameters.requestBody;
115
+ } else if (Object.hasOwn(pathItem, methodOrParameters)) {
116
+ const operationItem = pathItem[methodOrParameters];
117
+ if (requestBodyObject) {
118
+ operationItem.requestBody = requestBodyObject;
119
+ }
120
+ if (operationItem.parameters) {
121
+ const migrationResult = migrateParameters(
122
+ operationItem.parameters,
123
+ operationItem.consumes ?? document.consumes ?? ["application/json"]
124
+ );
125
+ operationItem.parameters = migrationResult.parameters;
126
+ if (migrationResult.requestBody) {
127
+ operationItem.requestBody = migrationResult.requestBody;
128
+ }
129
+ }
130
+ delete operationItem.consumes;
131
+ if (operationItem.responses) {
132
+ for (const response in operationItem.responses) {
133
+ if (Object.hasOwn(operationItem.responses, response)) {
134
+ const responseItem = operationItem.responses[response];
135
+ if (responseItem.headers && typeof responseItem.headers === "object") {
136
+ responseItem.headers = Object.entries(responseItem.headers).reduce(
137
+ (acc, [name, header]) => {
138
+ if (header && typeof header === "object") {
139
+ return {
140
+ [name]: transformParameterObject(header),
141
+ ...acc
142
+ };
143
+ }
144
+ return acc;
145
+ },
146
+ {}
147
+ );
148
+ }
149
+ if (responseItem.schema) {
150
+ const produces = document.produces ?? operationItem.produces ?? ["application/json"];
151
+ if (typeof responseItem.content !== "object") {
152
+ responseItem.content = {};
153
+ }
154
+ for (const type of produces) {
155
+ responseItem.content[type] = {
156
+ schema: responseItem.schema
157
+ };
158
+ }
159
+ delete responseItem.schema;
160
+ }
161
+ }
162
+ }
163
+ }
164
+ delete operationItem.produces;
165
+ if (operationItem.parameters?.length === 0) {
166
+ delete operationItem.parameters;
167
+ }
168
+ }
169
+ }
170
+ }
171
+ }
172
+ }
173
+ if (document.securityDefinitions) {
174
+ if (typeof document.components !== "object" || document.components === null) {
175
+ document.components = {};
176
+ }
177
+ if (document.components && typeof document.components === "object") {
178
+ Object.assign(document.components, { securitySchemes: {} });
179
+ }
180
+ for (const [key, securityScheme] of Object.entries(document.securityDefinitions)) {
181
+ if (typeof securityScheme === "object") {
182
+ if ("type" in securityScheme && securityScheme.type === "oauth2") {
183
+ const { flow, authorizationUrl, tokenUrl, scopes } = securityScheme;
184
+ if (document.components && typeof document.components === "object" && "securitySchemes" in document.components && document.components.securitySchemes) {
185
+ Object.assign(document.components.securitySchemes, {
186
+ [key]: {
187
+ type: "oauth2",
188
+ flows: {
189
+ [upgradeFlow(flow || "implicit")]: Object.assign(
190
+ {},
191
+ authorizationUrl && { authorizationUrl },
192
+ tokenUrl && { tokenUrl },
193
+ scopes && { scopes }
194
+ )
195
+ }
196
+ }
197
+ });
198
+ }
199
+ } else if ("type" in securityScheme && securityScheme.type === "basic") {
200
+ if (document.components && typeof document.components === "object" && "securitySchemes" in document.components && document.components.securitySchemes) {
201
+ Object.assign(document.components.securitySchemes, {
202
+ [key]: {
203
+ type: "http",
204
+ scheme: "basic"
205
+ }
206
+ });
207
+ }
208
+ } else {
209
+ if (document.components && typeof document.components === "object" && "securitySchemes" in document.components && document.components.securitySchemes) {
210
+ Object.assign(document.components.securitySchemes, {
211
+ [key]: securityScheme
212
+ });
213
+ }
214
+ }
215
+ }
216
+ }
217
+ delete document.securityDefinitions;
218
+ }
219
+ delete document.consumes;
220
+ delete document.produces;
221
+ return document;
222
+ }
223
+ function transformItemsObject(obj) {
224
+ const schemaProperties = [
225
+ "type",
226
+ "format",
227
+ "items",
228
+ "maximum",
229
+ "exclusiveMaximum",
230
+ "minimum",
231
+ "exclusiveMinimum",
232
+ "maxLength",
233
+ "minLength",
234
+ "pattern",
235
+ "maxItems",
236
+ "minItems",
237
+ "uniqueItems",
238
+ "enum",
239
+ "multipleOf"
240
+ ];
241
+ return schemaProperties.reduce((acc, property) => {
242
+ if (Object.hasOwn(obj, property)) {
243
+ acc[property] = obj[property];
244
+ delete obj[property];
245
+ }
246
+ return acc;
247
+ }, {});
248
+ }
249
+ function transformParameterObject(parameter) {
250
+ if (Object.hasOwn(parameter, "$ref")) {
251
+ return parameter;
252
+ }
253
+ const serializationStyle = getParameterSerializationStyle(parameter);
254
+ const schema = transformItemsObject(parameter);
255
+ delete parameter.collectionFormat;
256
+ delete parameter.default;
257
+ return {
258
+ schema,
259
+ ...serializationStyle,
260
+ ...parameter
261
+ };
262
+ }
263
+ const querySerialization = {
264
+ ssv: {
265
+ style: "spaceDelimited",
266
+ explode: false
267
+ },
268
+ pipes: {
269
+ style: "pipeDelimited",
270
+ explode: false
271
+ },
272
+ multi: {
273
+ style: "form",
274
+ explode: true
275
+ },
276
+ csv: {
277
+ style: "form",
278
+ explode: false
279
+ },
280
+ tsv: {}
281
+ };
282
+ const pathAndHeaderSerialization = {
283
+ ssv: {},
284
+ pipes: {},
285
+ multi: {},
286
+ csv: {
287
+ style: "simple",
288
+ explode: false
289
+ },
290
+ tsv: {}
291
+ };
292
+ const serializationStyles = {
293
+ header: pathAndHeaderSerialization,
294
+ query: querySerialization,
295
+ path: pathAndHeaderSerialization
296
+ };
297
+ function getParameterSerializationStyle(parameter) {
298
+ if (parameter.type !== "array" || !(parameter.in === "query" || parameter.in === "path" || parameter.in === "header")) {
299
+ return {};
300
+ }
301
+ const collectionFormat = parameter.collectionFormat ?? "csv";
302
+ if (parameter.in in serializationStyles && collectionFormat in serializationStyles[parameter.in]) {
303
+ return serializationStyles[parameter.in][collectionFormat];
304
+ }
305
+ return {};
306
+ }
307
+ function migrateBodyParameter(bodyParameter, consumes) {
308
+ delete bodyParameter.name;
309
+ delete bodyParameter.in;
310
+ const { schema, ...requestBody } = bodyParameter;
311
+ const requestBodyObject = {
312
+ content: {},
313
+ ...requestBody
314
+ };
315
+ if (requestBodyObject.content) {
316
+ for (const type of consumes) {
317
+ requestBodyObject.content[type] = {
318
+ schema
319
+ };
320
+ }
321
+ }
322
+ return requestBodyObject;
323
+ }
324
+ function migrateFormDataParameter(parameters) {
325
+ const requestBodyObject = {
326
+ content: {}
327
+ };
328
+ if (requestBodyObject.content) {
329
+ requestBodyObject.content["application/x-www-form-urlencoded"] = {
330
+ schema: {
331
+ type: "object",
332
+ properties: {},
333
+ required: []
334
+ // Initialize required array
335
+ }
336
+ };
337
+ const formContent = requestBodyObject.content?.["application/x-www-form-urlencoded"];
338
+ if (formContent?.schema && typeof formContent.schema === "object" && "properties" in formContent.schema) {
339
+ for (const param of parameters) {
340
+ if (param.name && formContent.schema.properties) {
341
+ formContent.schema.properties[param.name] = {
342
+ type: param.type,
343
+ description: param.description
344
+ };
345
+ if (param.required && Array.isArray(formContent.schema.required)) {
346
+ formContent.schema.required.push(param.name);
347
+ }
348
+ }
349
+ }
350
+ }
351
+ }
352
+ return requestBodyObject;
353
+ }
354
+ function migrateParameters(parameters, consumes) {
355
+ const result = {
356
+ parameters: parameters.filter((parameter) => !(parameter.in === "body" || parameter.in === "formData")).map((parameter) => transformParameterObject(parameter))
357
+ };
358
+ const bodyParameter = structuredClone(
359
+ parameters.find((parameter) => parameter.in === "body") ?? {}
360
+ );
361
+ if (bodyParameter && Object.keys(bodyParameter).length) {
362
+ result.requestBody = migrateBodyParameter(bodyParameter, consumes);
363
+ }
364
+ const formDataParameters = parameters.filter((parameter) => parameter.in === "formData");
365
+ if (formDataParameters.length > 0) {
366
+ const requestBodyObject = migrateFormDataParameter(formDataParameters);
367
+ if (typeof result.requestBody !== "object") {
368
+ result.requestBody = requestBodyObject;
369
+ } else {
370
+ result.requestBody = {
371
+ ...result.requestBody,
372
+ content: {
373
+ ...result.requestBody.content,
374
+ ...requestBodyObject.content
375
+ }
376
+ };
377
+ }
378
+ if (typeof result.requestBody !== "object") {
379
+ result.requestBody = {
380
+ content: {}
381
+ };
382
+ }
383
+ }
384
+ return result;
385
+ }
386
+ export {
387
+ upgradeFromTwoToThree
388
+ };
389
+ //# sourceMappingURL=upgrade-from-two-to-three.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/2.0-to-3.0/upgrade-from-two-to-three.ts"],
4
+ "sourcesContent": ["import type { OpenAPIV2, OpenAPIV3 } from '@scalar/openapi-types'\nimport type { UnknownObject } from '@scalar/types/utils'\n\nimport { traverse } from '@/helpers/traverse'\n\n/** Update the flow names to OpenAPI 3.1.0 format */\nconst upgradeFlow = (flow: string): 'implicit' | 'password' | 'clientCredentials' | 'authorizationCode' => {\n switch (flow) {\n case 'application':\n return 'clientCredentials'\n case 'accessCode':\n return 'authorizationCode'\n case 'implicit':\n return 'implicit'\n case 'password':\n return 'password'\n default:\n return flow as never\n }\n}\n\n/**\n * Upgrade Swagger 2.0 to OpenAPI 3.0\n *\n * https://swagger.io/blog/news/whats-new-in-openapi-3-0/\n */\nexport function upgradeFromTwoToThree(originalSpecification: UnknownObject) {\n let document = originalSpecification\n\n // Version\n if (\n document !== null &&\n typeof document === 'object' &&\n typeof document.swagger === 'string' &&\n document.swagger?.startsWith('2.0')\n ) {\n document.openapi = '3.0.4'\n delete document.swagger\n } else {\n // Skip if it's something else than 3.0.x\n return document\n }\n\n // Servers\n if (document.host) {\n const schemes = Array.isArray(document.schemes) && document.schemes?.length ? document.schemes : ['http']\n\n document.servers = schemes.map((scheme: string[]) => ({\n url: `${scheme}://${document.host}${document.basePath ?? ''}`,\n }))\n\n delete document.basePath\n delete document.schemes\n delete document.host\n } else if (document.basePath) {\n document.servers = [{ url: document.basePath }]\n delete document.basePath\n }\n\n // Schemas\n if (document.definitions) {\n document.components = Object.assign({}, document.components, {\n schemas: document.definitions,\n })\n\n delete document.definitions\n\n // Rewrite $refs to definitions\n document = traverse(document, (schema) => {\n // Rewrite $refs to components\n if (typeof schema.$ref === 'string' && schema.$ref.startsWith('#/definitions/')) {\n schema.$ref = schema.$ref.replace(/^#\\/definitions\\//, '#/components/schemas/')\n }\n\n return schema\n })\n }\n\n // Transform file type to string with binary format\n document = traverse(document, (schema) => {\n if (schema.type === 'file') {\n schema.type = 'string'\n schema.format = 'binary'\n }\n\n return schema\n })\n\n if (Object.hasOwn(document, 'parameters')) {\n // update all the $refs before we do any transformations\n document = traverse(document, (schema) => {\n if (typeof schema.$ref === 'string' && schema.$ref.startsWith('#/parameters/')) {\n const schemaName = schema.$ref.split('/')[2]\n\n if (!schemaName) {\n return schema\n }\n\n const param =\n document.parameters && typeof document.parameters === 'object' && schemaName in document.parameters\n ? (document.parameters as Record<string, unknown>)[schemaName]\n : undefined\n\n if (param && typeof param === 'object' && 'in' in param && (param.in === 'body' || param.in === 'formData')) {\n schema.$ref = schema.$ref.replace(/^#\\/parameters\\//, '#/components/requestBodies/')\n } else {\n schema.$ref = schema.$ref.replace(/^#\\/parameters\\//, '#/components/parameters/')\n }\n }\n\n return schema\n })\n\n document.components ??= {}\n\n const params: Record<string, OpenAPIV3.ParameterObject> = {}\n const bodyParams: Record<string, OpenAPIV3.RequestBodyObject> = {}\n const parameters =\n document.parameters && typeof document.parameters === 'object'\n ? (document.parameters as Record<string, unknown>)\n : {}\n for (const [name, param] of Object.entries(parameters)) {\n if (param && typeof param === 'object' && 'in' in param) {\n if (param.in === 'body') {\n bodyParams[name] = migrateBodyParameter(\n param as OpenAPIV2.ParameterObject,\n (document.consumes as string[] | undefined) ?? ['application/json'],\n )\n } else if (param.in === 'formData') {\n bodyParams[name] = migrateFormDataParameter([param as OpenAPIV2.ParameterObject])\n } else {\n params[name] = transformParameterObject(param as OpenAPIV2.ParameterObject)\n }\n }\n }\n\n if (Object.keys(params).length > 0) {\n ;(document.components as UnknownObject).parameters = params\n }\n\n if (Object.keys(bodyParams).length > 0) {\n ;(document.components as UnknownObject).requestBodies = bodyParams\n }\n\n delete document.parameters\n }\n\n // Paths\n if (typeof document.paths === 'object') {\n for (const path in document.paths) {\n if (Object.hasOwn(document.paths, path)) {\n const pathItem =\n document.paths && typeof document.paths === 'object' && path in document.paths\n ? (document.paths as Record<string, unknown>)[path]\n : undefined\n\n if (!pathItem || typeof pathItem !== 'object') {\n continue\n }\n\n let requestBodyObject: OpenAPIV3.RequestBodyObject | undefined\n\n for (const methodOrParameters in pathItem) {\n if (methodOrParameters === 'parameters' && Object.hasOwn(pathItem, methodOrParameters)) {\n const pathItemParameters = migrateParameters(\n (pathItem as any).parameters,\n (document.consumes as string[] | undefined) ?? ['application/json'],\n )\n\n ;(pathItem as any).parameters = pathItemParameters.parameters\n requestBodyObject = pathItemParameters.requestBody\n } else if (Object.hasOwn(pathItem, methodOrParameters)) {\n const operationItem = (pathItem as any)[methodOrParameters]\n\n if (requestBodyObject) {\n operationItem.requestBody = requestBodyObject\n }\n\n if (operationItem.parameters) {\n const migrationResult = migrateParameters(\n operationItem.parameters,\n operationItem.consumes ?? document.consumes ?? ['application/json'],\n )\n\n operationItem.parameters = migrationResult.parameters\n\n if (migrationResult.requestBody) {\n operationItem.requestBody = migrationResult.requestBody\n }\n }\n\n delete operationItem.consumes\n\n // Responses\n if (operationItem.responses) {\n for (const response in operationItem.responses) {\n if (Object.hasOwn(operationItem.responses, response)) {\n const responseItem = operationItem.responses[response]\n\n if (responseItem.headers && typeof responseItem.headers === 'object') {\n responseItem.headers = Object.entries(responseItem.headers).reduce(\n (acc, [name, header]) => {\n if (header && typeof header === 'object') {\n return {\n [name]: transformParameterObject(header as OpenAPIV2.ParameterObject),\n ...acc,\n }\n }\n return acc\n },\n {} as Record<string, OpenAPIV3.ParameterObject>,\n )\n }\n if (responseItem.schema) {\n const produces = document.produces ?? operationItem.produces ?? ['application/json']\n\n if (typeof responseItem.content !== 'object') {\n responseItem.content = {}\n }\n\n for (const type of produces) {\n responseItem.content[type] = {\n schema: responseItem.schema,\n }\n }\n\n delete responseItem.schema\n }\n }\n }\n }\n\n delete operationItem.produces\n\n // Delete empty parameters\n if (operationItem.parameters?.length === 0) {\n delete operationItem.parameters\n }\n }\n }\n }\n }\n }\n\n // Upgrade securityDefinitions\n if (document.securityDefinitions) {\n if (typeof document.components !== 'object' || document.components === null) {\n document.components = {}\n }\n\n if (document.components && typeof document.components === 'object') {\n Object.assign(document.components, { securitySchemes: {} })\n }\n\n for (const [key, securityScheme] of Object.entries(document.securityDefinitions)) {\n if (typeof securityScheme === 'object') {\n if ('type' in securityScheme && securityScheme.type === 'oauth2') {\n const { flow, authorizationUrl, tokenUrl, scopes } = securityScheme as {\n type: 'oauth2'\n flow?: string\n authorizationUrl?: string\n tokenUrl?: string\n scopes?: Record<string, string>\n }\n\n // Convert flow values to OpenAPI 3.1.0 format\n\n if (\n document.components &&\n typeof document.components === 'object' &&\n 'securitySchemes' in document.components &&\n document.components.securitySchemes\n ) {\n Object.assign(document.components.securitySchemes, {\n [key]: {\n type: 'oauth2',\n flows: {\n [upgradeFlow(flow || 'implicit')]: Object.assign(\n {},\n authorizationUrl && { authorizationUrl },\n tokenUrl && { tokenUrl },\n scopes && { scopes },\n ),\n },\n },\n })\n }\n } else if ('type' in securityScheme && securityScheme.type === 'basic') {\n if (\n document.components &&\n typeof document.components === 'object' &&\n 'securitySchemes' in document.components &&\n document.components.securitySchemes\n ) {\n Object.assign(document.components.securitySchemes, {\n [key]: {\n type: 'http',\n scheme: 'basic',\n },\n })\n }\n } else {\n if (\n document.components &&\n typeof document.components === 'object' &&\n 'securitySchemes' in document.components &&\n document.components.securitySchemes\n ) {\n Object.assign(document.components.securitySchemes, {\n [key]: securityScheme,\n })\n }\n }\n }\n }\n\n delete document.securityDefinitions\n }\n\n delete document.consumes\n delete document.produces\n\n return document as OpenAPIV3.Document\n}\n\nfunction transformItemsObject<T extends Record<PropertyKey, unknown>>(obj: T): OpenAPIV3.SchemaObject {\n const schemaProperties = [\n 'type',\n 'format',\n 'items',\n 'maximum',\n 'exclusiveMaximum',\n 'minimum',\n 'exclusiveMinimum',\n 'maxLength',\n 'minLength',\n 'pattern',\n 'maxItems',\n 'minItems',\n 'uniqueItems',\n 'enum',\n 'multipleOf',\n ]\n\n return schemaProperties.reduce((acc, property) => {\n if (Object.hasOwn(obj, property)) {\n acc[property] = obj[property]\n delete obj[property]\n }\n\n return acc\n }, {} as OpenAPIV3.SchemaObject)\n}\n\nfunction transformParameterObject(parameter: OpenAPIV2.ParameterObject): OpenAPIV3.ParameterObject {\n if (Object.hasOwn(parameter, '$ref')) {\n return parameter\n }\n\n // it is important to call getParameterSerializationStyle first because transformItemsObject modifies properties on which getParameterSerializationStyle rely on\n const serializationStyle = getParameterSerializationStyle(parameter)\n const schema = transformItemsObject(parameter)\n\n delete parameter.collectionFormat\n delete parameter.default\n\n return {\n schema,\n ...serializationStyle,\n ...parameter,\n }\n}\n\ntype CollectionFormat = 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi'\n\ntype ParameterSerializationStyle = { style?: string; explode?: boolean }\n\nconst querySerialization: Record<CollectionFormat, ParameterSerializationStyle> = {\n ssv: {\n style: 'spaceDelimited',\n explode: false,\n },\n pipes: {\n style: 'pipeDelimited',\n explode: false,\n },\n multi: {\n style: 'form',\n explode: true,\n },\n csv: {\n style: 'form',\n explode: false,\n },\n tsv: {},\n}\n\nconst pathAndHeaderSerialization: Record<CollectionFormat, ParameterSerializationStyle> = {\n ssv: {},\n pipes: {},\n multi: {},\n csv: {\n style: 'simple',\n explode: false,\n },\n tsv: {},\n}\n\nconst serializationStyles = {\n header: pathAndHeaderSerialization,\n query: querySerialization,\n path: pathAndHeaderSerialization,\n} as const\n\nfunction getParameterSerializationStyle(parameter: OpenAPIV2.ParameterObject): ParameterSerializationStyle {\n if (\n parameter.type !== 'array' ||\n !(parameter.in === 'query' || parameter.in === 'path' || parameter.in === 'header')\n ) {\n return {}\n }\n\n const collectionFormat = parameter.collectionFormat ?? 'csv'\n\n if (\n parameter.in in serializationStyles &&\n collectionFormat in serializationStyles[parameter.in as keyof typeof serializationStyles]\n ) {\n return serializationStyles[parameter.in as keyof typeof serializationStyles][collectionFormat as CollectionFormat]\n }\n\n return {}\n}\n\ntype ParameterMigrationResult = {\n parameters: OpenAPIV3.ParameterObject[]\n requestBody?: OpenAPIV3.RequestBodyObject\n}\n\nfunction migrateBodyParameter(\n bodyParameter: OpenAPIV2.ParameterObject,\n consumes: string[],\n): OpenAPIV3.RequestBodyObject {\n delete bodyParameter.name\n delete bodyParameter.in\n\n const { schema, ...requestBody } = bodyParameter\n\n const requestBodyObject: OpenAPIV3.RequestBodyObject = {\n content: {},\n ...requestBody,\n }\n\n if (requestBodyObject.content) {\n for (const type of consumes) {\n requestBodyObject.content[type] = {\n schema: schema,\n }\n }\n }\n\n return requestBodyObject\n}\n\nfunction migrateFormDataParameter(parameters: OpenAPIV2.ParameterObject[]): OpenAPIV3.RequestBodyObject {\n const requestBodyObject: OpenAPIV3.RequestBodyObject = {\n content: {},\n }\n\n if (requestBodyObject.content) {\n requestBodyObject.content['application/x-www-form-urlencoded'] = {\n schema: {\n type: 'object',\n properties: {},\n required: [], // Initialize required array\n },\n }\n\n const formContent = requestBodyObject.content?.['application/x-www-form-urlencoded']\n if (formContent?.schema && typeof formContent.schema === 'object' && 'properties' in formContent.schema) {\n for (const param of parameters) {\n if (param.name && formContent.schema.properties) {\n formContent.schema.properties[param.name] = {\n type: param.type,\n description: param.description,\n }\n\n // Add to required array if param is required\n if (param.required && Array.isArray(formContent.schema.required)) {\n formContent.schema.required.push(param.name)\n }\n }\n }\n }\n }\n\n return requestBodyObject\n}\n\nfunction migrateParameters(parameters: OpenAPIV2.ParameterObject[], consumes: string[]): ParameterMigrationResult {\n const result: ParameterMigrationResult = {\n parameters: parameters\n .filter((parameter) => !(parameter.in === 'body' || parameter.in === 'formData'))\n .map((parameter) => transformParameterObject(parameter)),\n }\n\n const bodyParameter = structuredClone(\n parameters.find((parameter: OpenAPIV3.ParameterObject) => parameter.in === 'body') ?? {},\n )\n\n if (bodyParameter && Object.keys(bodyParameter).length) {\n result.requestBody = migrateBodyParameter(bodyParameter, consumes)\n }\n\n const formDataParameters = parameters.filter((parameter: OpenAPIV2.ParameterObject) => parameter.in === 'formData')\n\n if (formDataParameters.length > 0) {\n const requestBodyObject = migrateFormDataParameter(formDataParameters)\n\n if (typeof result.requestBody !== 'object') {\n result.requestBody = requestBodyObject\n } else {\n result.requestBody = {\n ...result.requestBody,\n content: {\n ...result.requestBody.content,\n ...requestBodyObject.content,\n },\n }\n }\n\n if (typeof result.requestBody !== 'object') {\n result.requestBody = {\n content: {},\n }\n }\n }\n\n return result\n}\n"],
5
+ "mappings": "AAGA,SAAS,gBAAgB;AAGzB,MAAM,cAAc,CAAC,SAAsF;AACzG,UAAQ,MAAM;AAAA,IACZ,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT,KAAK;AACH,aAAO;AAAA,IACT;AACE,aAAO;AAAA,EACX;AACF;AAOO,SAAS,sBAAsB,uBAAsC;AAC1E,MAAI,WAAW;AAGf,MAC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UAAU,UAAU,OAAO,WAAW,EAC/E,IAAI,CAAC,cAAc,yBAAyB,SAAS,CAAC;AAAA,EAC3D;AAEA,QAAM,gBAAgB;AAAA,IACpB,WAAW,KAAK,CAAC,cAAyC,UAAU,OAAO,MAAM,KAAK,CAAC;AAAA,EACzF;AAEA,MAAI,iBAAiB,OAAO,KAAK,aAAa,EAAE,QAAQ;AACtD,WAAO,cAAc,qBAAqB,eAAe,QAAQ;AAAA,EACnE;AAEA,QAAM,qBAAqB,WAAW,OAAO,CAAC,cAAyC,UAAU,OAAO,UAAU;AAElH,MAAI,mBAAmB,SAAS,GAAG;AACjC,UAAM,oBAAoB,yBAAyB,kBAAkB;AAErE,QAAI,OAAO,OAAO,gBAAgB,UAAU;AAC1C,aAAO,cAAc;AAAA,IACvB,OAAO;AACL,aAAO,cAAc;AAAA,QACnB,GAAG,OAAO;AAAA,QACV,SAAS;AAAA,UACP,GAAG,OAAO,YAAY;AAAA,UACtB,GAAG,kBAAkB;AAAA,QACvB;AAAA,MACF;AAAA,IACF;AAEA,QAAI,OAAO,OAAO,gBAAgB,UAAU;AAC1C,aAAO,cAAc;AAAA,QACnB,SAAS,CAAC;AAAA,MACZ;AAAA,IACF;AAAA,EACF;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export { upgradeFromThreeToThreeOne } from './upgrade-from-three-to-three-one.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/3.0-to-3.1/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,0BAA0B,EAAE,MAAM,mCAAmC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { upgradeFromThreeToThreeOne } from "./upgrade-from-three-to-three-one.js";
2
+ export {
3
+ upgradeFromThreeToThreeOne
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/3.0-to-3.1/index.ts"],
4
+ "sourcesContent": ["export { upgradeFromThreeToThreeOne } from './upgrade-from-three-to-three-one'\n"],
5
+ "mappings": "AAAA,SAAS,kCAAkC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,31 @@
1
+ import type { OpenAPIV3_1 } from '@scalar/openapi-types';
2
+ import type { UnknownObject } from '@scalar/types/utils';
3
+ /** Determine if the current path is within a schema - optimized version */
4
+ export declare function isSchemaPath(path: string[] | undefined): boolean;
5
+ /**
6
+ * Upgrade from OpenAPI 3.0.x to 3.1.1
7
+ *
8
+ * https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0
9
+ */
10
+ export declare function upgradeFromThreeToThreeOne(originalContent: UnknownObject): UnknownObject | (Omit<Omit<import("@scalar/openapi-types").OpenAPIV3.Document<{}>, "components" | "paths">, keyof {
11
+ [customExtension: `x-${string}`]: any;
12
+ [key: string]: any;
13
+ }> & {
14
+ openapi?: "3.1.0" | "3.1.1";
15
+ swagger?: undefined;
16
+ info?: OpenAPIV3_1.InfoObject;
17
+ jsonSchemaDialect?: string;
18
+ servers?: OpenAPIV3_1.ServerObject[];
19
+ } & Pick<{
20
+ paths?: OpenAPIV3_1.PathsObject<{}, {}> | undefined;
21
+ webhooks?: Record<string, OpenAPIV3_1.PathItemObject | OpenAPIV3_1.ReferenceObject>;
22
+ components?: OpenAPIV3_1.ComponentsObject;
23
+ }, "paths"> & Omit<Partial<{
24
+ paths?: OpenAPIV3_1.PathsObject<{}, {}> | undefined;
25
+ webhooks?: Record<string, OpenAPIV3_1.PathItemObject | OpenAPIV3_1.ReferenceObject>;
26
+ components?: OpenAPIV3_1.ComponentsObject;
27
+ }>, "paths"> & {
28
+ [customExtension: `x-${string}`]: any;
29
+ [key: string]: any;
30
+ });
31
+ //# sourceMappingURL=upgrade-from-three-to-three-one.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade-from-three-to-three-one.d.ts","sourceRoot":"","sources":["../../src/3.0-to-3.1/upgrade-from-three-to-three-one.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAgBxD,2EAA2E;AAC3E,wBAAgB,YAAY,CAAC,IAAI,EAAE,MAAM,EAAE,GAAG,SAAS,GAAG,OAAO,CAsBhE;AAED;;;;GAIG;AACH,wBAAgB,0BAA0B,CAAC,eAAe,EAAE,aAAa;;;;;;;;;;;;;;;;;;;;GAcxE"}
@@ -0,0 +1,119 @@
1
+ import { traverse } from "../helpers/traverse.js";
2
+ const SCHEMA_SEGMENTS = /* @__PURE__ */ new Set([
3
+ "properties",
4
+ "items",
5
+ "allOf",
6
+ "anyOf",
7
+ "oneOf",
8
+ "not",
9
+ "additionalProperties",
10
+ "schema"
11
+ ]);
12
+ function isSchemaPath(path) {
13
+ if (!path) {
14
+ return false;
15
+ }
16
+ if (path.some((segment) => SCHEMA_SEGMENTS.has(segment))) {
17
+ return true;
18
+ }
19
+ if (path.some((segment) => segment.endsWith("Schema"))) {
20
+ return true;
21
+ }
22
+ if (path.length >= 2 && path[0] === "components" && path[1] === "schemas") {
23
+ return true;
24
+ }
25
+ return false;
26
+ }
27
+ function upgradeFromThreeToThreeOne(originalContent) {
28
+ let content = originalContent;
29
+ if (content === null || typeof content.openapi !== "string" || !content.openapi.startsWith("3.0")) {
30
+ return content;
31
+ }
32
+ content.openapi = "3.1.1";
33
+ content = traverse(content, applyChangesToDocument);
34
+ return content;
35
+ }
36
+ const applyChangesToDocument = (schema, path) => {
37
+ if (schema.type !== void 0 && schema.nullable === true) {
38
+ schema.type = [schema.type, "null"];
39
+ delete schema.nullable;
40
+ }
41
+ if (schema.exclusiveMinimum === true) {
42
+ schema.exclusiveMinimum = schema.minimum;
43
+ delete schema.minimum;
44
+ } else if (schema.exclusiveMinimum === false) {
45
+ delete schema.exclusiveMinimum;
46
+ }
47
+ if (schema.exclusiveMaximum === true) {
48
+ schema.exclusiveMaximum = schema.maximum;
49
+ delete schema.maximum;
50
+ } else if (schema.exclusiveMaximum === false) {
51
+ delete schema.exclusiveMaximum;
52
+ }
53
+ if (schema.example !== void 0) {
54
+ if (isSchemaPath(path)) {
55
+ schema.examples = [schema.example];
56
+ } else {
57
+ schema.examples = {
58
+ default: {
59
+ value: schema.example
60
+ }
61
+ };
62
+ }
63
+ delete schema.example;
64
+ }
65
+ if (schema.type === "object" && schema.properties !== void 0) {
66
+ const parentPath = path?.slice(0, -1);
67
+ const isMultipart = parentPath?.some((segment, index) => {
68
+ return segment === "content" && path?.[index + 1] === "multipart/form-data";
69
+ });
70
+ if (isMultipart && schema.properties !== null) {
71
+ for (const value of Object.values(schema.properties)) {
72
+ if (typeof value === "object" && value !== null && "type" in value && "format" in value && value.type === "string" && value.format === "binary") {
73
+ value.contentMediaType = "application/octet-stream";
74
+ delete value.format;
75
+ }
76
+ }
77
+ }
78
+ }
79
+ if (path?.includes("content") && path?.includes("application/octet-stream")) {
80
+ return {};
81
+ }
82
+ const { format: _, ...rest } = schema;
83
+ if (schema.type === "string") {
84
+ if (schema.format === "binary") {
85
+ return {
86
+ ...rest,
87
+ type: "string",
88
+ contentMediaType: "application/octet-stream"
89
+ };
90
+ }
91
+ if (schema.format === "base64") {
92
+ return {
93
+ ...rest,
94
+ type: "string",
95
+ contentEncoding: "base64"
96
+ };
97
+ }
98
+ if (schema.format === "byte") {
99
+ const parentPath = path?.slice(0, -1);
100
+ const contentMediaType = parentPath?.find((_2, index) => path?.[index - 1] === "content");
101
+ return {
102
+ ...rest,
103
+ type: "string",
104
+ contentEncoding: "base64",
105
+ contentMediaType
106
+ };
107
+ }
108
+ }
109
+ if (schema["x-webhooks"] !== void 0) {
110
+ schema.webhooks = schema["x-webhooks"];
111
+ delete schema["x-webhooks"];
112
+ }
113
+ return schema;
114
+ };
115
+ export {
116
+ isSchemaPath,
117
+ upgradeFromThreeToThreeOne
118
+ };
119
+ //# sourceMappingURL=upgrade-from-three-to-three-one.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/3.0-to-3.1/upgrade-from-three-to-three-one.ts"],
4
+ "sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type { UnknownObject } from '@scalar/types/utils'\n\nimport { traverse } from '@/helpers/traverse'\n\n// Create Sets for faster schema path lookups\nconst SCHEMA_SEGMENTS = new Set([\n 'properties',\n 'items',\n 'allOf',\n 'anyOf',\n 'oneOf',\n 'not',\n 'additionalProperties',\n 'schema',\n])\n\n/** Determine if the current path is within a schema - optimized version */\nexport function isSchemaPath(path: string[] | undefined): boolean {\n // Early return if path is undefined\n if (!path) {\n return false\n }\n\n // Check for schema segments first (most common case)\n if (path.some((segment) => SCHEMA_SEGMENTS.has(segment))) {\n return true\n }\n\n // Check for schema suffix\n if (path.some((segment) => segment.endsWith('Schema'))) {\n return true\n }\n\n // Check for components/schemas path\n if (path.length >= 2 && path[0] === 'components' && path[1] === 'schemas') {\n return true\n }\n\n return false\n}\n\n/**\n * Upgrade from OpenAPI 3.0.x to 3.1.1\n *\n * https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0\n */\nexport function upgradeFromThreeToThreeOne(originalContent: UnknownObject) {\n let content = originalContent\n\n // Version check - early return if not 3.0.x\n if (content === null || typeof content.openapi !== 'string' || !content.openapi.startsWith('3.0')) {\n return content\n }\n\n content.openapi = '3.1.1'\n\n // Single traversal that handles all transformations\n content = traverse(content, applyChangesToDocument)\n\n return content as OpenAPIV3_1.Document\n}\n\nconst applyChangesToDocument = (schema: UnknownObject, path?: string[]) => {\n // 1. Handle nullable types\n if (schema.type !== undefined && schema.nullable === true) {\n schema.type = [schema.type, 'null']\n delete schema.nullable\n }\n\n // 2. Handle exclusiveMinimum and exclusiveMaximum\n if (schema.exclusiveMinimum === true) {\n schema.exclusiveMinimum = schema.minimum\n delete schema.minimum\n } else if (schema.exclusiveMinimum === false) {\n delete schema.exclusiveMinimum\n }\n\n if (schema.exclusiveMaximum === true) {\n schema.exclusiveMaximum = schema.maximum\n delete schema.maximum\n } else if (schema.exclusiveMaximum === false) {\n delete schema.exclusiveMaximum\n }\n\n // 3. Handle examples\n if (schema.example !== undefined) {\n if (isSchemaPath(path)) {\n schema.examples = [schema.example]\n } else {\n schema.examples = {\n default: {\n value: schema.example,\n },\n }\n }\n\n delete schema.example\n }\n\n // 4. Handle multipart file uploads\n if (schema.type === 'object' && schema.properties !== undefined) {\n const parentPath = path?.slice(0, -1)\n const isMultipart = parentPath?.some((segment, index) => {\n return segment === 'content' && path?.[index + 1] === 'multipart/form-data'\n })\n\n if (isMultipart && schema.properties !== null) {\n for (const value of Object.values(schema.properties)) {\n if (\n typeof value === 'object' &&\n value !== null &&\n 'type' in value &&\n 'format' in value &&\n value.type === 'string' &&\n value.format === 'binary'\n ) {\n value.contentMediaType = 'application/octet-stream'\n\n delete value.format\n }\n }\n }\n }\n\n // 5. Handle binary file uploads\n if (path?.includes('content') && path?.includes('application/octet-stream')) {\n return {}\n }\n\n // 6. Handle older formats\n const { format: _, ...rest } = schema\n\n if (schema.type === 'string') {\n if (schema.format === 'binary') {\n return {\n ...rest,\n type: 'string',\n contentMediaType: 'application/octet-stream',\n }\n }\n\n if (schema.format === 'base64') {\n return {\n ...rest,\n type: 'string',\n contentEncoding: 'base64',\n }\n }\n\n if (schema.format === 'byte') {\n const parentPath = path?.slice(0, -1)\n const contentMediaType = parentPath?.find((_, index) => path?.[index - 1] === 'content')\n return {\n ...rest,\n type: 'string',\n contentEncoding: 'base64',\n contentMediaType,\n }\n }\n }\n\n // 7. Handle x-webhooks\n if (schema['x-webhooks'] !== undefined) {\n schema.webhooks = schema['x-webhooks']\n delete schema['x-webhooks']\n }\n\n return schema\n}\n"],
5
+ "mappings": "AAGA,SAAS,gBAAgB;AAGzB,MAAM,kBAAkB,oBAAI,IAAI;AAAA,EAC9B;AAAA,EACA;AAAA,EACA;AA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B;AAAA,QACjB;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAGA,MAAI,OAAO,YAAY,MAAM,QAAW;AACtC,WAAO,WAAW,OAAO,YAAY;AACrC,WAAO,OAAO,YAAY;AAAA,EAC5B;AAEA,SAAO;AACT;",
6
+ "names": ["_"]
7
+ }
@@ -0,0 +1,2 @@
1
+ export { upgradeFromThreeOneToThreeTwo } from './upgrade-from-three-one-to-three-two.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/3.1-to-3.2/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,6BAA6B,EAAE,MAAM,uCAAuC,CAAA"}
@@ -0,0 +1,5 @@
1
+ import { upgradeFromThreeOneToThreeTwo } from "./upgrade-from-three-one-to-three-two.js";
2
+ export {
3
+ upgradeFromThreeOneToThreeTwo
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/3.1-to-3.2/index.ts"],
4
+ "sourcesContent": ["export { upgradeFromThreeOneToThreeTwo } from './upgrade-from-three-one-to-three-two'\n"],
5
+ "mappings": "AAAA,SAAS,qCAAqC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,8 @@
1
+ import type { UnknownObject } from '@scalar/types/utils';
2
+ /**
3
+ * Upgrade OpenAPI 3.1 to 3.2
4
+ *
5
+ * @see https://github.com/OAI/OpenAPI-Specification/compare/main...v3.2-dev
6
+ */
7
+ export declare function upgradeFromThreeOneToThreeTwo(originalDocument: UnknownObject): UnknownObject;
8
+ //# sourceMappingURL=upgrade-from-three-one-to-three-two.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade-from-three-one-to-three-two.d.ts","sourceRoot":"","sources":["../../src/3.1-to-3.2/upgrade-from-three-one-to-three-two.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,gBAAgB,EAAE,aAAa,iBAmE5E"}
@@ -0,0 +1,45 @@
1
+ function upgradeFromThreeOneToThreeTwo(originalDocument) {
2
+ const document = originalDocument;
3
+ if (document !== null && typeof document === "object" && typeof document.openapi === "string" && document.openapi?.startsWith("3.1")) {
4
+ document.openapi = "3.2.0";
5
+ } else {
6
+ return document;
7
+ }
8
+ console.warn("\u26A0\uFE0F Experimental: Upgrading document from OpenAPI 3.1 to 3.2");
9
+ if (document["x-tagGroups"] && Array.isArray(document["x-tagGroups"])) {
10
+ const tagGroups = document["x-tagGroups"];
11
+ if (!document.tags) {
12
+ document.tags = [];
13
+ }
14
+ const tagGroupMap = /* @__PURE__ */ new Map();
15
+ for (const group of tagGroups) {
16
+ for (const tagName of group.tags) {
17
+ tagGroupMap.set(tagName, group.name);
18
+ }
19
+ }
20
+ if (Array.isArray(document.tags)) {
21
+ for (const tag of document.tags) {
22
+ if (typeof tag === "object" && tag !== null && "name" in tag) {
23
+ const groupName = tagGroupMap.get(tag.name);
24
+ if (groupName) {
25
+ if (groupName.toLowerCase().includes("nav") || groupName.toLowerCase().includes("navigation")) {
26
+ tag.kind = "nav";
27
+ } else if (groupName.toLowerCase().includes("audience")) {
28
+ tag.kind = "audience";
29
+ } else if (groupName.toLowerCase().includes("badge")) {
30
+ tag.kind = "badge";
31
+ } else {
32
+ tag.kind = "nav";
33
+ }
34
+ }
35
+ }
36
+ }
37
+ }
38
+ delete document["x-tagGroups"];
39
+ }
40
+ return document;
41
+ }
42
+ export {
43
+ upgradeFromThreeOneToThreeTwo
44
+ };
45
+ //# sourceMappingURL=upgrade-from-three-one-to-three-two.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/3.1-to-3.2/upgrade-from-three-one-to-three-two.ts"],
4
+ "sourcesContent": ["import type { UnknownObject } from '@scalar/types/utils'\n\n/**\n * Upgrade OpenAPI 3.1 to 3.2\n *\n * @see https://github.com/OAI/OpenAPI-Specification/compare/main...v3.2-dev\n */\nexport function upgradeFromThreeOneToThreeTwo(originalDocument: UnknownObject) {\n const document = originalDocument\n\n // Version\n if (\n document !== null &&\n typeof document === 'object' &&\n typeof document.openapi === 'string' &&\n document.openapi?.startsWith('3.1')\n ) {\n document.openapi = '3.2.0'\n } else {\n // Skip if it's something else than 3.1.x\n return document\n }\n\n console.warn('\u26A0\uFE0F Experimental: Upgrading document from OpenAPI 3.1 to 3.2')\n\n // Migrate x-tagGroups to kind property\n if (document['x-tagGroups'] && Array.isArray(document['x-tagGroups'])) {\n const tagGroups = document['x-tagGroups'] as Array<{\n name: string\n tags: string[]\n }>\n\n // Ensure tags array exists\n if (!document.tags) {\n document.tags = []\n }\n\n // Create a map of tag names to their group information\n const tagGroupMap = new Map<string, string>()\n\n for (const group of tagGroups) {\n for (const tagName of group.tags) {\n tagGroupMap.set(tagName, group.name)\n }\n }\n\n // Update existing tags with kind property based on group name\n if (Array.isArray(document.tags)) {\n for (const tag of document.tags) {\n if (typeof tag === 'object' && tag !== null && 'name' in tag) {\n const groupName = tagGroupMap.get(tag.name as string)\n if (groupName) {\n // Map group names to kind values\n // This is a simplified mapping - in practice, you might want more sophisticated logic\n if (groupName.toLowerCase().includes('nav') || groupName.toLowerCase().includes('navigation')) {\n tag.kind = 'nav'\n } else if (groupName.toLowerCase().includes('audience')) {\n tag.kind = 'audience'\n } else if (groupName.toLowerCase().includes('badge')) {\n tag.kind = 'badge'\n } else {\n // Default to nav for unknown group types\n tag.kind = 'nav'\n }\n }\n }\n }\n }\n\n // Remove x-tagGroups\n delete document['x-tagGroups']\n }\n\n return document\n}\n"],
5
+ "mappings": "AAOO,SAAS,8BAA8B,kBAAiC;AAC7E,QAAM,WAAW;AAGjB,MACE,aAAa,QACb,OAAO,aAAa,YACpB,OAAO,SAAS,YAAY,YAC5B,SAAS,SAAS,WAAW,KAAK,GAClC;AACA,aAAS,UAAU;AAAA,EACrB,OAAO;AAEL,WAAO;AAAA,EACT;AAEA,UAAQ,KAAK,uEAA6D;AAG1E,MAAI,SAAS,aAAa,KAAK,MAAM,QAAQ,SAAS,aAAa,CAAC,GAAG;AACrE,UAAM,YAAY,SAAS,aAAa;AAMxC,QAAI,CAAC,SAAS,MAAM;AAClB,eAAS,OAAO,CAAC;AAAA,IACnB;AAGA,UAAM,cAAc,oBAAI,IAAoB;AAE5C,eAAW,SAAS,WAAW;AAC7B,iBAAW,WAAW,MAAM,MAAM;AAChC,oBAAY,IAAI,SAAS,MAAM,IAAI;AAAA,MACrC;AAAA,IACF;AAGA,QAAI,MAAM,QAAQ,SAAS,IAAI,GAAG;AAChC,iBAAW,OAAO,SAAS,MAAM;AAC/B,YAAI,OAAO,QAAQ,YAAY,QAAQ,QAAQ,UAAU,KAAK;AAC5D,gBAAM,YAAY,YAAY,IAAI,IAAI,IAAc;AACpD,cAAI,WAAW;AAGb,gBAAI,UAAU,YAAY,EAAE,SAAS,KAAK,KAAK,UAAU,YAAY,EAAE,SAAS,YAAY,GAAG;AAC7F,kBAAI,OAAO;AAAA,YACb,WAAW,UAAU,YAAY,EAAE,SAAS,UAAU,GAAG;AACvD,kBAAI,OAAO;AAAA,YACb,WAAW,UAAU,YAAY,EAAE,SAAS,OAAO,GAAG;AACpD,kBAAI,OAAO;AAAA,YACb,OAAO;AAEL,kBAAI,OAAO;AAAA,YACb;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF;AAGA,WAAO,SAAS,aAAa;AAAA,EAC/B;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
@@ -0,0 +1,6 @@
1
+ import type { UnknownObject } from '@scalar/types/utils';
2
+ /**
3
+ * Recursively traverses the content and applies the transform function to each node.
4
+ */
5
+ export declare function traverse(content: UnknownObject, transform: (content: UnknownObject, path?: string[]) => UnknownObject, path?: string[]): UnknownObject;
6
+ //# sourceMappingURL=traverse.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"traverse.d.ts","sourceRoot":"","sources":["../../src/helpers/traverse.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD;;GAEG;AACH,wBAAgB,QAAQ,CACtB,OAAO,EAAE,aAAa,EACtB,SAAS,EAAE,CAAC,OAAO,EAAE,aAAa,EAAE,IAAI,CAAC,EAAE,MAAM,EAAE,KAAK,aAAa,EACrE,IAAI,GAAE,MAAM,EAAO,iBA6BpB"}
@@ -0,0 +1,25 @@
1
+ function traverse(content, transform, path = []) {
2
+ const result = {};
3
+ for (const [key, value] of Object.entries(content)) {
4
+ const currentPath = [...path, key];
5
+ if (Array.isArray(value)) {
6
+ result[key] = value.map((item, index) => {
7
+ if (typeof item === "object" && !Array.isArray(item) && item !== null) {
8
+ return traverse(item, transform, [...currentPath, index.toString()]);
9
+ }
10
+ return item;
11
+ });
12
+ continue;
13
+ }
14
+ if (typeof value === "object" && value !== null) {
15
+ result[key] = traverse(value, transform, currentPath);
16
+ continue;
17
+ }
18
+ result[key] = value;
19
+ }
20
+ return transform(result, path);
21
+ }
22
+ export {
23
+ traverse
24
+ };
25
+ //# sourceMappingURL=traverse.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../src/helpers/traverse.ts"],
4
+ "sourcesContent": ["import type { UnknownObject } from '@scalar/types/utils'\n\n/**\n * Recursively traverses the content and applies the transform function to each node.\n */\nexport function traverse(\n content: UnknownObject,\n transform: (content: UnknownObject, path?: string[]) => UnknownObject,\n path: string[] = [],\n) {\n const result: UnknownObject = {}\n\n for (const [key, value] of Object.entries(content)) {\n const currentPath = [...path, key]\n\n if (Array.isArray(value)) {\n result[key] = value.map((item, index) => {\n if (typeof item === 'object' && !Array.isArray(item) && item !== null) {\n return traverse(item, transform, [...currentPath, index.toString()])\n }\n\n return item\n })\n\n continue\n }\n\n if (typeof value === 'object' && value !== null) {\n result[key] = traverse(value as UnknownObject, transform, currentPath)\n\n continue\n }\n\n result[key] = value\n }\n\n return transform(result, path)\n}\n"],
5
+ "mappings": "AAKO,SAAS,SACd,SACA,WACA,OAAiB,CAAC,GAClB;AACA,QAAM,SAAwB,CAAC;AAE/B,aAAW,CAAC,KAAK,KAAK,KAAK,OAAO,QAAQ,OAAO,GAAG;AAClD,UAAM,cAAc,CAAC,GAAG,MAAM,GAAG;AAEjC,QAAI,MAAM,QAAQ,KAAK,GAAG;AACxB,aAAO,GAAG,IAAI,MAAM,IAAI,CAAC,MAAM,UAAU;AACvC,YAAI,OAAO,SAAS,YAAY,CAAC,MAAM,QAAQ,IAAI,KAAK,SAAS,MAAM;AACrE,iBAAO,SAAS,MAAM,WAAW,CAAC,GAAG,aAAa,MAAM,SAAS,CAAC,CAAC;AAAA,QACrE;AAEA,eAAO;AAAA,MACT,CAAC;AAED;AAAA,IACF;AAEA,QAAI,OAAO,UAAU,YAAY,UAAU,MAAM;AAC/C,aAAO,GAAG,IAAI,SAAS,OAAwB,WAAW,WAAW;AAErE;AAAA,IACF;AAEA,WAAO,GAAG,IAAI;AAAA,EAChB;AAEA,SAAO,UAAU,QAAQ,IAAI;AAC/B;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export { upgrade } from './upgrade.js';
2
+ //# sourceMappingURL=index.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,OAAO,EAAE,MAAM,WAAW,CAAA"}
package/dist/index.js ADDED
@@ -0,0 +1,5 @@
1
+ import { upgrade } from "./upgrade.js";
2
+ export {
3
+ upgrade
4
+ };
5
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/index.ts"],
4
+ "sourcesContent": ["// biome-ignore lint/performance/noBarrelFile: root entry point\nexport { upgrade } from './upgrade'\n"],
5
+ "mappings": "AACA,SAAS,eAAe;",
6
+ "names": []
7
+ }
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=upgrade.bench.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade.bench.d.ts","sourceRoot":"","sources":["../src/upgrade.bench.ts"],"names":[],"mappings":""}
@@ -0,0 +1,31 @@
1
+ import { bench, describe, expect } from "vitest";
2
+ import { upgradeFromTwoToThree } from "./2.0-to-3.0/upgrade-from-two-to-three.js";
3
+ import { upgrade } from "./upgrade.js";
4
+ const STRIPE = await fetch(
5
+ "https://raw.githubusercontent.com/stripe/openapi/refs/heads/master/openapi/spec3.json"
6
+ ).then((r) => r.json());
7
+ const PETSTORE = await fetch("https://petstore.swagger.io/v2/swagger.json").then((r) => r.json());
8
+ describe("upgrade", () => {
9
+ describe("Petstore: Swagger 2.0 to OpenAPI 3.0", () => {
10
+ bench("new", () => {
11
+ expect(PETSTORE.swagger).toBe("2.0");
12
+ const result = upgradeFromTwoToThree({ ...PETSTORE });
13
+ expect(result.openapi).toBe("3.0.4");
14
+ });
15
+ });
16
+ describe("Stripe: OpenAPI 3.0 to 3.1", () => {
17
+ bench("new", () => {
18
+ expect(STRIPE.openapi).toBe("3.0.0");
19
+ const document = upgrade(STRIPE, "3.1");
20
+ expect(document?.openapi).toBe("3.1.1");
21
+ });
22
+ });
23
+ describe("Petstore: Swagger 2.0 to OpenAPI 3.1", () => {
24
+ bench("new", () => {
25
+ expect(PETSTORE.swagger).toBe("2.0");
26
+ const document = upgrade(PETSTORE, "3.1");
27
+ expect(document?.openapi).toBe("3.1.1");
28
+ });
29
+ });
30
+ });
31
+ //# sourceMappingURL=upgrade.bench.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/upgrade.bench.ts"],
4
+ "sourcesContent": ["import { bench, describe, expect } from 'vitest'\n\nimport { upgradeFromTwoToThree } from './2.0-to-3.0/upgrade-from-two-to-three'\n// import { upgrade as upgradeOld } from './slow/upgrade'\n// import { upgradeFromTwoToThree as upgradeFromTwoToThreeOld } from './slow/upgradeFromTwoToThree'\nimport { upgrade } from './upgrade'\n\n// Setup the test data\nconst STRIPE = await fetch(\n 'https://raw.githubusercontent.com/stripe/openapi/refs/heads/master/openapi/spec3.json',\n).then((r) => r.json())\n\nconst PETSTORE = await fetch('https://petstore.swagger.io/v2/swagger.json').then((r) => r.json())\n\ndescribe('upgrade', () => {\n describe('Petstore: Swagger 2.0 to OpenAPI 3.0', () => {\n bench('new', () => {\n expect(PETSTORE.swagger).toBe('2.0')\n\n const result = upgradeFromTwoToThree({ ...PETSTORE })\n\n expect(result.openapi).toBe('3.0.4')\n })\n\n // bench('old', () => {\n // expect(PETSTORE.swagger).toBe('2.0')\n\n // const result = upgradeFromTwoToThreeOld({ ...PETSTORE })\n\n // expect(result.openapi).toBe('3.0.4')\n // })\n })\n\n describe('Stripe: OpenAPI 3.0 to 3.1', () => {\n bench('new', () => {\n expect(STRIPE.openapi).toBe('3.0.0')\n\n const document = upgrade(STRIPE, '3.1')\n\n expect(document?.openapi).toBe('3.1.1')\n })\n\n // bench('old', () => {\n // expect(STRIPE.openapi).toBe('3.0.0')\n\n // const document = upgradeOld(STRIPE)\n\n // expect(document?.openapi).toBe('3.1.1')\n // })\n })\n\n describe('Petstore: Swagger 2.0 to OpenAPI 3.1', () => {\n bench('new', () => {\n expect(PETSTORE.swagger).toBe('2.0')\n\n const document = upgrade(PETSTORE, '3.1')\n\n expect(document?.openapi).toBe('3.1.1')\n })\n\n // bench('old', () => {\n // expect(PETSTORE.swagger).toBe('2.0')\n\n // const document = upgradeOld(PETSTORE)\n\n // expect(document?.openapi).toBe('3.1.1')\n // })\n })\n})\n"],
5
+ "mappings": "AAAA,SAAS,OAAO,UAAU,cAAc;AAExC,SAAS,6BAA6B;AAGtC,SAAS,eAAe;AAGxB,MAAM,SAAS,MAAM;AAAA,EACnB;AACF,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC;AAEtB,MAAM,WAAW,MAAM,MAAM,6CAA6C,EAAE,KAAK,CAAC,MAAM,EAAE,KAAK,CAAC;AAEhG,SAAS,WAAW,MAAM;AACxB,WAAS,wCAAwC,MAAM;AACrD,UAAM,OAAO,MAAM;AACjB,aAAO,SAAS,OAAO,EAAE,KAAK,KAAK;AAEnC,YAAM,SAAS,sBAAsB,EAAE,GAAG,SAAS,CAAC;AAEpD,aAAO,OAAO,OAAO,EAAE,KAAK,OAAO;AAAA,IACrC,CAAC;AAAA,EASH,CAAC;AAED,WAAS,8BAA8B,MAAM;AAC3C,UAAM,OAAO,MAAM;AACjB,aAAO,OAAO,OAAO,EAAE,KAAK,OAAO;AAEnC,YAAM,WAAW,QAAQ,QAAQ,KAAK;AAEtC,aAAO,UAAU,OAAO,EAAE,KAAK,OAAO;AAAA,IACxC,CAAC;AAAA,EASH,CAAC;AAED,WAAS,wCAAwC,MAAM;AACrD,UAAM,OAAO,MAAM;AACjB,aAAO,SAAS,OAAO,EAAE,KAAK,KAAK;AAEnC,YAAM,WAAW,QAAQ,UAAU,KAAK;AAExC,aAAO,UAAU,OAAO,EAAE,KAAK,OAAO;AAAA,IACxC,CAAC;AAAA,EASH,CAAC;AACH,CAAC;",
6
+ "names": []
7
+ }
@@ -0,0 +1,27 @@
1
+ import type { OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-types';
2
+ import type { UnknownObject } from '@scalar/types/utils';
3
+ /**
4
+ * Upgrade OpenAPI documents from Swagger 2.0 or OpenAPI 3.0 to OpenAPI 3.1.0
5
+ */
6
+ export declare function upgrade(value: UnknownObject, targetVersion: '3.0' | '3.1' | '3.2'): UnknownObject | OpenAPIV3.Document<{}> | (Omit<Omit<OpenAPIV3.Document<{}>, "components" | "paths">, keyof {
7
+ [customExtension: `x-${string}`]: any;
8
+ [key: string]: any;
9
+ }> & {
10
+ openapi?: "3.1.0" | "3.1.1";
11
+ swagger?: undefined;
12
+ info?: OpenAPIV3_1.InfoObject;
13
+ jsonSchemaDialect?: string;
14
+ servers?: OpenAPIV3_1.ServerObject[];
15
+ } & Pick<{
16
+ paths?: OpenAPIV3_1.PathsObject<{}, {}> | undefined;
17
+ webhooks?: Record<string, OpenAPIV3_1.PathItemObject | OpenAPIV3_1.ReferenceObject>;
18
+ components?: OpenAPIV3_1.ComponentsObject;
19
+ }, "paths"> & Omit<Partial<{
20
+ paths?: OpenAPIV3_1.PathsObject<{}, {}> | undefined;
21
+ webhooks?: Record<string, OpenAPIV3_1.PathItemObject | OpenAPIV3_1.ReferenceObject>;
22
+ components?: OpenAPIV3_1.ComponentsObject;
23
+ }>, "paths"> & {
24
+ [customExtension: `x-${string}`]: any;
25
+ [key: string]: any;
26
+ });
27
+ //# sourceMappingURL=upgrade.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"upgrade.d.ts","sourceRoot":"","sources":["../src/upgrade.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAOxD;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,GAAG,KAAK,GAAG,KAAK;;;;;;;;;;;;;;;;;;;;GAqBjF"}
@@ -0,0 +1,22 @@
1
+ import { upgradeFromThreeOneToThreeTwo } from "./3.1-to-3.2/index.js";
2
+ import { upgradeFromTwoToThree } from "./2.0-to-3.0/index.js";
3
+ import { upgradeFromThreeToThreeOne } from "./3.0-to-3.1/index.js";
4
+ function upgrade(value, targetVersion) {
5
+ const openapi30 = upgradeFromTwoToThree(value);
6
+ if (targetVersion === "3.0") {
7
+ return openapi30;
8
+ }
9
+ const openapi31 = upgradeFromThreeToThreeOne(openapi30);
10
+ if (targetVersion === "3.1") {
11
+ return openapi31;
12
+ }
13
+ const openapi32 = upgradeFromThreeOneToThreeTwo(openapi31);
14
+ if (targetVersion === "3.2") {
15
+ return openapi32;
16
+ }
17
+ return openapi32;
18
+ }
19
+ export {
20
+ upgrade
21
+ };
22
+ //# sourceMappingURL=upgrade.js.map
@@ -0,0 +1,7 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../src/upgrade.ts"],
4
+ "sourcesContent": ["import type { OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type { UnknownObject } from '@scalar/types/utils'\n\nimport { upgradeFromThreeOneToThreeTwo } from '@/3.1-to-3.2'\n\nimport { upgradeFromTwoToThree } from './2.0-to-3.0'\nimport { upgradeFromThreeToThreeOne } from './3.0-to-3.1'\n\n/**\n * Upgrade OpenAPI documents from Swagger 2.0 or OpenAPI 3.0 to OpenAPI 3.1.0\n */\nexport function upgrade(value: UnknownObject, targetVersion: '3.0' | '3.1' | '3.2') {\n // Swagger 2.0 -> OpenAPI 3.0\n const openapi30 = upgradeFromTwoToThree(value)\n if (targetVersion === '3.0') {\n return openapi30 as OpenAPIV3.Document\n }\n\n // OpenAPI 3.0 -> OpenAPI 3.1\n const openapi31 = upgradeFromThreeToThreeOne(openapi30)\n if (targetVersion === '3.1') {\n return openapi31 as OpenAPIV3_1.Document\n }\n\n // OpenAPI 3.1 -> OpenAPI 3.2\n const openapi32 = upgradeFromThreeOneToThreeTwo(openapi31)\n if (targetVersion === '3.2') {\n // TODO: We need OpenAPI 3.2 types\n return openapi32 as OpenAPIV3_1.Document\n }\n\n return openapi32\n}\n"],
5
+ "mappings": "AAGA,SAAS,qCAAqC;AAE9C,SAAS,6BAA6B;AACtC,SAAS,kCAAkC;AAKpC,SAAS,QAAQ,OAAsB,eAAsC;AAElF,QAAM,YAAY,sBAAsB,KAAK;AAC7C,MAAI,kBAAkB,OAAO;AAC3B,WAAO;AAAA,EACT;AAGA,QAAM,YAAY,2BAA2B,SAAS;AACtD,MAAI,kBAAkB,OAAO;AAC3B,WAAO;AAAA,EACT;AAGA,QAAM,YAAY,8BAA8B,SAAS;AACzD,MAAI,kBAAkB,OAAO;AAE3B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;",
6
+ "names": []
7
+ }
package/package.json ADDED
@@ -0,0 +1,73 @@
1
+ {
2
+ "name": "@scalar/openapi-upgrader",
3
+ "description": "Upgrade OpenAPI documents to the latest and greatest version",
4
+ "license": "MIT",
5
+ "author": "Scalar (https://github.com/scalar)",
6
+ "homepage": "https://github.com/scalar/scalar",
7
+ "bugs": "https://github.com/scalar/scalar/issues/new/choose",
8
+ "repository": {
9
+ "type": "git",
10
+ "url": "git+https://github.com/scalar/scalar.git",
11
+ "directory": "packages/openapi-upgrader"
12
+ },
13
+ "keywords": [
14
+ "openapi",
15
+ "scalar",
16
+ "swagger",
17
+ "parser",
18
+ "typescript",
19
+ "upgrade",
20
+ "openapi 3.0",
21
+ "openapi 3.1"
22
+ ],
23
+ "version": "0.1.0",
24
+ "engines": {
25
+ "node": ">=20"
26
+ },
27
+ "type": "module",
28
+ "main": "./dist/index.js",
29
+ "types": "./dist/index.d.ts",
30
+ "exports": {
31
+ ".": {
32
+ "import": "./dist/index.js",
33
+ "types": "./dist/index.d.ts",
34
+ "default": "./dist/index.js"
35
+ },
36
+ "./2.0-to-3.0": {
37
+ "import": "./dist/2.0-to-3.0/index.js",
38
+ "types": "./dist/2.0-to-3.0/index.d.ts",
39
+ "default": "./dist/2.0-to-3.0/index.js"
40
+ },
41
+ "./3.0-to-3.1": {
42
+ "import": "./dist/3.0-to-3.1/index.js",
43
+ "types": "./dist/3.0-to-3.1/index.d.ts",
44
+ "default": "./dist/3.0-to-3.1/index.js"
45
+ },
46
+ "./3.1-to-3.2": {
47
+ "import": "./dist/3.1-to-3.2/index.js",
48
+ "types": "./dist/3.1-to-3.2/index.d.ts",
49
+ "default": "./dist/3.1-to-3.2/index.js"
50
+ }
51
+ },
52
+ "files": [
53
+ "dist",
54
+ "CHANGELOG.md"
55
+ ],
56
+ "module": "./dist/index.js",
57
+ "sideEffects": false,
58
+ "dependencies": {
59
+ "@scalar/openapi-types": "0.3.7"
60
+ },
61
+ "devDependencies": {
62
+ "tinybench": "^2.8.0",
63
+ "vite": "7.1.5",
64
+ "@scalar/build-tooling": "0.2.7",
65
+ "@scalar/types": "0.2.16"
66
+ },
67
+ "scripts": {
68
+ "build": "scalar-build-esbuild",
69
+ "test": "vitest",
70
+ "types:build": "scalar-types-build",
71
+ "types:check": "scalar-types-check"
72
+ }
73
+ }