@scalar/fastify-api-reference 1.25.18 → 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
@@ -14109,33 +14109,39 @@ function t$5(t5) {
14109
14109
  return ((_a2 = e4.$ref) == null ? void 0 : _a2.startsWith("#/definitions/")) && (e4.$ref = e4.$ref.replace(/^#\/definitions\//, "#/components/schemas/")), e4;
14110
14110
  })), t5.paths) {
14111
14111
  for (const e4 in t5.paths) if (Object.hasOwn(t5.paths, e4)) {
14112
- const s2 = t5.paths[e4];
14113
- for (const e5 in s2) if (Object.hasOwn(s2, e5)) {
14114
- const o2 = s2[e5];
14115
- if (o2.parameters) {
14116
- const e6 = structuredClone(o2.parameters.find((e7) => "body" === e7.in) ?? {});
14112
+ const o2 = t5.paths[e4];
14113
+ for (const e5 in o2) if (Object.hasOwn(o2, e5)) {
14114
+ const s2 = o2[e5];
14115
+ if (s2.parameters) {
14116
+ const e6 = structuredClone(s2.parameters.find((e7) => "body" === e7.in) ?? {});
14117
14117
  if (e6 && Object.keys(e6).length) {
14118
14118
  delete e6.name, delete e6.in;
14119
- const s3 = t5.consumes ?? o2.consumes ?? ["application/json"];
14120
- "object" != typeof o2.requestBody && (o2.requestBody = {}), "object" != typeof o2.requestBody.content && (o2.requestBody.content = {});
14119
+ const o4 = t5.consumes ?? s2.consumes ?? ["application/json"];
14120
+ "object" != typeof s2.requestBody && (s2.requestBody = {}), "object" != typeof s2.requestBody.content && (s2.requestBody.content = {});
14121
14121
  const { schema: n2, ...r3 } = e6;
14122
- o2.requestBody = { ...o2.requestBody, ...r3 };
14123
- for (const e7 of s3) o2.requestBody.content[e7] = { schema: n2 };
14122
+ s2.requestBody = { ...s2.requestBody, ...r3 };
14123
+ for (const e7 of o4) s2.requestBody.content[e7] = { schema: n2 };
14124
+ }
14125
+ s2.parameters = s2.parameters.filter((e7) => "body" !== e7.in), delete s2.consumes;
14126
+ const o3 = s2.parameters.filter((e7) => "formData" === e7.in);
14127
+ if (o3.length > 0) {
14128
+ "object" != typeof s2.requestBody && (s2.requestBody = {}), "object" != typeof s2.requestBody.content && (s2.requestBody.content = {}), s2.requestBody.content["application/x-www-form-urlencoded"] = { schema: { type: "object", properties: {}, required: [] } };
14129
+ for (const e7 of o3) s2.requestBody.content["application/x-www-form-urlencoded"].schema.properties[e7.name] = { type: e7.type, description: e7.description }, e7.required && s2.requestBody.content["application/x-www-form-urlencoded"].schema.required.push(e7.name);
14130
+ s2.parameters = s2.parameters.filter((e7) => "formData" !== e7.in);
14124
14131
  }
14125
- o2.parameters = o2.parameters.filter((e7) => "body" !== e7.in), delete o2.consumes;
14126
14132
  }
14127
- if (o2.responses) {
14128
- for (const e6 in o2.responses) if (Object.hasOwn(o2.responses, e6)) {
14129
- const s3 = o2.responses[e6];
14130
- if (s3.schema) {
14131
- const e7 = t5.produces ?? o2.produces ?? ["application/json"];
14132
- "object" != typeof s3.content && (s3.content = {});
14133
- for (const t6 of e7) s3.content[t6] = { schema: s3.schema };
14134
- delete s3.schema;
14133
+ if (s2.responses) {
14134
+ for (const e6 in s2.responses) if (Object.hasOwn(s2.responses, e6)) {
14135
+ const o3 = s2.responses[e6];
14136
+ if (o3.schema) {
14137
+ const e7 = t5.produces ?? s2.produces ?? ["application/json"];
14138
+ "object" != typeof o3.content && (o3.content = {});
14139
+ for (const t6 of e7) o3.content[t6] = { schema: o3.schema };
14140
+ delete o3.schema;
14135
14141
  }
14136
14142
  }
14137
14143
  }
14138
- delete o2.produces, 0 === ((_c = o2.parameters) == null ? void 0 : _c.length) && delete o2.parameters;
14144
+ delete s2.produces, 0 === ((_c = s2.parameters) == null ? void 0 : _c.length) && delete s2.parameters;
14139
14145
  }
14140
14146
  }
14141
14147
  }
@@ -14246,12 +14252,16 @@ function getJavaScriptFile() {
14246
14252
  const schemaToHideRoute = {
14247
14253
  hide: true
14248
14254
  };
14249
- const getRoutePrefix = (routePrefix) => routePrefix ?? "/reference";
14255
+ const getRoutePrefix = (routePrefix) => {
14256
+ const prefix = routePrefix ?? "/reference";
14257
+ return prefix.endsWith("/") ? prefix.slice(0, -1) : prefix;
14258
+ };
14250
14259
  const getOpenApiDocumentEndpoints = (openApiDocumentEndpoints) => {
14251
14260
  const { json = "/openapi.json", yaml = "/openapi.yaml" } = openApiDocumentEndpoints ?? {};
14252
14261
  return { json, yaml };
14253
14262
  };
14254
- 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(
14255
14265
  /\/\//g,
14256
14266
  "/"
14257
14267
  );
@@ -14336,7 +14346,7 @@ const javascript = (options) => {
14336
14346
  id="api-reference"
14337
14347
  type="application/json"
14338
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>
14339
- <script src="${getJavaScriptUrl(options.routePrefix, options.publicPath)}"><\/script>
14349
+ <script src="${RELATIVE_JAVASCRIPT_PATH}"><\/script>
14340
14350
  `;
14341
14351
  };
14342
14352
  function htmlDocument(options) {
@@ -14437,9 +14447,21 @@ const fastifyApiReference = fp(
14437
14447
  return reply.header("Content-Type", `application/yaml`).header("Content-Disposition", `filename=${filename}.yaml`).send(yaml);
14438
14448
  }
14439
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
+ }
14440
14462
  fastify.route({
14441
14463
  method: "GET",
14442
- url: getRoutePrefix(options.routePrefix),
14464
+ url: `${getRoutePrefix(options.routePrefix)}/`,
14443
14465
  // We don’t know whether @fastify/swagger is registered, but it doesn’t hurt to add a schema anyway.
14444
14466
  // @ts-ignore We don’t know whether @fastify/swagger is loaded.
14445
14467
  schema: schemaToHideRoute,
@@ -5,7 +5,7 @@
5
5
  * ___/ / /___/ ___ |/ /___/ ___ |/ _, _/
6
6
  * /____/\____/_/ |_/_____/_/ |_/_/ |_|
7
7
  *
8
- * @scalar/api-reference 1.25.18
8
+ * @scalar/api-reference 1.25.20
9
9
  *
10
10
  * Website: https://scalar.com
11
11
  * GitHub: https://github.com/scalar/scalar
@@ -11889,7 +11889,16 @@ const t=structuredClone(o.parameters.find((e=>"body"===e.in))??{})
11889
11889
  "object"!=typeof o.requestBody.content&&(o.requestBody.content={})
11890
11890
  ;const{schema:r,...a}=t;o.requestBody={...o.requestBody,...a}
11891
11891
  ;for(const e of n)o.requestBody.content[e]={schema:r}}
11892
- o.parameters=o.parameters.filter((e=>"body"!==e.in)),delete o.consumes}
11892
+ o.parameters=o.parameters.filter((e=>"body"!==e.in)),delete o.consumes
11893
+ ;const n=o.parameters.filter((e=>"formData"===e.in));if(n.length>0){
11894
+ "object"!=typeof o.requestBody&&(o.requestBody={}),
11895
+ "object"!=typeof o.requestBody.content&&(o.requestBody.content={}),
11896
+ o.requestBody.content["application/x-www-form-urlencoded"]={schema:{
11897
+ type:"object",properties:{},required:[]}}
11898
+ ;for(const e of n)o.requestBody.content["application/x-www-form-urlencoded"].schema.properties[e.name]={
11899
+ type:e.type,description:e.description
11900
+ },e.required&&o.requestBody.content["application/x-www-form-urlencoded"].schema.required.push(e.name)
11901
+ ;o.parameters=o.parameters.filter((e=>"formData"!==e.in))}}
11893
11902
  if(o.responses)for(const t in o.responses)if(Object.hasOwn(o.responses,t)){
11894
11903
  const n=o.responses[t];if(n.schema){
11895
11904
  const t=e.produces??o.produces??["application/json"]
@@ -26741,7 +26750,7 @@ default:Tr((()=>[ei("span",qOe,st(a.value||"Select a value"),1),ti(Fn(kZ),{
26741
26750
  icon:"ChevronDown",size:"xs"})])),_:1})])),_:1},8,["value"]))]))}})
26742
26751
  ;function VOe(e){return e.flatMap((e=>{if("value"===e.key)try{
26743
26752
  const t=JSON.parse(e.value);return Object.keys(t).map((e=>({key:e,value:t[e]})))
26744
- }catch{}return[]}))}
26753
+ }catch{}return[e]}))}
26745
26754
  var WOe=Object.defineProperty,XOe=(e,t,n)=>((e,t,n)=>t in e?WOe(e,t,{
26746
26755
  enumerable:!0,configurable:!0,writable:!0,value:n
26747
26756
  }):e[t]=n)(e,"symbol"!=typeof t?t+"":t,n);let YOe=class e extends jie{
@@ -28382,10 +28391,10 @@ r.delete(e),o.value===e&&(o.value=null)})(e.uid)
28382
28391
  button:Tr((()=>[ti(Rxe,{click:s},{title:Tr((()=>[oi("Add Environment")])),_:1
28383
28392
  })])),_:1}),ti(Wne,{class:"flex-1"},{default:Tr((()=>[ti(Lre,null,Jr({
28384
28393
  default:Tr((()=>[o.value?(za(),Xa(lye,{key:0,class:"pl-px pr-2 md:px-2 py-2.5",
28385
- lineNumbers:"",modelValue:Fn(n)[o.value].value,"onUpdate:modelValue":l
28386
- },null,8,["modelValue"])):ii("",!0)])),_:2},[o.value?{name:"title",
28387
- fn:Tr((()=>[!i.value||Fn(n)[o.value].isDefault?(za(),Wa("span",{key:0,
28388
- onDblclick:u},st(Fn(n)[o.value].name),33)):(za(),Wa("input",{key:1,
28394
+ language:"json",lineNumbers:"",modelValue:Fn(n)[o.value].value,
28395
+ "onUpdate:modelValue":l},null,8,["modelValue"])):ii("",!0)])),_:2},[o.value?{
28396
+ name:"title",fn:Tr((()=>[!i.value||Fn(n)[o.value].isDefault?(za(),Wa("span",{
28397
+ key:0,onDblclick:u},st(Fn(n)[o.value].name),33)):(za(),Wa("input",{key:1,
28389
28398
  ref_key:"nameInputRef",ref:a,
28390
28399
  class:"ring-1 ring-offset-4 ring-b-outline rounded",spellcheck:"false",
28391
28400
  type:"text",value:Fn(n)[o.value].name,onBlur:t[0]||(t[0]=e=>i.value=!1),
@@ -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.18",
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,8 +52,8 @@
51
52
  "vitest": "^1.6.0",
52
53
  "vue": "^3.4.29",
53
54
  "yaml": "^2.4.5",
54
- "@scalar/api-reference": "1.25.18",
55
- "@scalar/openapi-parser": "0.8.3"
55
+ "@scalar/api-reference": "1.25.20",
56
+ "@scalar/openapi-parser": "0.8.4"
56
57
  },
57
58
  "scripts": {
58
59
  "build": "vite build && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",