@scalar/fastify-api-reference 1.25.19 → 1.25.20

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,
@@ -5,7 +5,7 @@
5
5
  * ___/ / /___/ ___ |/ /___/ ___ |/ _, _/
6
6
  * /____/\____/_/ |_/_____/_/ |_/_/ |_|
7
7
  *
8
- * @scalar/api-reference 1.25.19
8
+ * @scalar/api-reference 1.25.20
9
9
  *
10
10
  * Website: https://scalar.com
11
11
  * GitHub: https://github.com/scalar/scalar
@@ -0,0 +1,65 @@
1
+ import type { ReferenceConfiguration } from '@scalar/types/legacy';
2
+ import type { onRequestHookHandler, preHandlerHookHandler } from 'fastify';
3
+ export type FastifyApiReferenceOptions = {
4
+ /**
5
+ * If you’re prefixing Fastify with a path, you can set it here.
6
+ * It’ll be added to the JavaScript URL and the route.
7
+ *
8
+ * Example: `${publicPath}${routePrefix}/js/scalar.js`
9
+ * @deprecated We don't use this anymore.
10
+ */
11
+ publicPath?: string;
12
+ /**
13
+ * Prefix the route with a path. This is where the API Reference will be available.
14
+ *
15
+ * @default '/reference'
16
+ */
17
+ routePrefix?: `/${string}`;
18
+ /**
19
+ * Set where the OpenAPI specification is exposed under `${routePrefix}`.
20
+ *
21
+ * The specification is always available on these endpoints, parsed by `@scalar/openapi-parser`.
22
+ *
23
+ * The specification is sourced from, in order of precedence:
24
+ * - `configuration.spec.content`
25
+ * - `configuration.spec.url` – fetched via `@scalar/openapi-parser/plugins/fetch-urls`
26
+ * - `@fastify/swagger` – if `configuration.spec` is not provided
27
+ *
28
+ * These endpoints can be used to fetch the OpenAPI specification for your own programmatic use.
29
+ *
30
+ * @default{ json: '/openapi.json', yaml: '/openapi.yaml' }
31
+ */
32
+ openApiDocumentEndpoints?: {
33
+ /**
34
+ * Set where the OpenAPI specification is exposed under `${routePrefix}`, in JSON format.
35
+ *
36
+ * With the default value, the endpoint is: `${publicPath}${routePrefix}/openapi.json`
37
+ *
38
+ * @default '/openapi.json'
39
+ */
40
+ json?: `/${string}`;
41
+ /**
42
+ * Set where the OpenAPI specification is exposed under `${routePrefix}`, in YAML format.
43
+ *
44
+ * With the default value, the endpoint is: `${publicPath}${routePrefix}/openapi.yaml`
45
+ *
46
+ * @default '/openapi.yaml'
47
+ */
48
+ yaml?: `/${string}`;
49
+ };
50
+ /**
51
+ * The universal configuration object for @scalar/api-reference.
52
+ *
53
+ * Read more: https://github.com/scalar/scalar
54
+ */
55
+ configuration?: ReferenceConfiguration;
56
+ /**
57
+ * The hooks for the API Reference.
58
+ */
59
+ hooks?: FastifyApiReferenceHooksOptions;
60
+ };
61
+ export type FastifyApiReferenceHooksOptions = Partial<{
62
+ onRequest?: onRequestHookHandler;
63
+ preHandler?: preHandlerHookHandler;
64
+ }>;
65
+ //# sourceMappingURL=types.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"types.d.ts","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":"AAAA,OAAO,KAAK,EAAE,sBAAsB,EAAE,MAAM,sBAAsB,CAAA;AAClE,OAAO,KAAK,EAAE,oBAAoB,EAAE,qBAAqB,EAAE,MAAM,SAAS,CAAA;AAE1E,MAAM,MAAM,0BAA0B,GAAG;IACvC;;;;;;OAMG;IACH,UAAU,CAAC,EAAE,MAAM,CAAA;IACnB;;;;OAIG;IACH,WAAW,CAAC,EAAE,IAAI,MAAM,EAAE,CAAA;IAC1B;;;;;;;;;;;;;OAaG;IACH,wBAAwB,CAAC,EAAE;QACzB;;;;;;WAMG;QACH,IAAI,CAAC,EAAE,IAAI,MAAM,EAAE,CAAA;QACnB;;;;;;WAMG;QACH,IAAI,CAAC,EAAE,IAAI,MAAM,EAAE,CAAA;KACpB,CAAA;IACD;;;;OAIG;IACH,aAAa,CAAC,EAAE,sBAAsB,CAAA;IACtC;;OAEG;IACH,KAAK,CAAC,EAAE,+BAA+B,CAAA;CACxC,CAAA;AAED,MAAM,MAAM,+BAA+B,GAAG,OAAO,CAAC;IACpD,SAAS,CAAC,EAAE,oBAAoB,CAAA;IAChC,UAAU,CAAC,EAAE,qBAAqB,CAAA;CACnC,CAAC,CAAA"}
package/package.json CHANGED
@@ -17,7 +17,7 @@
17
17
  "openapi",
18
18
  "swagger"
19
19
  ],
20
- "version": "1.25.19",
20
+ "version": "1.25.20",
21
21
  "engines": {
22
22
  "node": ">=18"
23
23
  },
@@ -39,6 +39,7 @@
39
39
  },
40
40
  "devDependencies": {
41
41
  "@fastify/basic-auth": "^5.1.1",
42
+ "@fastify/http-proxy": "^9.0.0",
42
43
  "@fastify/swagger": "^8.10.1",
43
44
  "@vitest/coverage-v8": "^1.6.0",
44
45
  "fastify": "^4.26.2",
@@ -51,7 +52,7 @@
51
52
  "vitest": "^1.6.0",
52
53
  "vue": "^3.4.29",
53
54
  "yaml": "^2.4.5",
54
- "@scalar/api-reference": "1.25.19",
55
+ "@scalar/api-reference": "1.25.20",
55
56
  "@scalar/openapi-parser": "0.8.4"
56
57
  },
57
58
  "scripts": {