@scalar/openapi-parser 0.18.0 → 0.18.2
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 +12 -0
- package/README.md +8 -8
- package/dist/configuration/index.d.ts +4 -4
- package/dist/configuration/index.js +4 -4
- package/dist/configuration/index.js.map +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/utils/betterAjvErrors/json/get-meta-from-path.js.map +1 -1
- package/dist/utils/bundle/plugins/fetch-urls/index.d.ts.map +1 -1
- package/dist/utils/bundle/plugins/fetch-urls/index.js +9 -2
- package/dist/utils/bundle/plugins/fetch-urls/index.js.map +2 -2
- package/dist/utils/get-list-of-references.d.ts +1 -1
- package/dist/utils/get-list-of-references.js.map +1 -1
- package/dist/utils/load/load.js.map +1 -1
- package/dist/utils/normalize.d.ts +1 -1
- package/dist/utils/normalize.js.map +1 -1
- package/dist/utils/resolve-references.js.map +1 -1
- package/dist/utils/transform/sanitize.d.ts +1 -1
- package/dist/utils/transform/sanitize.js.map +1 -1
- package/dist/utils/upgrade-from-three-to-three-one.js +1 -1
- package/dist/utils/upgrade-from-three-to-three-one.js.map +2 -2
- package/dist/utils/upgrade-from-two-to-three.d.ts.map +1 -1
- package/dist/utils/upgrade-from-two-to-three.js +15 -1
- package/dist/utils/upgrade-from-two-to-three.js.map +2 -2
- package/package.json +6 -6
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,17 @@
|
|
|
1
1
|
# @scalar/openapi-parser
|
|
2
2
|
|
|
3
|
+
## 0.18.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 1c2b9f3: feat: add application and accessCode to swagger 2 upgrader
|
|
8
|
+
|
|
9
|
+
## 0.18.1
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- 2d7f995: refactor: use more common straight apostrophe ' instead of the real apostrophe ’
|
|
14
|
+
|
|
3
15
|
## 0.18.0
|
|
4
16
|
|
|
5
17
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -293,7 +293,7 @@ const { specification } = filter(
|
|
|
293
293
|
|
|
294
294
|
### Upgrade your OpenAPI document
|
|
295
295
|
|
|
296
|
-
There
|
|
296
|
+
There's an `upgrade` command to upgrade all your OpenAPI documents to the latest OpenAPI version.
|
|
297
297
|
|
|
298
298
|
```ts
|
|
299
299
|
import { upgrade } from '@scalar/openapi-parser'
|
|
@@ -320,7 +320,7 @@ and adds them to the global tags array and normalizes security scheme types.
|
|
|
320
320
|
This makes your document as OpenAPI-compliant as possible with minimal effort, handling many common specification
|
|
321
321
|
requirements automatically.
|
|
322
322
|
|
|
323
|
-
> ⚠️ This doesn
|
|
323
|
+
> ⚠️ This doesn't support Swagger 2.0 documents.
|
|
324
324
|
|
|
325
325
|
```ts
|
|
326
326
|
import { sanitize } from '@scalar/openapi-parser'
|
|
@@ -336,7 +336,7 @@ console.log(result)
|
|
|
336
336
|
|
|
337
337
|
### Then/Catch syntax
|
|
338
338
|
|
|
339
|
-
If you
|
|
339
|
+
If you're more the then/catch type of guy, that's fine:
|
|
340
340
|
|
|
341
341
|
```ts
|
|
342
342
|
import { validate } from '@scalar/openapi-parser'
|
|
@@ -400,7 +400,7 @@ const { filesystem } = await load('./openapi.yaml', {
|
|
|
400
400
|
const result = await dereference(filesystem)
|
|
401
401
|
```
|
|
402
402
|
|
|
403
|
-
As you see, `load()` supports plugins. You can write your own plugin, if you
|
|
403
|
+
As you see, `load()` supports plugins. You can write your own plugin, if you'd like to fetch API defintions from another data source, for example your database. Look at the source code of the `readFiles` to learn how this could look like.
|
|
404
404
|
|
|
405
405
|
#### Directly load URLs
|
|
406
406
|
|
|
@@ -421,7 +421,7 @@ const { filesystem } = await load(
|
|
|
421
421
|
|
|
422
422
|
#### Intercept HTTP requests
|
|
423
423
|
|
|
424
|
-
If you
|
|
424
|
+
If you're using the package in a browser environment, you may run into CORS issues when fetching from URLs. You can intercept the requests, for example to use a proxy, though:
|
|
425
425
|
|
|
426
426
|
```ts
|
|
427
427
|
import { dereference, load } from '@scalar/openapi-parser'
|
|
@@ -442,15 +442,15 @@ const { filesystem } = await load(
|
|
|
442
442
|
|
|
443
443
|
## Community
|
|
444
444
|
|
|
445
|
-
We are API nerds. You too? Let
|
|
445
|
+
We are API nerds. You too? Let's chat on Discord: <https://discord.gg/scalar>
|
|
446
446
|
|
|
447
447
|
## Thank you!
|
|
448
448
|
|
|
449
449
|
Thanks a ton for all the help and inspiration:
|
|
450
450
|
|
|
451
|
-
- [@philsturgeon](https://github.com/philsturgeon) to make sure we build something we won
|
|
451
|
+
- [@philsturgeon](https://github.com/philsturgeon) to make sure we build something we won't hate.
|
|
452
452
|
- We took a lot of inspiration from [@seriousme](https://github.com/seriousme) and his package [openapi-schema-validator](https://github.com/seriousme/openapi-schema-validator) early-on.
|
|
453
|
-
- You could consider this package the modern successor of [@apidevtools/swagger-parser](https://github.com/APIDevTools/swagger-parser), we even test against it to make sure we
|
|
453
|
+
- You could consider this package the modern successor of [@apidevtools/swagger-parser](https://github.com/APIDevTools/swagger-parser), we even test against it to make sure we're getting the same results (where intended).
|
|
454
454
|
- We stole a lot of example specification from [@mermade](https://github.com/mermade) to test against.
|
|
455
455
|
|
|
456
456
|
## License
|
|
@@ -3897,10 +3897,10 @@ export declare const OpenApiVersions: OpenApiVersion[];
|
|
|
3897
3897
|
* List of error messages used in the Validator
|
|
3898
3898
|
*/
|
|
3899
3899
|
export declare const ERRORS: {
|
|
3900
|
-
readonly EMPTY_OR_INVALID: "Can
|
|
3901
|
-
readonly OPENAPI_VERSION_NOT_SUPPORTED: "Can
|
|
3902
|
-
readonly INVALID_REFERENCE: "Can
|
|
3903
|
-
readonly EXTERNAL_REFERENCE_NOT_FOUND: "Can
|
|
3900
|
+
readonly EMPTY_OR_INVALID: "Can't find JSON, YAML or filename in data.";
|
|
3901
|
+
readonly OPENAPI_VERSION_NOT_SUPPORTED: "Can't find supported Swagger/OpenAPI version in the provided document, version must be a string.";
|
|
3902
|
+
readonly INVALID_REFERENCE: "Can't resolve reference: %s";
|
|
3903
|
+
readonly EXTERNAL_REFERENCE_NOT_FOUND: "Can't resolve external reference: %s";
|
|
3904
3904
|
readonly FILE_DOES_NOT_EXIST: "File does not exist: %s";
|
|
3905
3905
|
readonly NO_CONTENT: "No content found";
|
|
3906
3906
|
};
|
|
@@ -8,11 +8,11 @@ const OpenApiSpecifications = {
|
|
|
8
8
|
};
|
|
9
9
|
const OpenApiVersions = Object.keys(OpenApiSpecifications);
|
|
10
10
|
const ERRORS = {
|
|
11
|
-
EMPTY_OR_INVALID: "Can
|
|
11
|
+
EMPTY_OR_INVALID: "Can't find JSON, YAML or filename in data.",
|
|
12
12
|
// URI_MUST_BE_STRING: 'uri parameter or $id attribute must be a string',
|
|
13
|
-
OPENAPI_VERSION_NOT_SUPPORTED: "Can
|
|
14
|
-
INVALID_REFERENCE: "Can
|
|
15
|
-
EXTERNAL_REFERENCE_NOT_FOUND: "Can
|
|
13
|
+
OPENAPI_VERSION_NOT_SUPPORTED: "Can't find supported Swagger/OpenAPI version in the provided document, version must be a string.",
|
|
14
|
+
INVALID_REFERENCE: "Can't resolve reference: %s",
|
|
15
|
+
EXTERNAL_REFERENCE_NOT_FOUND: "Can't resolve external reference: %s",
|
|
16
16
|
FILE_DOES_NOT_EXIST: "File does not exist: %s",
|
|
17
17
|
NO_CONTENT: "No content found"
|
|
18
18
|
};
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/configuration/index.ts"],
|
|
4
|
-
"sourcesContent": ["import Swagger20 from '@/schemas/v2.0/schema'\nimport OpenApi30 from '@/schemas/v3.0/schema'\nimport OpenApi31 from '@/schemas/v3.1/schema'\n\n/**\n * A list of the supported OpenAPI specifications\n */\nexport const OpenApiSpecifications = {\n '2.0': Swagger20,\n '3.0': OpenApi30,\n '3.1': OpenApi31,\n}\n\nexport type OpenApiVersion = keyof typeof OpenApiSpecifications\n\nexport const OpenApiVersions = Object.keys(OpenApiSpecifications) as OpenApiVersion[]\n\n/**\n * List of error messages used in the Validator\n */\nexport const ERRORS = {\n EMPTY_OR_INVALID: '
|
|
4
|
+
"sourcesContent": ["import Swagger20 from '@/schemas/v2.0/schema'\nimport OpenApi30 from '@/schemas/v3.0/schema'\nimport OpenApi31 from '@/schemas/v3.1/schema'\n\n/**\n * A list of the supported OpenAPI specifications\n */\nexport const OpenApiSpecifications = {\n '2.0': Swagger20,\n '3.0': OpenApi30,\n '3.1': OpenApi31,\n}\n\nexport type OpenApiVersion = keyof typeof OpenApiSpecifications\n\nexport const OpenApiVersions = Object.keys(OpenApiSpecifications) as OpenApiVersion[]\n\n/**\n * List of error messages used in the Validator\n */\nexport const ERRORS = {\n EMPTY_OR_INVALID: \"Can't find JSON, YAML or filename in data.\",\n // URI_MUST_BE_STRING: 'uri parameter or $id attribute must be a string',\n OPENAPI_VERSION_NOT_SUPPORTED:\n \"Can't find supported Swagger/OpenAPI version in the provided document, version must be a string.\",\n INVALID_REFERENCE: \"Can't resolve reference: %s\",\n EXTERNAL_REFERENCE_NOT_FOUND: \"Can't resolve external reference: %s\",\n FILE_DOES_NOT_EXIST: 'File does not exist: %s',\n NO_CONTENT: 'No content found',\n} as const\n\nexport type ValidationError = keyof typeof ERRORS\n"],
|
|
5
5
|
"mappings": "AAAA,OAAO,eAAe;AACtB,OAAO,eAAe;AACtB,OAAO,eAAe;AAKf,MAAM,wBAAwB;AAAA,EACnC,OAAO;AAAA,EACP,OAAO;AAAA,EACP,OAAO;AACT;AAIO,MAAM,kBAAkB,OAAO,KAAK,qBAAqB;AAKzD,MAAM,SAAS;AAAA,EACpB,kBAAkB;AAAA;AAAA,EAElB,+BACE;AAAA,EACF,mBAAmB;AAAA,EACnB,8BAA8B;AAAA,EAC9B,qBAAqB;AAAA,EACrB,YAAY;AACd;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/dist/types/index.d.ts
CHANGED
|
@@ -53,7 +53,7 @@ export type AjvOptions = {
|
|
|
53
53
|
*/
|
|
54
54
|
export type Filesystem = FilesystemEntry[];
|
|
55
55
|
/**
|
|
56
|
-
* Holds all information about a single file (doesn
|
|
56
|
+
* Holds all information about a single file (doesn't have to be a literal file, see Filesystem).
|
|
57
57
|
*/
|
|
58
58
|
export type FilesystemEntry = {
|
|
59
59
|
dir: string;
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../src/utils/betterAjvErrors/json/get-meta-from-path.ts"],
|
|
4
|
-
"sourcesContent": ["import { getPointers } from './utils'\n\nexport default function getMetaFromPath(jsonAst, dataPath, includeIdentifierLocation) {\n const pointers = getPointers(dataPath)\n const lastPointerIndex = pointers.length - 1\n return pointers.reduce((obj, pointer, idx) => {\n switch (obj?.type) {\n case 'Object': {\n const filtered = obj.members.filter((child) => child.name.value === pointer)\n if (filtered.length !== 1) {\n throw new Error(`Couldn't find property ${pointer} of ${dataPath}`)\n }\n\n const { name, value } = filtered[0]\n return includeIdentifierLocation && idx === lastPointerIndex ? name : value\n }\n case 'Array':\n return obj.elements[pointer]\n default:\n // Unexpected type\n // console.log(obj)\n\n // Anyway, if there
|
|
4
|
+
"sourcesContent": ["import { getPointers } from './utils'\n\nexport default function getMetaFromPath(jsonAst, dataPath, includeIdentifierLocation) {\n const pointers = getPointers(dataPath)\n const lastPointerIndex = pointers.length - 1\n return pointers.reduce((obj, pointer, idx) => {\n switch (obj?.type) {\n case 'Object': {\n const filtered = obj.members.filter((child) => child.name.value === pointer)\n if (filtered.length !== 1) {\n throw new Error(`Couldn't find property ${pointer} of ${dataPath}`)\n }\n\n const { name, value } = filtered[0]\n return includeIdentifierLocation && idx === lastPointerIndex ? name : value\n }\n case 'Array':\n return obj.elements[pointer]\n default:\n // Unexpected type\n // console.log(obj)\n\n // Anyway, if there's location, let's just use it.\n if (obj.loc) {\n return obj\n }\n }\n }, jsonAst.body)\n}\n"],
|
|
5
5
|
"mappings": "AAAA,SAAS,mBAAmB;AAEb,SAAR,gBAAiC,SAAS,UAAU,2BAA2B;AACpF,QAAM,WAAW,YAAY,QAAQ;AACrC,QAAM,mBAAmB,SAAS,SAAS;AAC3C,SAAO,SAAS,OAAO,CAAC,KAAK,SAAS,QAAQ;AAC5C,YAAQ,KAAK,MAAM;AAAA,MACjB,KAAK,UAAU;AACb,cAAM,WAAW,IAAI,QAAQ,OAAO,CAAC,UAAU,MAAM,KAAK,UAAU,OAAO;AAC3E,YAAI,SAAS,WAAW,GAAG;AACzB,gBAAM,IAAI,MAAM,0BAA0B,OAAO,OAAO,QAAQ,EAAE;AAAA,QACpE;AAEA,cAAM,EAAE,MAAM,MAAM,IAAI,SAAS,CAAC;AAClC,eAAO,6BAA6B,QAAQ,mBAAmB,OAAO;AAAA,MACxE;AAAA,MACA,KAAK;AACH,eAAO,IAAI,SAAS,OAAO;AAAA,MAC7B;AAKE,YAAI,IAAI,KAAK;AACX,iBAAO;AAAA,QACT;AAAA,IACJ;AAAA,EACF,GAAG,QAAQ,IAAI;AACjB;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/utils/bundle/plugins/fetch-urls/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAGpF,KAAK,WAAW,GAAG,OAAO,CAAC;IACzB,OAAO,EAAE;QAAE,OAAO,EAAE,WAAW,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAA;IACtD,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC3F,CAAC,CAAA;
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../../../../src/utils/bundle/plugins/fetch-urls/index.ts"],"names":[],"mappings":"AACA,OAAO,EAAe,KAAK,MAAM,EAAE,KAAK,aAAa,EAAE,MAAM,uBAAuB,CAAA;AAGpF,KAAK,WAAW,GAAG,OAAO,CAAC;IACzB,OAAO,EAAE;QAAE,OAAO,EAAE,WAAW,CAAC;QAAC,OAAO,EAAE,MAAM,EAAE,CAAA;KAAE,EAAE,CAAA;IACtD,KAAK,EAAE,CAAC,KAAK,EAAE,MAAM,GAAG,GAAG,GAAG,UAAU,CAAC,OAAO,EAAE,IAAI,CAAC,EAAE,WAAW,KAAK,OAAO,CAAC,QAAQ,CAAC,CAAA;CAC3F,CAAC,CAAA;AAcF;;;;;;;;;;;;;GAaG;AACH,wBAAsB,QAAQ,CAC5B,GAAG,EAAE,MAAM,EACX,OAAO,EAAE,CAAC,CAAC,EAAE,EAAE,EAAE,MAAM,OAAO,CAAC,CAAC,CAAC,KAAK,OAAO,CAAC,CAAC,CAAC,EAChD,MAAM,CAAC,EAAE,WAAW,GACnB,OAAO,CAAC,aAAa,CAAC,CAgCxB;AAED;;;;;;;;;;GAUG;AACH,wBAAgB,SAAS,CAAC,MAAM,CAAC,EAAE,WAAW,GAAG,OAAO,CAAC;IAAE,KAAK,EAAE,MAAM,GAAG,IAAI,CAAA;CAAE,CAAC,GAAG,MAAM,CAQ1F"}
|
|
@@ -1,10 +1,17 @@
|
|
|
1
1
|
import { normalize } from "../../../../utils/normalize.js";
|
|
2
2
|
import { isRemoteUrl } from "../../../../utils/bundle/bundle.js";
|
|
3
3
|
import { createLimiter } from "../../../../utils/bundle/create-limiter.js";
|
|
4
|
+
const getHost = (url) => {
|
|
5
|
+
try {
|
|
6
|
+
return new URL(url).host;
|
|
7
|
+
} catch {
|
|
8
|
+
return null;
|
|
9
|
+
}
|
|
10
|
+
};
|
|
4
11
|
async function fetchUrl(url, limiter, config) {
|
|
5
12
|
try {
|
|
6
|
-
const
|
|
7
|
-
const headers = config?.headers?.find((a) => a.domains.find((d) => d ===
|
|
13
|
+
const host = getHost(url);
|
|
14
|
+
const headers = config?.headers?.find((a) => a.domains.find((d) => d === host) !== void 0)?.headers;
|
|
8
15
|
const exec = config?.fetch ?? fetch;
|
|
9
16
|
const result = await limiter(
|
|
10
17
|
() => exec(url, {
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../../../src/utils/bundle/plugins/fetch-urls/index.ts"],
|
|
4
|
-
"sourcesContent": ["import { normalize } from '@/utils/normalize'\nimport { isRemoteUrl, type Plugin, type ResolveResult } from '@/utils/bundle/bundle'\nimport { createLimiter } from '@/utils/bundle/create-limiter'\n\ntype FetchConfig = Partial<{\n headers: { headers: HeadersInit; domains: string[] }[]\n fetch: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>\n}>\n\n/**\n * Fetches and normalizes data from a remote URL\n * @param url - The URL to fetch data from\n * @returns A promise that resolves to either the normalized data or an error result\n * @example\n * ```ts\n * const result = await fetchUrl('https://api.example.com/data.json')\n * if (result.ok) {\n * console.log(result.data) // The normalized data\n * } else {\n * console.log('Failed to fetch data')\n * }\n * ```\n */\nexport async function fetchUrl(\n url: string,\n limiter: <T>(fn: () => Promise<T>) => Promise<T>,\n config?: FetchConfig,\n): Promise<ResolveResult> {\n try {\n const
|
|
5
|
-
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,mBAAoD;AAC7D,SAAS,qBAAqB;
|
|
4
|
+
"sourcesContent": ["import { normalize } from '@/utils/normalize'\nimport { isRemoteUrl, type Plugin, type ResolveResult } from '@/utils/bundle/bundle'\nimport { createLimiter } from '@/utils/bundle/create-limiter'\n\ntype FetchConfig = Partial<{\n headers: { headers: HeadersInit; domains: string[] }[]\n fetch: (input: string | URL | globalThis.Request, init?: RequestInit) => Promise<Response>\n}>\n\n/**\n * Safely checks for host from a URL\n * Needed because we cannot create a URL from a relative remote URL ex: examples/openapi.json\n */\nconst getHost = (url: string): string | null => {\n try {\n return new URL(url).host\n } catch {\n return null\n }\n}\n\n/**\n * Fetches and normalizes data from a remote URL\n * @param url - The URL to fetch data from\n * @returns A promise that resolves to either the normalized data or an error result\n * @example\n * ```ts\n * const result = await fetchUrl('https://api.example.com/data.json')\n * if (result.ok) {\n * console.log(result.data) // The normalized data\n * } else {\n * console.log('Failed to fetch data')\n * }\n * ```\n */\nexport async function fetchUrl(\n url: string,\n limiter: <T>(fn: () => Promise<T>) => Promise<T>,\n config?: FetchConfig,\n): Promise<ResolveResult> {\n try {\n const host = getHost(url)\n\n // Get the headers that match the domain\n const headers = config?.headers?.find((a) => a.domains.find((d) => d === host) !== undefined)?.headers\n\n const exec = config?.fetch ?? fetch\n\n const result = await limiter(() =>\n exec(url, {\n headers,\n }),\n )\n\n if (result.ok) {\n const body = await result.text()\n\n return {\n ok: true,\n data: normalize(body),\n }\n }\n\n return {\n ok: false,\n }\n } catch {\n return {\n ok: false,\n }\n }\n}\n\n/**\n * Creates a plugin for handling remote URL references.\n * This plugin validates and fetches data from HTTP/HTTPS URLs.\n *\n * @returns A plugin object with validate and exec functions\n * @example\n * const urlPlugin = fetchUrls()\n * if (urlPlugin.validate('https://example.com/schema.json')) {\n * const result = await urlPlugin.exec('https://example.com/schema.json')\n * }\n */\nexport function fetchUrls(config?: FetchConfig & Partial<{ limit: number | null }>): Plugin {\n // If there is a limit specified we limit the number of concurrent calls\n const limiter = config?.limit ? createLimiter(config.limit) : <T>(fn: () => Promise<T>) => fn()\n\n return {\n validate: isRemoteUrl,\n exec: (value) => fetchUrl(value, limiter, config),\n }\n}\n"],
|
|
5
|
+
"mappings": "AAAA,SAAS,iBAAiB;AAC1B,SAAS,mBAAoD;AAC7D,SAAS,qBAAqB;AAW9B,MAAM,UAAU,CAAC,QAA+B;AAC9C,MAAI;AACF,WAAO,IAAI,IAAI,GAAG,EAAE;AAAA,EACtB,QAAQ;AACN,WAAO;AAAA,EACT;AACF;AAgBA,eAAsB,SACpB,KACA,SACA,QACwB;AACxB,MAAI;AACF,UAAM,OAAO,QAAQ,GAAG;AAGxB,UAAM,UAAU,QAAQ,SAAS,KAAK,CAAC,MAAM,EAAE,QAAQ,KAAK,CAAC,MAAM,MAAM,IAAI,MAAM,MAAS,GAAG;AAE/F,UAAM,OAAO,QAAQ,SAAS;AAE9B,UAAM,SAAS,MAAM;AAAA,MAAQ,MAC3B,KAAK,KAAK;AAAA,QACR;AAAA,MACF,CAAC;AAAA,IACH;AAEA,QAAI,OAAO,IAAI;AACb,YAAM,OAAO,MAAM,OAAO,KAAK;AAE/B,aAAO;AAAA,QACL,IAAI;AAAA,QACJ,MAAM,UAAU,IAAI;AAAA,MACtB;AAAA,IACF;AAEA,WAAO;AAAA,MACL,IAAI;AAAA,IACN;AAAA,EACF,QAAQ;AACN,WAAO;AAAA,MACL,IAAI;AAAA,IACN;AAAA,EACF;AACF;AAaO,SAAS,UAAU,QAAkE;AAE1F,QAAM,UAAU,QAAQ,QAAQ,cAAc,OAAO,KAAK,IAAI,CAAI,OAAyB,GAAG;AAE9F,SAAO;AAAA,IACL,UAAU;AAAA,IACV,MAAM,CAAC,UAAU,SAAS,OAAO,SAAS,MAAM;AAAA,EAClD;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -2,7 +2,7 @@ import type { AnyObject } from '../types/index.js';
|
|
|
2
2
|
/**
|
|
3
3
|
* Walks through the specification and returns all references as an array.
|
|
4
4
|
*
|
|
5
|
-
* Warning: Doesn
|
|
5
|
+
* Warning: Doesn't return internal references.
|
|
6
6
|
*/
|
|
7
7
|
export declare function getListOfReferences(specification: AnyObject): string[];
|
|
8
8
|
//# sourceMappingURL=get-list-of-references.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/get-list-of-references.ts"],
|
|
4
|
-
"sourcesContent": ["import type { AnyObject } from '@/types/index'\nimport { traverse } from './traverse'\n\n/**\n * Walks through the specification and returns all references as an array.\n *\n * Warning: Doesn
|
|
4
|
+
"sourcesContent": ["import type { AnyObject } from '@/types/index'\nimport { traverse } from './traverse'\n\n/**\n * Walks through the specification and returns all references as an array.\n *\n * Warning: Doesn't return internal references.\n */\nexport function getListOfReferences(specification: AnyObject) {\n const references: string[] = []\n\n // Make sure we're dealing with an object\n if (!specification || typeof specification !== 'object') {\n return references\n }\n\n // Traverse the specification and collect all references\n traverse(specification, (value: any) => {\n if (value.$ref && typeof value.$ref === 'string' && !value.$ref.startsWith('#')) {\n references.push(value.$ref.split('#')[0])\n }\n\n return value\n })\n\n // Remove duplicates\n return [...new Set(references)]\n}\n"],
|
|
5
5
|
"mappings": "AACA,SAAS,gBAAgB;AAOlB,SAAS,oBAAoB,eAA0B;AAC5D,QAAM,aAAuB,CAAC;AAG9B,MAAI,CAAC,iBAAiB,OAAO,kBAAkB,UAAU;AACvD,WAAO;AAAA,EACT;AAGA,WAAS,eAAe,CAAC,UAAe;AACtC,QAAI,MAAM,QAAQ,OAAO,MAAM,SAAS,YAAY,CAAC,MAAM,KAAK,WAAW,GAAG,GAAG;AAC/E,iBAAW,KAAK,MAAM,KAAK,MAAM,GAAG,EAAE,CAAC,CAAC;AAAA,IAC1C;AAEA,WAAO;AAAA,EACT,CAAC;AAGD,SAAO,CAAC,GAAG,IAAI,IAAI,UAAU,CAAC;AAChC;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/load/load.ts"],
|
|
4
|
-
"sourcesContent": ["import { ERRORS } from '@/configuration'\nimport type {\n AnyApiDefinitionFormat,\n AnyObject,\n ErrorObject,\n Filesystem,\n LoadResult,\n ThrowOnErrorOption,\n} from '@/types/index'\nimport { getEntrypoint } from '@/utils/get-entrypoint'\nimport { getListOfReferences } from '@/utils/get-list-of-references'\nimport { makeFilesystem } from '@/utils/make-filesystem'\nimport { normalize } from '@/utils/normalize'\n\nexport type LoadPlugin = {\n check: (value?: any) => boolean\n get: (value: any) => any\n resolvePath?: (value: any, reference: string) => string\n getDir?: (value: any) => string\n getFilename?: (value: any) => string\n}\n\nexport type LoadOptions = {\n plugins?: LoadPlugin[]\n filename?: string\n filesystem?: Filesystem\n} & ThrowOnErrorOption\n\n/**\n * @deprecated This function is deprecated and will be removed in a future version.\n * Please use the new bundler utility instead:\n * ```ts\n * import { bundle } from \"@scalar/openapi-parser\"\n * ```\n *\n * Loads an OpenAPI document, including any external references.\n *\n * This function handles loading content from various sources, normalizes the content,\n * and recursively loads any external references found within the definition.\n *\n * It builds a filesystem representation of all loaded content and collects any errors\n * encountered during the process.\n */\nexport async function load(value: AnyApiDefinitionFormat, options?: LoadOptions): Promise<LoadResult> {\n const errors: ErrorObject[] = []\n\n // Don
|
|
4
|
+
"sourcesContent": ["import { ERRORS } from '@/configuration'\nimport type {\n AnyApiDefinitionFormat,\n AnyObject,\n ErrorObject,\n Filesystem,\n LoadResult,\n ThrowOnErrorOption,\n} from '@/types/index'\nimport { getEntrypoint } from '@/utils/get-entrypoint'\nimport { getListOfReferences } from '@/utils/get-list-of-references'\nimport { makeFilesystem } from '@/utils/make-filesystem'\nimport { normalize } from '@/utils/normalize'\n\nexport type LoadPlugin = {\n check: (value?: any) => boolean\n get: (value: any) => any\n resolvePath?: (value: any, reference: string) => string\n getDir?: (value: any) => string\n getFilename?: (value: any) => string\n}\n\nexport type LoadOptions = {\n plugins?: LoadPlugin[]\n filename?: string\n filesystem?: Filesystem\n} & ThrowOnErrorOption\n\n/**\n * @deprecated This function is deprecated and will be removed in a future version.\n * Please use the new bundler utility instead:\n * ```ts\n * import { bundle } from \"@scalar/openapi-parser\"\n * ```\n *\n * Loads an OpenAPI document, including any external references.\n *\n * This function handles loading content from various sources, normalizes the content,\n * and recursively loads any external references found within the definition.\n *\n * It builds a filesystem representation of all loaded content and collects any errors\n * encountered during the process.\n */\nexport async function load(value: AnyApiDefinitionFormat, options?: LoadOptions): Promise<LoadResult> {\n const errors: ErrorObject[] = []\n\n // Don't load a reference twice, check the filesystem before fetching something\n if (options?.filesystem?.find((entry) => entry.filename === value)) {\n return {\n specification: getEntrypoint(options.filesystem)?.specification,\n filesystem: options.filesystem,\n errors,\n }\n }\n\n // Check whether the value is an URL or file path\n const plugin = options?.plugins?.find((thisPlugin) => thisPlugin.check(value))\n\n let content: AnyObject\n\n if (plugin) {\n try {\n content = normalize(await plugin.get(value))\n } catch (_error) {\n if (options?.throwOnError) {\n throw new Error(ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace('%s', value as string))\n }\n\n errors.push({\n code: 'EXTERNAL_REFERENCE_NOT_FOUND',\n message: ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace('%s', value as string),\n })\n\n return {\n specification: null,\n filesystem: [],\n errors,\n }\n }\n } else {\n content = normalize(value)\n }\n\n // No content\n if (content === undefined) {\n if (options?.throwOnError) {\n throw new Error('No content to load')\n }\n\n errors.push({\n code: 'NO_CONTENT',\n message: ERRORS.NO_CONTENT,\n })\n\n return {\n specification: null,\n filesystem: [],\n errors,\n }\n }\n\n let filesystem = makeFilesystem(content, {\n filename: options?.filename ?? null,\n })\n\n // Get references from file system entry, or from the content\n const newEntry = options?.filename\n ? filesystem.find((entry) => entry.filename === options?.filename)\n : getEntrypoint(filesystem)\n\n const listOfReferences = newEntry.references ?? getListOfReferences(content)\n\n // No other references\n if (listOfReferences.length === 0) {\n return {\n specification: getEntrypoint(filesystem)?.specification,\n filesystem,\n errors,\n }\n }\n\n // Load other external references\n for (const reference of listOfReferences) {\n // Find a matching plugin\n const otherPlugin = options?.plugins?.find((thisPlugin) => thisPlugin.check(reference))\n\n // Skip if no plugin is found (internal references don't need a plugin for example)\n if (!otherPlugin) {\n continue\n }\n\n const target =\n otherPlugin.check(reference) && otherPlugin.resolvePath ? otherPlugin.resolvePath(value, reference) : reference\n\n // Don't load a reference twice, check the filesystem before fetching something\n if (filesystem.find((entry) => entry.filename === reference)) {\n continue\n }\n\n const { filesystem: referencedFiles, errors: newErrors } = await load(target, {\n ...options,\n // Make the filename the exact same value as the $ref\n // TODO: This leads to problems, if there are multiple references with the same file name but in different folders\n filename: reference,\n })\n\n errors.push(...newErrors)\n\n filesystem = [\n ...filesystem,\n ...referencedFiles.map((file) => {\n return {\n ...file,\n isEntrypoint: false,\n }\n }),\n ]\n }\n\n return {\n specification: getEntrypoint(filesystem)?.specification,\n filesystem,\n errors,\n }\n}\n"],
|
|
5
5
|
"mappings": "AAAA,SAAS,cAAc;AASvB,SAAS,qBAAqB;AAC9B,SAAS,2BAA2B;AACpC,SAAS,sBAAsB;AAC/B,SAAS,iBAAiB;AA+B1B,eAAsB,KAAK,OAA+B,SAA4C;AACpG,QAAM,SAAwB,CAAC;AAG/B,MAAI,SAAS,YAAY,KAAK,CAAC,UAAU,MAAM,aAAa,KAAK,GAAG;AAClE,WAAO;AAAA,MACL,eAAe,cAAc,QAAQ,UAAU,GAAG;AAAA,MAClD,YAAY,QAAQ;AAAA,MACpB;AAAA,IACF;AAAA,EACF;AAGA,QAAM,SAAS,SAAS,SAAS,KAAK,CAAC,eAAe,WAAW,MAAM,KAAK,CAAC;AAE7E,MAAI;AAEJ,MAAI,QAAQ;AACV,QAAI;AACF,gBAAU,UAAU,MAAM,OAAO,IAAI,KAAK,CAAC;AAAA,IAC7C,SAAS,QAAQ;AACf,UAAI,SAAS,cAAc;AACzB,cAAM,IAAI,MAAM,OAAO,6BAA6B,QAAQ,MAAM,KAAe,CAAC;AAAA,MACpF;AAEA,aAAO,KAAK;AAAA,QACV,MAAM;AAAA,QACN,SAAS,OAAO,6BAA6B,QAAQ,MAAM,KAAe;AAAA,MAC5E,CAAC;AAED,aAAO;AAAA,QACL,eAAe;AAAA,QACf,YAAY,CAAC;AAAA,QACb;AAAA,MACF;AAAA,IACF;AAAA,EACF,OAAO;AACL,cAAU,UAAU,KAAK;A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AC;AAAA,IACH;AAAA,EACF;AAEA,SAAO;AAAA,IACL,eAAe,cAAc,UAAU,GAAG;AAAA,IAC1C;AAAA,IACA;AAAA,EACF;AACF;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -3,7 +3,7 @@ import type { Filesystem } from '../types/index.js';
|
|
|
3
3
|
/**
|
|
4
4
|
* Normalize the OpenAPI document (YAML, JSON, object) to a JavaScript object.
|
|
5
5
|
*
|
|
6
|
-
* Doesn
|
|
6
|
+
* Doesn't modify the object if it's a `Filesystem` (multiple files) already.
|
|
7
7
|
*/
|
|
8
8
|
export declare function normalize(content: string | UnknownObject | Filesystem): UnknownObject | Filesystem;
|
|
9
9
|
//# sourceMappingURL=normalize.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/normalize.ts"],
|
|
4
|
-
"sourcesContent": ["import type { UnknownObject } from '@scalar/types/utils'\nimport { parse } from 'yaml'\n\nimport type { Filesystem } from '@/types/index'\nimport { isFilesystem } from './is-filesystem'\n\n/**\n * Normalize the OpenAPI document (YAML, JSON, object) to a JavaScript object.\n *\n * Doesn
|
|
4
|
+
"sourcesContent": ["import type { UnknownObject } from '@scalar/types/utils'\nimport { parse } from 'yaml'\n\nimport type { Filesystem } from '@/types/index'\nimport { isFilesystem } from './is-filesystem'\n\n/**\n * Normalize the OpenAPI document (YAML, JSON, object) to a JavaScript object.\n *\n * Doesn't modify the object if it's a `Filesystem` (multiple files) already.\n */\nexport function normalize(content: string | UnknownObject | Filesystem): UnknownObject | Filesystem {\n if (content === null) {\n return undefined\n }\n\n if (typeof content === 'string') {\n if (content.trim() === '') {\n return undefined\n }\n\n try {\n return JSON.parse(content)\n } catch (_error) {\n // Does it look like YAML?\n const hasColon = /^[^:]+:/.test(content)\n const isJson = content.slice(0, 50).trimStart().startsWith('{')\n\n if (!hasColon || isJson) {\n return undefined\n }\n\n return parse(content, {\n maxAliasCount: 10000,\n })\n }\n }\n\n if (isFilesystem(content)) {\n return content\n }\n\n return content\n}\n"],
|
|
5
5
|
"mappings": "AACA,SAAS,aAAa;AAGtB,SAAS,oBAAoB;AAOtB,SAAS,UAAU,SAA0E;AAClG,MAAI,YAAY,MAAM;AACpB,WAAO;AAAA,EACT;AAEA,MAAI,OAAO,YAAY,UAAU;AAC/B,QAAI,QAAQ,KAAK,MAAM,IAAI;AACzB,aAAO;AAAA,IACT;AAEA,QAAI;AACF,aAAO,KAAK,MAAM,OAAO;AAAA,IAC3B,SAAS,QAAQ;AAEf,YAAM,WAAW,UAAU,KAAK,OAAO;AACvC,YAAM,SAAS,QAAQ,MAAM,GAAG,EAAE,EAAE,UAAU,EAAE,WAAW,GAAG;AAE9D,UAAI,CAAC,YAAY,QAAQ;AACvB,eAAO;AAAA,MACT;AAEA,aAAO,MAAM,SAAS;AAAA,QACpB,eAAe;AAAA,MACjB,CAAC;AAAA,IACH;AAAA,EACF;AAEA,MAAI,aAAa,OAAO,GAAG;AACzB,WAAO;AAAA,EACT;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/resolve-references.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPI } from '@scalar/openapi-types'\n\nimport { ERRORS } from '@/configuration'\nimport type { AnyObject, ErrorObject, Filesystem, FilesystemEntry, ThrowOnErrorOption } from '@/types/index'\nimport { getEntrypoint } from './get-entrypoint'\nimport { getSegmentsFromPath } from './get-segments-from-path'\nimport { isObject } from './is-object'\nimport { makeFilesystem } from './make-filesystem'\n\n// TODO: Add support for all pointer words\n// export const pointerWords = new Set([\n// '$ref',\n// '$id',\n// '$anchor',\n// '$dynamicRef',\n// '$dynamicAnchor',\n// '$schema',\n// ])\n\nexport type ResolveReferencesResult = {\n valid: boolean\n errors: ErrorObject[]\n schema: OpenAPI.Document\n}\n\nexport type ResolveReferencesOptions = ThrowOnErrorOption & {\n /**\n * Fired when dereferenced a schema.\n *\n * Note that for object schemas, its properties may not be dereferenced when the hook is called.\n */\n onDereference?: (data: { schema: AnyObject; ref: string }) => void\n}\n\n/**\n * Takes a specification and resolves all references.\n */\nexport function resolveReferences(\n // Just a specification, or a set of files.\n input: AnyObject | Filesystem,\n // Additional options to control the behaviour\n options?: ResolveReferencesOptions,\n // Fallback to the entrypoint\n file?: FilesystemEntry,\n // Errors that occurred during the process\n errors: ErrorObject[] = [],\n): ResolveReferencesResult {\n // Detach from input\n const clonedInput = structuredClone(input)\n\n // Make it a filesystem, even if it
|
|
4
|
+
"sourcesContent": ["import type { OpenAPI } from '@scalar/openapi-types'\n\nimport { ERRORS } from '@/configuration'\nimport type { AnyObject, ErrorObject, Filesystem, FilesystemEntry, ThrowOnErrorOption } from '@/types/index'\nimport { getEntrypoint } from './get-entrypoint'\nimport { getSegmentsFromPath } from './get-segments-from-path'\nimport { isObject } from './is-object'\nimport { makeFilesystem } from './make-filesystem'\n\n// TODO: Add support for all pointer words\n// export const pointerWords = new Set([\n// '$ref',\n// '$id',\n// '$anchor',\n// '$dynamicRef',\n// '$dynamicAnchor',\n// '$schema',\n// ])\n\nexport type ResolveReferencesResult = {\n valid: boolean\n errors: ErrorObject[]\n schema: OpenAPI.Document\n}\n\nexport type ResolveReferencesOptions = ThrowOnErrorOption & {\n /**\n * Fired when dereferenced a schema.\n *\n * Note that for object schemas, its properties may not be dereferenced when the hook is called.\n */\n onDereference?: (data: { schema: AnyObject; ref: string }) => void\n}\n\n/**\n * Takes a specification and resolves all references.\n */\nexport function resolveReferences(\n // Just a specification, or a set of files.\n input: AnyObject | Filesystem,\n // Additional options to control the behaviour\n options?: ResolveReferencesOptions,\n // Fallback to the entrypoint\n file?: FilesystemEntry,\n // Errors that occurred during the process\n errors: ErrorObject[] = [],\n): ResolveReferencesResult {\n // Detach from input\n const clonedInput = structuredClone(input)\n\n // Make it a filesystem, even if it's just one file\n const filesystem = makeFilesystem(clonedInput)\n\n // Get the main file\n const entrypoint = getEntrypoint(filesystem)\n\n const finalInput = file?.specification ?? entrypoint.specification\n\n // Does it look like an OpenAPI document?\n if (!isObject(finalInput)) {\n if (options?.throwOnError) {\n throw new Error(ERRORS.NO_CONTENT)\n }\n\n return {\n valid: false,\n errors,\n schema: finalInput as OpenAPI.Document,\n }\n }\n\n // Recursively resolve all references\n dereference(finalInput, filesystem, file ?? entrypoint, new WeakSet(), errors, options)\n\n // Remove duplicats (according to message) from errors\n errors = errors.filter(\n (error, index, self) => index === self.findIndex((t) => t.message === error.message && t.code === error.code),\n )\n\n // Return the resolved specification\n return {\n valid: errors.length === 0,\n errors,\n schema: finalInput as OpenAPI.Document,\n }\n}\n\n/**\n * Resolves the circular reference to an object and deletes the $ref properties (in-place).\n */\nfunction dereference(\n schema: AnyObject,\n filesystem: Filesystem,\n entrypoint: FilesystemEntry,\n // references to resolved object\n resolvedSchemas: WeakSet<object>,\n // error output\n errors: ErrorObject[],\n\n options?: ResolveReferencesOptions,\n): void {\n if (schema === null || resolvedSchemas.has(schema)) {\n return\n }\n resolvedSchemas.add(schema)\n\n function resolveExternal(externalFile: FilesystemEntry) {\n dereference(externalFile.specification, filesystem, externalFile, resolvedSchemas, errors, options)\n\n return externalFile\n }\n\n while (schema.$ref !== undefined) {\n // Find the referenced content\n const resolved = resolveUri(schema.$ref, options, entrypoint, filesystem, resolveExternal, errors)\n\n // invalid\n if (typeof resolved !== 'object' || resolved === null) {\n break\n }\n const dereferencedRef = schema.$ref\n\n // Get rid of the reference\n delete schema.$ref\n\n for (const key of Object.keys(resolved)) {\n if (schema[key] === undefined) {\n schema[key] = resolved[key]\n }\n }\n\n if (dereferencedRef) {\n options?.onDereference?.({ schema, ref: dereferencedRef })\n }\n }\n\n // Iterate over the whole object\n for (const value of Object.values(schema)) {\n if (typeof value === 'object' && value !== null) {\n dereference(value, filesystem, entrypoint, resolvedSchemas, errors, options)\n }\n }\n}\n\n/**\n * Resolves a URI to a part of the specification\n *\n * The output is not necessarily dereferenced\n */\nfunction resolveUri(\n // 'foobar.json#/foo/bar'\n uri: string,\n options: ResolveReferencesOptions,\n // { filename: './foobar.json '}\n file: FilesystemEntry,\n // [ { filename: './foobar.json '} ]\n filesystem: Filesystem,\n\n // a function to resolve references in external file\n resolve: (file: FilesystemEntry) => FilesystemEntry,\n\n errors: ErrorObject[],\n): AnyObject | undefined {\n // Ignore invalid URIs\n if (typeof uri !== 'string') {\n if (options?.throwOnError) {\n throw new Error(ERRORS.INVALID_REFERENCE.replace('%s', uri))\n }\n\n errors.push({\n code: 'INVALID_REFERENCE',\n message: ERRORS.INVALID_REFERENCE.replace('%s', uri),\n })\n\n return undefined\n }\n\n // Understand the URI\n const [prefix, path] = uri.split('#', 2)\n\n /** Check whether the file is pointing to itself */\n const isDifferentFile = prefix !== file.filename\n\n // External references\n if (prefix && isDifferentFile) {\n const externalReference = filesystem.find((entry) => {\n return entry.filename === prefix\n })\n\n if (!externalReference) {\n if (options?.throwOnError) {\n throw new Error(ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace('%s', prefix))\n }\n\n errors.push({\n code: 'EXTERNAL_REFERENCE_NOT_FOUND',\n message: ERRORS.EXTERNAL_REFERENCE_NOT_FOUND.replace('%s', prefix),\n })\n\n return undefined\n }\n // $ref: 'other-file.yaml'\n if (path === undefined) {\n return externalReference.specification\n }\n\n // $ref: 'other-file.yaml#/foo/bar'\n // resolve refs first before accessing properties directly\n return resolveUri(`#${path}`, options, resolve(externalReference), filesystem, resolve, errors)\n }\n\n // Pointers\n const segments = getSegmentsFromPath(path)\n\n // Try to find the URI\n try {\n return segments.reduce((acc, key) => {\n return acc[key]\n }, file.specification)\n } catch (_error) {\n if (options?.throwOnError) {\n throw new Error(ERRORS.INVALID_REFERENCE.replace('%s', uri))\n }\n\n errors.push({\n code: 'INVALID_REFERENCE',\n message: ERRORS.INVALID_REFERENCE.replace('%s', uri),\n })\n }\n\n return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EA,QAAI,SAAS,QAAW;AACtB,aAAO,kBAAkB;AAAA,IAC3B;AAIA,WAAO,WAAW,IAAI,IAAI,IAAI,SAAS,QAAQ,iBAAiB,GAAG,YAAY,SAAS,MAAM;AAAA,EAChG;AAGA,QAAM,WAAW,oBAAoB,IAAI;AAGzC,MAAI;AACF,WAAO,SAAS,OAAO,CAAC,KAAK,QAAQ;AACnC,aAAO,IAAI,GAAG;AAAA,IAChB,GAAG,KAAK,aAAa;AAAA,EACvB,SAAS,QAAQ;AACf,QAAI,SAAS,cAAc;AACzB,YAAM,IAAI,MAAM,OAAO,kBAAkB,QAAQ,MAAM,GAAG,CAAC;AAAA,IAC7D;AAEA,WAAO,KAAK;AAAA,MACV,MAAM;AAAA,MACN,SAAS,OAAO,kBAAkB,QAAQ,MAAM,GAAG;AAAA,IACrD,CAAC;AAAA,EACH;AAEA,SAAO;AACT;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -5,7 +5,7 @@ export { DEFAULT_TITLE, DEFAULT_VERSION } from './utils/addInfoObject.js';
|
|
|
5
5
|
/**
|
|
6
6
|
* Make an OpenAPI document a valid and clean OpenAPI document
|
|
7
7
|
*
|
|
8
|
-
* @deprecated We
|
|
8
|
+
* @deprecated We're about to drop this from the package.
|
|
9
9
|
*/
|
|
10
10
|
export declare function sanitize(definition: AnyObject): OpenAPI.Document;
|
|
11
11
|
//# sourceMappingURL=sanitize.d.ts.map
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../../src/utils/transform/sanitize.ts"],
|
|
4
|
-
"sourcesContent": ["import type { OpenAPI } from '@scalar/openapi-types'\n\nimport type { AnyObject } from '@/types/index'\nimport { addInfoObject } from './utils/addInfoObject'\nimport { addLatestOpenApiVersion } from './utils/addLatestOpenApiVersion'\nimport { addMissingTags } from './utils/addMissingTags'\nimport { normalizeSecuritySchemes } from './utils/normalizeSecuritySchemes'\nimport { rejectSwaggerDocuments } from './utils/rejectSwaggerDocuments'\n\nexport { DEFAULT_OPENAPI_VERSION } from './utils/addLatestOpenApiVersion'\nexport { DEFAULT_TITLE, DEFAULT_VERSION } from './utils/addInfoObject'\n\n/**\n * Make an OpenAPI document a valid and clean OpenAPI document\n *\n * @deprecated We
|
|
4
|
+
"sourcesContent": ["import type { OpenAPI } from '@scalar/openapi-types'\n\nimport type { AnyObject } from '@/types/index'\nimport { addInfoObject } from './utils/addInfoObject'\nimport { addLatestOpenApiVersion } from './utils/addLatestOpenApiVersion'\nimport { addMissingTags } from './utils/addMissingTags'\nimport { normalizeSecuritySchemes } from './utils/normalizeSecuritySchemes'\nimport { rejectSwaggerDocuments } from './utils/rejectSwaggerDocuments'\n\nexport { DEFAULT_OPENAPI_VERSION } from './utils/addLatestOpenApiVersion'\nexport { DEFAULT_TITLE, DEFAULT_VERSION } from './utils/addInfoObject'\n\n/**\n * Make an OpenAPI document a valid and clean OpenAPI document\n *\n * @deprecated We're about to drop this from the package.\n */\nexport function sanitize(definition: AnyObject): OpenAPI.Document {\n const transformers = [\n rejectSwaggerDocuments,\n addLatestOpenApiVersion,\n addInfoObject,\n addMissingTags,\n normalizeSecuritySchemes,\n ]\n\n return transformers.reduce((doc, transformer) => transformer(doc), definition)\n}\n"],
|
|
5
5
|
"mappings": "AAGA,SAAS,qBAAqB;AAC9B,SAAS,+BAA+B;AACxC,SAAS,sBAAsB;AAC/B,SAAS,gCAAgC;AACzC,SAAS,8BAA8B;AAEvC,SAAS,+BAA+B;AACxC,SAAS,eAAe,uBAAuB;AAOxC,SAAS,SAAS,YAAyC;AAChE,QAAM,eAAe;AAAA,IACnB;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,IACA;AAAA,EACF;AAEA,SAAO,aAAa,OAAO,CAAC,KAAK,gBAAgB,YAAY,GAAG,GAAG,UAAU;AAC/E;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
|
@@ -31,7 +31,7 @@ function upgradeFromThreeToThreeOne(originalContent) {
|
|
|
31
31
|
return content;
|
|
32
32
|
}
|
|
33
33
|
const applyChangesToDocument = (schema, path) => {
|
|
34
|
-
if (schema.type !==
|
|
34
|
+
if (schema.type !== void 0 && schema.nullable === true) {
|
|
35
35
|
schema.type = [schema.type, "null"];
|
|
36
36
|
delete schema.nullable;
|
|
37
37
|
}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/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 './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[]): boolean {\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 !==
|
|
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,MAAyB;AAEpD,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,SAAmB;AAExE,MAAI,OAAO,SAAS,
|
|
4
|
+
"sourcesContent": ["import type { OpenAPIV3_1 } from '@scalar/openapi-types'\nimport type { UnknownObject } from '@scalar/types/utils'\n\nimport { traverse } from './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[]): boolean {\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 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) {\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 as any).contentMediaType = 'application/octet-stream'\n delete (value as any).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 if (schema.type === 'string') {\n if (schema.format === 'binary') {\n return {\n type: 'string',\n contentMediaType: 'application/octet-stream',\n }\n }\n\n if (schema.format === 'base64') {\n return {\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 type: 'string',\n contentEncoding: 'base64',\n contentMediaType,\n }\n }\n }\n\n // 6. 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,MAAyB;AAEpD,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,SAAmB;AAExE,MAAI,OAAO,SAAS,UAA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,UAAU;AAC9B,aAAO;AAAA,QACL,MAAM;AAAA,QACN,kBAAkB;AAAA,MACpB;AAAA,IACF;AAEA,QAAI,OAAO,WAAW,UAAU;AAC9B,aAAO;AAAA,QACL,MAAM;AAAA,QACN,iBAAiB;AAAA,MACnB;AAAA,IACF;AAEA,QAAI,OAAO,WAAW,QAAQ;AAC5B,YAAM,aAAa,KAAK,MAAM,GAAG,EAAE;AACnC,YAAM,mBAAmB,WAAW,KAAK,CAAC,GAAG,UAAU,KAAK,QAAQ,CAAC,MAAM,SAAS;AACpF,aAAO;AAAA,QACL,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-two-to-three.d.ts","sourceRoot":"","sources":["../../src/utils/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;
|
|
1
|
+
{"version":3,"file":"upgrade-from-two-to-three.d.ts","sourceRoot":"","sources":["../../src/utils/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,0CAwQzE"}
|
|
@@ -1,4 +1,18 @@
|
|
|
1
1
|
import { traverse } from "./traverse.js";
|
|
2
|
+
const upgradeFlow = (flow) => {
|
|
3
|
+
switch (flow) {
|
|
4
|
+
case "application":
|
|
5
|
+
return "clientCredentials";
|
|
6
|
+
case "accessCode":
|
|
7
|
+
return "authorizationCode";
|
|
8
|
+
case "implicit":
|
|
9
|
+
return "implicit";
|
|
10
|
+
case "password":
|
|
11
|
+
return "password";
|
|
12
|
+
default:
|
|
13
|
+
return flow;
|
|
14
|
+
}
|
|
15
|
+
};
|
|
2
16
|
function upgradeFromTwoToThree(originalSpecification) {
|
|
3
17
|
let specification = originalSpecification;
|
|
4
18
|
if (specification !== null && typeof specification === "object" && typeof specification.swagger === "string" && specification.swagger?.startsWith("2.0")) {
|
|
@@ -161,7 +175,7 @@ function upgradeFromTwoToThree(originalSpecification) {
|
|
|
161
175
|
[key]: {
|
|
162
176
|
type: "oauth2",
|
|
163
177
|
flows: {
|
|
164
|
-
[flow]: Object.assign(
|
|
178
|
+
[upgradeFlow(flow)]: Object.assign(
|
|
165
179
|
{},
|
|
166
180
|
authorizationUrl && { authorizationUrl },
|
|
167
181
|
tokenUrl && { tokenUrl },
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"version": 3,
|
|
3
3
|
"sources": ["../../src/utils/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 './traverse'\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 specification = originalSpecification\n\n // Version\n if (\n specification !== null &&\n typeof specification === 'object' &&\n typeof specification.swagger === 'string' &&\n specification.swagger?.startsWith('2.0')\n ) {\n specification.openapi = '3.0.4'\n delete specification.swagger\n } else {\n // Skip if it\u2019s something else than 3.0.x\n return specification\n }\n\n // Servers\n if (specification.host) {\n const schemes =\n Array.isArray(specification.schemes) && specification.schemes?.length ? specification.schemes : ['http']\n\n specification.servers = schemes.map((scheme: string[]) => ({\n url: `${scheme}://${specification.host}${specification.basePath ?? ''}`,\n }))\n\n delete specification.basePath\n delete specification.schemes\n delete specification.host\n } else if (specification.basePath) {\n specification.servers = [{ url: specification.basePath }]\n delete specification.basePath\n }\n\n // Schemas\n if (specification.definitions) {\n specification.components = Object.assign({}, specification.components, {\n schemas: specification.definitions,\n })\n\n delete specification.definitions\n\n // Rewrite $refs to definitions\n specification = traverse(specification, (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 specification = traverse(specification, (schema) => {\n if (schema.type === 'file') {\n schema.type = 'string'\n schema.format = 'binary'\n }\n\n return schema\n })\n\n // Paths\n if (typeof specification.paths === 'object') {\n for (const path in specification.paths) {\n if (Object.hasOwn(specification.paths, path)) {\n const pathItem = specification.paths[path]\n\n for (const method in pathItem) {\n if (Object.hasOwn(pathItem, method)) {\n const operationItem = pathItem[method]\n\n // Request bodies\n if (operationItem.parameters) {\n const bodyParameter = structuredClone(\n operationItem.parameters.find((parameter: OpenAPIV3.ParameterObject) => parameter.in === 'body') ?? {},\n )\n\n if (bodyParameter && Object.keys(bodyParameter).length) {\n delete bodyParameter.name\n delete bodyParameter.in\n\n const consumes = specification.consumes ?? operationItem.consumes ?? ['application/json']\n\n if (typeof operationItem.requestBody !== 'object') {\n operationItem.requestBody = {}\n }\n\n if (typeof operationItem.requestBody.content !== 'object') {\n operationItem.requestBody.content = {}\n }\n\n const { schema, ...requestBody } = bodyParameter\n\n operationItem.requestBody = {\n ...operationItem.requestBody,\n ...requestBody,\n }\n\n for (const type of consumes) {\n operationItem.requestBody.content[type] = {\n schema: schema,\n }\n }\n }\n\n // Delete body parameter\n operationItem.parameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in !== 'body',\n )\n\n delete operationItem.consumes\n\n // formData parameters\n const formDataParameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in === 'formData',\n )\n\n if (formDataParameters.length > 0) {\n if (typeof operationItem.requestBody !== 'object') {\n operationItem.requestBody = {}\n }\n\n if (typeof operationItem.requestBody.content !== 'object') {\n operationItem.requestBody.content = {}\n }\n\n operationItem.requestBody.content['application/x-www-form-urlencoded'] = {\n schema: {\n type: 'object',\n properties: {},\n required: [], // Initialize required array\n },\n }\n\n for (const param of formDataParameters) {\n operationItem.requestBody.content['application/x-www-form-urlencoded'].schema.properties[param.name] =\n {\n type: param.type,\n description: param.description,\n }\n\n // Add to required array if param is required\n if (param.required) {\n operationItem.requestBody.content['application/x-www-form-urlencoded'].schema.required.push(\n param.name,\n )\n }\n }\n\n // Remove formData parameters from the parameters array\n operationItem.parameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in !== 'formData',\n )\n }\n\n operationItem.parameters = operationItem.parameters.map((parameter) =>\n transformParameterObject(parameter),\n )\n }\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) {\n responseItem.headers = Object.entries(responseItem.headers).reduce((acc, [name, header]) => {\n return {\n [name]: transformParameterObject(header),\n ...acc,\n }\n }, {})\n }\n if (responseItem.schema) {\n const produces = specification.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 (specification.securityDefinitions) {\n if (typeof specification.components !== 'object') {\n specification.components = {}\n }\n\n // Assert that components is of type OpenAPIV3.ComponentsObject\n specification.components = specification.components as OpenAPIV3.ComponentsObject\n\n Object.assign(specification.components, { securitySchemes: {} })\n\n for (const [key, securityScheme] of Object.entries(specification.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 // Assert that securitySchemes is of type OpenAPIV3.SecuritySchemeObject\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: {\n type: 'oauth2',\n flows: {\n [flow as string]: Object.assign(\n {},\n authorizationUrl && { authorizationUrl },\n tokenUrl && { tokenUrl },\n scopes && { scopes },\n ),\n },\n },\n })\n } else if ('type' in securityScheme && securityScheme.type === 'basic') {\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: {\n type: 'http',\n scheme: 'basic',\n },\n })\n } else {\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: securityScheme,\n })\n }\n }\n }\n\n delete specification.securityDefinitions\n }\n\n return specification 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 // 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 return serializationStyles[parameter.in][collectionFormat]\n}\n"],
|
|
5
|
-
"mappings": "AAGA,SAAS,gBAAgB;
|
|
4
|
+
"sourcesContent": ["import type { OpenAPIV2, OpenAPIV3 } from '@scalar/openapi-types'\nimport type { UnknownObject } from '@scalar/types/utils'\n\nimport { traverse } from './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 specification = originalSpecification\n\n // Version\n if (\n specification !== null &&\n typeof specification === 'object' &&\n typeof specification.swagger === 'string' &&\n specification.swagger?.startsWith('2.0')\n ) {\n specification.openapi = '3.0.4'\n delete specification.swagger\n } else {\n // Skip if it's something else than 3.0.x\n return specification\n }\n\n // Servers\n if (specification.host) {\n const schemes =\n Array.isArray(specification.schemes) && specification.schemes?.length ? specification.schemes : ['http']\n\n specification.servers = schemes.map((scheme: string[]) => ({\n url: `${scheme}://${specification.host}${specification.basePath ?? ''}`,\n }))\n\n delete specification.basePath\n delete specification.schemes\n delete specification.host\n } else if (specification.basePath) {\n specification.servers = [{ url: specification.basePath }]\n delete specification.basePath\n }\n\n // Schemas\n if (specification.definitions) {\n specification.components = Object.assign({}, specification.components, {\n schemas: specification.definitions,\n })\n\n delete specification.definitions\n\n // Rewrite $refs to definitions\n specification = traverse(specification, (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 specification = traverse(specification, (schema) => {\n if (schema.type === 'file') {\n schema.type = 'string'\n schema.format = 'binary'\n }\n\n return schema\n })\n\n // Paths\n if (typeof specification.paths === 'object') {\n for (const path in specification.paths) {\n if (Object.hasOwn(specification.paths, path)) {\n const pathItem = specification.paths[path]\n\n for (const method in pathItem) {\n if (Object.hasOwn(pathItem, method)) {\n const operationItem = pathItem[method]\n\n // Request bodies\n if (operationItem.parameters) {\n const bodyParameter = structuredClone(\n operationItem.parameters.find((parameter: OpenAPIV3.ParameterObject) => parameter.in === 'body') ?? {},\n )\n\n if (bodyParameter && Object.keys(bodyParameter).length) {\n delete bodyParameter.name\n delete bodyParameter.in\n\n const consumes = specification.consumes ?? operationItem.consumes ?? ['application/json']\n\n if (typeof operationItem.requestBody !== 'object') {\n operationItem.requestBody = {}\n }\n\n if (typeof operationItem.requestBody.content !== 'object') {\n operationItem.requestBody.content = {}\n }\n\n const { schema, ...requestBody } = bodyParameter\n\n operationItem.requestBody = {\n ...operationItem.requestBody,\n ...requestBody,\n }\n\n for (const type of consumes) {\n operationItem.requestBody.content[type] = {\n schema: schema,\n }\n }\n }\n\n // Delete body parameter\n operationItem.parameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in !== 'body',\n )\n\n delete operationItem.consumes\n\n // formData parameters\n const formDataParameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in === 'formData',\n )\n\n if (formDataParameters.length > 0) {\n if (typeof operationItem.requestBody !== 'object') {\n operationItem.requestBody = {}\n }\n\n if (typeof operationItem.requestBody.content !== 'object') {\n operationItem.requestBody.content = {}\n }\n\n operationItem.requestBody.content['application/x-www-form-urlencoded'] = {\n schema: {\n type: 'object',\n properties: {},\n required: [], // Initialize required array\n },\n }\n\n for (const param of formDataParameters) {\n operationItem.requestBody.content['application/x-www-form-urlencoded'].schema.properties[param.name] =\n {\n type: param.type,\n description: param.description,\n }\n\n // Add to required array if param is required\n if (param.required) {\n operationItem.requestBody.content['application/x-www-form-urlencoded'].schema.required.push(\n param.name,\n )\n }\n }\n\n // Remove formData parameters from the parameters array\n operationItem.parameters = operationItem.parameters.filter(\n (parameter: OpenAPIV2.ParameterObject) => parameter.in !== 'formData',\n )\n }\n\n operationItem.parameters = operationItem.parameters.map((parameter) =>\n transformParameterObject(parameter),\n )\n }\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) {\n responseItem.headers = Object.entries(responseItem.headers).reduce((acc, [name, header]) => {\n return {\n [name]: transformParameterObject(header),\n ...acc,\n }\n }, {})\n }\n if (responseItem.schema) {\n const produces = specification.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 (specification.securityDefinitions) {\n if (typeof specification.components !== 'object') {\n specification.components = {}\n }\n\n // Assert that components is of type OpenAPIV3.ComponentsObject\n specification.components = specification.components as OpenAPIV3.ComponentsObject\n\n Object.assign(specification.components, { securitySchemes: {} })\n\n for (const [key, securityScheme] of Object.entries(specification.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 // Assert that securitySchemes is of type OpenAPIV3.SecuritySchemeObject\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: {\n type: 'oauth2',\n flows: {\n [upgradeFlow(flow)]: Object.assign(\n {},\n authorizationUrl && { authorizationUrl },\n tokenUrl && { tokenUrl },\n scopes && { scopes },\n ),\n },\n },\n })\n } else if ('type' in securityScheme && securityScheme.type === 'basic') {\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: {\n type: 'http',\n scheme: 'basic',\n },\n })\n } else {\n Object.assign((specification.components as OpenAPIV3.ComponentsObject).securitySchemes, {\n [key]: securityScheme,\n })\n }\n }\n }\n\n delete specification.securityDefinitions\n }\n\n return specification 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 // 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 return serializationStyles[parameter.in][collectionF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IACL,OAAO;AAAA,IACP,SAAS;AAAA,EACX;AAAA,EACA,KAAK;AAAA,IACH,OAAO;AAAA,IACP,SAAS;AAAA,EACX;AAAA,EACA,KAAK,CAAC;AACR;AAEA,MAAM,6BAAoF;AAAA,EACxF,KAAK,CAAC;AAAA,EACN,OAAO,CAAC;AAAA,EACR,OAAO,CAAC;AAAA,EACR,KAAK;AAAA,IACH,OAAO;AAAA,IACP,SAAS;AAAA,EACX;AAAA,EACA,KAAK,CAAC;AACR;AAEA,MAAM,sBAAsB;AAAA,EAC1B,QAAQ;AAAA,EACR,OAAO;AAAA,EACP,MAAM;AACR;AAEA,SAAS,+BAA+B,WAAmE;AACzG,MACE,UAAU,SAAS,WACnB,EAAE,UAAU,OAAO,WAAW,UAAU,OAAO,UAAU,UAAU,OAAO,WAC1E;AACA,WAAO,CAAC;AAAA,EACV;AAEA,QAAM,mBAAmB,UAAU,oBAAoB;AAEvD,SAAO,oBAAoB,UAAU,EAAE,EAAE,gBAAgB;AAC3D;",
|
|
6
6
|
"names": []
|
|
7
7
|
}
|
package/package.json
CHANGED
|
@@ -17,7 +17,7 @@
|
|
|
17
17
|
"parser",
|
|
18
18
|
"typescript"
|
|
19
19
|
],
|
|
20
|
-
"version": "0.18.
|
|
20
|
+
"version": "0.18.2",
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=20"
|
|
23
23
|
},
|
|
@@ -63,19 +63,19 @@
|
|
|
63
63
|
"ajv-formats": "^3.0.1",
|
|
64
64
|
"jsonpointer": "^5.0.1",
|
|
65
65
|
"leven": "^4.0.0",
|
|
66
|
-
"yaml": "
|
|
66
|
+
"yaml": "2.8.0"
|
|
67
67
|
},
|
|
68
68
|
"devDependencies": {
|
|
69
69
|
"@apidevtools/swagger-parser": "^10.1.0",
|
|
70
|
-
"@types/node": "^
|
|
70
|
+
"@types/node": "^22.9.0",
|
|
71
71
|
"fastify": "^5.3.3",
|
|
72
72
|
"json-to-ast": "^2.1.0",
|
|
73
73
|
"just-diff": "^6.0.2",
|
|
74
74
|
"tinybench": "^2.8.0",
|
|
75
75
|
"vite": "5.4.19",
|
|
76
|
-
"@scalar/build-tooling": "0.2.
|
|
77
|
-
"@scalar/openapi-types": "0.3.
|
|
78
|
-
"@scalar/types": "0.2.
|
|
76
|
+
"@scalar/build-tooling": "0.2.4",
|
|
77
|
+
"@scalar/openapi-types": "0.3.6",
|
|
78
|
+
"@scalar/types": "0.2.10"
|
|
79
79
|
},
|
|
80
80
|
"scripts": {
|
|
81
81
|
"build": "scalar-build-esbuild",
|