fumadocs-openapi 11.4.3 → 12.0.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/css/generated/shared.css +1 -1
- package/css/preset.css +0 -1
- package/dist/_virtual/_rolldown/runtime.js +10 -1
- package/dist/generate-file.d.ts +2 -2
- package/dist/generate-file.js +1 -1
- package/dist/i18n.d.ts +6 -8
- package/dist/i18n.js +2 -17
- package/dist/index.browser.d.ts +13 -0
- package/dist/index.browser.js +11 -0
- package/dist/index.d.ts +5 -2
- package/dist/index.js +3 -1
- package/dist/operation.d.ts +133 -0
- package/dist/operation.js +296 -0
- package/dist/packages/shared-api/dist/.translations/index.d.ts +29 -0
- package/dist/packages/shared-api/dist/.translations/keys.js +28 -0
- package/dist/packages/shared-api/dist/auto-anchor/client.js +20 -0
- package/dist/packages/shared-api/dist/auto-anchor/index.js +17 -0
- package/dist/packages/shared-api/dist/codegen.d.ts +42 -0
- package/dist/packages/shared-api/dist/codegen.js +35 -0
- package/dist/packages/shared-api/dist/components/accordion.js +71 -0
- package/dist/packages/shared-api/dist/components/badge.js +21 -0
- package/dist/packages/shared-api/dist/components/collapsible.d.ts +7 -0
- package/dist/packages/shared-api/dist/components/collapsible.js +16 -0
- package/dist/packages/shared-api/dist/components/defaults.d.ts +20 -0
- package/dist/packages/shared-api/dist/components/defaults.js +70 -0
- package/dist/packages/shared-api/dist/components/dialog.js +55 -0
- package/dist/packages/shared-api/dist/components/input.js +14 -0
- package/dist/packages/shared-api/dist/components/label.js +11 -0
- package/dist/packages/shared-api/dist/components/playground/inputs.js +439 -0
- package/dist/packages/shared-api/dist/components/playground/schema.js +112 -0
- package/dist/packages/shared-api/dist/components/popover.js +23 -0
- package/dist/packages/shared-api/dist/components/schema/client.d.ts +12 -0
- package/dist/packages/shared-api/dist/components/schema/client.js +508 -0
- package/dist/packages/shared-api/dist/components/schema/index.d.ts +9 -0
- package/dist/packages/shared-api/dist/components/schema/index.js +28 -0
- package/dist/packages/shared-api/dist/components/select-tab.js +54 -0
- package/dist/packages/shared-api/dist/components/select.js +70 -0
- package/dist/packages/shared-api/dist/components/spinner.js +14 -0
- package/dist/packages/shared-api/dist/i18n.d.ts +3 -0
- package/dist/packages/shared-api/dist/i18n.js +7 -0
- package/dist/packages/shared-api/dist/utils/cn.js +2 -0
- package/dist/packages/shared-api/dist/utils/id-to-title.js +12 -0
- package/dist/packages/shared-api/dist/utils/is-plain-object.js +8 -0
- package/dist/packages/shared-api/dist/utils/merge-refs.js +11 -0
- package/dist/packages/shared-api/dist/utils/url.js +13 -0
- package/dist/{utils → packages/shared-api/dist/utils}/use-query.js +2 -1
- package/dist/packages/shared-api/dist/utils/use-server-store.js +56 -0
- package/dist/playground/auth.d.ts +37 -0
- package/dist/playground/auth.js +216 -21
- package/dist/playground/fetcher.d.ts +11 -1
- package/dist/playground/index.d.ts +3 -0
- package/dist/playground/index.js +3 -0
- package/dist/requests/generators/index.d.ts +4 -4
- package/dist/requests/generators/index.js +2 -2
- package/dist/requests/index.d.ts +4 -0
- package/dist/requests/index.js +3 -0
- package/dist/requests/media/adapter.d.ts +1 -0
- package/dist/requests/media/encode.d.ts +7 -2
- package/dist/requests/media/resolve-adapter.d.ts +20 -0
- package/dist/server/index.d.ts +4 -7
- package/dist/server/index.js +1 -7
- package/dist/types.d.ts +0 -14
- package/dist/ui/base.d.ts +3 -2
- package/dist/ui/base.js +15 -166
- package/dist/ui/components/codeblock.js +3 -10
- package/dist/ui/components/heading.js +10 -19
- package/dist/ui/components/markdown.js +4 -6
- package/dist/ui/components/method-label.js +2 -17
- package/dist/ui/components/schema.js +28 -0
- package/dist/ui/index.d.ts +7 -198
- package/dist/ui/index.js +1 -3
- package/dist/ui/operation/index.js +142 -229
- package/dist/ui/operation/request-tabs.js +15 -23
- package/dist/ui/operation/response-tabs.js +9 -53
- package/dist/ui/operation/usage-tabs.js +35 -93
- package/dist/{playground → ui/playground}/client.d.ts +10 -21
- package/dist/ui/playground/client.js +432 -0
- package/dist/{playground → ui/playground}/components/oauth-dialog.js +26 -91
- package/dist/{playground → ui/playground}/components/result-display.d.ts +2 -2
- package/dist/{playground → ui/playground}/components/result-display.js +7 -7
- package/dist/{playground → ui/playground}/components/server-select.js +12 -13
- package/dist/{playground → ui/playground}/status-info.js +2 -2
- package/dist/{scalar → ui/scalar}/client.js +7 -5
- package/dist/{scalar → ui/scalar}/index.d.ts +2 -2
- package/dist/{scalar → ui/scalar}/index.js +3 -7
- package/dist/utils/create-page.d.ts +216 -0
- package/dist/utils/create-page.js +221 -0
- package/dist/utils/document/dereference.d.ts +2 -2
- package/dist/utils/document/dereference.js +8 -3
- package/dist/utils/document/load.js +2 -2
- package/dist/utils/get-example-requests.js +11 -13
- package/dist/utils/pages/builder.d.ts +15 -2
- package/dist/utils/pages/builder.js +6 -6
- package/dist/utils/pages/preset-auto.d.ts +1 -1
- package/dist/utils/pages/preset-auto.js +3 -3
- package/dist/utils/pages/to-static-data.js +4 -4
- package/dist/utils/pages/to-text.d.ts +1 -1
- package/dist/utils/pages/to-text.js +3 -5
- package/dist/utils/schema.js +5 -5
- package/dist/utils/use-server.d.ts +24 -0
- package/dist/utils/use-server.js +57 -0
- package/package.json +28 -20
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.15/node_modules/@scalar/openapi-upgrader/dist/2.0-to-3.0/upgrade-from-two-to-three.js +0 -508
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.15/node_modules/@scalar/openapi-upgrader/dist/3.0-to-3.1/upgrade-from-three-to-three-one.js +0 -152
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.15/node_modules/@scalar/openapi-upgrader/dist/3.1-to-3.2/upgrade-from-three-one-to-three-two.js +0 -61
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.15/node_modules/@scalar/openapi-upgrader/dist/helpers/traverse.js +0 -25
- package/dist/node_modules/.pnpm/@scalar_openapi-upgrader@0.2.15/node_modules/@scalar/openapi-upgrader/dist/upgrade.js +0 -15
- package/dist/playground/client.js +0 -574
- package/dist/ui/contexts/api.d.ts +0 -17
- package/dist/ui/contexts/api.js +0 -84
- package/dist/ui/create-client.d.ts +0 -9
- package/dist/ui/create-client.js +0 -7
- package/dist/ui/operation/context.d.ts +0 -15
- package/dist/ui/operation/context.js +0 -48
- package/dist/ui/operation/request-tabs.d.ts +0 -12
- package/dist/ui/operation/response-tabs.d.ts +0 -30
- package/dist/utils/get-example-requests.d.ts +0 -11
- package/dist/utils/schema.d.ts +0 -3
- package/dist/utils/storage-key.js +0 -15
|
@@ -1,508 +0,0 @@
|
|
|
1
|
-
import { traverse } from "../helpers/traverse.js";
|
|
2
|
-
//#region ../../node_modules/.pnpm/@scalar+openapi-upgrader@0.2.15/node_modules/@scalar/openapi-upgrader/dist/2.0-to-3.0/upgrade-from-two-to-three.js
|
|
3
|
-
const DEFAULT_MEDIA_TYPE = "application/json";
|
|
4
|
-
/** Extracts and removes x-example and x-examples extensions from an object */
|
|
5
|
-
function extractXExampleExtensions(obj) {
|
|
6
|
-
const xExample = obj["x-example"];
|
|
7
|
-
const xExamples = obj["x-examples"];
|
|
8
|
-
delete obj["x-example"];
|
|
9
|
-
delete obj["x-examples"];
|
|
10
|
-
return {
|
|
11
|
-
xExample,
|
|
12
|
-
xExamples
|
|
13
|
-
};
|
|
14
|
-
}
|
|
15
|
-
/** Checks if a value is a non-null, non-array object with at least one entry */
|
|
16
|
-
function isNonEmptyObject(value) {
|
|
17
|
-
return typeof value === "object" && value !== null && !Array.isArray(value) && Object.keys(value).length > 0;
|
|
18
|
-
}
|
|
19
|
-
/**
|
|
20
|
-
* Checks if a value looks like a collection of named examples (all values are objects).
|
|
21
|
-
* This helps distinguish between:
|
|
22
|
-
* - A single example: { message: 'OK', type: 'success' } - values are primitives
|
|
23
|
-
* - Named examples: { 'my-example': { message: 'OK' } } - values are objects
|
|
24
|
-
*/
|
|
25
|
-
function isNamedExamplesCollection(value) {
|
|
26
|
-
return isNonEmptyObject(value) && Object.values(value).every((v) => typeof v === "object" && v !== null && !Array.isArray(v));
|
|
27
|
-
}
|
|
28
|
-
/** Checks if a schema is empty (no meaningful properties defined) */
|
|
29
|
-
function isEmptySchema(schema) {
|
|
30
|
-
if (typeof schema !== "object" || schema === null) return true;
|
|
31
|
-
const s = schema;
|
|
32
|
-
if (s.allOf || s.oneOf || s.anyOf || s.items || s.$ref || "additionalProperties" in s || [
|
|
33
|
-
"enum",
|
|
34
|
-
"const",
|
|
35
|
-
"not",
|
|
36
|
-
"format",
|
|
37
|
-
"multipleOf",
|
|
38
|
-
"maximum",
|
|
39
|
-
"exclusiveMaximum",
|
|
40
|
-
"minimum",
|
|
41
|
-
"exclusiveMinimum",
|
|
42
|
-
"maxLength",
|
|
43
|
-
"minLength",
|
|
44
|
-
"pattern",
|
|
45
|
-
"maxItems",
|
|
46
|
-
"minItems",
|
|
47
|
-
"uniqueItems",
|
|
48
|
-
"maxProperties",
|
|
49
|
-
"minProperties",
|
|
50
|
-
"required"
|
|
51
|
-
].some((key) => key in s)) return false;
|
|
52
|
-
if (typeof s.properties === "object" && s.properties !== null && Object.keys(s.properties).length > 0) return false;
|
|
53
|
-
return true;
|
|
54
|
-
}
|
|
55
|
-
/**
|
|
56
|
-
* Removes content entries that only have an empty schema (no example/examples)
|
|
57
|
-
* when other entries with actual examples exist. This prevents the UI from
|
|
58
|
-
* selecting a meaningless produces-based entry over one with a real example.
|
|
59
|
-
*/
|
|
60
|
-
function removeEmptySchemaOnlyContentEntries(content) {
|
|
61
|
-
const keys = Object.keys(content);
|
|
62
|
-
if (!keys.some((key) => {
|
|
63
|
-
const entry = content[key];
|
|
64
|
-
return entry?.example !== void 0 || entry?.examples !== void 0;
|
|
65
|
-
})) return;
|
|
66
|
-
for (const key of keys) {
|
|
67
|
-
const entry = content[key];
|
|
68
|
-
if (!entry) continue;
|
|
69
|
-
const hasExample = entry.example !== void 0 || entry.examples !== void 0;
|
|
70
|
-
if (entry.schema !== void 0 && !hasExample && Object.keys(entry).length === 1 && isEmptySchema(entry.schema)) delete content[key];
|
|
71
|
-
}
|
|
72
|
-
}
|
|
73
|
-
/** The allowed properties for an OpenAPI 3.x ExampleObject */
|
|
74
|
-
const EXAMPLE_OBJECT_PROPERTIES = /* @__PURE__ */ new Set([
|
|
75
|
-
"summary",
|
|
76
|
-
"description",
|
|
77
|
-
"value",
|
|
78
|
-
"externalValue"
|
|
79
|
-
]);
|
|
80
|
-
/**
|
|
81
|
-
* Checks if a value is a valid OpenAPI 3.x ExampleObject.
|
|
82
|
-
*
|
|
83
|
-
* An ExampleObject must have a `value` (or `externalValue`) property and can only contain
|
|
84
|
-
* properties from the allowed set: `summary`, `description`, `value`, `externalValue`.
|
|
85
|
-
*
|
|
86
|
-
* This prevents false positives when user's example data happens to have a `value` property
|
|
87
|
-
* (e.g., `{ value: "some data", count: 5 }` should NOT be treated as an ExampleObject).
|
|
88
|
-
*/
|
|
89
|
-
function isExampleObject(value) {
|
|
90
|
-
if (typeof value !== "object" || value === null) return false;
|
|
91
|
-
const obj = value;
|
|
92
|
-
const hasValueOrExternalValue = "value" in obj || "externalValue" in obj;
|
|
93
|
-
const onlyHasAllowedProperties = Object.keys(obj).every((key) => EXAMPLE_OBJECT_PROPERTIES.has(key));
|
|
94
|
-
return hasValueOrExternalValue && onlyHasAllowedProperties;
|
|
95
|
-
}
|
|
96
|
-
/** Wraps a value as an ExampleObject, preserving existing structure if valid */
|
|
97
|
-
function wrapAsExampleObject(value) {
|
|
98
|
-
if (isExampleObject(value)) return value;
|
|
99
|
-
return { value };
|
|
100
|
-
}
|
|
101
|
-
/**
|
|
102
|
-
* True if the key looks like a MIME media type (e.g. application/json, text/plain).
|
|
103
|
-
* Used to distinguish media-type example keys from named example keys when migrating
|
|
104
|
-
* Swagger 2.0 examples to OpenAPI 3.0 content. Requires exactly one slash and
|
|
105
|
-
* token-style type/subtype (no spaces or semicolons) to avoid false positives
|
|
106
|
-
* for named keys that contain a slash (e.g. "Error 404/Not Found").
|
|
107
|
-
*/
|
|
108
|
-
const MEDIA_TYPE_KEY_PATTERN = /^[a-zA-Z0-9*+.-]+\/[a-zA-Z0-9*+.+-]+$/;
|
|
109
|
-
function isMediaTypeKey(key) {
|
|
110
|
-
return MEDIA_TYPE_KEY_PATTERN.test(key);
|
|
111
|
-
}
|
|
112
|
-
/** Transforms x-example entries to OpenAPI 3.x examples format */
|
|
113
|
-
function transformXExampleToExamples(xExample) {
|
|
114
|
-
return Object.entries(xExample).reduce((acc, [key, value]) => {
|
|
115
|
-
acc[key] = { value };
|
|
116
|
-
return acc;
|
|
117
|
-
}, {});
|
|
118
|
-
}
|
|
119
|
-
/** Update the flow names to OpenAPI 3.1.0 format */
|
|
120
|
-
const upgradeFlow = (flow) => {
|
|
121
|
-
switch (flow) {
|
|
122
|
-
case "application": return "clientCredentials";
|
|
123
|
-
case "accessCode": return "authorizationCode";
|
|
124
|
-
case "implicit": return "implicit";
|
|
125
|
-
case "password": return "password";
|
|
126
|
-
default: return flow;
|
|
127
|
-
}
|
|
128
|
-
};
|
|
129
|
-
/**
|
|
130
|
-
* Upgrade Swagger 2.0 to OpenAPI 3.0
|
|
131
|
-
*
|
|
132
|
-
* https://swagger.io/blog/news/whats-new-in-openapi-3-0/
|
|
133
|
-
*/
|
|
134
|
-
function upgradeFromTwoToThree(originalSpecification) {
|
|
135
|
-
let document = originalSpecification;
|
|
136
|
-
if (document !== null && typeof document === "object" && typeof document.swagger === "string" && document.swagger?.startsWith("2.0")) {
|
|
137
|
-
document.openapi = "3.0.4";
|
|
138
|
-
delete document.swagger;
|
|
139
|
-
} else return document;
|
|
140
|
-
if (document.host) {
|
|
141
|
-
const schemes = Array.isArray(document.schemes) && document.schemes?.length ? document.schemes : ["http"];
|
|
142
|
-
document.servers = schemes.map((scheme) => ({ url: `${scheme}://${document.host}${document.basePath ?? ""}` }));
|
|
143
|
-
delete document.basePath;
|
|
144
|
-
delete document.schemes;
|
|
145
|
-
delete document.host;
|
|
146
|
-
} else if (document.basePath) {
|
|
147
|
-
document.servers = [{ url: document.basePath }];
|
|
148
|
-
delete document.basePath;
|
|
149
|
-
}
|
|
150
|
-
if (document.definitions) {
|
|
151
|
-
document.components = Object.assign({}, document.components, { schemas: document.definitions });
|
|
152
|
-
delete document.definitions;
|
|
153
|
-
document = traverse(document, (schema) => {
|
|
154
|
-
if (typeof schema.$ref === "string" && schema.$ref.startsWith("#/definitions/")) schema.$ref = schema.$ref.replace(/^#\/definitions\//, "#/components/schemas/");
|
|
155
|
-
return schema;
|
|
156
|
-
});
|
|
157
|
-
}
|
|
158
|
-
document = traverse(document, (schema) => {
|
|
159
|
-
if (schema.type === "file") {
|
|
160
|
-
schema.type = "string";
|
|
161
|
-
schema.format = "binary";
|
|
162
|
-
}
|
|
163
|
-
return schema;
|
|
164
|
-
});
|
|
165
|
-
if (Object.hasOwn(document, "parameters")) {
|
|
166
|
-
document = traverse(document, (schema) => {
|
|
167
|
-
if (typeof schema.$ref === "string" && schema.$ref.startsWith("#/parameters/")) {
|
|
168
|
-
const schemaName = schema.$ref.split("/")[2];
|
|
169
|
-
if (!schemaName) return schema;
|
|
170
|
-
const param = document.parameters && typeof document.parameters === "object" && schemaName in document.parameters ? document.parameters[schemaName] : void 0;
|
|
171
|
-
if (param && typeof param === "object" && "in" in param && (param.in === "body" || param.in === "formData")) schema.$ref = schema.$ref.replace(/^#\/parameters\//, "#/components/requestBodies/");
|
|
172
|
-
else schema.$ref = schema.$ref.replace(/^#\/parameters\//, "#/components/parameters/");
|
|
173
|
-
}
|
|
174
|
-
return schema;
|
|
175
|
-
});
|
|
176
|
-
document.components ??= {};
|
|
177
|
-
const params = {};
|
|
178
|
-
const bodyParams = {};
|
|
179
|
-
const parameters = document.parameters && typeof document.parameters === "object" ? document.parameters : {};
|
|
180
|
-
for (const [name, param] of Object.entries(parameters)) if (param && typeof param === "object") {
|
|
181
|
-
if ("$ref" in param) params[name] = transformParameterObject(param);
|
|
182
|
-
else if ("in" in param) {
|
|
183
|
-
if (param.in === "body") bodyParams[name] = migrateBodyParameter(param, document.consumes ?? [DEFAULT_MEDIA_TYPE]);
|
|
184
|
-
else if (param.in === "formData") bodyParams[name] = migrateFormDataParameter([param], document.consumes);
|
|
185
|
-
else params[name] = transformParameterObject(param);
|
|
186
|
-
}
|
|
187
|
-
}
|
|
188
|
-
if (Object.keys(params).length > 0) document.components.parameters = params;
|
|
189
|
-
if (Object.keys(bodyParams).length > 0) document.components.requestBodies = bodyParams;
|
|
190
|
-
delete document.parameters;
|
|
191
|
-
}
|
|
192
|
-
if (Object.hasOwn(document, "responses") && typeof document.responses === "object" && document.responses !== null) {
|
|
193
|
-
document = traverse(document, (schema) => {
|
|
194
|
-
if (typeof schema.$ref === "string" && schema.$ref.startsWith("#/responses/")) schema.$ref = schema.$ref.replace(/^#\/responses\//, "#/components/responses/");
|
|
195
|
-
return schema;
|
|
196
|
-
});
|
|
197
|
-
document.components ??= {};
|
|
198
|
-
const migratedResponses = {};
|
|
199
|
-
const responses = document.responses;
|
|
200
|
-
for (const [name, response] of Object.entries(responses)) if (response && typeof response === "object") {
|
|
201
|
-
if ("$ref" in response) migratedResponses[name] = response;
|
|
202
|
-
else {
|
|
203
|
-
const responseObj = response;
|
|
204
|
-
const produces = document.produces ?? [DEFAULT_MEDIA_TYPE];
|
|
205
|
-
if (responseObj.schema) {
|
|
206
|
-
if (typeof responseObj.content !== "object") responseObj.content = {};
|
|
207
|
-
for (const type of produces) responseObj.content[type] = { schema: responseObj.schema };
|
|
208
|
-
delete responseObj.schema;
|
|
209
|
-
}
|
|
210
|
-
if (responseObj.examples && typeof responseObj.examples === "object") {
|
|
211
|
-
if (typeof responseObj.content !== "object") responseObj.content = {};
|
|
212
|
-
const defaultMediaType = produces[0] ?? DEFAULT_MEDIA_TYPE;
|
|
213
|
-
for (const [key, exampleValue] of Object.entries(responseObj.examples)) if (isMediaTypeKey(key)) {
|
|
214
|
-
if (typeof responseObj.content[key] !== "object") responseObj.content[key] = {};
|
|
215
|
-
responseObj.content[key].example = exampleValue;
|
|
216
|
-
} else {
|
|
217
|
-
if (typeof responseObj.content[defaultMediaType] !== "object") responseObj.content[defaultMediaType] = {};
|
|
218
|
-
const mediaEntry = responseObj.content[defaultMediaType];
|
|
219
|
-
if (typeof mediaEntry.examples !== "object") mediaEntry.examples = {};
|
|
220
|
-
mediaEntry.examples[key] = wrapAsExampleObject(exampleValue);
|
|
221
|
-
}
|
|
222
|
-
delete responseObj.examples;
|
|
223
|
-
}
|
|
224
|
-
if (responseObj.content && typeof responseObj.content === "object") removeEmptySchemaOnlyContentEntries(responseObj.content);
|
|
225
|
-
if (responseObj.headers && typeof responseObj.headers === "object") responseObj.headers = Object.entries(responseObj.headers).reduce((acc, [headerName, header]) => {
|
|
226
|
-
if (header && typeof header === "object") return {
|
|
227
|
-
[headerName]: transformResponseHeader(header),
|
|
228
|
-
...acc
|
|
229
|
-
};
|
|
230
|
-
return acc;
|
|
231
|
-
}, {});
|
|
232
|
-
migratedResponses[name] = responseObj;
|
|
233
|
-
}
|
|
234
|
-
}
|
|
235
|
-
if (Object.keys(migratedResponses).length > 0) document.components.responses = migratedResponses;
|
|
236
|
-
delete document.responses;
|
|
237
|
-
}
|
|
238
|
-
if (typeof document.paths === "object") {
|
|
239
|
-
for (const path in document.paths) if (Object.hasOwn(document.paths, path)) {
|
|
240
|
-
const pathItem = document.paths && typeof document.paths === "object" && path in document.paths ? document.paths[path] : void 0;
|
|
241
|
-
if (!pathItem || typeof pathItem !== "object") continue;
|
|
242
|
-
let requestBodyObject;
|
|
243
|
-
for (const methodOrParameters in pathItem) if (methodOrParameters === "parameters" && Object.hasOwn(pathItem, methodOrParameters)) {
|
|
244
|
-
const pathItemParameters = migrateParameters(pathItem.parameters, document.consumes ?? [DEFAULT_MEDIA_TYPE]);
|
|
245
|
-
pathItem.parameters = pathItemParameters.parameters;
|
|
246
|
-
requestBodyObject = pathItemParameters.requestBody;
|
|
247
|
-
} else if (Object.hasOwn(pathItem, methodOrParameters)) {
|
|
248
|
-
const operationItem = pathItem[methodOrParameters];
|
|
249
|
-
if (requestBodyObject) operationItem.requestBody = requestBodyObject;
|
|
250
|
-
if (operationItem.parameters) {
|
|
251
|
-
const migrationResult = migrateParameters(operationItem.parameters, operationItem.consumes ?? document.consumes ?? [DEFAULT_MEDIA_TYPE]);
|
|
252
|
-
operationItem.parameters = migrationResult.parameters;
|
|
253
|
-
if (migrationResult.requestBody) operationItem.requestBody = migrationResult.requestBody;
|
|
254
|
-
}
|
|
255
|
-
delete operationItem.consumes;
|
|
256
|
-
if (operationItem.responses) {
|
|
257
|
-
for (const response in operationItem.responses) if (Object.hasOwn(operationItem.responses, response)) {
|
|
258
|
-
const responseItem = operationItem.responses[response];
|
|
259
|
-
if (responseItem.headers && typeof responseItem.headers === "object") responseItem.headers = Object.entries(responseItem.headers).reduce((acc, [name, header]) => {
|
|
260
|
-
if (header && typeof header === "object") return {
|
|
261
|
-
[name]: transformResponseHeader(header),
|
|
262
|
-
...acc
|
|
263
|
-
};
|
|
264
|
-
return acc;
|
|
265
|
-
}, {});
|
|
266
|
-
if (responseItem.schema) {
|
|
267
|
-
const produces = document.produces ?? operationItem.produces ?? [DEFAULT_MEDIA_TYPE];
|
|
268
|
-
if (typeof responseItem.content !== "object") responseItem.content = {};
|
|
269
|
-
for (const type of produces) responseItem.content[type] = { schema: responseItem.schema };
|
|
270
|
-
delete responseItem.schema;
|
|
271
|
-
}
|
|
272
|
-
if (responseItem.examples && typeof responseItem.examples === "object") {
|
|
273
|
-
if (typeof responseItem.content !== "object") responseItem.content = {};
|
|
274
|
-
const defaultMediaType = (document.produces ?? operationItem.produces ?? [DEFAULT_MEDIA_TYPE])[0] ?? DEFAULT_MEDIA_TYPE;
|
|
275
|
-
for (const [key, exampleValue] of Object.entries(responseItem.examples)) if (isMediaTypeKey(key)) {
|
|
276
|
-
if (typeof responseItem.content[key] !== "object") responseItem.content[key] = {};
|
|
277
|
-
responseItem.content[key].example = exampleValue;
|
|
278
|
-
} else {
|
|
279
|
-
if (typeof responseItem.content[defaultMediaType] !== "object") responseItem.content[defaultMediaType] = {};
|
|
280
|
-
const mediaEntry = responseItem.content[defaultMediaType];
|
|
281
|
-
if (typeof mediaEntry.examples !== "object") mediaEntry.examples = {};
|
|
282
|
-
mediaEntry.examples[key] = wrapAsExampleObject(exampleValue);
|
|
283
|
-
}
|
|
284
|
-
delete responseItem.examples;
|
|
285
|
-
}
|
|
286
|
-
if (responseItem.content && typeof responseItem.content === "object") removeEmptySchemaOnlyContentEntries(responseItem.content);
|
|
287
|
-
}
|
|
288
|
-
}
|
|
289
|
-
delete operationItem.produces;
|
|
290
|
-
if (operationItem.parameters?.length === 0) delete operationItem.parameters;
|
|
291
|
-
}
|
|
292
|
-
}
|
|
293
|
-
}
|
|
294
|
-
if (document.securityDefinitions) {
|
|
295
|
-
if (typeof document.components !== "object" || document.components === null) document.components = {};
|
|
296
|
-
if (document.components && typeof document.components === "object") Object.assign(document.components, { securitySchemes: {} });
|
|
297
|
-
for (const [key, securityScheme] of Object.entries(document.securityDefinitions)) if (typeof securityScheme === "object") {
|
|
298
|
-
if ("type" in securityScheme && securityScheme.type === "oauth2") {
|
|
299
|
-
const { flow, authorizationUrl, tokenUrl, scopes } = securityScheme;
|
|
300
|
-
if (document.components && typeof document.components === "object" && "securitySchemes" in document.components && document.components.securitySchemes) Object.assign(document.components.securitySchemes, { [key]: {
|
|
301
|
-
type: "oauth2",
|
|
302
|
-
flows: { [upgradeFlow(flow || "implicit")]: Object.assign({}, authorizationUrl && { authorizationUrl }, tokenUrl && { tokenUrl }, scopes && { scopes }) }
|
|
303
|
-
} });
|
|
304
|
-
} else if ("type" in securityScheme && securityScheme.type === "basic") {
|
|
305
|
-
if (document.components && typeof document.components === "object" && "securitySchemes" in document.components && document.components.securitySchemes) Object.assign(document.components.securitySchemes, { [key]: {
|
|
306
|
-
type: "http",
|
|
307
|
-
scheme: "basic"
|
|
308
|
-
} });
|
|
309
|
-
} else if (document.components && typeof document.components === "object" && "securitySchemes" in document.components && document.components.securitySchemes) Object.assign(document.components.securitySchemes, { [key]: securityScheme });
|
|
310
|
-
}
|
|
311
|
-
delete document.securityDefinitions;
|
|
312
|
-
}
|
|
313
|
-
delete document.consumes;
|
|
314
|
-
delete document.produces;
|
|
315
|
-
return document;
|
|
316
|
-
}
|
|
317
|
-
function transformItemsObject(obj) {
|
|
318
|
-
return [
|
|
319
|
-
"type",
|
|
320
|
-
"format",
|
|
321
|
-
"default",
|
|
322
|
-
"items",
|
|
323
|
-
"maximum",
|
|
324
|
-
"exclusiveMaximum",
|
|
325
|
-
"minimum",
|
|
326
|
-
"exclusiveMinimum",
|
|
327
|
-
"maxLength",
|
|
328
|
-
"minLength",
|
|
329
|
-
"pattern",
|
|
330
|
-
"maxItems",
|
|
331
|
-
"minItems",
|
|
332
|
-
"uniqueItems",
|
|
333
|
-
"enum",
|
|
334
|
-
"multipleOf"
|
|
335
|
-
].reduce((acc, property) => {
|
|
336
|
-
if (Object.hasOwn(obj, property)) {
|
|
337
|
-
acc[property] = obj[property];
|
|
338
|
-
delete obj[property];
|
|
339
|
-
}
|
|
340
|
-
return acc;
|
|
341
|
-
}, {});
|
|
342
|
-
}
|
|
343
|
-
function getParameterLocation(location) {
|
|
344
|
-
if (location === "formData") throw new Error("Encountered a formData parameter which should have been filtered out by the caller");
|
|
345
|
-
if (location === "body") throw new Error("Encountered a body parameter which should have been filtered out by the caller");
|
|
346
|
-
return location;
|
|
347
|
-
}
|
|
348
|
-
function transformParameterObject(parameter) {
|
|
349
|
-
if (Object.hasOwn(parameter, "$ref") && typeof parameter.$ref === "string") return { $ref: parameter.$ref };
|
|
350
|
-
const serializationStyle = getParameterSerializationStyle(parameter);
|
|
351
|
-
const schema = transformItemsObject(parameter);
|
|
352
|
-
const { xExample, xExamples } = extractXExampleExtensions(parameter);
|
|
353
|
-
if (isNonEmptyObject(xExample)) parameter.examples = transformXExampleToExamples(xExample);
|
|
354
|
-
else if (isNonEmptyObject(xExamples)) parameter.examples = Object.entries(xExamples).reduce((acc, [key, exampleValue]) => {
|
|
355
|
-
acc[key] = wrapAsExampleObject(exampleValue);
|
|
356
|
-
return acc;
|
|
357
|
-
}, {});
|
|
358
|
-
delete parameter.collectionFormat;
|
|
359
|
-
delete parameter.default;
|
|
360
|
-
if (!parameter.in) throw new Error("Parameter object must have an \"in\" property");
|
|
361
|
-
return {
|
|
362
|
-
schema,
|
|
363
|
-
...serializationStyle,
|
|
364
|
-
...parameter,
|
|
365
|
-
in: getParameterLocation(parameter.in)
|
|
366
|
-
};
|
|
367
|
-
}
|
|
368
|
-
/**
|
|
369
|
-
* Transform OpenAPI 2.0 response header to OpenAPI 3.0 format.
|
|
370
|
-
* Response headers do not have "in", "name", "style", or "explode" properties.
|
|
371
|
-
*/
|
|
372
|
-
function transformResponseHeader(header) {
|
|
373
|
-
if (Object.hasOwn(header, "$ref") && typeof header.$ref === "string") return { $ref: header.$ref };
|
|
374
|
-
const schema = transformItemsObject(header);
|
|
375
|
-
return {
|
|
376
|
-
...header,
|
|
377
|
-
schema
|
|
378
|
-
};
|
|
379
|
-
}
|
|
380
|
-
const querySerialization = {
|
|
381
|
-
ssv: {
|
|
382
|
-
style: "spaceDelimited",
|
|
383
|
-
explode: false
|
|
384
|
-
},
|
|
385
|
-
pipes: {
|
|
386
|
-
style: "pipeDelimited",
|
|
387
|
-
explode: false
|
|
388
|
-
},
|
|
389
|
-
multi: {
|
|
390
|
-
style: "form",
|
|
391
|
-
explode: true
|
|
392
|
-
},
|
|
393
|
-
csv: {
|
|
394
|
-
style: "form",
|
|
395
|
-
explode: false
|
|
396
|
-
},
|
|
397
|
-
tsv: {}
|
|
398
|
-
};
|
|
399
|
-
const pathAndHeaderSerialization = {
|
|
400
|
-
ssv: {},
|
|
401
|
-
pipes: {},
|
|
402
|
-
multi: {},
|
|
403
|
-
csv: {
|
|
404
|
-
style: "simple",
|
|
405
|
-
explode: false
|
|
406
|
-
},
|
|
407
|
-
tsv: {}
|
|
408
|
-
};
|
|
409
|
-
const serializationStyles = {
|
|
410
|
-
header: pathAndHeaderSerialization,
|
|
411
|
-
query: querySerialization,
|
|
412
|
-
path: pathAndHeaderSerialization
|
|
413
|
-
};
|
|
414
|
-
function getParameterSerializationStyle(parameter) {
|
|
415
|
-
if (parameter.type !== "array" || !(parameter.in === "query" || parameter.in === "path" || parameter.in === "header")) return {};
|
|
416
|
-
const collectionFormat = parameter.collectionFormat ?? "csv";
|
|
417
|
-
if (parameter.in in serializationStyles && collectionFormat in serializationStyles[parameter.in]) return serializationStyles[parameter.in][collectionFormat];
|
|
418
|
-
return {};
|
|
419
|
-
}
|
|
420
|
-
/**
|
|
421
|
-
* Translate the Swagger 2.0 `collectionFormat` of a formData array parameter into an OpenAPI 3.0
|
|
422
|
-
* encoding entry. Form bodies serialize arrays with the same styles as query parameters, so the
|
|
423
|
-
* query serialization mapping is reused. Returns undefined when there is nothing to preserve, for
|
|
424
|
-
* example a non-array parameter, one without a `collectionFormat`, or `tsv` which has no OpenAPI
|
|
425
|
-
* 3.0 equivalent.
|
|
426
|
-
*/
|
|
427
|
-
function getFormDataEncoding(parameter) {
|
|
428
|
-
if (parameter.type !== "array" || typeof parameter.collectionFormat !== "string") return;
|
|
429
|
-
const encoding = querySerialization[parameter.collectionFormat];
|
|
430
|
-
if (!encoding || Object.keys(encoding).length === 0) return;
|
|
431
|
-
return encoding;
|
|
432
|
-
}
|
|
433
|
-
function migrateBodyParameter(bodyParameter, consumes) {
|
|
434
|
-
const { xExample, xExamples } = extractXExampleExtensions(bodyParameter);
|
|
435
|
-
delete bodyParameter.name;
|
|
436
|
-
delete bodyParameter.in;
|
|
437
|
-
const { schema, ...requestBody } = bodyParameter;
|
|
438
|
-
const requestBodyObject = {
|
|
439
|
-
content: {},
|
|
440
|
-
...requestBody
|
|
441
|
-
};
|
|
442
|
-
if (requestBodyObject.content) for (const type of consumes) {
|
|
443
|
-
requestBodyObject.content[type] = { schema };
|
|
444
|
-
if (isNonEmptyObject(xExamples) && type in xExamples) {
|
|
445
|
-
const examples = xExamples[type];
|
|
446
|
-
if (isNonEmptyObject(examples) && Object.values(examples).every((example) => isExampleObject(example))) requestBodyObject.content[type].examples = examples;
|
|
447
|
-
else if (isNamedExamplesCollection(examples)) requestBodyObject.content[type].examples = Object.entries(examples).reduce((acc, [key, exampleValue]) => {
|
|
448
|
-
acc[key] = wrapAsExampleObject(exampleValue);
|
|
449
|
-
return acc;
|
|
450
|
-
}, {});
|
|
451
|
-
else requestBodyObject.content[type].examples = { default: wrapAsExampleObject(examples) };
|
|
452
|
-
} else if (isNonEmptyObject(xExamples) && !Object.keys(xExamples).some(isMediaTypeKey)) requestBodyObject.content[type].examples = Object.entries(xExamples).reduce((acc, [key, exampleValue]) => {
|
|
453
|
-
acc[key] = wrapAsExampleObject(exampleValue);
|
|
454
|
-
return acc;
|
|
455
|
-
}, {});
|
|
456
|
-
if (!requestBodyObject.content[type].examples && isNonEmptyObject(xExample) && type in xExample) requestBodyObject.content[type].example = xExample[type];
|
|
457
|
-
}
|
|
458
|
-
return requestBodyObject;
|
|
459
|
-
}
|
|
460
|
-
function migrateFormDataParameter(parameters, consumes = ["multipart/form-data"]) {
|
|
461
|
-
const requestBodyObject = { content: {} };
|
|
462
|
-
const filtered = consumes.filter((type) => type === "multipart/form-data" || type === "application/x-www-form-urlencoded");
|
|
463
|
-
const contentTypes = filtered.length > 0 ? filtered : ["multipart/form-data"];
|
|
464
|
-
if (requestBodyObject.content) for (const contentType of contentTypes) {
|
|
465
|
-
requestBodyObject.content[contentType] = { schema: {
|
|
466
|
-
type: "object",
|
|
467
|
-
properties: {},
|
|
468
|
-
required: []
|
|
469
|
-
} };
|
|
470
|
-
const formContent = requestBodyObject.content?.[contentType];
|
|
471
|
-
if (formContent?.schema && typeof formContent.schema === "object" && "properties" in formContent.schema) {
|
|
472
|
-
for (const param of parameters) if (param.name && formContent.schema.properties) {
|
|
473
|
-
formContent.schema.properties[param.name] = {
|
|
474
|
-
...transformItemsObject(structuredClone(param)),
|
|
475
|
-
...param.description !== void 0 ? { description: param.description } : {}
|
|
476
|
-
};
|
|
477
|
-
const encoding = getFormDataEncoding(param);
|
|
478
|
-
if (encoding) {
|
|
479
|
-
formContent.encoding ??= {};
|
|
480
|
-
formContent.encoding[param.name] = encoding;
|
|
481
|
-
}
|
|
482
|
-
if (param.required && Array.isArray(formContent.schema.required)) formContent.schema.required.push(param.name);
|
|
483
|
-
}
|
|
484
|
-
}
|
|
485
|
-
}
|
|
486
|
-
return requestBodyObject;
|
|
487
|
-
}
|
|
488
|
-
function migrateParameters(parameters, consumes) {
|
|
489
|
-
const result = { parameters: parameters.filter((parameter) => !(parameter.in === "body" || parameter.in === "formData")).map((parameter) => transformParameterObject(parameter)) };
|
|
490
|
-
const bodyParameter = structuredClone(parameters.find((parameter) => parameter.in === "body") ?? {});
|
|
491
|
-
if (bodyParameter && Object.keys(bodyParameter).length) result.requestBody = migrateBodyParameter(bodyParameter, consumes);
|
|
492
|
-
const formDataParameters = parameters.filter((parameter) => parameter.in === "formData");
|
|
493
|
-
if (formDataParameters.length > 0) {
|
|
494
|
-
const requestBodyObject = migrateFormDataParameter(formDataParameters, consumes);
|
|
495
|
-
if (typeof result.requestBody !== "object") result.requestBody = requestBodyObject;
|
|
496
|
-
else result.requestBody = {
|
|
497
|
-
...result.requestBody,
|
|
498
|
-
content: {
|
|
499
|
-
...result.requestBody.content,
|
|
500
|
-
...requestBodyObject.content
|
|
501
|
-
}
|
|
502
|
-
};
|
|
503
|
-
if (typeof result.requestBody !== "object") result.requestBody = { content: {} };
|
|
504
|
-
}
|
|
505
|
-
return result;
|
|
506
|
-
}
|
|
507
|
-
//#endregion
|
|
508
|
-
export { upgradeFromTwoToThree };
|
|
@@ -1,152 +0,0 @@
|
|
|
1
|
-
import { traverse } from "../helpers/traverse.js";
|
|
2
|
-
//#region ../../node_modules/.pnpm/@scalar+openapi-upgrader@0.2.15/node_modules/@scalar/openapi-upgrader/dist/3.0-to-3.1/upgrade-from-three-to-three-one.js
|
|
3
|
-
const SCHEMA_SEGMENTS = /* @__PURE__ */ new Set([
|
|
4
|
-
"properties",
|
|
5
|
-
"items",
|
|
6
|
-
"allOf",
|
|
7
|
-
"anyOf",
|
|
8
|
-
"oneOf",
|
|
9
|
-
"not",
|
|
10
|
-
"additionalProperties",
|
|
11
|
-
"schema"
|
|
12
|
-
]);
|
|
13
|
-
/** Determine if the current path is within a schema - optimized version */
|
|
14
|
-
function isSchemaPath(path) {
|
|
15
|
-
if (!path) return false;
|
|
16
|
-
if (path.some((segment) => SCHEMA_SEGMENTS.has(segment))) return true;
|
|
17
|
-
if (path.some((segment) => segment.endsWith("Schema"))) return true;
|
|
18
|
-
if (path.length >= 2 && path[0] === "components" && path[1] === "schemas") return true;
|
|
19
|
-
return false;
|
|
20
|
-
}
|
|
21
|
-
const NAMED_SCHEMA_MAP_SEGMENTS = /* @__PURE__ */ new Set([
|
|
22
|
-
"properties",
|
|
23
|
-
"patternProperties",
|
|
24
|
-
"$defs",
|
|
25
|
-
"definitions"
|
|
26
|
-
]);
|
|
27
|
-
/**
|
|
28
|
-
* Determine if the node at `path` is a map of named subschemas rather than a schema object.
|
|
29
|
-
*
|
|
30
|
-
* This matters because the 3.0 to 3.1 upgrade rewrites the `example` keyword into `examples`.
|
|
31
|
-
* A key called `example` (or `examples`) inside one of these maps is a member *name*, not the
|
|
32
|
-
* schema keyword, so it must be left untouched.
|
|
33
|
-
*/
|
|
34
|
-
function isNamedSchemaMap(path) {
|
|
35
|
-
const last = path?.[path.length - 1];
|
|
36
|
-
if (last === void 0) return false;
|
|
37
|
-
if (last === "schemas" && path?.[path.length - 2] === "components") return true;
|
|
38
|
-
return NAMED_SCHEMA_MAP_SEGMENTS.has(last);
|
|
39
|
-
}
|
|
40
|
-
const DATA_KEYWORDS = /* @__PURE__ */ new Set([
|
|
41
|
-
"example",
|
|
42
|
-
"default",
|
|
43
|
-
"const",
|
|
44
|
-
"enum"
|
|
45
|
-
]);
|
|
46
|
-
/**
|
|
47
|
-
* Determine if the node at `path` lives inside a data value rather than a schema.
|
|
48
|
-
*
|
|
49
|
-
* The traversal visits every object node, but a value held by keywords like `example` or
|
|
50
|
-
* `default` is user data, not a schema. Applying the schema transforms to it would mangle it
|
|
51
|
-
* (turning `nullable: true` into a type array, renaming a nested `x-webhooks`, and so on).
|
|
52
|
-
*/
|
|
53
|
-
function isInsideDataValue(path) {
|
|
54
|
-
if (!path) return false;
|
|
55
|
-
for (const [index, segment] of path.entries()) {
|
|
56
|
-
if (DATA_KEYWORDS.has(segment) && !isNamedSchemaMap(path.slice(0, index))) return true;
|
|
57
|
-
if (segment === "value" && path[index - 2] === "examples" && !isNamedSchemaMap(path.slice(0, index - 2))) return true;
|
|
58
|
-
}
|
|
59
|
-
return false;
|
|
60
|
-
}
|
|
61
|
-
/**
|
|
62
|
-
* Upgrade from OpenAPI 3.0.x to 3.1.1
|
|
63
|
-
*
|
|
64
|
-
* https://www.openapis.org/blog/2021/02/16/migrating-from-openapi-3-0-to-3-1-0
|
|
65
|
-
*/
|
|
66
|
-
function upgradeFromThreeToThreeOne(originalContent) {
|
|
67
|
-
let content = originalContent;
|
|
68
|
-
if (content === null || typeof content.openapi !== "string" || !content.openapi.startsWith("3.0")) return content;
|
|
69
|
-
content.openapi = "3.1.1";
|
|
70
|
-
content = traverse(content, applyChangesToDocument);
|
|
71
|
-
return content;
|
|
72
|
-
}
|
|
73
|
-
const applyChangesToDocument = (schema, path) => {
|
|
74
|
-
if (isInsideDataValue(path)) return schema;
|
|
75
|
-
if (schema.type !== void 0 && schema.nullable === true) {
|
|
76
|
-
schema.type = [schema.type, "null"];
|
|
77
|
-
delete schema.nullable;
|
|
78
|
-
} else if (schema.nullable === true && schema.type === void 0) {
|
|
79
|
-
if (typeof schema.$ref === "string") {
|
|
80
|
-
const { nullable: _nullable, $ref, ...rest } = schema;
|
|
81
|
-
return {
|
|
82
|
-
...rest,
|
|
83
|
-
anyOf: [{ $ref }, { type: "null" }]
|
|
84
|
-
};
|
|
85
|
-
}
|
|
86
|
-
if (Array.isArray(schema.allOf)) {
|
|
87
|
-
const { nullable: _nullable, allOf, ...rest } = schema;
|
|
88
|
-
const base = allOf.length === 1 ? allOf[0] : { allOf };
|
|
89
|
-
return {
|
|
90
|
-
...rest,
|
|
91
|
-
anyOf: [base, { type: "null" }]
|
|
92
|
-
};
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
if (schema.exclusiveMinimum === true) {
|
|
96
|
-
schema.exclusiveMinimum = schema.minimum;
|
|
97
|
-
delete schema.minimum;
|
|
98
|
-
} else if (schema.exclusiveMinimum === false) delete schema.exclusiveMinimum;
|
|
99
|
-
if (schema.exclusiveMaximum === true) {
|
|
100
|
-
schema.exclusiveMaximum = schema.maximum;
|
|
101
|
-
delete schema.maximum;
|
|
102
|
-
} else if (schema.exclusiveMaximum === false) delete schema.exclusiveMaximum;
|
|
103
|
-
const isInsideExamplesMap = path?.some((segment, index) => {
|
|
104
|
-
if (segment === "examples" && index > 0) return !isNamedSchemaMap(path.slice(0, index));
|
|
105
|
-
return false;
|
|
106
|
-
});
|
|
107
|
-
if (schema.example !== void 0 && !isInsideExamplesMap && !isNamedSchemaMap(path)) {
|
|
108
|
-
if (isSchemaPath(path)) schema.examples = [schema.example];
|
|
109
|
-
else schema.examples = { default: { value: schema.example } };
|
|
110
|
-
delete schema.example;
|
|
111
|
-
}
|
|
112
|
-
if (schema.type === "object" && schema.properties !== void 0) {
|
|
113
|
-
if ((path?.slice(0, -1))?.some((segment, index) => {
|
|
114
|
-
return segment === "content" && path?.[index + 1] === "multipart/form-data";
|
|
115
|
-
}) && schema.properties !== null) {
|
|
116
|
-
for (const value of Object.values(schema.properties)) if (typeof value === "object" && value !== null && "type" in value && "format" in value && value.type === "string" && value.format === "binary") {
|
|
117
|
-
value.contentMediaType = "application/octet-stream";
|
|
118
|
-
delete value.format;
|
|
119
|
-
}
|
|
120
|
-
}
|
|
121
|
-
}
|
|
122
|
-
if (path?.includes("content") && path?.includes("application/octet-stream")) return {};
|
|
123
|
-
const { format: _, ...rest } = schema;
|
|
124
|
-
if (schema.type === "string") {
|
|
125
|
-
if (schema.format === "binary") return {
|
|
126
|
-
...rest,
|
|
127
|
-
type: "string",
|
|
128
|
-
contentMediaType: "application/octet-stream"
|
|
129
|
-
};
|
|
130
|
-
if (schema.format === "base64") return {
|
|
131
|
-
...rest,
|
|
132
|
-
type: "string",
|
|
133
|
-
contentEncoding: "base64"
|
|
134
|
-
};
|
|
135
|
-
if (schema.format === "byte") {
|
|
136
|
-
const contentMediaType = (path?.slice(0, -1))?.find((_, index) => path?.[index - 1] === "content");
|
|
137
|
-
return {
|
|
138
|
-
...rest,
|
|
139
|
-
type: "string",
|
|
140
|
-
contentEncoding: "base64",
|
|
141
|
-
contentMediaType
|
|
142
|
-
};
|
|
143
|
-
}
|
|
144
|
-
}
|
|
145
|
-
if (schema["x-webhooks"] !== void 0 && (path === void 0 || path.length === 0)) {
|
|
146
|
-
schema.webhooks = schema["x-webhooks"];
|
|
147
|
-
delete schema["x-webhooks"];
|
|
148
|
-
}
|
|
149
|
-
return schema;
|
|
150
|
-
};
|
|
151
|
-
//#endregion
|
|
152
|
-
export { isSchemaPath, upgradeFromThreeToThreeOne };
|