@scalar/fastify-api-reference 1.39.1 → 1.39.3

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,22 @@
1
1
  # @scalar/fastify-api-reference
2
2
 
3
+ ## 1.39.3
4
+
5
+ ### Patch Changes
6
+
7
+ - Updated dependencies []:
8
+ - @scalar/openapi-parser@0.23.2
9
+
10
+ ## 1.39.2
11
+
12
+ ### Patch Changes
13
+
14
+ - [#7233](https://github.com/scalar/scalar/pull/7233) [`d7f9845`](https://github.com/scalar/scalar/commit/d7f98454b54b92a497ea9e2addaa4fa42b25d452) Thanks [@marcalexiei](https://github.com/marcalexiei)! - fix(fastify): remove empty customTheme
15
+
16
+ - Updated dependencies [[`c1ecd0c`](https://github.com/scalar/scalar/commit/c1ecd0c6096f3fbe2e3d8ad3794ea718bb6bce66), [`2377b76`](https://github.com/scalar/scalar/commit/2377b76d050f8de70037b17a32d0dd1181d3311d)]:
17
+ - @scalar/openapi-parser@0.23.1
18
+ - @scalar/core@0.3.22
19
+
3
20
  ## 1.39.1
4
21
 
5
22
  ## 1.39.0
package/README.md CHANGED
@@ -1,17 +1,30 @@
1
- # Scalar for Fastify
1
+ <!--
2
+ This file is auto-generated by the Scalar README generator.
3
+ Command: pnpm --filter @scalar-internal/build-scripts start generate-readme
4
+
5
+ Do not edit this file manually. Changes will be lost when the file is regenerated.
6
+ -->
2
7
 
3
- [![Version](https://img.shields.io/npm/v/%40scalar/fastify-api-reference)](https://www.npmjs.com/package/@scalar/fastify-api-reference)
4
- [![Downloads](https://img.shields.io/npm/dm/%40scalar/fastify-api-reference)](https://www.npmjs.com/package/@scalar/fastify-api-reference)
5
- [![License](https://img.shields.io/npm/l/%40scalar%2Ffastify-api-reference)](https://www.npmjs.com/package/@scalar/fastify-api-reference)
8
+ # Scalar API Reference for Fastify
9
+
10
+ [![Version](https://img.shields.io/npm/v/@scalar/fastify-api-reference)](https://www.npmjs.com/package/@scalar/fastify-api-reference)
11
+ [![Downloads](https://img.shields.io/npm/dm/@scalar/fastify-api-reference)](https://www.npmjs.com/package/@scalar/fastify-api-reference)
12
+ [![License](https://img.shields.io/npm/l/@scalar/fastify-api-reference)](https://www.npmjs.com/package/@scalar/fastify-api-reference)
6
13
  [![Discord](https://img.shields.io/discord/1135330207960678410?style=flat&color=5865F2)](https://discord.gg/scalar)
7
14
 
15
+ A Fastify plugin to render beautiful, interactive API documentation from OpenAPI/Swagger documents.
16
+
8
17
  ## Documentation
9
18
 
10
19
  [Read the documentation here](https://guides.scalar.com/scalar/scalar-api-references/integrations/fastify)
11
20
 
21
+ ## Changelog
22
+
23
+ See [CHANGELOG.md](https://github.com/scalar/scalar/blob/main/integrations/fastify/CHANGELOG.md) for a list of changes.
24
+
12
25
  ## Community
13
26
 
14
- We are API nerds. You too? Let's chat on Discord: <https://discord.gg/scalar>
27
+ We are API nerds. You too? Lets chat on Discord: <https://discord.gg/scalar>
15
28
 
16
29
  ## License
17
30
 
@@ -1,9 +1,5 @@
1
1
  import type { FastifyBaseLogger, FastifyTypeProviderDefault, RawServerDefault } from 'fastify';
2
2
  import type { FastifyApiReferenceOptions } from './types.js';
3
- /**
4
- * The custom theme for Fastify
5
- */
6
- export declare const customTheme = "";
7
3
  declare const fastifyApiReference: import("fastify").FastifyPluginCallback<FastifyApiReferenceOptions, RawServerDefault, FastifyTypeProviderDefault, FastifyBaseLogger>;
8
4
  export default fastifyApiReference;
9
5
  //# sourceMappingURL=fastifyApiReference.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAI9F,OAAO,KAAK,EAA8D,0BAA0B,EAAE,MAAM,SAAS,CAAA;AA0CrH;;GAEG;AACH,eAAO,MAAM,WAAW,KAAK,CAAA;AAS7B,QAAA,MAAM,mBAAmB,sIAyMxB,CAAA;AAED,eAAe,mBAAmB,CAAA"}
1
+ {"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AAGA,OAAO,KAAK,EAAE,iBAAiB,EAAE,0BAA0B,EAAE,gBAAgB,EAAE,MAAM,SAAS,CAAA;AAI9F,OAAO,KAAK,EAA8D,0BAA0B,EAAE,MAAM,SAAS,CAAA;AAiDrH,QAAA,MAAM,mBAAmB,sIAsMxB,CAAA;AAED,eAAe,mBAAmB,CAAA"}
@@ -16,7 +16,6 @@ const getOpenApiDocumentEndpoints = (openApiDocumentEndpoints) => {
16
16
  return { json, yaml };
17
17
  };
18
18
  const getJavaScriptUrl = (routePrefix) => `${getRoutePrefix(routePrefix)}/${RELATIVE_JAVASCRIPT_PATH}`.replace(/\/\//g, "/");
19
- const customTheme = "";
20
19
  const DEFAULT_CONFIGURATION = {
21
20
  _integration: "fastify"
22
21
  };
@@ -140,14 +139,11 @@ const fastifyApiReference = fp(
140
139
  };
141
140
  }
142
141
  return reply.header("Content-Type", "text/html; charset=utf-8").send(
143
- getHtmlDocument(
144
- {
145
- // We're using the bundled JS here by default, but the user can pass a CDN URL.
146
- cdn: RELATIVE_JAVASCRIPT_PATH,
147
- ...configuration
148
- },
149
- customTheme
150
- )
142
+ getHtmlDocument({
143
+ // We're using the bundled JS here by default, but the user can pass a CDN URL.
144
+ cdn: RELATIVE_JAVASCRIPT_PATH,
145
+ ...configuration
146
+ })
151
147
  );
152
148
  }
153
149
  });
@@ -170,7 +166,6 @@ const fastifyApiReference = fp(
170
166
  );
171
167
  var fastifyApiReference_default = fastifyApiReference;
172
168
  export {
173
- customTheme,
174
169
  fastifyApiReference_default as default
175
170
  };
176
171
  //# sourceMappingURL=fastifyApiReference.js.map
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "version": 3,
3
3
  "sources": ["../src/fastifyApiReference.ts"],
4
- "sourcesContent": ["import { getHtmlDocument } from '@scalar/core/libs/html-rendering'\nimport { normalize, toJson, toYaml } from '@scalar/openapi-parser'\nimport type { OpenAPI } from '@scalar/openapi-types'\nimport type { FastifyBaseLogger, FastifyTypeProviderDefault, RawServerDefault } from 'fastify'\nimport fp from 'fastify-plugin'\nimport { slug } from 'github-slugger'\n\nimport type { ApiReferenceConfiguration, FastifyApiReferenceHooksOptions, FastifyApiReferenceOptions } from './types'\nimport { getJavaScriptFile } from './utils/getJavaScriptFile'\n\n/**\n * Path to the bundled Scalar JavaScript file\n */\nconst RELATIVE_JAVASCRIPT_PATH = 'js/scalar.js'\n\n/**\n * This Schema is used to hide the route from the documentation.\n *\n * We don't know whether `@fastify/swagger` is registered, but it doesn't hurt to add a schema anyway.\n *\n * @see https://github.com/fastify/fastify-swagger#hide-a-route\n */\nconst schemaToHideRoute = {\n hide: true,\n}\n\nconst getRoutePrefix = (routePrefix?: string) => {\n const prefix = routePrefix ?? '/reference'\n\n // Remove trailing slash if present\n return prefix.endsWith('/') ? prefix.slice(0, -1) : prefix\n}\n\n/**\n * Get the endpoints for the OpenAPI specification.\n */\nconst getOpenApiDocumentEndpoints = (\n openApiDocumentEndpoints: FastifyApiReferenceOptions['openApiDocumentEndpoints'],\n) => {\n const { json = '/openapi.json', yaml = '/openapi.yaml' } = openApiDocumentEndpoints ?? {}\n return { json, yaml }\n}\n\n/**\n * Get the URL for the Scalar JavaScript file.\n */\nconst getJavaScriptUrl = (routePrefix?: string) =>\n `${getRoutePrefix(routePrefix)}/${RELATIVE_JAVASCRIPT_PATH}`.replace(/\\/\\//g, '/')\n\n/**\n * The custom theme for Fastify\n */\nexport const customTheme = ''\n\n/**\n * The default configuration for Fastify\n */\nconst DEFAULT_CONFIGURATION: Partial<ApiReferenceConfiguration> = {\n _integration: 'fastify',\n}\n\nconst fastifyApiReference = fp<\n FastifyApiReferenceOptions,\n RawServerDefault,\n FastifyTypeProviderDefault,\n FastifyBaseLogger\n>(\n (fastify, options, next) => {\n const { configuration: givenConfiguration } = options\n\n // Merge the defaults\n let configuration = {\n ...DEFAULT_CONFIGURATION,\n ...givenConfiguration,\n }\n\n const specSource = (() => {\n const { content, url } = configuration ?? {}\n if (content) {\n return {\n type: 'content' as const,\n get: () => {\n if (typeof content === 'function') {\n return content()\n }\n return content\n },\n }\n }\n if (url) {\n return {\n type: 'url' as const,\n get: () => url,\n }\n }\n\n // Even if @fastify/swagger is loaded, when the `decorator` option is set, the `swagger` function is not available.\n if (fastify.hasPlugin('@fastify/swagger') && typeof fastify.swagger === 'function') {\n return {\n type: 'swagger' as const,\n get: () => fastify.swagger(),\n }\n }\n\n return void 0\n })()\n\n // If no OpenAPI specification is passed and @fastify/swagger isn't loaded, show a warning.\n if (!specSource && !configuration.sources) {\n fastify.log.warn(\n \"[@scalar/fastify-api-reference] You didn't provide a `content`, `url`, `sources` or @fastify/swagger could not be found. Please provide one of these options.\",\n )\n\n return next()\n }\n\n // Read the JavaScript file once.\n const fileContent = getJavaScriptFile()\n\n const hooks: FastifyApiReferenceHooksOptions = {}\n if (options.hooks) {\n const additionalHooks: (keyof FastifyApiReferenceHooksOptions)[] = ['onRequest', 'preHandler']\n\n for (const hook of additionalHooks) {\n if (options.hooks[hook]) {\n hooks[hook] = options.hooks[hook]\n }\n }\n }\n\n const getSpecFilenameSlug = (spec: OpenAPI.Document) => {\n // Same GitHub Slugger and default file name as in `@scalar/api-reference`, when generating the download\n return slug(spec?.specification?.info?.title ?? 'spec')\n }\n\n // Only expose the endpoints if specSource is available\n if (specSource) {\n const openApiSpecUrlJson = `${getRoutePrefix(options.routePrefix)}${getOpenApiDocumentEndpoints(options.openApiDocumentEndpoints).json}`\n fastify.route({\n method: 'GET',\n url: openApiSpecUrlJson,\n schema: schemaToHideRoute,\n ...hooks,\n ...(options.logLevel && { logLevel: options.logLevel }),\n handler(_, reply) {\n const spec = normalize(specSource.get())\n const filename = getSpecFilenameSlug(spec)\n const json = JSON.parse(toJson(spec)) // parsing minifies the JSON\n\n return reply\n .header('Content-Type', 'application/json')\n .header('Content-Disposition', `filename=${filename}.json`)\n .header('Access-Control-Allow-Origin', '*')\n .header('Access-Control-Allow-Methods', '*')\n .send(json)\n },\n })\n\n const openApiSpecUrlYaml = `${getRoutePrefix(options.routePrefix)}${getOpenApiDocumentEndpoints(options.openApiDocumentEndpoints).yaml}`\n fastify.route({\n method: 'GET',\n url: openApiSpecUrlYaml,\n schema: schemaToHideRoute,\n ...hooks,\n ...(options.logLevel && { logLevel: options.logLevel }),\n handler(_, reply) {\n const spec = normalize(specSource.get())\n const filename = getSpecFilenameSlug(spec)\n const yaml = toYaml(spec)\n return reply\n .header('Content-Type', 'application/yaml')\n .header('Content-Disposition', `filename=${filename}.yaml`)\n .header('Access-Control-Allow-Origin', '*')\n .header('Access-Control-Allow-Methods', '*')\n .send(yaml)\n },\n })\n }\n\n // Redirect route without a trailing slash to force a trailing slash:\n // We need this so the request to the JS file is relative.\n\n // With ignoreTrailingSlash: true, fastify responds to both routes anyway.\n const ignoreTrailingSlash =\n // @ts-expect-error We're still on Fastify 4, this is introduced in Fastify 5\n fastify.initialConfig?.routerOptions?.ignoreTrailingSlash === true ||\n fastify.initialConfig?.ignoreTrailingSlash === true\n\n if (!ignoreTrailingSlash && getRoutePrefix(options.routePrefix)) {\n fastify.route({\n method: 'GET',\n url: getRoutePrefix(options.routePrefix),\n schema: schemaToHideRoute,\n ...hooks,\n ...(options.logLevel && { logLevel: options.logLevel }),\n handler(request, reply) {\n // we are in a route without a trailing slash so redirect directly to the one with a trailing slash\n const currentUrl = new URL(request.url, `${request.protocol}://${request.hostname}`)\n return reply.redirect(`${currentUrl.pathname}/`, 301)\n },\n })\n }\n\n // If no theme is passed, use the default theme.\n fastify.route({\n method: 'GET',\n url: `${getRoutePrefix(options.routePrefix)}/`,\n // We don't know whether @fastify/swagger is registered, but it doesn't hurt to add a schema anyway.\n schema: schemaToHideRoute,\n ...hooks,\n ...(options.logLevel && { logLevel: options.logLevel }),\n handler(request, reply) {\n // Redirect if it's the route without a slash\n const currentUrl = new URL(request.url, `${request.protocol}://${request.hostname}`)\n if (!currentUrl.pathname.endsWith('/')) {\n return reply.redirect(`${currentUrl.pathname}/`, 301)\n }\n\n /**\n * Regardless of where we source the spec from, provide it as a URL, to have the\n * download button point to the exposed endpoint.\n * If the URL is explicitly passed, defer to that URL instead.\n */\n if (specSource && specSource.type !== 'url') {\n configuration = {\n ...configuration,\n // Use a relative URL in case we're proxied\n url: `.${getOpenApiDocumentEndpoints(options.openApiDocumentEndpoints).json}`,\n }\n }\n\n // Respond with the HTML document\n return reply.header('Content-Type', 'text/html; charset=utf-8').send(\n getHtmlDocument(\n {\n // We're using the bundled JS here by default, but the user can pass a CDN URL.\n cdn: RELATIVE_JAVASCRIPT_PATH,\n ...configuration,\n },\n customTheme,\n ),\n )\n },\n })\n\n fastify.route({\n method: 'GET',\n url: getJavaScriptUrl(options.routePrefix),\n // We don't know whether @fastify/swagger is registered, but it doesn't hurt to add a schema anyway.\n schema: schemaToHideRoute,\n ...hooks,\n ...(options.logLevel && { logLevel: options.logLevel }),\n handler(_, reply) {\n return reply.header('Content-Type', 'application/javascript; charset=utf-8').send(fileContent)\n },\n })\n\n next()\n },\n {\n name: '@scalar/fastify-api-reference',\n },\n)\n\nexport default fastifyApiReference\n"],
5
- "mappings": "AAAA,SAAS,uBAAuB;AAChC,SAAS,WAAW,QAAQ,cAAc;AAG1C,OAAO,QAAQ;AACf,SAAS,YAAY;AAGrB,SAAS,yBAAyB;AAKlC,MAAM,2BAA2B;AASjC,MAAM,oBAAoB;AAAA,EACxB,MAAM;AACR;AAEA,MAAM,iBAAiB,CAAC,gBAAyB;AAC/C,QAAM,SAAS,eAAe;AAG9B,SAAO,OAAO,SAAS,GAAG,IAAI,OAAO,MAAM,GAAG,EAAE,IAAI;AACtD;AAKA,MAAM,8BAA8B,CAClC,6BACG;AACH,QAAM,EAAE,OAAO,iBAAiB,OAAO,gBAAgB,IAAI,4BAA4B,C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AA,UAC9D;AAAA,YACE;AAAA;AAAA,cAEE,KAAK;AAAA,cACL,GAAG;AAAA,YACL;AAAA,YACA;AAAA,UACF;AAAA,QACF;AAAA,MACF;AAAA,IACF,CAAC;AAED,YAAQ,MAAM;AAAA,MACZ,QAAQ;AAAA,MACR,KAAK,iBAAiB,QAAQ,WAAW;AAAA;AAAA,MAEzC,QAAQ;AAAA,MACR,GAAG;AAAA,MACH,GAAI,QAAQ,YAAY,EAAE,UAAU,QAAQ,SAAS;AAAA,MACrD,QAAQ,GAAG,OAAO;AAChB,eAAO,MAAM,OAAO,gBAAgB,uCAAuC,EAAE,KAAK,WAAW;AAAA,MAC/F;AAAA,IACF,CAAC;AAED,SAAK;AAAA,EACP;AAAA,EACA;AAAA,IACE,MAAM;AAAA,EACR;AACF;AAEA,IAAO,8BAAQ;",
4
+ "sourcesContent": ["import { getHtmlDocument } from '@scalar/core/libs/html-rendering'\nimport { normalize, toJson, toYaml } from '@scalar/openapi-parser'\nimport type { OpenAPI } from '@scalar/openapi-types'\nimport type { FastifyBaseLogger, FastifyTypeProviderDefault, RawServerDefault } from 'fastify'\nimport fp from 'fastify-plugin'\nimport { slug } from 'github-slugger'\n\nimport type { ApiReferenceConfiguration, FastifyApiReferenceHooksOptions, FastifyApiReferenceOptions } from './types'\nimport { getJavaScriptFile } from './utils/getJavaScriptFile'\n\n/**\n * Path to the bundled Scalar JavaScript file\n */\nconst RELATIVE_JAVASCRIPT_PATH = 'js/scalar.js'\n\n/**\n * This Schema is used to hide the route from the documentation.\n *\n * We don't know whether `@fastify/swagger` is registered, but it doesn't hurt to add a schema anyway.\n *\n * @see https://github.com/fastify/fastify-swagger#hide-a-route\n */\nconst schemaToHideRoute = {\n hide: true,\n}\n\nconst getRoutePrefix = (routePrefix?: string) => {\n const prefix = routePrefix ?? '/reference'\n\n // Remove trailing slash if present\n return prefix.endsWith('/') ? prefix.slice(0, -1) : prefix\n}\n\n/**\n * Get the endpoints for the OpenAPI specification.\n */\nconst getOpenApiDocumentEndpoints = (\n openApiDocumentEndpoints: FastifyApiReferenceOptions['openApiDocumentEndpoints'],\n) => {\n const { json = '/openapi.json', yaml = '/openapi.yaml' } = openApiDocumentEndpoints ?? {}\n return { json, yaml }\n}\n\n/**\n * Get the URL for the Scalar JavaScript file.\n */\nconst getJavaScriptUrl = (routePrefix?: string) =>\n `${getRoutePrefix(routePrefix)}/${RELATIVE_JAVASCRIPT_PATH}`.replace(/\\/\\//g, '/')\n\n/**\n * The default configuration for Fastify\n */\nconst DEFAULT_CONFIGURATION: Partial<ApiReferenceConfiguration> = {\n _integration: 'fastify',\n}\n\nconst fastifyApiReference = fp<\n FastifyApiReferenceOptions,\n RawServerDefault,\n FastifyTypeProviderDefault,\n FastifyBaseLogger\n>(\n (fastify, options, next) => {\n const { configuration: givenConfiguration } = options\n\n // Merge the defaults\n let configuration = {\n ...DEFAULT_CONFIGURATION,\n ...givenConfiguration,\n }\n\n const specSource = (() => {\n const { content, url } = configuration ?? {}\n if (content) {\n return {\n type: 'content' as const,\n get: () => {\n if (typeof content === 'function') {\n return content()\n }\n return content\n },\n }\n }\n if (url) {\n return {\n type: 'url' as const,\n get: () => url,\n }\n }\n\n // Even if @fastify/swagger is loaded, when the `decorator` option is set, the `swagger` function is not available.\n if (fastify.hasPlugin('@fastify/swagger') && typeof fastify.swagger === 'function') {\n return {\n type: 'swagger' as const,\n get: () => fastify.swagger(),\n }\n }\n\n return void 0\n })()\n\n // If no OpenAPI specification is passed and @fastify/swagger isn't loaded, show a warning.\n if (!specSource && !configuration.sources) {\n fastify.log.warn(\n \"[@scalar/fastify-api-reference] You didn't provide a `content`, `url`, `sources` or @fastify/swagger could not be found. Please provide one of these options.\",\n )\n\n return next()\n }\n\n // Read the JavaScript file once.\n const fileContent = getJavaScriptFile()\n\n const hooks: FastifyApiReferenceHooksOptions = {}\n if (options.hooks) {\n const additionalHooks: (keyof FastifyApiReferenceHooksOptions)[] = ['onRequest', 'preHandler']\n\n for (const hook of additionalHooks) {\n if (options.hooks[hook]) {\n hooks[hook] = options.hooks[hook]\n }\n }\n }\n\n const getSpecFilenameSlug = (spec: OpenAPI.Document) => {\n // Same GitHub Slugger and default file name as in `@scalar/api-reference`, when generating the download\n return slug(spec?.specification?.info?.title ?? 'spec')\n }\n\n // Only expose the endpoints if specSource is available\n if (specSource) {\n const openApiSpecUrlJson = `${getRoutePrefix(options.routePrefix)}${getOpenApiDocumentEndpoints(options.openApiDocumentEndpoints).json}`\n fastify.route({\n method: 'GET',\n url: openApiSpecUrlJson,\n schema: schemaToHideRoute,\n ...hooks,\n ...(options.logLevel && { logLevel: options.logLevel }),\n handler(_, reply) {\n const spec = normalize(specSource.get())\n const filename = getSpecFilenameSlug(spec)\n const json = JSON.parse(toJson(spec)) // parsing minifies the JSON\n\n return reply\n .header('Content-Type', 'application/json')\n .header('Content-Disposition', `filename=${filename}.json`)\n .header('Access-Control-Allow-Origin', '*')\n .header('Access-Control-Allow-Methods', '*')\n .send(json)\n },\n })\n\n const openApiSpecUrlYaml = `${getRoutePrefix(options.routePrefix)}${getOpenApiDocumentEndpoints(options.openApiDocumentEndpoints).yaml}`\n fastify.route({\n method: 'GET',\n url: openApiSpecUrlYaml,\n schema: schemaToHideRoute,\n ...hooks,\n ...(options.logLevel && { logLevel: options.logLevel }),\n handler(_, reply) {\n const spec = normalize(specSource.get())\n const filename = getSpecFilenameSlug(spec)\n const yaml = toYaml(spec)\n return reply\n .header('Content-Type', 'application/yaml')\n .header('Content-Disposition', `filename=${filename}.yaml`)\n .header('Access-Control-Allow-Origin', '*')\n .header('Access-Control-Allow-Methods', '*')\n .send(yaml)\n },\n })\n }\n\n // Redirect route without a trailing slash to force a trailing slash:\n // We need this so the request to the JS file is relative.\n\n // With ignoreTrailingSlash: true, fastify responds to both routes anyway.\n const ignoreTrailingSlash =\n // @ts-expect-error We're still on Fastify 4, this is introduced in Fastify 5\n fastify.initialConfig?.routerOptions?.ignoreTrailingSlash === true ||\n fastify.initialConfig?.ignoreTrailingSlash === true\n\n if (!ignoreTrailingSlash && getRoutePrefix(options.routePrefix)) {\n fastify.route({\n method: 'GET',\n url: getRoutePrefix(options.routePrefix),\n schema: schemaToHideRoute,\n ...hooks,\n ...(options.logLevel && { logLevel: options.logLevel }),\n handler(request, reply) {\n // we are in a route without a trailing slash so redirect directly to the one with a trailing slash\n const currentUrl = new URL(request.url, `${request.protocol}://${request.hostname}`)\n return reply.redirect(`${currentUrl.pathname}/`, 301)\n },\n })\n }\n\n // If no theme is passed, use the default theme.\n fastify.route({\n method: 'GET',\n url: `${getRoutePrefix(options.routePrefix)}/`,\n // We don't know whether @fastify/swagger is registered, but it doesn't hurt to add a schema anyway.\n schema: schemaToHideRoute,\n ...hooks,\n ...(options.logLevel && { logLevel: options.logLevel }),\n handler(request, reply) {\n // Redirect if it's the route without a slash\n const currentUrl = new URL(request.url, `${request.protocol}://${request.hostname}`)\n if (!currentUrl.pathname.endsWith('/')) {\n return reply.redirect(`${currentUrl.pathname}/`, 301)\n }\n\n /**\n * Regardless of where we source the spec from, provide it as a URL, to have the\n * download button point to the exposed endpoint.\n * If the URL is explicitly passed, defer to that URL instead.\n */\n if (specSource && specSource.type !== 'url') {\n configuration = {\n ...configuration,\n // Use a relative URL in case we're proxied\n url: `.${getOpenApiDocumentEndpoints(options.openApiDocumentEndpoints).json}`,\n }\n }\n\n // Respond with the HTML document\n return reply.header('Content-Type', 'text/html; charset=utf-8').send(\n getHtmlDocument({\n // We're using the bundled JS here by default, but the user can pass a CDN URL.\n cdn: RELATIVE_JAVASCRIPT_PATH,\n ...configuration,\n }),\n )\n },\n })\n\n fastify.route({\n method: 'GET',\n url: getJavaScriptUrl(options.routePrefix),\n // We don't know whether @fastify/swagger is registered, but it doesn't hurt to add a schema anyway.\n schema: schemaToHideRoute,\n ...hooks,\n ...(options.logLevel && { logLevel: options.logLevel }),\n handler(_, reply) {\n return reply.header('Content-Type', 'application/javascript; charset=utf-8').send(fileContent)\n },\n })\n\n next()\n },\n {\n name: '@scalar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