@scalar/openapi-upgrader 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +18 -0
- package/dist/2.0-to-3.0/upgrade-from-two-to-three.d.ts.map +1 -1
- package/dist/2.0-to-3.0/upgrade-from-two-to-three.js +47 -14
- package/dist/2.0-to-3.0/upgrade-from-two-to-three.js.map +2 -2
- package/dist/3.0-to-3.1/upgrade-from-three-to-three-one.d.ts +2 -10
- package/dist/3.0-to-3.1/upgrade-from-three-to-three-one.d.ts.map +1 -1
- package/dist/3.0-to-3.1/upgrade-from-three-to-three-one.js +8 -1
- package/dist/3.0-to-3.1/upgrade-from-three-to-three-one.js.map +2 -2
- package/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.d.ts.map +1 -1
- package/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.js +39 -7
- package/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.js.map +2 -2
- package/dist/upgrade.d.ts +5 -23
- package/dist/upgrade.d.ts.map +1 -1
- package/dist/upgrade.js.map +2 -2
- package/package.json +5 -5
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @scalar/openapi-upgrader
|
|
2
2
|
|
|
3
|
+
## 0.1.4
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [#7215](https://github.com/scalar/scalar/pull/7215) [`11a6e64`](https://github.com/scalar/scalar/commit/11a6e6405d4f30f001a16d6afda4d2b759c0ed09) Thanks [@luke-hagar-sp](https://github.com/luke-hagar-sp)! - fix: don't upgrade "example" if it's just a key
|
|
8
|
+
|
|
9
|
+
- [#7092](https://github.com/scalar/scalar/pull/7092) [`134ff5f`](https://github.com/scalar/scalar/commit/134ff5f32aa6842696bf146c7e0817b1662905eb) Thanks [@baywet](https://github.com/baywet)! - feat - upgrader - adds support for migrating XML nodes to 3.2.0
|
|
10
|
+
|
|
11
|
+
- Updated dependencies [[`2239843`](https://github.com/scalar/scalar/commit/2239843150ed16d1ca35b0b1f8e90cd3e35be7ce)]:
|
|
12
|
+
- @scalar/openapi-types@0.5.1
|
|
13
|
+
|
|
14
|
+
## 0.1.3
|
|
15
|
+
|
|
16
|
+
### Patch Changes
|
|
17
|
+
|
|
18
|
+
- Updated dependencies [f69e7cc]
|
|
19
|
+
- @scalar/openapi-types@0.5.0
|
|
20
|
+
|
|
3
21
|
## 0.1.2
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
|
@@ -1 +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,
|
|
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,0CAgTzE"}
|
|
@@ -73,16 +73,22 @@ function upgradeFromTwoToThree(originalSpecification) {
|
|
|
73
73
|
const bodyParams = {};
|
|
74
74
|
const parameters = document.parameters && typeof document.parameters === "object" ? document.parameters : {};
|
|
75
75
|
for (const [name, param] of Object.entries(parameters)) {
|
|
76
|
-
if (param && typeof param === "object"
|
|
77
|
-
if (
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
)
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
76
|
+
if (param && typeof param === "object") {
|
|
77
|
+
if ("$ref" in param) {
|
|
78
|
+
const convertedParam = transformParameterObject(param);
|
|
79
|
+
params[name] = convertedParam;
|
|
80
|
+
} else if ("in" in param) {
|
|
81
|
+
if (param.in === "body") {
|
|
82
|
+
bodyParams[name] = migrateBodyParameter(
|
|
83
|
+
param,
|
|
84
|
+
document.consumes ?? ["application/json"]
|
|
85
|
+
);
|
|
86
|
+
} else if (param.in === "formData") {
|
|
87
|
+
bodyParams[name] = migrateFormDataParameter([param]);
|
|
88
|
+
} else {
|
|
89
|
+
const convertedParam = transformParameterObject(param);
|
|
90
|
+
params[name] = convertedParam;
|
|
91
|
+
}
|
|
86
92
|
}
|
|
87
93
|
}
|
|
88
94
|
}
|
|
@@ -137,7 +143,7 @@ function upgradeFromTwoToThree(originalSpecification) {
|
|
|
137
143
|
(acc, [name, header]) => {
|
|
138
144
|
if (header && typeof header === "object") {
|
|
139
145
|
return {
|
|
140
|
-
[name]:
|
|
146
|
+
[name]: transformResponseHeader(header),
|
|
141
147
|
...acc
|
|
142
148
|
};
|
|
143
149
|
}
|
|
@@ -246,18 +252,45 @@ function transformItemsObject(obj) {
|
|
|
246
252
|
return acc;
|
|
247
253
|
}, {});
|
|
248
254
|
}
|
|
255
|
+
function getParameterLocation(location) {
|
|
256
|
+
if (location === "formData") {
|
|
257
|
+
throw new Error("Encountered a formData parameter which should have been filtered out by the caller");
|
|
258
|
+
}
|
|
259
|
+
if (location === "body") {
|
|
260
|
+
throw new Error("Encountered a body parameter which should have been filtered out by the caller");
|
|
261
|
+
}
|
|
262
|
+
return location;
|
|
263
|
+
}
|
|
249
264
|
function transformParameterObject(parameter) {
|
|
250
|
-
if (Object.hasOwn(parameter, "$ref")) {
|
|
251
|
-
return
|
|
265
|
+
if (Object.hasOwn(parameter, "$ref") && "$ref" in parameter) {
|
|
266
|
+
return {
|
|
267
|
+
$ref: parameter.$ref
|
|
268
|
+
};
|
|
252
269
|
}
|
|
253
270
|
const serializationStyle = getParameterSerializationStyle(parameter);
|
|
254
271
|
const schema = transformItemsObject(parameter);
|
|
255
272
|
delete parameter.collectionFormat;
|
|
256
273
|
delete parameter.default;
|
|
274
|
+
if (!parameter.in) {
|
|
275
|
+
throw new Error('Parameter object must have an "in" property');
|
|
276
|
+
}
|
|
257
277
|
return {
|
|
258
278
|
schema,
|
|
259
279
|
...serializationStyle,
|
|
260
|
-
...parameter
|
|
280
|
+
...parameter,
|
|
281
|
+
in: getParameterLocation(parameter.in)
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
function transformResponseHeader(header) {
|
|
285
|
+
if (Object.hasOwn(header, "$ref") && "$ref" in header) {
|
|
286
|
+
return {
|
|
287
|
+
$ref: header.$ref
|
|
288
|
+
};
|
|
289
|
+
}
|
|
290
|
+
const schema = transformItemsObject(header);
|
|
291
|
+
return {
|
|
292
|
+
...header,
|
|
293
|
+
schema
|
|
261
294
|
};
|
|
262
295
|
}
|
|
263
296
|
const querySerialization = {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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,MACE,aAAa,QACb,OAAO,aAAa,YACpB,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AAG,EAAE,CAAC;AAE3C,YAAI,CAAC,YAAY;AACf,iBAAO;AAAA,QACT;AAEA,cAAM,QACJ,SAAS,cAAc,OAAO,SAAS,eAAe,YAAY,cAAc,SAAS,aACpF,SAAS,WAAuC,UAAU,IAC3D;AAEN,YAAI,SAAS,OAAO,UAAU,YAAY,QAAQ,UAAU,MAAM,OAAO,UAAU,MAAM,OAAO,aAAa;AAC3G,iBAAO,OAAO,OAAO,KAAK,QAAQ,oBAAoB,6BAA6B;AAAA,QACrF,OAAO;AACL,iBAAO,OAAO,OAAO,KAAK,QAAQ,oBAAoB,0BAA0B;AAAA,QAClF;AAAA,MACF;AAEA,aAAO;AAAA,IACT,CAAC;AAED,aAAS,eAAe,CAAC;AAEzB,UAAM,
|
|
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 | OpenAPIV3.ReferenceObject> = {}\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') {\n // Handle reference objects\n if ('$ref' in param) {\n const convertedParam = transformParameterObject(param as OpenAPIV2.ReferenceObject)\n params[name] = convertedParam\n } else if ('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 const convertedParam = transformParameterObject(param as OpenAPIV2.ParameterObject)\n params[name] = convertedParam\n }\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]: transformResponseHeader(header as OpenAPIV2.HeaderObject),\n ...acc,\n }\n }\n return acc\n },\n {} as Record<string, OpenAPIV3.HeaderObject | OpenAPIV3.ReferenceObject>,\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 getParameterLocation(location: OpenAPIV2.ParameterLocation): OpenAPIV3.ParameterLocation {\n if (location === 'formData') {\n throw new Error('Encountered a formData parameter which should have been filtered out by the caller')\n }\n if (location === 'body') {\n throw new Error('Encountered a body parameter which should have been filtered out by the caller')\n }\n return location as OpenAPIV3.ParameterLocation\n}\n\nfunction transformParameterObject(\n parameter: OpenAPIV2.ParameterObject | OpenAPIV2.ReferenceObject,\n): OpenAPIV3.ParameterObject | OpenAPIV3.ReferenceObject {\n if (Object.hasOwn(parameter, '$ref') && '$ref' in parameter) {\n return {\n $ref: parameter.$ref,\n }\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 if (!parameter.in) {\n throw new Error('Parameter object must have an \"in\" property')\n }\n\n return {\n schema,\n ...serializationStyle,\n ...parameter,\n in: getParameterLocation(parameter.in),\n }\n}\n\n/**\n * Transform OpenAPI 2.0 response header to OpenAPI 3.0 format.\n * Response headers do not have \"in\", \"name\", \"style\", or \"explode\" properties.\n */\nfunction transformResponseHeader(\n header: OpenAPIV2.HeaderObject | OpenAPIV2.ReferenceObject,\n): OpenAPIV3.HeaderObject | OpenAPIV3.ReferenceObject {\n if (Object.hasOwn(header, '$ref') && '$ref' in header) {\n return {\n $ref: header.$ref,\n }\n }\n\n const schema = transformItemsObject(header)\n\n return {\n ...header,\n schema,\n }\n}\n\ntype CollectionFormat = 'csv' | 'ssv' | 'tsv' | 'pipes' | 'multi'\n\ntype ParameterSerializationStyle = { style?: OpenAPIV3.ParameterStyle; 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 | OpenAPIV3.ReferenceObject)[]\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: OpenAPIV2.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,MACE,aAAa,QACb,OAAO,aAAa,YACpB,OAAO,SAAS,YAAY,YAC5B,SAAS,SAAS,WAAW,KAAK,GAClC;AACA,aAAS,UAAU;AACnB,WAAO,SAAS;AAAA,EAClB,OAAO;AAEL,WAAO;AAAA,EACT;AAGA,MAAI,SAAS,MAAM;AACjB,UAAM,UAAU,MAAM,QAAQ,SAAS,OAAO,KAAK,SAAS,SAAS,SAAS,SAAS,UAAU,CAAC,MAAM;AAExG,aAAS,UAAU,QAAQ,IAAI,CAAC,YAAsB;AAAA,MACpD,KAAK,GAAG,MAAM,MAAM,SAAS,IAAI,GAAG,SAAS,YAAY,EAAE;AAAA,IAC7D,EAAE;AAEF,WAAO,SAAS;AAChB,WAAO,SAAS;AAChB,WAAO,SAAS;AAAA,EAClB,WAAW,SAAS,UAAU;AAC5B,aAAS,UAAU,CAAC,EAAE,KAAK,SAAS,SAAS,CAAC;AAC9C,WAAO,SAAS;AAAA,EAClB;AAGA,MAAI,SAAS,aAAa;AACxB,aAAS,aAAa,OAAO,OAAO,CAAC,GAAG,SAAS,YAAY;AAAA,MAC3D,SAAS,SAAS;AAAA,IACpB,CAAC;AAED,WAAO,SAAS;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AW,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
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -12,19 +12,11 @@ export declare function upgradeFromThreeToThreeOne(originalContent: UnknownObjec
|
|
|
12
12
|
[key: string]: any;
|
|
13
13
|
}> & {
|
|
14
14
|
openapi?: "3.1.0" | "3.1.1" | "3.1.2";
|
|
15
|
-
swagger?:
|
|
15
|
+
swagger?: never;
|
|
16
16
|
info?: OpenAPIV3_1.InfoObject;
|
|
17
17
|
jsonSchemaDialect?: string;
|
|
18
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"> & {
|
|
19
|
+
} & Pick<OpenAPIV3_1.PathsWebhooksComponents<{}>, "paths"> & Omit<Partial<OpenAPIV3_1.PathsWebhooksComponents<{}>>, "paths"> & {
|
|
28
20
|
[customExtension: `x-${string}`]: any;
|
|
29
21
|
[key: string]: any;
|
|
30
22
|
});
|
|
@@ -1 +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
|
|
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"}
|
|
@@ -50,7 +50,14 @@ const applyChangesToDocument = (schema, path) => {
|
|
|
50
50
|
} else if (schema.exclusiveMaximum === false) {
|
|
51
51
|
delete schema.exclusiveMaximum;
|
|
52
52
|
}
|
|
53
|
-
|
|
53
|
+
const isInsideExamplesMap = path?.some((segment, index) => {
|
|
54
|
+
if (segment === "examples" && index > 0) {
|
|
55
|
+
const parent = path[index - 1];
|
|
56
|
+
return parent !== "properties";
|
|
57
|
+
}
|
|
58
|
+
return false;
|
|
59
|
+
});
|
|
60
|
+
if (schema.example !== void 0 && !isInsideExamplesMap) {
|
|
54
61
|
if (isSchemaPath(path)) {
|
|
55
62
|
schema.examples = [schema.example];
|
|
56
63
|
} else {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,SAAS,aAAa,MAAqC;AAEhE,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,KAAK,CAAC,YAAY,gBAAgB,IAAI,OAAO,CAAC,GAAG;AACxD,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,KAAK,CAAC,YAAY,QAAQ,SAAS,QAAQ,CAAC,GAAG;AACtD,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,UAAU,KAAK,KAAK,CAAC,MAAM,gBAAgB,KAAK,CAAC,MAAM,WAAW;AACzE,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAOO,SAAS,2BAA2B,iBAAgC;AACzE,MAAI,UAAU;AAGd,MAAI,YAAY,QAAQ,OAAO,QAAQ,YAAY,YAAY,CAAC,QAAQ,QAAQ,WAAW,KAAK,GAAG;AACjG,WAAO;AAAA,EACT;AAEA,UAAQ,UAAU;AAGlB,YAAU,SAAS,SAAS,sBAAsB;AAElD,SAAO;AACT;AAEA,MAAM,yBAAyB,CAAC,QAAuB,SAAoB;AAEzE,MAAI,OAAO,SAAS,UAAa,OAAO,aAAa,MAAM;AACzD,WAAO,OAAO,CAAC,OAAO,MAAM,MAAM;AAClC,WAAO,OAAO;AAAA,EAChB;AAGA,MAAI,OAAO,qBAAqB,MAAM;AACpC,WAAO,mBAAmB,OAAO;AACjC,WAAO,OAAO;AAAA,EAChB,WAAW,OAAO,qBAAqB,OAAO;AAC5C,WAAO,OAAO;AAAA,EAChB;AAEA,MAAI,OAAO,qBAAqB,MAAM;AACpC,WAAO,mBAAmB,OAAO;AACjC,WAAO,OAAO;AAAA,EAChB,WAAW,OAAO,qBAAqB,OAAO;AAC5C,WAAO,OAAO;AAAA,EAChB;
|
|
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 // Skip conversion if we're already inside an examples map to avoid double nesting\n // Check if 'examples' appears as an exact path segment (not just a substring)\n // BUT exclude cases where 'examples' is just a schema property name\n const isInsideExamplesMap = path?.some((segment, index) => {\n // Only consider it an examples map if 'examples' is not a schema property name\n if (segment === 'examples' && index > 0) {\n const parent = path[index - 1]\n // If parent is 'properties', then 'examples' is just a property name, not an examples map\n return parent !== 'properties'\n }\n return false\n })\n\n if (schema.example !== undefined && !isInsideExamplesMap) {\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;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AAAA,EACA;AACF,CAAC;AAGM,SAAS,aAAa,MAAqC;AAEhE,MAAI,CAAC,MAAM;AACT,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,KAAK,CAAC,YAAY,gBAAgB,IAAI,OAAO,CAAC,GAAG;AACxD,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,KAAK,CAAC,YAAY,QAAQ,SAAS,QAAQ,CAAC,GAAG;AACtD,WAAO;AAAA,EACT;AAGA,MAAI,KAAK,UAAU,KAAK,KAAK,CAAC,MAAM,gBAAgB,KAAK,CAAC,MAAM,WAAW;AACzE,WAAO;AAAA,EACT;AAEA,SAAO;AACT;AAOO,SAAS,2BAA2B,iBAAgC;AACzE,MAAI,UAAU;AAGd,MAAI,YAAY,QAAQ,OAAO,QAAQ,YAAY,YAAY,CAAC,QAAQ,QAAQ,WAAW,KAAK,GAAG;AACjG,WAAO;AAAA,EACT;AAEA,UAAQ,UAAU;AAGlB,YAAU,SAAS,SAAS,sBAAsB;AAElD,SAAO;AACT;AAEA,MAAM,yBAAyB,CAAC,QAAu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AAM,WAAW,UACjB;AACA,gBAAM,mBAAmB;AAEzB,iBAAO,MAAM;AAAA,QACf;AAAA,MACF;AAAA,IACF;AAAA,EACF;AAGA,MAAI,MAAM,SAAS,SAAS,KAAK,MAAM,SAAS,0BAA0B,GAAG;AAC3E,WAAO,CAAC;AAAA,EACV;AAGA,QAAM,EAAE,QAAQ,GAAG,GAAG,KAAK,IAAI;AAE/B,MAAI,OAAO,SAAS,UAAU;AAC5B,QAAI,OAAO,WAAW,UAAU;AAC9B,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM;AAAA,QACN,kBAAkB;AAAA,MACpB;AAAA,IACF;AAEA,QAAI,OAAO,WAAW,UAAU;AAC9B,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM;AAAA,QACN,iBAAiB;AAAA,MACnB;AAAA,IACF;AAEA,QAAI,OAAO,WAAW,QAAQ;AAC5B,YAAM,aAAa,MAAM,MAAM,GAAG,EAAE;AACpC,YAAM,mBAAmB,YAAY,KAAK,CAACA,IAAG,UAAU,OAAO,QAAQ,CAAC,MAAM,SAAS;AACvF,aAAO;AAAA,QACL,GAAG;AAAA,QACH,MAAM;AAAA,QACN,iBAAiB;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
6
|
"names": ["_"]
|
|
7
7
|
}
|
|
@@ -1 +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;
|
|
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;AAiGxD;;;;GAIG;AACH,wBAAgB,6BAA6B,CAAC,gBAAgB,EAAE,aAAa,iBAuB5E"}
|
|
@@ -1,11 +1,33 @@
|
|
|
1
|
-
function
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
1
|
+
function migrateXmlObjects(obj) {
|
|
2
|
+
if (obj === null || typeof obj !== "object") {
|
|
3
|
+
return;
|
|
4
|
+
}
|
|
5
|
+
if (Array.isArray(obj)) {
|
|
6
|
+
for (const item of obj) {
|
|
7
|
+
migrateXmlObjects(item);
|
|
8
|
+
}
|
|
9
|
+
return;
|
|
10
|
+
}
|
|
11
|
+
if (obj.xml && typeof obj.xml === "object") {
|
|
12
|
+
if (obj.xml.wrapped === true && obj.xml.attribute === true) {
|
|
13
|
+
throw new Error("Invalid XML configuration: wrapped and attribute cannot be true at the same time.");
|
|
14
|
+
}
|
|
15
|
+
if (obj.xml.wrapped === true) {
|
|
16
|
+
delete obj.xml.wrapped;
|
|
17
|
+
obj.xml.nodeType = "element";
|
|
18
|
+
}
|
|
19
|
+
if (obj.xml.attribute === true) {
|
|
20
|
+
delete obj.xml.attribute;
|
|
21
|
+
obj.xml.nodeType = "attribute";
|
|
22
|
+
}
|
|
7
23
|
}
|
|
8
|
-
|
|
24
|
+
for (const key in obj) {
|
|
25
|
+
if (Object.hasOwn(obj, key)) {
|
|
26
|
+
migrateXmlObjects(obj[key]);
|
|
27
|
+
}
|
|
28
|
+
}
|
|
29
|
+
}
|
|
30
|
+
function migrateTagGroups(document) {
|
|
9
31
|
if (document["x-tagGroups"] && Array.isArray(document["x-tagGroups"])) {
|
|
10
32
|
const tagGroups = document["x-tagGroups"];
|
|
11
33
|
if (!document.tags) {
|
|
@@ -37,6 +59,16 @@ function upgradeFromThreeOneToThreeTwo(originalDocument) {
|
|
|
37
59
|
}
|
|
38
60
|
delete document["x-tagGroups"];
|
|
39
61
|
}
|
|
62
|
+
}
|
|
63
|
+
function upgradeFromThreeOneToThreeTwo(originalDocument) {
|
|
64
|
+
const document = originalDocument;
|
|
65
|
+
if (document !== null && typeof document === "object" && typeof document.openapi === "string" && document.openapi?.startsWith("3.1")) {
|
|
66
|
+
document.openapi = "3.2.0";
|
|
67
|
+
} else {
|
|
68
|
+
return document;
|
|
69
|
+
}
|
|
70
|
+
migrateTagGroups(document);
|
|
71
|
+
migrateXmlObjects(document);
|
|
40
72
|
return document;
|
|
41
73
|
}
|
|
42
74
|
export {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
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 *
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { UnknownObject } from '@scalar/types/utils'\n\n/**\n * Recursively migrate XML object properties from 3.1 to 3.2 format\n */\nfunction migrateXmlObjects(obj: any): void {\n if (obj === null || typeof obj !== 'object') {\n return\n }\n\n // Handle arrays\n if (Array.isArray(obj)) {\n for (const item of obj) {\n migrateXmlObjects(item)\n }\n return\n }\n\n // Handle xml property migration\n if (obj.xml && typeof obj.xml === 'object') {\n if (obj.xml.wrapped === true && obj.xml.attribute === true) {\n throw new Error('Invalid XML configuration: wrapped and attribute cannot be true at the same time.')\n }\n\n // Migrate wrapped: true to nodeType: 'element'\n if (obj.xml.wrapped === true) {\n delete obj.xml.wrapped\n obj.xml.nodeType = 'element'\n }\n\n // Migrate attribute: true to nodeType: 'attribute'\n if (obj.xml.attribute === true) {\n delete obj.xml.attribute\n obj.xml.nodeType = 'attribute'\n }\n }\n\n // Recursively process all object properties\n for (const key in obj) {\n if (Object.hasOwn(obj, key)) {\n migrateXmlObjects(obj[key])\n }\n }\n}\n\n/**\n * Migrate x-tagGroups to kind property on tags\n */\nfunction migrateTagGroups(document: UnknownObject) {\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\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 // Migrate x-tagGroups to kind property\n migrateTagGroups(document)\n\n // Migrate XML object properties\n migrateXmlObjects(document)\n\n return document\n}\n"],
|
|
5
|
+
"mappings": "AAKA,SAAS,kBAAkB,KAAgB;AACzC,MAAI,QAAQ,QAAQ,OAAO,QAAQ,UAAU;AAC3C;AAAA,EACF;AAGA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I,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;AACF;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;AAGA,mBAAiB,QAAQ;AAGzB,oBAAkB,QAAQ;AAE1B,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/upgrade.d.ts
CHANGED
|
@@ -1,27 +1,9 @@
|
|
|
1
|
-
import type { OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-types';
|
|
1
|
+
import type { OpenAPIV3, OpenAPIV3_1, OpenAPIV3_2 } from '@scalar/openapi-types';
|
|
2
2
|
import type { UnknownObject } from '@scalar/types/utils';
|
|
3
3
|
/**
|
|
4
|
-
* Upgrade OpenAPI documents from Swagger 2.0 or OpenAPI 3.0 to
|
|
4
|
+
* Upgrade OpenAPI documents from Swagger 2.0 or OpenAPI 3.0 to the specified target version
|
|
5
5
|
*/
|
|
6
|
-
export declare function upgrade(value: UnknownObject, targetVersion: '3.0'
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
}> & {
|
|
10
|
-
openapi?: "3.1.0" | "3.1.1" | "3.1.2";
|
|
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
|
-
});
|
|
6
|
+
export declare function upgrade(value: UnknownObject, targetVersion: '3.0'): OpenAPIV3.Document;
|
|
7
|
+
export declare function upgrade(value: UnknownObject, targetVersion: '3.1'): OpenAPIV3_1.Document;
|
|
8
|
+
export declare function upgrade(value: UnknownObject, targetVersion: '3.2'): OpenAPIV3_2.Document;
|
|
27
9
|
//# sourceMappingURL=upgrade.d.ts.map
|
package/dist/upgrade.d.ts.map
CHANGED
|
@@ -1 +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;
|
|
1
|
+
{"version":3,"file":"upgrade.d.ts","sourceRoot":"","sources":["../src/upgrade.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,SAAS,EAAE,WAAW,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AAMhF,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAExD;;GAEG;AACH,wBAAgB,OAAO,CAAC,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,GAAG,SAAS,CAAC,QAAQ,CAAA;AACvF,wBAAgB,OAAO,CAAC,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,GAAG,WAAW,CAAC,QAAQ,CAAA;AACzF,wBAAgB,OAAO,CAAC,KAAK,EAAE,aAAa,EAAE,aAAa,EAAE,KAAK,GAAG,WAAW,CAAC,QAAQ,CAAA"}
|
package/dist/upgrade.js.map
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../src/upgrade.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPIV3, OpenAPIV3_1 } from '@scalar/openapi-types'\
|
|
5
|
-
"mappings": "
|
|
4
|
+
"sourcesContent": ["import type { OpenAPIV3, OpenAPIV3_1, OpenAPIV3_2 } from '@scalar/openapi-types'\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'\nimport type { UnknownObject } from '@scalar/types/utils'\n\n/**\n * Upgrade OpenAPI documents from Swagger 2.0 or OpenAPI 3.0 to the specified target version\n */\nexport function upgrade(value: UnknownObject, targetVersion: '3.0'): OpenAPIV3.Document\nexport function upgrade(value: UnknownObject, targetVersion: '3.1'): OpenAPIV3_1.Document\nexport function upgrade(value: UnknownObject, targetVersion: '3.2'): OpenAPIV3_2.Document\nexport function upgrade(\n value: UnknownObject,\n targetVersion: '3.0' | '3.1' | '3.2',\n): OpenAPIV3.Document | OpenAPIV3_1.Document | OpenAPIV3_2.Document {\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 return openapi32 as OpenAPIV3_2.Document\n }\n\n return openapi32\n}\n"],
|
|
5
|
+
"mappings": "AAEA,SAAS,qCAAqC;AAE9C,SAAS,6BAA6B;AACtC,SAAS,kCAAkC;AASpC,SAAS,QACd,OACA,eACkE;AAElE,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;AAC3B,WAAO;AAAA,EACT;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -20,7 +20,7 @@
|
|
|
20
20
|
"openapi 3.0",
|
|
21
21
|
"openapi 3.1"
|
|
22
22
|
],
|
|
23
|
-
"version": "0.1.
|
|
23
|
+
"version": "0.1.4",
|
|
24
24
|
"engines": {
|
|
25
25
|
"node": ">=20"
|
|
26
26
|
},
|
|
@@ -56,13 +56,13 @@
|
|
|
56
56
|
"module": "./dist/index.js",
|
|
57
57
|
"sideEffects": false,
|
|
58
58
|
"dependencies": {
|
|
59
|
-
"@scalar/openapi-types": "0.
|
|
59
|
+
"@scalar/openapi-types": "0.5.1"
|
|
60
60
|
},
|
|
61
61
|
"devDependencies": {
|
|
62
62
|
"tinybench": "^2.8.0",
|
|
63
|
-
"vite": "7.1.
|
|
64
|
-
"@scalar/
|
|
65
|
-
"@scalar/
|
|
63
|
+
"vite": "7.1.11",
|
|
64
|
+
"@scalar/types": "0.4.0",
|
|
65
|
+
"@scalar/build-tooling": "0.2.8"
|
|
66
66
|
},
|
|
67
67
|
"scripts": {
|
|
68
68
|
"build": "scalar-build-esbuild",
|