@scalar/fastify-api-reference 0.7.0 → 0.7.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 +16 -0
- package/README.md +4 -4
- package/dist/fastifyApiReference.d.ts +15 -5
- package/dist/fastifyApiReference.d.ts.map +1 -1
- package/dist/index.cjs +1 -1
- package/dist/index.js +141 -23
- package/package.json +3 -5
- package/dist/templates/fastify-api-reference.js +0 -43729
- package/dist/templates/index.ejs +0 -107
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,21 @@
|
|
|
1
1
|
# @scalar/fastify-api-reference
|
|
2
2
|
|
|
3
|
+
## 0.7.2
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- 185a85d: breaking change: use `configuration` instead of `apiReference` to pass the configuration
|
|
8
|
+
- 185a85d: refactor: use CDN version, remove pageTitle option (the API reference supports more attributes already)
|
|
9
|
+
- Updated dependencies [37b974c]
|
|
10
|
+
- Updated dependencies [b77d087]
|
|
11
|
+
- @scalar/api-reference@1.3.0
|
|
12
|
+
|
|
13
|
+
## 0.7.1
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- @scalar/api-reference@1.2.7
|
|
18
|
+
|
|
3
19
|
## 0.7.0
|
|
4
20
|
|
|
5
21
|
### Minor Changes
|
package/README.md
CHANGED
|
@@ -31,7 +31,7 @@ If you have a OpenAPI/Swagger file already, you can pass an URL to the plugin:
|
|
|
31
31
|
// Render an API reference for a given OpenAPI/Swagger spec URL
|
|
32
32
|
fastify.register(require('@scalar/fastify-api-reference'), {
|
|
33
33
|
routePrefix: '/reference',
|
|
34
|
-
|
|
34
|
+
configuration: {
|
|
35
35
|
title: 'Our API Reference',
|
|
36
36
|
spec: {
|
|
37
37
|
url: '/swagger.json',
|
|
@@ -45,7 +45,7 @@ With the [@fastify/swagger](https://github.com/fastify/fastify-swagger) you can
|
|
|
45
45
|
```ts
|
|
46
46
|
await fastify.register(require('@scalar/fastify-api-reference'), {
|
|
47
47
|
routePrefix: '/reference',
|
|
48
|
-
|
|
48
|
+
configuration: {
|
|
49
49
|
spec: {
|
|
50
50
|
content: () => fastify.swagger(),
|
|
51
51
|
},
|
|
@@ -66,7 +66,7 @@ Or, if you just have a static OpenAPI spec, you can directly pass it, too:
|
|
|
66
66
|
```ts
|
|
67
67
|
await fastify.register(require('@scalar/fastify-api-reference'), {
|
|
68
68
|
routePrefix: '/reference',
|
|
69
|
-
|
|
69
|
+
configuration: {
|
|
70
70
|
spec: {
|
|
71
71
|
content: { … }
|
|
72
72
|
},
|
|
@@ -83,7 +83,7 @@ By default, we’re using a custom Fastify theme and it’s beautiful. But you c
|
|
|
83
83
|
```ts
|
|
84
84
|
await fastify.register(require('@scalar/fastify-api-reference'), {
|
|
85
85
|
routePrefix: '/reference',
|
|
86
|
-
|
|
86
|
+
configuration: {
|
|
87
87
|
theme: 'purple',
|
|
88
88
|
},
|
|
89
89
|
})
|
|
@@ -1,16 +1,26 @@
|
|
|
1
1
|
import { type ReferenceConfiguration } from '@scalar/api-reference';
|
|
2
2
|
import type { FastifyPluginAsync } from 'fastify';
|
|
3
|
-
export type
|
|
3
|
+
export type FastifyApiReferenceOptions = {
|
|
4
4
|
/**
|
|
5
5
|
* Prefix for the registered route
|
|
6
6
|
*
|
|
7
7
|
* @default '/'
|
|
8
8
|
*/
|
|
9
9
|
routePrefix: string;
|
|
10
|
-
|
|
11
|
-
pageTitle?: string;
|
|
12
|
-
};
|
|
10
|
+
configuration?: ReferenceConfiguration;
|
|
13
11
|
};
|
|
14
|
-
|
|
12
|
+
/**
|
|
13
|
+
* The Fastify custom theme CSS
|
|
14
|
+
*/
|
|
15
|
+
export declare const defaultCss = "\n:root {\n --theme-font: 'Inter', var(--system-fonts);\n}\n\n.light-mode {\n color-scheme: light;\n --theme-color-1: #1c1e21;\n --theme-color-2: #757575;\n --theme-color-3: #8e8e8e;\n --theme-color-disabled: #b4b1b1;\n --theme-color-ghost: #a7a7a7;\n --theme-color-accent: #2f8555;\n --theme-background-1: #fff;\n --theme-background-2: #f5f5f5;\n --theme-background-3: #ededed;\n --theme-background-4: rgba(0, 0, 0, 0.06);\n --theme-background-accent: #2f85551f;\n\n --theme-border-color: rgba(0, 0, 0, 0.1);\n --theme-scrollbar-color: rgba(0, 0, 0, 0.18);\n --theme-scrollbar-color-active: rgba(0, 0, 0, 0.36);\n --theme-lifted-brightness: 1;\n --theme-backdrop-brightness: 1;\n\n --theme-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.11);\n --theme-shadow-2: rgba(0, 0, 0, 0.08) 0px 13px 20px 0px,\n rgba(0, 0, 0, 0.08) 0px 3px 8px 0px, #eeeeed 0px 0 0 1px;\n\n --theme-button-1: rgb(49 53 56);\n --theme-button-1-color: #fff;\n --theme-button-1-hover: rgb(28 31 33);\n\n --theme-color-green: #007300;\n --theme-color-red: #af272b;\n --theme-color-yellow: #b38200;\n --theme-color-blue: #3b8ba5;\n --theme-color-orange: #fb892c;\n --theme-color-purple: #5203d1;\n}\n\n.dark-mode {\n color-scheme: dark;\n --theme-color-1: rgba(255, 255, 255, 0.9);\n --theme-color-2: rgba(255, 255, 255, 0.62);\n --theme-color-3: rgba(255, 255, 255, 0.44);\n --theme-color-disabled: rgba(255, 255, 255, 0.34);\n --theme-color-ghost: rgba(255, 255, 255, 0.26);\n --theme-color-accent: #27c2a0;\n --theme-background-1: #1b1b1d;\n --theme-background-2: #242526;\n --theme-background-3: #3b3b3b;\n --theme-background-4: rgba(255, 255, 255, 0.06);\n --theme-background-accent: #27c2a01f;\n\n --theme-border-color: rgba(255, 255, 255, 0.1);\n --theme-scrollbar-color: rgba(255, 255, 255, 0.24);\n --theme-scrollbar-color-active: rgba(255, 255, 255, 0.48);\n --theme-lifted-brightness: 1.45;\n --theme-backdrop-brightness: 0.5;\n\n --theme-shadow-1: 0 1px 3px 0 rgb(0, 0, 0, 0.1);\n --theme-shadow-2: rgba(15, 15, 15, 0.2) 0px 3px 6px,\n rgba(15, 15, 15, 0.4) 0px 9px 24px, 0 0 0 1px rgba(255, 255, 255, 0.1);\n\n --theme-button-1: #f6f6f6;\n --theme-button-1-color: #000;\n --theme-button-1-hover: #e7e7e7;\n\n --theme-color-green: #26b226;\n --theme-color-red: #fb565b;\n --theme-color-yellow: #ffc426;\n --theme-color-blue: #6ecfef;\n --theme-color-orange: #ff8d4d;\n --theme-color-purple: #b191f9;\n}\n.scalar-card:nth-of-type(3) {\n display: none;\n}\n";
|
|
16
|
+
/**
|
|
17
|
+
* The HTML to load the @scalar/api-reference JavaScript package.
|
|
18
|
+
*/
|
|
19
|
+
export declare const javascript: (configuration: ReferenceConfiguration) => string;
|
|
20
|
+
/**
|
|
21
|
+
* The HTML template to render the API Reference.
|
|
22
|
+
*/
|
|
23
|
+
export declare function htmlDocument(configuration: ReferenceConfiguration): string;
|
|
24
|
+
declare const _default: FastifyPluginAsync<FastifyApiReferenceOptions>;
|
|
15
25
|
export default _default;
|
|
16
26
|
//# sourceMappingURL=fastifyApiReference.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;
|
|
1
|
+
{"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAKjD,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB,aAAa,CAAC,EAAE,sBAAsB,CAAA;CACvC,CAAA;AAQD;;GAEG;AACH,eAAO,MAAM,UAAU,i8EA+EtB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,kBAAmB,sBAAsB,WAgB/D,CAAA;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,aAAa,EAAE,sBAAsB,UAqBjE;;AA4FD,wBAAsC"}
|
package/dist/index.cjs
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
"use strict";const e=require("
|
|
1
|
+
"use strict";const e=require("fastify-plugin"),n=require("node:fs"),t=require("node:path"),o={hide:!0};function r(e){return`\n<!DOCTYPE html>\n<html>\n <head>\n <title>API Reference</title>\n <meta charset="utf-8" />\n <meta\n name="viewport"\n content="width=device-width, initial-scale=1" />\n <style>\n body {\n margin: 0;\n }\n </style>\n </head>\n <body>\n ${(e=>{var n,t,o,r;return`\n <script\n id="api-reference"\n type="application/json"\n data-configuration="${JSON.stringify(e).split('"').join(""")}">${(null==(n=e.spec)?void 0:n.content)?"function"==typeof(null==(t=e.spec)?void 0:t.content)?JSON.stringify(null==(o=e.spec)?void 0:o.content()):JSON.stringify(null==(r=e.spec)?void 0:r.content):""}<\/script>\n <script src="/@scalar/fastify-api-reference/browser.js"><\/script>\n `})(e)}\n </body>\n</html>\n`}const c=e((async(e,c)=>{var a,l;let{configuration:s}=c;const h=e.hasPlugin("@fastify/swagger");(null==(a=null==s?void 0:s.spec)?void 0:a.content)||(null==(l=null==s?void 0:s.spec)?void 0:l.url)||h?(e.route({method:"GET",url:c.routePrefix??"/",schema:o,async handler(n,t){var o,c;t.header("Content-Type","text/html; charset=utf-8"),(null==(o=null==s?void 0:s.spec)?void 0:o.content)||(null==(c=null==s?void 0:s.spec)?void 0:c.url)||!h||(s={...s,spec:{content:()=>e.swagger()}}),(null==s?void 0:s.customCss)||(null==s?void 0:s.theme)||(s={...s,customCss:"\n:root {\n --theme-font: 'Inter', var(--system-fonts);\n}\n\n.light-mode {\n color-scheme: light;\n --theme-color-1: #1c1e21;\n --theme-color-2: #757575;\n --theme-color-3: #8e8e8e;\n --theme-color-disabled: #b4b1b1;\n --theme-color-ghost: #a7a7a7;\n --theme-color-accent: #2f8555;\n --theme-background-1: #fff;\n --theme-background-2: #f5f5f5;\n --theme-background-3: #ededed;\n --theme-background-4: rgba(0, 0, 0, 0.06);\n --theme-background-accent: #2f85551f;\n\n --theme-border-color: rgba(0, 0, 0, 0.1);\n --theme-scrollbar-color: rgba(0, 0, 0, 0.18);\n --theme-scrollbar-color-active: rgba(0, 0, 0, 0.36);\n --theme-lifted-brightness: 1;\n --theme-backdrop-brightness: 1;\n\n --theme-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.11);\n --theme-shadow-2: rgba(0, 0, 0, 0.08) 0px 13px 20px 0px,\n rgba(0, 0, 0, 0.08) 0px 3px 8px 0px, #eeeeed 0px 0 0 1px;\n\n --theme-button-1: rgb(49 53 56);\n --theme-button-1-color: #fff;\n --theme-button-1-hover: rgb(28 31 33);\n\n --theme-color-green: #007300;\n --theme-color-red: #af272b;\n --theme-color-yellow: #b38200;\n --theme-color-blue: #3b8ba5;\n --theme-color-orange: #fb892c;\n --theme-color-purple: #5203d1;\n}\n\n.dark-mode {\n color-scheme: dark;\n --theme-color-1: rgba(255, 255, 255, 0.9);\n --theme-color-2: rgba(255, 255, 255, 0.62);\n --theme-color-3: rgba(255, 255, 255, 0.44);\n --theme-color-disabled: rgba(255, 255, 255, 0.34);\n --theme-color-ghost: rgba(255, 255, 255, 0.26);\n --theme-color-accent: #27c2a0;\n --theme-background-1: #1b1b1d;\n --theme-background-2: #242526;\n --theme-background-3: #3b3b3b;\n --theme-background-4: rgba(255, 255, 255, 0.06);\n --theme-background-accent: #27c2a01f;\n\n --theme-border-color: rgba(255, 255, 255, 0.1);\n --theme-scrollbar-color: rgba(255, 255, 255, 0.24);\n --theme-scrollbar-color-active: rgba(255, 255, 255, 0.48);\n --theme-lifted-brightness: 1.45;\n --theme-backdrop-brightness: 0.5;\n\n --theme-shadow-1: 0 1px 3px 0 rgb(0, 0, 0, 0.1);\n --theme-shadow-2: rgba(15, 15, 15, 0.2) 0px 3px 6px,\n rgba(15, 15, 15, 0.4) 0px 9px 24px, 0 0 0 1px rgba(255, 255, 255, 0.1);\n\n --theme-button-1: #f6f6f6;\n --theme-button-1-color: #000;\n --theme-button-1-hover: #e7e7e7;\n\n --theme-color-green: #26b226;\n --theme-color-red: #fb565b;\n --theme-color-yellow: #ffc426;\n --theme-color-blue: #6ecfef;\n --theme-color-orange: #ff8d4d;\n --theme-color-purple: #b191f9;\n}\n.scalar-card:nth-of-type(3) {\n display: none;\n}\n"});const a=r(s);t.send(a)}}),e.route({method:"GET",url:"/@scalar/fastify-api-reference/browser.js",schema:o,async handler(e,o){o.header("Content-Type","application/javascript; charset=utf-8");const r=t.join(__dirname,"../","node_modules","@scalar/api-reference","dist/browser/standalone.js"),c=n.readFileSync(r,"utf8");o.send(c)}})):console.warn("[@scalar/fastify-api-reference] You didn’t provide a spec.content or spec.url and @fastify/swagger could not be find either. Please provide one of these options.")}));module.exports=c;
|
package/dist/index.js
CHANGED
|
@@ -7,17 +7,129 @@ const __dirname = __getDirname();
|
|
|
7
7
|
const __filename = __getFilename();
|
|
8
8
|
const self = globalThis;
|
|
9
9
|
const require2 = __createRequire(import.meta.url);
|
|
10
|
-
import ejs from "ejs";
|
|
11
10
|
import fp from "fastify-plugin";
|
|
12
11
|
import fs from "node:fs";
|
|
13
12
|
import path from "node:path";
|
|
14
13
|
const schemaToHideRoute = {
|
|
15
14
|
hide: true
|
|
16
15
|
};
|
|
17
|
-
const
|
|
16
|
+
const defaultCss = `
|
|
17
|
+
:root {
|
|
18
|
+
--theme-font: 'Inter', var(--system-fonts);
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
.light-mode {
|
|
22
|
+
color-scheme: light;
|
|
23
|
+
--theme-color-1: #1c1e21;
|
|
24
|
+
--theme-color-2: #757575;
|
|
25
|
+
--theme-color-3: #8e8e8e;
|
|
26
|
+
--theme-color-disabled: #b4b1b1;
|
|
27
|
+
--theme-color-ghost: #a7a7a7;
|
|
28
|
+
--theme-color-accent: #2f8555;
|
|
29
|
+
--theme-background-1: #fff;
|
|
30
|
+
--theme-background-2: #f5f5f5;
|
|
31
|
+
--theme-background-3: #ededed;
|
|
32
|
+
--theme-background-4: rgba(0, 0, 0, 0.06);
|
|
33
|
+
--theme-background-accent: #2f85551f;
|
|
34
|
+
|
|
35
|
+
--theme-border-color: rgba(0, 0, 0, 0.1);
|
|
36
|
+
--theme-scrollbar-color: rgba(0, 0, 0, 0.18);
|
|
37
|
+
--theme-scrollbar-color-active: rgba(0, 0, 0, 0.36);
|
|
38
|
+
--theme-lifted-brightness: 1;
|
|
39
|
+
--theme-backdrop-brightness: 1;
|
|
40
|
+
|
|
41
|
+
--theme-shadow-1: 0 1px 3px 0 rgba(0, 0, 0, 0.11);
|
|
42
|
+
--theme-shadow-2: rgba(0, 0, 0, 0.08) 0px 13px 20px 0px,
|
|
43
|
+
rgba(0, 0, 0, 0.08) 0px 3px 8px 0px, #eeeeed 0px 0 0 1px;
|
|
44
|
+
|
|
45
|
+
--theme-button-1: rgb(49 53 56);
|
|
46
|
+
--theme-button-1-color: #fff;
|
|
47
|
+
--theme-button-1-hover: rgb(28 31 33);
|
|
48
|
+
|
|
49
|
+
--theme-color-green: #007300;
|
|
50
|
+
--theme-color-red: #af272b;
|
|
51
|
+
--theme-color-yellow: #b38200;
|
|
52
|
+
--theme-color-blue: #3b8ba5;
|
|
53
|
+
--theme-color-orange: #fb892c;
|
|
54
|
+
--theme-color-purple: #5203d1;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.dark-mode {
|
|
58
|
+
color-scheme: dark;
|
|
59
|
+
--theme-color-1: rgba(255, 255, 255, 0.9);
|
|
60
|
+
--theme-color-2: rgba(255, 255, 255, 0.62);
|
|
61
|
+
--theme-color-3: rgba(255, 255, 255, 0.44);
|
|
62
|
+
--theme-color-disabled: rgba(255, 255, 255, 0.34);
|
|
63
|
+
--theme-color-ghost: rgba(255, 255, 255, 0.26);
|
|
64
|
+
--theme-color-accent: #27c2a0;
|
|
65
|
+
--theme-background-1: #1b1b1d;
|
|
66
|
+
--theme-background-2: #242526;
|
|
67
|
+
--theme-background-3: #3b3b3b;
|
|
68
|
+
--theme-background-4: rgba(255, 255, 255, 0.06);
|
|
69
|
+
--theme-background-accent: #27c2a01f;
|
|
70
|
+
|
|
71
|
+
--theme-border-color: rgba(255, 255, 255, 0.1);
|
|
72
|
+
--theme-scrollbar-color: rgba(255, 255, 255, 0.24);
|
|
73
|
+
--theme-scrollbar-color-active: rgba(255, 255, 255, 0.48);
|
|
74
|
+
--theme-lifted-brightness: 1.45;
|
|
75
|
+
--theme-backdrop-brightness: 0.5;
|
|
76
|
+
|
|
77
|
+
--theme-shadow-1: 0 1px 3px 0 rgb(0, 0, 0, 0.1);
|
|
78
|
+
--theme-shadow-2: rgba(15, 15, 15, 0.2) 0px 3px 6px,
|
|
79
|
+
rgba(15, 15, 15, 0.4) 0px 9px 24px, 0 0 0 1px rgba(255, 255, 255, 0.1);
|
|
80
|
+
|
|
81
|
+
--theme-button-1: #f6f6f6;
|
|
82
|
+
--theme-button-1-color: #000;
|
|
83
|
+
--theme-button-1-hover: #e7e7e7;
|
|
84
|
+
|
|
85
|
+
--theme-color-green: #26b226;
|
|
86
|
+
--theme-color-red: #fb565b;
|
|
87
|
+
--theme-color-yellow: #ffc426;
|
|
88
|
+
--theme-color-blue: #6ecfef;
|
|
89
|
+
--theme-color-orange: #ff8d4d;
|
|
90
|
+
--theme-color-purple: #b191f9;
|
|
91
|
+
}
|
|
92
|
+
.scalar-card:nth-of-type(3) {
|
|
93
|
+
display: none;
|
|
94
|
+
}
|
|
95
|
+
`;
|
|
96
|
+
const javascript = (configuration) => {
|
|
18
97
|
var _a, _b, _c, _d;
|
|
98
|
+
return `
|
|
99
|
+
<script
|
|
100
|
+
id="api-reference"
|
|
101
|
+
type="application/json"
|
|
102
|
+
data-configuration="${JSON.stringify(configuration).split('"').join(""")}">${((_a = configuration.spec) == null ? void 0 : _a.content) ? typeof ((_b = configuration.spec) == null ? void 0 : _b.content) === "function" ? JSON.stringify((_c = configuration.spec) == null ? void 0 : _c.content()) : JSON.stringify((_d = configuration.spec) == null ? void 0 : _d.content) : ""}<\/script>
|
|
103
|
+
<script src="/@scalar/fastify-api-reference/browser.js"><\/script>
|
|
104
|
+
`;
|
|
105
|
+
};
|
|
106
|
+
function htmlDocument(configuration) {
|
|
107
|
+
return `
|
|
108
|
+
<!DOCTYPE html>
|
|
109
|
+
<html>
|
|
110
|
+
<head>
|
|
111
|
+
<title>API Reference</title>
|
|
112
|
+
<meta charset="utf-8" />
|
|
113
|
+
<meta
|
|
114
|
+
name="viewport"
|
|
115
|
+
content="width=device-width, initial-scale=1" />
|
|
116
|
+
<style>
|
|
117
|
+
body {
|
|
118
|
+
margin: 0;
|
|
119
|
+
}
|
|
120
|
+
</style>
|
|
121
|
+
</head>
|
|
122
|
+
<body>
|
|
123
|
+
${javascript(configuration)}
|
|
124
|
+
</body>
|
|
125
|
+
</html>
|
|
126
|
+
`;
|
|
127
|
+
}
|
|
128
|
+
const fastifyApiReference = async (fastify, options) => {
|
|
129
|
+
var _a, _b;
|
|
130
|
+
let { configuration } = options;
|
|
19
131
|
const hasSwaggerPlugin = fastify.hasPlugin("@fastify/swagger");
|
|
20
|
-
if (!((
|
|
132
|
+
if (!((_a = configuration == null ? void 0 : configuration.spec) == null ? void 0 : _a.content) && !((_b = configuration == null ? void 0 : configuration.spec) == null ? void 0 : _b.url) && !hasSwaggerPlugin) {
|
|
21
133
|
console.warn(
|
|
22
134
|
"[@scalar/fastify-api-reference] You didn’t provide a spec.content or spec.url and @fastify/swagger could not be find either. Please provide one of these options."
|
|
23
135
|
);
|
|
@@ -30,41 +142,47 @@ const fastifyApiReference = async (fastify, options) => {
|
|
|
30
142
|
// @ts-ignore
|
|
31
143
|
schema: schemaToHideRoute,
|
|
32
144
|
async handler(_, reply) {
|
|
33
|
-
var _a2, _b2
|
|
145
|
+
var _a2, _b2;
|
|
34
146
|
reply.header("Content-Type", "text/html; charset=utf-8");
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
spec: { content: () => fastify.swagger() }
|
|
147
|
+
if (!((_a2 = configuration == null ? void 0 : configuration.spec) == null ? void 0 : _a2.content) && !((_b2 = configuration == null ? void 0 : configuration.spec) == null ? void 0 : _b2.url) && hasSwaggerPlugin) {
|
|
148
|
+
configuration = {
|
|
149
|
+
...configuration,
|
|
150
|
+
spec: {
|
|
151
|
+
content: () => {
|
|
152
|
+
return fastify.swagger();
|
|
153
|
+
}
|
|
43
154
|
}
|
|
44
155
|
};
|
|
45
156
|
}
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
}
|
|
51
|
-
|
|
157
|
+
if (!(configuration == null ? void 0 : configuration.customCss) && !(configuration == null ? void 0 : configuration.theme)) {
|
|
158
|
+
configuration = {
|
|
159
|
+
...configuration,
|
|
160
|
+
customCss: defaultCss
|
|
161
|
+
};
|
|
162
|
+
}
|
|
163
|
+
const html = htmlDocument(configuration);
|
|
52
164
|
reply.send(html);
|
|
53
165
|
}
|
|
54
166
|
});
|
|
55
167
|
fastify.route({
|
|
56
168
|
method: "GET",
|
|
57
|
-
url:
|
|
169
|
+
url: "/@scalar/fastify-api-reference/browser.js",
|
|
58
170
|
// We don’t know whether @fastify/swagger is registered, but it doesn’t hurt to add a schema anyway.
|
|
59
171
|
// @ts-ignore
|
|
60
172
|
schema: schemaToHideRoute,
|
|
61
173
|
async handler(_, reply) {
|
|
62
174
|
reply.header("Content-Type", "application/javascript; charset=utf-8");
|
|
63
|
-
const
|
|
64
|
-
|
|
65
|
-
|
|
175
|
+
const packageName = "@scalar/api-reference";
|
|
176
|
+
const jsFilePath = "dist/browser/standalone.js";
|
|
177
|
+
const filePath = path.join(
|
|
178
|
+
__dirname,
|
|
179
|
+
"../",
|
|
180
|
+
"node_modules",
|
|
181
|
+
packageName,
|
|
182
|
+
jsFilePath
|
|
66
183
|
);
|
|
67
|
-
|
|
184
|
+
const fileContent = fs.readFileSync(filePath, "utf8");
|
|
185
|
+
reply.send(fileContent);
|
|
68
186
|
}
|
|
69
187
|
});
|
|
70
188
|
};
|
package/package.json
CHANGED
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
"openapi",
|
|
13
13
|
"swagger"
|
|
14
14
|
],
|
|
15
|
-
"version": "0.7.
|
|
15
|
+
"version": "0.7.2",
|
|
16
16
|
"engines": {
|
|
17
17
|
"node": ">=20"
|
|
18
18
|
},
|
|
@@ -34,9 +34,8 @@
|
|
|
34
34
|
"directory": "packages/fastify-api-reference"
|
|
35
35
|
},
|
|
36
36
|
"dependencies": {
|
|
37
|
-
"ejs": "^3.1.9",
|
|
38
37
|
"terser": "^5.24.0",
|
|
39
|
-
"@scalar/api-reference": "1.
|
|
38
|
+
"@scalar/api-reference": "1.3.0"
|
|
40
39
|
},
|
|
41
40
|
"devDependencies": {
|
|
42
41
|
"@rollup/plugin-terser": "^0.4.4",
|
|
@@ -61,8 +60,7 @@
|
|
|
61
60
|
"fastify-plugin": "^4.0.0"
|
|
62
61
|
},
|
|
63
62
|
"scripts": {
|
|
64
|
-
"build": "vite build &&
|
|
65
|
-
"build:template": "vite build -c vite.template.config.ts",
|
|
63
|
+
"build": "vite build && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
|
|
66
64
|
"lint:check": "eslint .",
|
|
67
65
|
"lint:fix": "eslint . --fix",
|
|
68
66
|
"test": "vitest",
|