@scalar/fastify-api-reference 0.6.0 → 0.6.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/dist/fastifyApiReference.d.ts.map +1 -1
- package/dist/fastifyApiReference.js +12 -30
- package/dist/templates/fastify-api-reference.js +102544 -0
- package/dist/templates/index.ejs +25 -0
- package/dist/templates/render.d.ts +2 -0
- package/dist/templates/render.d.ts.map +1 -0
- package/dist/templates/render.js +69 -0
- package/dist/vite-plugins/index.d.ts +3 -0
- package/dist/vite-plugins/index.d.ts.map +1 -0
- package/dist/vite-plugins/index.js +2 -0
- package/dist/vite-plugins/nodeExternals.d.ts +8 -0
- package/dist/vite-plugins/nodeExternals.d.ts.map +1 -0
- package/dist/vite-plugins/nodeExternals.js +14 -0
- package/dist/vite-plugins/nodeShims.d.ts +6 -0
- package/dist/vite-plugins/nodeShims.d.ts.map +1 -0
- package/dist/vite-plugins/nodeShims.js +32 -0
- package/package.json +19 -6
- package/dist/index.umd.cjs +0 -17
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"
|
|
1
|
+
{"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAKjD,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE;QACZ,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;QACxD,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,CAAA;CACF,CAAA;;AA0CD,wBAAsC"}
|
|
@@ -1,41 +1,23 @@
|
|
|
1
|
+
import ejs from 'ejs';
|
|
1
2
|
import fp from 'fastify-plugin';
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
? `<div data-spec-url="${options.apiReference?.specUrl}" />`
|
|
5
|
-
: typeof options.apiReference?.spec === 'object'
|
|
6
|
-
? `<div data-spec='${JSON.stringify(options.apiReference?.spec)}' />`
|
|
7
|
-
: options.apiReference?.spec
|
|
8
|
-
? `<div data-spec='${JSON.stringify(options.apiReference?.spec())}' />`
|
|
9
|
-
: '';
|
|
10
|
-
return `
|
|
11
|
-
<!DOCTYPE html>
|
|
12
|
-
<html>
|
|
13
|
-
<head>
|
|
14
|
-
<title>${options.apiReference.title || 'API Reference'}</title>
|
|
15
|
-
<meta charset="utf-8" />
|
|
16
|
-
<meta
|
|
17
|
-
name="viewport"
|
|
18
|
-
content="width=device-width, initial-scale=1" />
|
|
19
|
-
</head>
|
|
20
|
-
<body>
|
|
21
|
-
<!-- Add your own OpenAPI/Swagger spec file URL here: -->
|
|
22
|
-
${htmlTag}
|
|
23
|
-
<script src="https://www.unpkg.com/@scalar/api-reference"></script>
|
|
24
|
-
</body>
|
|
25
|
-
</html>
|
|
26
|
-
`;
|
|
27
|
-
};
|
|
3
|
+
import fs from 'fs';
|
|
4
|
+
import path from 'path';
|
|
28
5
|
const fastifyApiReference = async (fastify, options) => {
|
|
29
6
|
if (!options.apiReference?.spec && !options.apiReference?.specUrl) {
|
|
30
7
|
console.warn('[@scalar/fastify-api-reference] You didn’t provide a spec or specUrl. Please provide one of these options.');
|
|
31
8
|
return;
|
|
32
9
|
}
|
|
33
|
-
fastify.
|
|
10
|
+
fastify.get(options.routePrefix ?? '/', async (_, reply) => {
|
|
34
11
|
reply.header('Content-Type', 'text/html; charset=utf-8');
|
|
35
|
-
|
|
12
|
+
const html = await ejs.renderFile(path.resolve(`${__dirname}/../dist/templates/index.ejs`), {
|
|
13
|
+
options,
|
|
14
|
+
});
|
|
15
|
+
reply.send(html);
|
|
36
16
|
});
|
|
37
|
-
fastify.get(options.routePrefix ?? '/', async (_, reply) => {
|
|
38
|
-
reply.
|
|
17
|
+
fastify.get((options.routePrefix ?? '/') + '/fastify-api-reference.js', async (_, reply) => {
|
|
18
|
+
reply.header('Content-Type', 'application/javascript; charset=utf-8');
|
|
19
|
+
const content = fs.readFileSync(path.resolve(`${__dirname}/../dist/templates/fastify-api-reference.js`), 'utf8');
|
|
20
|
+
reply.send(content);
|
|
39
21
|
});
|
|
40
22
|
};
|
|
41
23
|
export default fp(fastifyApiReference);
|