@scalar/fastify-api-reference 1.25.19 → 1.25.21

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/dist/index.d.ts CHANGED
@@ -1,2 +1,3 @@
1
1
  export { default } from './fastifyApiReference';
2
+ export * from './types';
2
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,OAAO,EAAE,MAAM,uBAAuB,CAAA;AAC/C,cAAc,SAAS,CAAA"}
package/dist/index.js CHANGED
@@ -14252,12 +14252,16 @@ function getJavaScriptFile() {
14252
14252
  const schemaToHideRoute = {
14253
14253
  hide: true
14254
14254
  };
14255
- const getRoutePrefix = (routePrefix) => routePrefix ?? "/reference";
14255
+ const getRoutePrefix = (routePrefix) => {
14256
+ const prefix = routePrefix ?? "/reference";
14257
+ return prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
14258
+ };
14256
14259
  const getOpenApiDocumentEndpoints = (openApiDocumentEndpoints) => {
14257
14260
  const { json = "/openapi.json", yaml = "/openapi.yaml" } = openApiDocumentEndpoints ?? {};
14258
14261
  return { json, yaml };
14259
14262
  };
14260
- const getJavaScriptUrl = (routePrefix, publicPath) => `${publicPath ?? ""}${getRoutePrefix(routePrefix)}/@scalar/fastify-api-reference/js/browser.js`.replace(
14263
+ const RELATIVE_JAVASCRIPT_PATH = "js/scalar.js";
14264
+ const getJavaScriptUrl = (routePrefix) => `${getRoutePrefix(routePrefix)}/${RELATIVE_JAVASCRIPT_PATH}`.replace(
14261
14265
  /\/\//g,
14262
14266
  "/"
14263
14267
  );
@@ -14342,7 +14346,7 @@ const javascript = (options) => {
14342
14346
  id="api-reference"
14343
14347
  type="application/json"
14344
14348
  data-configuration="${JSON.stringify(configuration ?? {}).split('"').join("&quot;")}">${((_a = configuration == null ? void 0 : configuration.spec) == null ? void 0 : _a.content) ? typeof ((_b = configuration == null ? void 0 : configuration.spec) == null ? void 0 : _b.content) === "function" ? JSON.stringify((_c = configuration == null ? void 0 : configuration.spec) == null ? void 0 : _c.content()) : JSON.stringify((_d = configuration == null ? void 0 : configuration.spec) == null ? void 0 : _d.content) : ""}<\/script>
14345
- <script src="${getJavaScriptUrl(options.routePrefix, options.publicPath)}"><\/script>
14349
+ <script src="${RELATIVE_JAVASCRIPT_PATH}"><\/script>
14346
14350
  `;
14347
14351
  };
14348
14352
  function htmlDocument(options) {
@@ -14443,9 +14447,21 @@ const fastifyApiReference = fp(
14443
14447
  return reply.header("Content-Type", `application/yaml`).header("Content-Disposition", `filename=${filename}.yaml`).send(yaml);
14444
14448
  }
14445
14449
  });
14450
+ if (getRoutePrefix(options.routePrefix)) {
14451
+ fastify.route({
14452
+ method: "GET",
14453
+ url: getRoutePrefix(options.routePrefix),
14454
+ // @ts-ignore We don't know whether @fastify/swagger is loaded.
14455
+ schema: schemaToHideRoute,
14456
+ ...hooks,
14457
+ handler(_, reply) {
14458
+ return reply.redirect(getRoutePrefix(options.routePrefix) + "/", 302);
14459
+ }
14460
+ });
14461
+ }
14446
14462
  fastify.route({
14447
14463
  method: "GET",
14448
- url: getRoutePrefix(options.routePrefix),
14464
+ url: `${getRoutePrefix(options.routePrefix)}/`,
14449
14465
  // We don’t know whether @fastify/swagger is registered, but it doesn’t hurt to add a schema anyway.
14450
14466
  // @ts-ignore We don’t know whether @fastify/swagger is loaded.
14451
14467
  schema: schemaToHideRoute,