@scalar/fastify-api-reference 0.4.2 → 0.5.0

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/README.md CHANGED
@@ -20,7 +20,7 @@ If you have a OpenAPI/Swagger file already, you can pass an URL to the plugin:
20
20
  ```ts
21
21
  // Render an API reference for a given OpenAPI/Swagger spec URL
22
22
  fastify.register(require('@scalar/fastify-api-reference'), {
23
- prefix: '/api-reference',
23
+ prefix: '/reference',
24
24
  apiReference: {
25
25
  title: 'Our API Reference',
26
26
  specUrl: '/swagger.json',
@@ -32,9 +32,20 @@ With the [@fastify/swagger](https://github.com/fastify/fastify-swagger) you can
32
32
 
33
33
  ```ts
34
34
  await fastify.register(require('@scalar/fastify-api-reference'), {
35
- prefix: '/api-reference',
35
+ prefix: '/reference',
36
36
  apiReference: {
37
- spec: fastify.swagger(),
37
+ spec: () => fastify.swagger(),
38
+ },
39
+ })
40
+ ```
41
+
42
+ Or, if you just have a static OpenAPI spec, you can directly pass it, too:
43
+
44
+ ```ts
45
+ await fastify.register(require('@scalar/fastify-api-reference'), {
46
+ prefix: '/reference',
47
+ apiReference: {
48
+ spec: { … },
38
49
  },
39
50
  })
40
51
  ```
@@ -5,7 +5,7 @@ export type ApiReferencePlugin = {
5
5
  export type ApiReferenceOptions = {
6
6
  title?: string;
7
7
  specUrl?: string;
8
- spec?: Record<string, any>;
8
+ spec?: Record<string, any> | (() => Record<string, any>);
9
9
  };
10
10
  declare const fastifyApiReferencePlugin: FastifyPluginAsync<ApiReferencePlugin>;
11
11
  export default fastifyApiReferencePlugin;
@@ -1 +1 @@
1
- {"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AACA,OAAO,EAAE,KAAK,kBAAkB,EAA6B,MAAM,SAAS,CAAA;AAE5E,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,EAAE,mBAAmB,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAA;CAC3B,CAAA;AA0BD,QAAA,MAAM,yBAAyB,EAAE,kBAAkB,CACjD,kBAAkB,CAoBnB,CAAA;AAED,eAAe,yBAAyB,CAAA"}
1
+ {"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AAAA,OAAO,EAEL,KAAK,kBAAkB,EAExB,MAAM,SAAS,CAAA;AAEhB,MAAM,MAAM,kBAAkB,GAAG;IAC/B,YAAY,EAAE,mBAAmB,CAAA;CAClC,CAAA;AAED,MAAM,MAAM,mBAAmB,GAAG;IAChC,KAAK,CAAC,EAAE,MAAM,CAAA;IACd,OAAO,CAAC,EAAE,MAAM,CAAA;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;CACzD,CAAA;AA8BD,QAAA,MAAM,yBAAyB,EAAE,kBAAkB,CACjD,kBAAkB,CAuBnB,CAAA;AAED,eAAe,yBAAyB,CAAA"}
package/dist/index.js CHANGED
@@ -1,5 +1,5 @@
1
- const l = (e) => {
2
- const t = e.specUrl ? `<div data-spec-url="${e.specUrl}" />` : `<div data-spec='${JSON.stringify(e.spec)}' />`;
1
+ const d = (e) => {
2
+ const t = e.specUrl ? `<div data-spec-url="${e.specUrl}" />` : typeof e.spec == "object" ? `<div data-spec='${JSON.stringify(e.spec)}' />` : e.spec ? `<div data-spec='${JSON.stringify(e.spec())}' />` : "";
3
3
  return `
4
4
  <!DOCTYPE html>
5
5
  <html>
@@ -17,20 +17,20 @@ const l = (e) => {
17
17
  </body>
18
18
  </html>
19
19
  `;
20
- }, n = async (e, t) => {
20
+ }, l = async (e, t) => {
21
21
  if (!t.apiReference.spec && !t.apiReference.specUrl) {
22
22
  console.warn(
23
23
  "[@scalar/fastify-api-reference] You didn’t provide a spec or specUrl. Please provide one of these options."
24
24
  );
25
25
  return;
26
26
  }
27
- e.addHook("onSend", (c, a, r, d) => {
28
- a.header("Content-Type", "text/html; charset=utf-8"), d();
29
- }), e.get("/", (c, a) => {
30
- const r = l(t == null ? void 0 : t.apiReference);
31
- a.send(r);
27
+ e.addHook("onSend", (r, a, c, s) => {
28
+ a.header("Content-Type", "text/html; charset=utf-8"), s();
29
+ }), e.get("/", async (r, a) => {
30
+ const c = d(t == null ? void 0 : t.apiReference);
31
+ a.send(c);
32
32
  });
33
33
  };
34
34
  export {
35
- n as default
35
+ l as default
36
36
  };
@@ -1,4 +1,4 @@
1
- (function(r,n){typeof exports=="object"&&typeof module<"u"?module.exports=n():typeof define=="function"&&define.amd?define(n):(r=typeof globalThis<"u"?globalThis:r||self,r["@scalar/fastify-api-reference"]=n())})(this,function(){"use strict";const r=e=>{const t=e.specUrl?`<div data-spec-url="${e.specUrl}" />`:`<div data-spec='${JSON.stringify(e.spec)}' />`;return`
1
+ (function(c,r){typeof exports=="object"&&typeof module<"u"?module.exports=r():typeof define=="function"&&define.amd?define(r):(c=typeof globalThis<"u"?globalThis:c||self,c["@scalar/fastify-api-reference"]=r())})(this,function(){"use strict";const c=e=>{const t=e.specUrl?`<div data-spec-url="${e.specUrl}" />`:typeof e.spec=="object"?`<div data-spec='${JSON.stringify(e.spec)}' />`:e.spec?`<div data-spec='${JSON.stringify(e.spec())}' />`:"";return`
2
2
  <!DOCTYPE html>
3
3
  <html>
4
4
  <head>
@@ -14,4 +14,4 @@
14
14
  <script src="https://cdn.scalar.com/api-reference.standalone.js"><\/script>
15
15
  </body>
16
16
  </html>
17
- `};return async(e,t)=>{if(!t.apiReference.spec&&!t.apiReference.specUrl){console.warn("[@scalar/fastify-api-reference] You didn’t provide a spec or specUrl. Please provide one of these options.");return}e.addHook("onSend",(i,c,a,s)=>{c.header("Content-Type","text/html; charset=utf-8"),s()}),e.get("/",(i,c)=>{const a=r(t==null?void 0:t.apiReference);c.send(a)})}});
17
+ `};return async(e,t)=>{if(!t.apiReference.spec&&!t.apiReference.specUrl){console.warn("[@scalar/fastify-api-reference] You didn’t provide a spec or specUrl. Please provide one of these options.");return}e.addHook("onSend",(s,a,n,i)=>{a.header("Content-Type","text/html; charset=utf-8"),i()}),e.get("/",async(s,a)=>{const n=c(t==null?void 0:t.apiReference);a.send(n)})}});
package/package.json CHANGED
@@ -1,51 +1,49 @@
1
1
  {
2
2
  "name": "@scalar/fastify-api-reference",
3
3
  "description": "a fastify plugin to render an API reference from an automatically generated OpenAPI spec",
4
- "keywords": [
5
- "fastify",
6
- "openapi",
7
- "swagger",
8
- "api",
9
- "documentation"
10
- ],
11
- "version": "0.4.2",
4
+ "version": "0.5.0",
12
5
  "author": "Scalar (https://github.com/scalar)",
13
- "homepage": "https://github.com/scalar/scalar",
14
- "repository": {
15
- "type": "git",
16
- "url": "https://github.com/scalar/scalar.git",
17
- "directory": "packages/fastify-api-reference"
6
+ "bugs": "https://github.com/scalar/scalar/issues/new",
7
+ "dependencies": {
8
+ "fastify": "4.23.2"
18
9
  },
19
- "bugs": {
20
- "url": "https://github.com/scalar/scalar/issues/new"
10
+ "devDependencies": {
11
+ "@vitest/coverage-v8": "0.34.4",
12
+ "nodemon": "3.0.1",
13
+ "tsc-alias": "1.8.8",
14
+ "typescript": "5.2.2",
15
+ "vite": "4.4.9",
16
+ "vite-node": "0.34.4",
17
+ "vitest": "0.34.4"
21
18
  },
22
- "license": "MIT",
23
19
  "engines": {
24
20
  "node": ">=18"
25
21
  },
26
- "type": "module",
22
+ "exports": {
23
+ "require": "./dist/index.umd.cjs",
24
+ "import": "./dist/index.js"
25
+ },
27
26
  "files": [
28
27
  "dist"
29
28
  ],
29
+ "homepage": "https://github.com/scalar/scalar",
30
+ "keywords": [
31
+ "api",
32
+ "documentation",
33
+ "fastify",
34
+ "openapi",
35
+ "swagger"
36
+ ],
37
+ "license": "MIT",
30
38
  "main": "./dist/index.umd.cjs",
31
39
  "module": "./dist/index.js",
32
- "exports": {
33
- "require": "./dist/index.umd.cjs",
34
- "import": "./dist/index.js"
40
+ "repository": {
41
+ "type": "git",
42
+ "url": "https://github.com/scalar/scalar.git",
43
+ "directory": "packages/fastify-api-reference"
35
44
  },
45
+ "type": "module",
36
46
  "types": "dist/index.d.ts",
37
- "dependencies": {
38
- "fastify": "^4.22.1"
39
- },
40
- "devDependencies": {
41
- "nodemon": "^3.0.1",
42
- "tsc-alias": "1.8.6",
43
- "typescript": "^5.2.2",
44
- "vite": "4.4.8",
45
- "vite-node": "^0.34.3",
46
- "vitest": "0.34.1",
47
- "@vitest/coverage-v8": "^0.34.4"
48
- },
49
47
  "scripts": {
50
48
  "build": "vite build && pnpm types:build && tsc-alias -p tsconfig.build.json",
51
49
  "lint:check": "eslint .",