@scalar/fastify-api-reference 0.6.0 → 0.6.1

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.
@@ -0,0 +1,21 @@
1
+ <!DOCTYPE html>
2
+ <html>
3
+ <head>
4
+ <title><%= options.apiReference.title || 'API Reference' %></title>
5
+ <meta charset="utf-8" />
6
+ <meta
7
+ name="viewport"
8
+ content="width=device-width, initial-scale=1" />
9
+ </head>
10
+ <body>
11
+ <% if (options.apiReference?.specUrl) { %>
12
+ <div data-spec-url="<%= options.apiReference?.specUrl %>" />
13
+ <% } else if (typeof options.apiReference?.spec === 'object') { %>
14
+ <div data-spec='<%= JSON.stringify(options.apiReference?.spec) %>' />
15
+ <% } else if (options.apiReference?.spec) { %>
16
+ <div data-spec='<%= JSON.stringify(options.apiReference?.spec()) %>' />
17
+ <% } %>
18
+
19
+ <script type="module" src="<%= options.routePrefix %>/fastify-api-reference.js"></script>
20
+ </body>
21
+ </html>
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=render.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/templates/render.ts"],"names":[],"mappings":""}
@@ -0,0 +1,19 @@
1
+ import { ApiReference } from '@scalar/api-reference';
2
+ import { createApp } from 'vue';
3
+ const specElement = document.querySelector('[data-spec]');
4
+ const specUrlElement = document.querySelector('[data-spec-url]');
5
+ if (!specUrlElement && !specElement) {
6
+ console.error('Couldn’t find a [data-spec] or [data-spec-url] element. Try adding it like this: %c<div data-spec-url="https://petstore.swagger.io/v2/swagger.json" />', 'font-family: monospace;');
7
+ }
8
+ else {
9
+ const properties = specElement
10
+ ? {
11
+ spec: specElement.getAttribute('data-spec'),
12
+ }
13
+ : {
14
+ specUrl: specUrlElement?.getAttribute('data-spec-url') ?? '',
15
+ };
16
+ document.querySelector('body')?.classList.add('light-mode');
17
+ const container = specElement ? '[data-spec]' : '[data-spec-url]';
18
+ createApp(ApiReference, properties).mount(container);
19
+ }
package/package.json CHANGED
@@ -1,23 +1,31 @@
1
1
  {
2
2
  "name": "@scalar/fastify-api-reference",
3
- "description": "a fastify plugin to render an API reference from an automatically generated OpenAPI spec",
4
- "version": "0.6.0",
3
+ "description": "a fastify plugin to render an API reference from a Swagger spec",
4
+ "version": "0.6.1",
5
5
  "author": "Scalar (https://github.com/scalar)",
6
6
  "bugs": "https://github.com/scalar/scalar/issues/new",
7
+ "dependencies": {
8
+ "ejs": "3.1.9",
9
+ "@scalar/api-reference": "0.6.2"
10
+ },
7
11
  "devDependencies": {
12
+ "@vitejs/plugin-vue": "4.3.4",
8
13
  "@vitest/coverage-v8": "0.34.4",
9
14
  "nodemon": "3.0.1",
10
15
  "tsc-alias": "1.8.8",
11
16
  "typescript": "5.2.2",
12
17
  "vite": "4.4.9",
13
18
  "vite-node": "0.34.4",
19
+ "vite-plugin-css-injected-by-js": "3.3.0",
20
+ "vite-plugin-node-polyfills": "0.14.1",
21
+ "vite-plugin-singlefile": "0.13.5",
22
+ "vite-plugin-static-copy": "0.17.0",
14
23
  "vitest": "0.34.4"
15
24
  },
16
25
  "engines": {
17
26
  "node": ">=18"
18
27
  },
19
28
  "exports": {
20
- "require": "./dist/index.umd.cjs",
21
29
  "import": "./dist/index.js"
22
30
  },
23
31
  "files": [
@@ -35,8 +43,10 @@
35
43
  "main": "./dist/index.umd.cjs",
36
44
  "module": "./dist/index.js",
37
45
  "peerDependencies": {
46
+ "@types/ejs": "3.1.3",
38
47
  "fastify": "4.23.2",
39
- "fastify-plugin": "4.5.1"
48
+ "fastify-plugin": "4.5.1",
49
+ "vue": "3.3.4"
40
50
  },
41
51
  "repository": {
42
52
  "type": "git",
@@ -46,10 +56,11 @@
46
56
  "type": "module",
47
57
  "types": "dist/index.d.ts",
48
58
  "scripts": {
49
- "build": "vite build && pnpm types:build && tsc-alias -p tsconfig.build.json",
59
+ "build": "vite build && pnpm run build:template && pnpm types:build && tsc-alias -p tsconfig.build.json",
60
+ "build:template": "vite build -c vite.template.config.ts",
50
61
  "lint:check": "eslint .",
51
62
  "lint:fix": "eslint . --fix",
52
- "test": "pnpm build && vitest",
63
+ "test": "vitest",
53
64
  "types:build": "tsc -p tsconfig.build.json",
54
65
  "types:check": "tsc --noEmit --skipLibCheck"
55
66
  }
@@ -1,17 +0,0 @@
1
- (function(s,c){typeof exports=="object"&&typeof module<"u"?module.exports=c():typeof define=="function"&&define.amd?define(c):(s=typeof globalThis<"u"?globalThis:s||self,s["@scalar/fastify-api-reference"]=c())})(this,function(){"use strict";function s(e){return e&&e.__esModule&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e}var c={exports:{}},l={exports:{}};const d=/at\s{1}(?:.*\.)?plugin\s{1}.*\n\s*(.*)/,m=/(\w*(\.\w*)*)\..*/;l.exports=function(t){if(t.name.length>0)return t.name;const r=Error.stackTraceLimit;Error.stackTraceLimit=10;try{throw new Error("anonymous function")}catch(a){return Error.stackTraceLimit=r,u(a.stack)}};function u(e){const t=e.match(d);return t?t[1].split(/[/\\]/).slice(-1)[0].match(m)[1]:"anonymous"}l.exports.extractPluginName=u;var y=l.exports,g=function(t){return t[0]==="@"&&(t=t.slice(1).replace("/","-")),t.replace(/-(.)/g,function(a,i){return i.toUpperCase()})};const h=y,w=g;let x=0;function o(e,t={}){let r=!1;if(typeof e.default<"u"&&(e=e.default),typeof e!="function")throw new TypeError(`fastify-plugin expects a function, instead got a '${typeof e}'`);if(typeof t=="string"&&(t={fastify:t}),typeof t!="object"||Array.isArray(t)||t===null)throw new TypeError("The options object should be an object");if(t.fastify!==void 0&&typeof t.fastify!="string")throw new TypeError(`fastify-plugin expects a version string, instead got '${typeof t.fastify}'`);t.name||(r=!0,t.name=h(e)+"-auto-"+x++),e[Symbol.for("skip-override")]=t.encapsulate!==!0,e[Symbol.for("fastify.display-name")]=t.name,e[Symbol.for("plugin-meta")]=t,e.default||(e.default=e);const a=w(t.name);return!r&&!e[a]&&(e[a]=e),e}c.exports=o,c.exports.default=o,c.exports.fastifyPlugin=o;var P=c.exports;const R=s(P),v=e=>{var r,a,i,n,p,f;const t=(r=e.apiReference)!=null&&r.specUrl?`<div data-spec-url="${(a=e.apiReference)==null?void 0:a.specUrl}" />`:typeof((i=e.apiReference)==null?void 0:i.spec)=="object"?`<div data-spec='${JSON.stringify((n=e.apiReference)==null?void 0:n.spec)}' />`:(p=e.apiReference)!=null&&p.spec?`<div data-spec='${JSON.stringify((f=e.apiReference)==null?void 0:f.spec())}' />`:"";return`
2
- <!DOCTYPE html>
3
- <html>
4
- <head>
5
- <title>${e.apiReference.title||"API Reference"}</title>
6
- <meta charset="utf-8" />
7
- <meta
8
- name="viewport"
9
- content="width=device-width, initial-scale=1" />
10
- </head>
11
- <body>
12
- <!-- Add your own OpenAPI/Swagger spec file URL here: -->
13
- ${t}
14
- <script src="https://www.unpkg.com/@scalar/api-reference"><\/script>
15
- </body>
16
- </html>
17
- `};return R(async(e,t)=>{var r,a;if(!((r=t.apiReference)!=null&&r.spec)&&!((a=t.apiReference)!=null&&a.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,n,p,f)=>{n.header("Content-Type","text/html; charset=utf-8"),f()}),e.get(t.routePrefix??"/",async(i,n)=>{n.send(v(t))})})});