@scalar/fastify-api-reference 1.20.26 → 1.21.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,17 @@
1
1
  # @scalar/fastify-api-reference
2
2
 
3
+ ## 1.21.0
4
+
5
+ ### Minor Changes
6
+
7
+ - b58b83e: Improved fastify-api-reference plugin.
8
+
9
+ ## 1.20.27
10
+
11
+ ### Patch Changes
12
+
13
+ - 605f522: feat: support tags with no operations
14
+
3
15
  ## 1.20.26
4
16
 
5
17
  ### Patch Changes
@@ -1,5 +1,5 @@
1
1
  import type { ReferenceConfiguration } from '@scalar/api-reference';
2
- import type { FastifyPluginAsync } from 'fastify';
2
+ import type { FastifyBaseLogger, FastifyTypeProviderDefault, RawServerDefault } from 'fastify';
3
3
  export type FastifyApiReferenceOptions = {
4
4
  /**
5
5
  * If you’re prefixing Fastify with a path, you can set it here.
@@ -33,6 +33,6 @@ export declare const javascript: (options: FastifyApiReferenceOptions) => string
33
33
  * The HTML template to render the API Reference.
34
34
  */
35
35
  export declare function htmlDocument(options: FastifyApiReferenceOptions): string;
36
- declare const fastifyApiReference: FastifyPluginAsync<FastifyApiReferenceOptions>;
36
+ declare const fastifyApiReference: import("fastify").FastifyPluginCallback<FastifyApiReferenceOptions, RawServerDefault, FastifyTypeProviderDefault, FastifyBaseLogger>;
37
37
  export default fastifyApiReference;
38
38
  //# sourceMappingURL=fastifyApiReference.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAIjD,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAAA;CACvC,CAAA;AAcD;;GAEG;AACH,eAAO,MAAM,UAAU,64EA4EtB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,YAAa,0BAA0B,WAkB7D,CAAA;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,0BAA0B,UAgB/D;AAED,QAAA,MAAM,mBAAmB,EAAE,kBAAkB,CAC3C,0BAA0B,CAiF3B,CAAA;AAED,eAAe,mBAAmB,CAAA"}
1
+ {"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,uBAAuB,CAAA;AACnE,OAAO,KAAK,EACV,iBAAiB,EACjB,0BAA0B,EAC1B,gBAAgB,EACjB,MAAM,SAAS,CAAA;AAKhB,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;;OAKG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,WAAW,CAAC,EAAE,MAAM,CAAA;IACpB;;;;OAIG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAAA;CACvC,CAAA;AAcD;;GAEG;AACH,eAAO,MAAM,UAAU,64EA4EtB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,UAAU,YAAa,0BAA0B,WAkB7D,CAAA;AAED;;GAEG;AACH,wBAAgB,YAAY,CAAC,OAAO,EAAE,0BAA0B,UAgB/D;AAED,QAAA,MAAM,mBAAmB,sIAiFxB,CAAA;AAED,eAAe,mBAAmB,CAAA"}
package/dist/index.cjs CHANGED
@@ -1 +1 @@
1
- "use strict";Object.create,Object.defineProperty,Object.getOwnPropertyDescriptor,Object.getOwnPropertyNames,Object.getPrototypeOf,Object.prototype.hasOwnProperty;const e=require("node:fs"),n=require("node:path"),t=require("node:url");var o="undefined"!=typeof document?document.currentScript:null;const r={hide:!0},c=(e,n)=>`${n??""}${e??""}/@scalar/fastify-api-reference/js/browser.js`.replace(/\/\//g,"/");function l(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 </head>\n <body>\n ${(e=>{var n,t,o,r;const{configuration:l}=e;return`\n <script\n id="api-reference"\n type="application/json"\n data-configuration="${JSON.stringify(l??{}).split('"').join("&quot;")}">${(null==(n=null==l?void 0:l.spec)?void 0:n.content)?"function"==typeof(null==(t=null==l?void 0:l.spec)?void 0:t.content)?JSON.stringify(null==(o=null==l?void 0:l.spec)?void 0:o.content()):JSON.stringify(null==(r=null==l?void 0:l.spec)?void 0:r.content):""}<\/script>\n <script src="${c(e.routePrefix,e.publicPath)}"><\/script>\n `})(e)}\n </body>\n</html>\n`}module.exports=async(a,i)=>{var s,h;let{configuration:d}=i;const u=a.hasPlugin("@fastify/swagger");if(a.hasPlugin("fastify-html")||await a.register(import("fastify-html")),!(null==(s=null==d?void 0:d.spec)?void 0:s.content)&&!(null==(h=null==d?void 0:d.spec)?void 0:h.url)&&!u)return void a.log.warn("[@scalar/fastify-api-reference] You didn’t provide a spec.content or spec.url, and @fastify/swagger could not be found. Please provide one of these options.");const m=function(){const r=n.dirname(t.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:o&&o.src||new URL("index.cjs",document.baseURI).href)),c=[n.resolve(`${r}/js/standalone.js`),n.resolve(`${r}/../../dist/js/standalone.js`)].find((n=>e.existsSync(n)));if(void 0===c)throw new Error(`JavaScript file not found: ${n.resolve(`${r}/js/standalone.js`)}`);return e.readFileSync(c,"utf8")}();a.route({method:"GET",url:i.routePrefix??"/",schema:r,async handler(e,n){var t,o;return n.header("Content-Type","text/html; charset=utf-8"),(null==(t=null==d?void 0:d.spec)?void 0:t.content)||(null==(o=null==d?void 0:d.spec)?void 0:o.url)||!u||(d={...d,spec:{content:()=>a.swagger()}}),(null==d?void 0:d.customCss)||(null==d?void 0:d.theme)||(d={...d,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"}),n.html`!${l({...i,configuration:d})}`}}),a.route({method:"GET",url:c(i.routePrefix),schema:r,async handler(e,n){n.header("Content-Type","application/javascript; charset=utf-8"),n.send(m)}})};
1
+ "use strict";const e=require("fastify-plugin"),n=require("node:fs"),o=require("node:path"),t=require("node:url");var r="undefined"!=typeof document?document.currentScript:null;const c={hide:!0},l=(e,n)=>`${n??""}${e??""}/@scalar/fastify-api-reference/js/browser.js`.replace(/\/\//g,"/");function a(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 </head>\n <body>\n ${(e=>{var n,o,t,r;const{configuration:c}=e;return`\n <script\n id="api-reference"\n type="application/json"\n data-configuration="${JSON.stringify(c??{}).split('"').join("&quot;")}">${(null==(n=null==c?void 0:c.spec)?void 0:n.content)?"function"==typeof(null==(o=null==c?void 0:c.spec)?void 0:o.content)?JSON.stringify(null==(t=null==c?void 0:c.spec)?void 0:t.content()):JSON.stringify(null==(r=null==c?void 0:c.spec)?void 0:r.content):""}<\/script>\n <script src="${l(e.routePrefix,e.publicPath)}"><\/script>\n `})(e)}\n </body>\n</html>\n`}const i=e((async(e,i)=>{var s,d;let{configuration:h}=i;const u=e.hasPlugin("@fastify/swagger");if(!(null==(s=null==h?void 0:h.spec)?void 0:s.content)&&!(null==(d=null==h?void 0:h.spec)?void 0:d.url)&&!u)return void e.log.warn("[@scalar/fastify-api-reference] You didn’t provide a spec.content or spec.url, and @fastify/swagger could not be found. Please provide one of these options.");const m=function(){const e=o.dirname(t.fileURLToPath("undefined"==typeof document?require("url").pathToFileURL(__filename).href:r&&r.src||new URL("index.cjs",document.baseURI).href)),c=[o.resolve(`${e}/js/standalone.js`),o.resolve(`${e}/../../dist/js/standalone.js`)].find((e=>n.existsSync(e)));if(void 0===c)throw new Error(`JavaScript file not found: ${o.resolve(`${e}/js/standalone.js`)}`);return n.readFileSync(c,"utf8")}();e.route({method:"GET",url:i.routePrefix??"/",schema:c,handler(n,o){var t,r;return(null==(t=null==h?void 0:h.spec)?void 0:t.content)||(null==(r=null==h?void 0:h.spec)?void 0:r.url)||!u||(h={...h,spec:{content:()=>e.swagger()}}),(null==h?void 0:h.customCss)||(null==h?void 0:h.theme)||(h={...h,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"}),o.header("Content-Type","text/html; charset=utf-8").send(a({...i,configuration:h}))}}),e.route({method:"GET",url:l(i.routePrefix),schema:c,handler:(e,n)=>n.header("Content-Type","application/javascript; charset=utf-8").send(m)})}),{name:"@scalar/fastify-api-reference"});module.exports=i;
package/dist/index.js CHANGED
@@ -1,3 +1,4 @@
1
+ import fp from "fastify-plugin";
1
2
  import fs from "node:fs";
2
3
  import path from "node:path";
3
4
  import { fileURLToPath } from "node:url";
@@ -128,63 +129,60 @@ function htmlDocument(options) {
128
129
  </html>
129
130
  `;
130
131
  }
131
- const fastifyApiReference = async (fastify, options) => {
132
- var _a, _b;
133
- let { configuration } = options;
134
- const hasSwaggerPlugin = fastify.hasPlugin("@fastify/swagger");
135
- if (!fastify.hasPlugin("fastify-html")) {
136
- await fastify.register(import("fastify-html"));
137
- }
138
- 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) {
139
- fastify.log.warn(
140
- "[@scalar/fastify-api-reference] You didn’t provide a spec.content or spec.url, and @fastify/swagger could not be found. Please provide one of these options."
141
- );
142
- return;
143
- }
144
- const fileContent = getJavaScriptFile();
145
- fastify.route({
146
- method: "GET",
147
- url: options.routePrefix ?? "/",
148
- // We don’t know whether @fastify/swagger is registered, but it doesn’t hurt to add a schema anyway.
149
- // @ts-ignore
150
- schema: schemaToHideRoute,
151
- async handler(_, reply) {
152
- var _a2, _b2;
153
- reply.header("Content-Type", "text/html; charset=utf-8");
154
- 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) {
155
- configuration = {
156
- ...configuration,
157
- spec: {
158
- content: () => {
159
- return fastify.swagger();
132
+ const fastifyApiReference = fp(
133
+ async (fastify, options) => {
134
+ var _a, _b;
135
+ let { configuration } = options;
136
+ const hasSwaggerPlugin = fastify.hasPlugin("@fastify/swagger");
137
+ 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) {
138
+ fastify.log.warn(
139
+ "[@scalar/fastify-api-reference] You didn’t provide a spec.content or spec.url, and @fastify/swagger could not be found. Please provide one of these options."
140
+ );
141
+ return;
142
+ }
143
+ const fileContent = getJavaScriptFile();
144
+ fastify.route({
145
+ method: "GET",
146
+ url: options.routePrefix ?? "/",
147
+ // We don’t know whether @fastify/swagger is registered, but it doesn’t hurt to add a schema anyway.
148
+ // @ts-ignore
149
+ schema: schemaToHideRoute,
150
+ handler(_, reply) {
151
+ var _a2, _b2;
152
+ 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) {
153
+ configuration = {
154
+ ...configuration,
155
+ spec: {
156
+ content: () => {
157
+ return fastify.swagger();
158
+ }
160
159
  }
161
- }
162
- };
160
+ };
161
+ }
162
+ if (!(configuration == null ? void 0 : configuration.customCss) && !(configuration == null ? void 0 : configuration.theme)) {
163
+ configuration = {
164
+ ...configuration,
165
+ customCss: defaultCss
166
+ };
167
+ }
168
+ return reply.header("Content-Type", "text/html; charset=utf-8").send(htmlDocument({ ...options, configuration }));
163
169
  }
164
- if (!(configuration == null ? void 0 : configuration.customCss) && !(configuration == null ? void 0 : configuration.theme)) {
165
- configuration = {
166
- ...configuration,
167
- customCss: defaultCss
168
- };
170
+ });
171
+ fastify.route({
172
+ method: "GET",
173
+ url: getJavaScriptUrl(options.routePrefix),
174
+ // We don’t know whether @fastify/swagger is registered, but it doesn’t hurt to add a schema anyway.
175
+ // @ts-ignore
176
+ schema: schemaToHideRoute,
177
+ handler(_, reply) {
178
+ return reply.header("Content-Type", "application/javascript; charset=utf-8").send(fileContent);
169
179
  }
170
- return reply.html`!${htmlDocument({
171
- ...options,
172
- configuration
173
- })}`;
174
- }
175
- });
176
- fastify.route({
177
- method: "GET",
178
- url: getJavaScriptUrl(options.routePrefix),
179
- // We don’t know whether @fastify/swagger is registered, but it doesn’t hurt to add a schema anyway.
180
- // @ts-ignore
181
- schema: schemaToHideRoute,
182
- async handler(_, reply) {
183
- reply.header("Content-Type", "application/javascript; charset=utf-8");
184
- reply.send(fileContent);
185
- }
186
- });
187
- };
180
+ });
181
+ },
182
+ {
183
+ name: "@scalar/fastify-api-reference"
184
+ }
185
+ );
188
186
  export {
189
187
  fastifyApiReference as default
190
188
  };