@scalar/fastify-api-reference 1.25.128 → 1.26.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/CHANGELOG.md +28 -0
- package/README.md +5 -5
- package/dist/fastifyApiReference.d.ts.map +1 -1
- package/dist/fastifyApiReference.js +280 -0
- package/dist/fastifyApiReference.test.d.ts +2 -0
- package/dist/fastifyApiReference.test.d.ts.map +1 -0
- package/dist/index.js +1 -19889
- package/dist/js/standalone.js +7981 -7915
- package/dist/packages/core/dist/libs/html-rendering/index.js +69 -0
- package/dist/proxy.test.d.ts +2 -0
- package/dist/proxy.test.d.ts.map +1 -0
- package/dist/types.d.ts +1 -1
- package/dist/types.d.ts.map +1 -1
- package/dist/utils/getJavaScriptFile.js +23 -0
- package/package.json +21 -18
- package/dist/index.cjs +0 -7
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import { htmlRenderingConfigurationSchema, apiReferenceConfigurationSchema } from '@scalar/types/api-reference';
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* The HTML document to render the Scalar API reference.
|
|
5
|
+
*
|
|
6
|
+
* We must check the passed in configuration and not the parsedConfig for the theme as the parsedConfig will have it
|
|
7
|
+
* defaulted to 'default'
|
|
8
|
+
*/
|
|
9
|
+
const getHtmlDocument = (configuration, customTheme = '') => {
|
|
10
|
+
const { cdn, pageTitle, ...rest } = configuration;
|
|
11
|
+
const parsedHtmlOptions = htmlRenderingConfigurationSchema.parse({ cdn, pageTitle, customTheme });
|
|
12
|
+
const parsedConfig = apiReferenceConfigurationSchema.parse(rest);
|
|
13
|
+
return `
|
|
14
|
+
<!DOCTYPE html>
|
|
15
|
+
<html>
|
|
16
|
+
<head>
|
|
17
|
+
<title>${parsedHtmlOptions.pageTitle}</title>
|
|
18
|
+
<meta charset="utf-8" />
|
|
19
|
+
<meta
|
|
20
|
+
name="viewport"
|
|
21
|
+
content="width=device-width, initial-scale=1" />
|
|
22
|
+
<style>
|
|
23
|
+
${configuration.theme ? '' : customTheme}
|
|
24
|
+
</style>
|
|
25
|
+
</head>
|
|
26
|
+
<body>
|
|
27
|
+
${getScriptTags(parsedConfig, parsedHtmlOptions.cdn)}
|
|
28
|
+
</body>
|
|
29
|
+
</html>
|
|
30
|
+
`;
|
|
31
|
+
};
|
|
32
|
+
/**
|
|
33
|
+
* The script tags to load the @scalar/api-reference package from the CDN.
|
|
34
|
+
*/
|
|
35
|
+
function getScriptTags(configuration, cdn) {
|
|
36
|
+
return `
|
|
37
|
+
<script
|
|
38
|
+
id="api-reference"
|
|
39
|
+
type="application/json"
|
|
40
|
+
data-configuration="${getConfiguration(configuration)}">${getScriptTagContent(configuration)}</script>
|
|
41
|
+
<script src="${cdn}"></script>
|
|
42
|
+
`;
|
|
43
|
+
}
|
|
44
|
+
/**
|
|
45
|
+
* The configuration to pass to the @scalar/api-reference package.
|
|
46
|
+
*/
|
|
47
|
+
const getConfiguration = (givenConfiguration) => {
|
|
48
|
+
// Clone before mutating
|
|
49
|
+
const configuration = {
|
|
50
|
+
...givenConfiguration,
|
|
51
|
+
};
|
|
52
|
+
if (!configuration.spec?.url) {
|
|
53
|
+
delete configuration.spec;
|
|
54
|
+
}
|
|
55
|
+
else if (configuration.spec?.content) {
|
|
56
|
+
delete configuration.spec?.content;
|
|
57
|
+
}
|
|
58
|
+
return JSON.stringify(configuration).split('"').join('"');
|
|
59
|
+
};
|
|
60
|
+
/**
|
|
61
|
+
* The content to pass to the @scalar/api-reference package as the <script> tag content.
|
|
62
|
+
*/
|
|
63
|
+
const getScriptTagContent = (configuration) => configuration.spec?.content
|
|
64
|
+
? typeof configuration.spec?.content === 'function'
|
|
65
|
+
? JSON.stringify(configuration.spec?.content())
|
|
66
|
+
: JSON.stringify(configuration.spec?.content)
|
|
67
|
+
: '';
|
|
68
|
+
|
|
69
|
+
export { getConfiguration, getHtmlDocument, getScriptTagContent, getScriptTags };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"proxy.test.d.ts","sourceRoot":"","sources":["../src/proxy.test.ts"],"names":[],"mappings":""}
|
package/dist/types.d.ts
CHANGED
|
@@ -1,5 +1,5 @@
|
|
|
1
|
-
import type { HtmlRenderingConfiguration } from '@scalar/api-reference/lib/html-rendering';
|
|
2
1
|
import type { onRequestHookHandler, preHandlerHookHandler } from 'fastify';
|
|
2
|
+
import type { HtmlRenderingConfiguration } from '@scalar/core/libs/html-rendering';
|
|
3
3
|
/**
|
|
4
4
|
* The configuration for the Scalar API Reference for Fastify
|
|
5
5
|
*/
|
package/dist/types.d.ts.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,
|
|
1
|
+
{"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAE1E,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,kCAAkC,CAAA;AAElF;;GAEG;AACH,MAAM,MAAM,yBAAyB,GAAG,0BAA0B,CAAA;AAElE,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,WAAW,CAAC,EAAE,IAAI,MAAM,EAAE,CAAA;IAC1B;;;;;;;;;;;;;OAaG;IACH,wBAAwB,CAAC,EAAE;QACzB;;;;;;WAMG;QACH,IAAI,CAAC,EAAE,IAAI,MAAM,EAAE,CAAA;QACnB;;;;;;WAMG;QACH,IAAI,CAAC,EAAE,IAAI,MAAM,EAAE,CAAA;KACpB,CAAA;IACD;;;;OAIG;IACH,aAAa,CAAC,EAAE,OAAO,CAAC,yBAAyB,CAAC,CAAA;IAClD;;OAEG;IACH,KAAK,CAAC,EAAE,+BAA+B,CAAA;IACvC;;;OAGG;IACH,QAAQ,CAAC,EAAE,OAAO,GAAG,OAAO,GAAG,MAAM,GAAG,MAAM,GAAG,OAAO,GAAG,OAAO,GAAG,QAAQ,CAAA;CAC9E,CAAA;AAED,MAAM,MAAM,+BAA+B,GAAG,OAAO,CAAC;IACpD,SAAS,CAAC,EAAE,oBAAoB,CAAA;IAChC,UAAU,CAAC,EAAE,qBAAqB,CAAA;CACnC,CAAC,CAAA"}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import fs from 'node:fs';
|
|
2
|
+
import path from 'node:path';
|
|
3
|
+
import { fileURLToPath } from 'node:url';
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* Read the JavaScript file.
|
|
7
|
+
*/
|
|
8
|
+
function getJavaScriptFile() {
|
|
9
|
+
// Get the directory name
|
|
10
|
+
const dirname = path.dirname(fileURLToPath(import.meta.url));
|
|
11
|
+
// Find the JavaScript file
|
|
12
|
+
const filePath = [
|
|
13
|
+
path.resolve(`${dirname}/js/standalone.js`),
|
|
14
|
+
path.resolve(`${dirname}/../../dist/js/standalone.js`),
|
|
15
|
+
].find((file) => fs.existsSync(file));
|
|
16
|
+
// Throw an error if the file is not found
|
|
17
|
+
if (filePath === undefined) {
|
|
18
|
+
throw new Error(`JavaScript file not found: ${path.resolve(`${dirname}/js/standalone.js`)}`);
|
|
19
|
+
}
|
|
20
|
+
return fs.readFileSync(filePath, 'utf8');
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export { getJavaScriptFile };
|
package/package.json
CHANGED
|
@@ -17,27 +17,32 @@
|
|
|
17
17
|
"openapi",
|
|
18
18
|
"swagger"
|
|
19
19
|
],
|
|
20
|
-
"version": "1.
|
|
20
|
+
"version": "1.26.0",
|
|
21
21
|
"engines": {
|
|
22
22
|
"node": ">=18"
|
|
23
23
|
},
|
|
24
24
|
"type": "module",
|
|
25
|
-
"main": "
|
|
26
|
-
"types": "
|
|
25
|
+
"main": "dist/index.js",
|
|
26
|
+
"types": "dist/index.d.ts",
|
|
27
27
|
"exports": {
|
|
28
|
-
"
|
|
29
|
-
|
|
30
|
-
|
|
28
|
+
".": {
|
|
29
|
+
"import": "./dist/index.js",
|
|
30
|
+
"types": "./dist/index.d.ts",
|
|
31
|
+
"default": "./dist/index.js"
|
|
32
|
+
}
|
|
31
33
|
},
|
|
32
34
|
"files": [
|
|
33
|
-
"dist",
|
|
35
|
+
"./dist",
|
|
34
36
|
"CHANGELOG.md"
|
|
35
37
|
],
|
|
36
|
-
"module": "
|
|
38
|
+
"module": "dist/index.js",
|
|
37
39
|
"dependencies": {
|
|
38
40
|
"fastify-plugin": "^4.5.1",
|
|
39
|
-
"
|
|
40
|
-
"@scalar/
|
|
41
|
+
"github-slugger": "^2.0.0",
|
|
42
|
+
"@scalar/core": "0.1.0",
|
|
43
|
+
"@scalar/openapi-types": "0.1.9",
|
|
44
|
+
"@scalar/openapi-parser": "0.10.9",
|
|
45
|
+
"@scalar/types": "0.0.39"
|
|
41
46
|
},
|
|
42
47
|
"devDependencies": {
|
|
43
48
|
"@fastify/basic-auth": "^5.1.1",
|
|
@@ -45,28 +50,26 @@
|
|
|
45
50
|
"@fastify/swagger": "^8.10.1",
|
|
46
51
|
"@vitest/coverage-v8": "^1.6.0",
|
|
47
52
|
"fastify": "^4.26.2",
|
|
48
|
-
"github-slugger": "^2.0.0",
|
|
49
|
-
"magic-string": "^0.30.8",
|
|
50
53
|
"rollup-plugin-node-externals": "^7.1.2",
|
|
51
54
|
"terser": "^5.30.0",
|
|
52
55
|
"vite": "^5.4.10",
|
|
53
56
|
"vite-plugin-static-copy": "^1.0.2",
|
|
54
57
|
"vitest": "^1.6.0",
|
|
55
|
-
"vue": "^3.5.12",
|
|
56
58
|
"yaml": "^2.4.5",
|
|
57
|
-
"@scalar/
|
|
58
|
-
"@scalar/
|
|
59
|
+
"@scalar/api-reference": "1.26.0",
|
|
60
|
+
"@scalar/build-tooling": "0.1.17"
|
|
59
61
|
},
|
|
60
62
|
"scripts": {
|
|
61
|
-
"build": "scalar-build-
|
|
63
|
+
"build": "scalar-build-rollup && pnpm copy:standalone",
|
|
62
64
|
"build:playground": "cd playground && pnpm build",
|
|
65
|
+
"copy:standalone": "mkdir -p ./dist/js && cp ../../packages/api-reference/dist/browser/standalone.js ./dist/js/standalone.js",
|
|
63
66
|
"dev": "cd playground && pnpm dev",
|
|
64
67
|
"docker:build": "docker build --build-arg BASE_IMAGE=scalar-base -t fastify-api-reference -f Dockerfile .",
|
|
65
68
|
"docker:run": "docker run -p 5053:5053 fastify-api-reference",
|
|
66
69
|
"format": "scalar-format",
|
|
67
70
|
"format:check": "scalar-format-check",
|
|
68
|
-
"lint:check": "
|
|
69
|
-
"lint:fix": "
|
|
71
|
+
"lint:check": "scalar-lint-check",
|
|
72
|
+
"lint:fix": "scalar-lint-fix",
|
|
70
73
|
"test": "vitest",
|
|
71
74
|
"types:build": "scalar-types-build",
|
|
72
75
|
"types:check": "scalar-types-check"
|