@scalar/fastify-api-reference 0.6.13 → 0.6.14
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 +8 -0
- package/dist/fastifyApiReference.d.ts.map +1 -1
- package/dist/index.cjs +37 -23
- package/dist/index.js +37 -23
- package/dist/templates/fastify-api-reference.js +15587 -15536
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1 +1 @@
|
|
|
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,CAAC,EAAE;QACb,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;;
|
|
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,CAAC,EAAE;QACb,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;;AAkFD,wBAAsC"}
|
package/dist/index.cjs
CHANGED
|
@@ -3,6 +3,9 @@ const ejs = require("ejs");
|
|
|
3
3
|
const fp = require("fastify-plugin");
|
|
4
4
|
const fs = require("node:fs");
|
|
5
5
|
const path = require("node:path");
|
|
6
|
+
const schemaToHideRoute = {
|
|
7
|
+
hide: true
|
|
8
|
+
};
|
|
6
9
|
const fastifyApiReference = async (fastify, options) => {
|
|
7
10
|
var _a, _b;
|
|
8
11
|
const hasSwaggerPlugin = fastify.hasPlugin("@fastify/swagger");
|
|
@@ -12,31 +15,42 @@ const fastifyApiReference = async (fastify, options) => {
|
|
|
12
15
|
);
|
|
13
16
|
return;
|
|
14
17
|
}
|
|
15
|
-
fastify.
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
18
|
+
fastify.route({
|
|
19
|
+
method: "GET",
|
|
20
|
+
url: options.routePrefix ?? "/",
|
|
21
|
+
// We don’t know whether @fastify/swagger is registered, but it doesn’t hurt to add a schema anyway.
|
|
22
|
+
// @ts-ignore
|
|
23
|
+
schema: schemaToHideRoute,
|
|
24
|
+
async handler(_, reply) {
|
|
25
|
+
var _a2, _b2;
|
|
26
|
+
reply.header("Content-Type", "text/html; charset=utf-8");
|
|
27
|
+
let mergedOptions = options;
|
|
28
|
+
if (!((_a2 = options.apiReference) == null ? void 0 : _a2.spec) && !((_b2 = options.apiReference) == null ? void 0 : _b2.specUrl) && hasSwaggerPlugin) {
|
|
29
|
+
mergedOptions = {
|
|
30
|
+
...options,
|
|
31
|
+
apiReference: {
|
|
32
|
+
...options.apiReference,
|
|
33
|
+
// @ts-ignore
|
|
34
|
+
spec: () => fastify.swagger()
|
|
35
|
+
}
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
const html = await ejs.renderFile(
|
|
39
|
+
path.resolve(`${__dirname}/../dist/templates/index.ejs`),
|
|
40
|
+
{
|
|
41
|
+
options: mergedOptions
|
|
26
42
|
}
|
|
27
|
-
|
|
43
|
+
);
|
|
44
|
+
reply.send(html);
|
|
28
45
|
}
|
|
29
|
-
const html = await ejs.renderFile(
|
|
30
|
-
path.resolve(`${__dirname}/../dist/templates/index.ejs`),
|
|
31
|
-
{
|
|
32
|
-
options: mergedOptions
|
|
33
|
-
}
|
|
34
|
-
);
|
|
35
|
-
reply.send(html);
|
|
36
46
|
});
|
|
37
|
-
fastify.
|
|
38
|
-
|
|
39
|
-
|
|
47
|
+
fastify.route({
|
|
48
|
+
method: "GET",
|
|
49
|
+
url: (options.routePrefix ?? "/") + "/fastify-api-reference.js",
|
|
50
|
+
// We don’t know whether @fastify/swagger is registered, but it doesn’t hurt to add a schema anyway.
|
|
51
|
+
// @ts-ignore
|
|
52
|
+
schema: schemaToHideRoute,
|
|
53
|
+
async handler(_, reply) {
|
|
40
54
|
reply.header("Content-Type", "application/javascript; charset=utf-8");
|
|
41
55
|
const content = fs.readFileSync(
|
|
42
56
|
path.resolve(`${__dirname}/../dist/templates/fastify-api-reference.js`),
|
|
@@ -44,7 +58,7 @@ const fastifyApiReference = async (fastify, options) => {
|
|
|
44
58
|
);
|
|
45
59
|
reply.send(content);
|
|
46
60
|
}
|
|
47
|
-
);
|
|
61
|
+
});
|
|
48
62
|
};
|
|
49
63
|
const fastifyApiReference$1 = fp(fastifyApiReference);
|
|
50
64
|
module.exports = fastifyApiReference$1;
|
package/dist/index.js
CHANGED
|
@@ -11,6 +11,9 @@ import ejs from "ejs";
|
|
|
11
11
|
import fp from "fastify-plugin";
|
|
12
12
|
import fs from "node:fs";
|
|
13
13
|
import path from "node:path";
|
|
14
|
+
const schemaToHideRoute = {
|
|
15
|
+
hide: true
|
|
16
|
+
};
|
|
14
17
|
const fastifyApiReference = async (fastify, options) => {
|
|
15
18
|
var _a, _b;
|
|
16
19
|
const hasSwaggerPlugin = fastify.hasPlugin("@fastify/swagger");
|
|
@@ -20,31 +23,42 @@ const fastifyApiReference = async (fastify, options) => {
|
|
|
20
23
|
);
|
|
21
24
|
return;
|
|
22
25
|
}
|
|
23
|
-
fastify.
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
26
|
+
fastify.route({
|
|
27
|
+
method: "GET",
|
|
28
|
+
url: options.routePrefix ?? "/",
|
|
29
|
+
// We don’t know whether @fastify/swagger is registered, but it doesn’t hurt to add a schema anyway.
|
|
30
|
+
// @ts-ignore
|
|
31
|
+
schema: schemaToHideRoute,
|
|
32
|
+
async handler(_, reply) {
|
|
33
|
+
var _a2, _b2;
|
|
34
|
+
reply.header("Content-Type", "text/html; charset=utf-8");
|
|
35
|
+
let mergedOptions = options;
|
|
36
|
+
if (!((_a2 = options.apiReference) == null ? void 0 : _a2.spec) && !((_b2 = options.apiReference) == null ? void 0 : _b2.specUrl) && hasSwaggerPlugin) {
|
|
37
|
+
mergedOptions = {
|
|
38
|
+
...options,
|
|
39
|
+
apiReference: {
|
|
40
|
+
...options.apiReference,
|
|
41
|
+
// @ts-ignore
|
|
42
|
+
spec: () => fastify.swagger()
|
|
43
|
+
}
|
|
44
|
+
};
|
|
45
|
+
}
|
|
46
|
+
const html = await ejs.renderFile(
|
|
47
|
+
path.resolve(`${__dirname}/../dist/templates/index.ejs`),
|
|
48
|
+
{
|
|
49
|
+
options: mergedOptions
|
|
34
50
|
}
|
|
35
|
-
|
|
51
|
+
);
|
|
52
|
+
reply.send(html);
|
|
36
53
|
}
|
|
37
|
-
const html = await ejs.renderFile(
|
|
38
|
-
path.resolve(`${__dirname}/../dist/templates/index.ejs`),
|
|
39
|
-
{
|
|
40
|
-
options: mergedOptions
|
|
41
|
-
}
|
|
42
|
-
);
|
|
43
|
-
reply.send(html);
|
|
44
54
|
});
|
|
45
|
-
fastify.
|
|
46
|
-
|
|
47
|
-
|
|
55
|
+
fastify.route({
|
|
56
|
+
method: "GET",
|
|
57
|
+
url: (options.routePrefix ?? "/") + "/fastify-api-reference.js",
|
|
58
|
+
// We don’t know whether @fastify/swagger is registered, but it doesn’t hurt to add a schema anyway.
|
|
59
|
+
// @ts-ignore
|
|
60
|
+
schema: schemaToHideRoute,
|
|
61
|
+
async handler(_, reply) {
|
|
48
62
|
reply.header("Content-Type", "application/javascript; charset=utf-8");
|
|
49
63
|
const content = fs.readFileSync(
|
|
50
64
|
path.resolve(`${__dirname}/../dist/templates/fastify-api-reference.js`),
|
|
@@ -52,7 +66,7 @@ const fastifyApiReference = async (fastify, options) => {
|
|
|
52
66
|
);
|
|
53
67
|
reply.send(content);
|
|
54
68
|
}
|
|
55
|
-
);
|
|
69
|
+
});
|
|
56
70
|
};
|
|
57
71
|
const fastifyApiReference$1 = fp(fastifyApiReference);
|
|
58
72
|
export {
|