@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 CHANGED
@@ -1,5 +1,13 @@
1
1
  # @scalar/fastify-api-reference
2
2
 
3
+ ## 0.6.14
4
+
5
+ ### Patch Changes
6
+
7
+ - 3cbfbe0d: fix: hide fastify plugin routes from the Swagger spec
8
+ - Updated dependencies [46142c0a]
9
+ - @scalar/api-reference@0.6.14
10
+
3
11
  ## 0.6.13
4
12
 
5
13
  ### Patch Changes
@@ -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;;AAiED,wBAAsC"}
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.get(options.routePrefix ?? "/", async (_, reply) => {
16
- var _a2, _b2;
17
- reply.header("Content-Type", "text/html; charset=utf-8");
18
- let mergedOptions = options;
19
- if (!((_a2 = options.apiReference) == null ? void 0 : _a2.spec) && !((_b2 = options.apiReference) == null ? void 0 : _b2.specUrl) && hasSwaggerPlugin) {
20
- mergedOptions = {
21
- ...options,
22
- apiReference: {
23
- ...options.apiReference,
24
- // @ts-ignore
25
- spec: () => fastify.swagger()
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.get(
38
- (options.routePrefix ?? "/") + "/fastify-api-reference.js",
39
- async (_, reply) => {
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.get(options.routePrefix ?? "/", async (_, reply) => {
24
- var _a2, _b2;
25
- reply.header("Content-Type", "text/html; charset=utf-8");
26
- let mergedOptions = options;
27
- if (!((_a2 = options.apiReference) == null ? void 0 : _a2.spec) && !((_b2 = options.apiReference) == null ? void 0 : _b2.specUrl) && hasSwaggerPlugin) {
28
- mergedOptions = {
29
- ...options,
30
- apiReference: {
31
- ...options.apiReference,
32
- // @ts-ignore
33
- spec: () => fastify.swagger()
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.get(
46
- (options.routePrefix ?? "/") + "/fastify-api-reference.js",
47
- async (_, reply) => {
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 {