@scalar/fastify-api-reference 0.6.68 → 0.7.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 CHANGED
@@ -1,5 +1,16 @@
1
1
  # @scalar/fastify-api-reference
2
2
 
3
+ ## 0.7.0
4
+
5
+ ### Minor Changes
6
+
7
+ - 4fc4ba8: feat: add terser minification to fastify integration
8
+
9
+ ### Patch Changes
10
+
11
+ - Updated dependencies [ed7cc0d]
12
+ - @scalar/api-reference@1.2.6
13
+
3
14
  ## 0.6.68
4
15
 
5
16
  ### Patch Changes
package/dist/index.cjs CHANGED
@@ -1,64 +1 @@
1
- "use strict";
2
- const ejs = require("ejs");
3
- const fp = require("fastify-plugin");
4
- const fs = require("node:fs");
5
- const path = require("node:path");
6
- const schemaToHideRoute = {
7
- hide: true
8
- };
9
- const fastifyApiReference = async (fastify, options) => {
10
- var _a, _b, _c, _d;
11
- const hasSwaggerPlugin = fastify.hasPlugin("@fastify/swagger");
12
- if (!((_b = (_a = options.apiReference) == null ? void 0 : _a.spec) == null ? void 0 : _b.content) && !((_d = (_c = options.apiReference) == null ? void 0 : _c.spec) == null ? void 0 : _d.url) && !hasSwaggerPlugin) {
13
- console.warn(
14
- "[@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."
15
- );
16
- return;
17
- }
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, _c2, _d2;
26
- reply.header("Content-Type", "text/html; charset=utf-8");
27
- let mergedOptions = options;
28
- if (!((_b2 = (_a2 = options.apiReference) == null ? void 0 : _a2.spec) == null ? void 0 : _b2.content) && !((_d2 = (_c2 = options.apiReference) == null ? void 0 : _c2.spec) == null ? void 0 : _d2.url) && hasSwaggerPlugin) {
29
- mergedOptions = {
30
- ...options,
31
- apiReference: {
32
- ...options.apiReference,
33
- // @ts-ignore
34
- spec: { content: () => fastify.swagger() }
35
- }
36
- };
37
- }
38
- const html = await ejs.renderFile(
39
- path.resolve(`${__dirname}/../dist/templates/index.ejs`),
40
- {
41
- options: mergedOptions
42
- }
43
- );
44
- reply.send(html);
45
- }
46
- });
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) {
54
- reply.header("Content-Type", "application/javascript; charset=utf-8");
55
- const content = fs.readFileSync(
56
- path.resolve(`${__dirname}/../dist/templates/fastify-api-reference.js`),
57
- "utf8"
58
- );
59
- reply.send(content);
60
- }
61
- });
62
- };
63
- const fastifyApiReference$1 = fp(fastifyApiReference);
64
- module.exports = fastifyApiReference$1;
1
+ "use strict";const e=require("ejs"),n=require("fastify-plugin"),r=require("node:fs"),t=require("node:path"),i={hide:!0},s=n((async(n,s)=>{var a,o,l,c;const d=n.hasPlugin("@fastify/swagger");(null==(o=null==(a=s.apiReference)?void 0:a.spec)?void 0:o.content)||(null==(c=null==(l=s.apiReference)?void 0:l.spec)?void 0:c.url)||d?(n.route({method:"GET",url:s.routePrefix??"/",schema:i,async handler(r,i){var a,o,l,c;i.header("Content-Type","text/html; charset=utf-8");let p=s;(null==(o=null==(a=s.apiReference)?void 0:a.spec)?void 0:o.content)||(null==(c=null==(l=s.apiReference)?void 0:l.spec)?void 0:c.url)||!d||(p={...s,apiReference:{...s.apiReference,spec:{content:()=>n.swagger()}}});const u=await e.renderFile(t.resolve(`${__dirname}/../dist/templates/index.ejs`),{options:p});i.send(u)}}),n.route({method:"GET",url:(s.routePrefix??"/")+"/fastify-api-reference.js",schema:i,async handler(e,n){n.header("Content-Type","application/javascript; charset=utf-8");const i=r.readFileSync(t.resolve(`${__dirname}/../dist/templates/fastify-api-reference.js`),"utf8");n.send(i)}})):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=s;