@scalar/fastify-api-reference 1.25.121 → 1.25.123

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.js CHANGED
@@ -5,6 +5,7 @@ import fp from "fastify-plugin";
5
5
  import fs from "node:fs";
6
6
  import path from "node:path";
7
7
  import { fileURLToPath } from "node:url";
8
+ import { getHtmlDocument } from "@scalar/api-reference/lib/html-rendering";
8
9
  var title$9 = "A JSON Schema for Swagger 2.0 API.";
9
10
  var id$3 = "http://swagger.io/v2/schema.json#";
10
11
  var $schema$c = "http://json-schema.org/draft-04/schema#";
@@ -18759,9 +18760,7 @@ class EnumValidationError extends BaseValidationError {
18759
18760
  const bestMatch = allowedValues.map((value) => ({
18760
18761
  value,
18761
18762
  weight: leven(value, currentValue.toString())
18762
- })).sort(
18763
- (x, y) => x.weight > y.weight ? 1 : x.weight < y.weight ? -1 : 0
18764
- )[0];
18763
+ })).sort((x, y) => x.weight > y.weight ? 1 : x.weight < y.weight ? -1 : 0)[0];
18765
18764
  return allowedValues.length === 1 || bestMatch.weight < bestMatch.value.length ? bestMatch.value : null;
18766
18765
  }
18767
18766
  }
@@ -19381,7 +19380,9 @@ function upgradeFromTwoToThree(originalSpecification) {
19381
19380
  }
19382
19381
  });
19383
19382
  } else {
19384
- Object.assign(specification.components.securitySchemes, { [key]: securityScheme });
19383
+ Object.assign(specification.components.securitySchemes, {
19384
+ [key]: securityScheme
19385
+ });
19385
19386
  }
19386
19387
  }
19387
19388
  }
@@ -19646,6 +19647,10 @@ function getJavaScriptFile() {
19646
19647
  }
19647
19648
  return fs.readFileSync(filePath, "utf8");
19648
19649
  }
19650
+ const RELATIVE_JAVASCRIPT_PATH = "js/scalar.js";
19651
+ const DEFAULT_CONFIGURATION = {
19652
+ _integration: "fastify"
19653
+ };
19649
19654
  const schemaToHideRoute = {
19650
19655
  hide: true
19651
19656
  };
@@ -19657,9 +19662,8 @@ const getOpenApiDocumentEndpoints = (openApiDocumentEndpoints) => {
19657
19662
  const { json = "/openapi.json", yaml = "/openapi.yaml" } = openApiDocumentEndpoints ?? {};
19658
19663
  return { json, yaml };
19659
19664
  };
19660
- const RELATIVE_JAVASCRIPT_PATH = "js/scalar.js";
19661
19665
  const getJavaScriptUrl = (routePrefix) => `${getRoutePrefix(routePrefix)}/${RELATIVE_JAVASCRIPT_PATH}`.replace(/\/\//g, "/");
19662
- const defaultCss = `
19666
+ const customTheme = `
19663
19667
  .light-mode {
19664
19668
  color-scheme: light;
19665
19669
  --scalar-color-1: #1c1e21;
@@ -19732,40 +19736,12 @@ const defaultCss = `
19732
19736
  --scalar-color-purple: #b191f9;
19733
19737
  }
19734
19738
  `;
19735
- const javascript = (options) => {
19736
- var _a, _b, _c, _d;
19737
- const { configuration } = options;
19738
- return `
19739
- <script
19740
- id="api-reference"
19741
- type="application/json"
19742
- 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>
19743
- <script src="${RELATIVE_JAVASCRIPT_PATH}"><\/script>
19744
- `;
19745
- };
19746
- function htmlDocument(options) {
19747
- return `
19748
- <!DOCTYPE html>
19749
- <html>
19750
- <head>
19751
- <title>Scalar API Reference</title>
19752
- <meta charset="utf-8" />
19753
- <meta
19754
- name="viewport"
19755
- content="width=device-width, initial-scale=1" />
19756
- </head>
19757
- <body>
19758
- ${javascript(options)}
19759
- </body>
19760
- </html>
19761
- `;
19762
- }
19763
19739
  const fastifyApiReference = fp(
19764
19740
  async (fastify, options) => {
19765
- let { configuration } = options;
19766
- configuration = {
19767
- _integration: "fastify",
19768
- ...configuration
19741
+ const { configuration: givenConfiguration } = options;
19742
+ let configuration = {
19743
+ ...DEFAULT_CONFIGURATION,
19744
+ ...givenConfiguration
19769
19745
  };
19770
19746
  const specSource = (() => {
19771
19747
  const { content: content2, url } = (configuration == null ? void 0 : configuration.spec) ?? {};
@@ -19872,7 +19848,6 @@ const fastifyApiReference = fp(
19872
19848
  }
19873
19849
  if (specSource.type !== "url") {
19874
19850
  configuration = {
19875
- _integration: "fastify",
19876
19851
  ...configuration,
19877
19852
  spec: {
19878
19853
  // Use a relative URL in case we're proxied
@@ -19880,14 +19855,16 @@ const fastifyApiReference = fp(
19880
19855
  }
19881
19856
  };
19882
19857
  }
19883
- if (!(configuration == null ? void 0 : configuration.customCss) && !(configuration == null ? void 0 : configuration.theme)) {
19884
- configuration = {
19885
- _integration: "fastify",
19886
- ...configuration,
19887
- customCss: defaultCss
19888
- };
19889
- }
19890
- return reply.header("Content-Type", "text/html; charset=utf-8").send(htmlDocument({ ...options, configuration }));
19858
+ return reply.header("Content-Type", "text/html; charset=utf-8").send(
19859
+ getHtmlDocument(
19860
+ {
19861
+ // We’re using the bundled JS here by default, but the user can pass a CDN URL.
19862
+ cdn: RELATIVE_JAVASCRIPT_PATH,
19863
+ ...configuration
19864
+ },
19865
+ customTheme
19866
+ )
19867
+ );
19891
19868
  }
19892
19869
  });
19893
19870
  fastify.route({