@scalar/fastify-api-reference 0.6.1 → 0.6.3

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.
@@ -9,11 +9,15 @@
9
9
  </head>
10
10
  <body>
11
11
  <% if (options.apiReference?.specUrl) { %>
12
- <div data-spec-url="<%= options.apiReference?.specUrl %>" />
12
+ <script id="api-reference" data-url="<%= options.apiReference?.specUrl %>"></script>
13
13
  <% } else if (typeof options.apiReference?.spec === 'object') { %>
14
- <div data-spec='<%= JSON.stringify(options.apiReference?.spec) %>' />
14
+ <script id="api-reference" type="application/json">
15
+ <%- JSON.stringify(options.apiReference?.spec) %>
16
+ </script>
15
17
  <% } else if (options.apiReference?.spec) { %>
16
- <div data-spec='<%= JSON.stringify(options.apiReference?.spec()) %>' />
18
+ <script id="api-reference" type="application/json">
19
+ <%- JSON.stringify(options.apiReference?.spec()) %>
20
+ </script>
17
21
  <% } %>
18
22
 
19
23
  <script type="module" src="<%= options.routePrefix %>/fastify-api-reference.js"></script>
package/package.json CHANGED
@@ -1,17 +1,19 @@
1
1
  {
2
2
  "name": "@scalar/fastify-api-reference",
3
3
  "description": "a fastify plugin to render an API reference from a Swagger spec",
4
- "version": "0.6.1",
4
+ "version": "0.6.3",
5
5
  "author": "Scalar (https://github.com/scalar)",
6
6
  "bugs": "https://github.com/scalar/scalar/issues/new",
7
7
  "dependencies": {
8
8
  "ejs": "3.1.9",
9
- "@scalar/api-reference": "0.6.2"
9
+ "@scalar/api-reference": "0.6.3"
10
10
  },
11
11
  "devDependencies": {
12
12
  "@vitejs/plugin-vue": "4.3.4",
13
13
  "@vitest/coverage-v8": "0.34.4",
14
+ "magic-string": "0.30.4",
14
15
  "nodemon": "3.0.1",
16
+ "rollup-plugin-node-externals": "6.1.1",
15
17
  "tsc-alias": "1.8.8",
16
18
  "typescript": "5.2.2",
17
19
  "vite": "4.4.9",
@@ -26,7 +28,8 @@
26
28
  "node": ">=18"
27
29
  },
28
30
  "exports": {
29
- "import": "./dist/index.js"
31
+ "import": "./dist/index.js",
32
+ "require": "./dist/index.cjs"
30
33
  },
31
34
  "files": [
32
35
  "dist"
@@ -40,7 +43,7 @@
40
43
  "swagger"
41
44
  ],
42
45
  "license": "MIT",
43
- "main": "./dist/index.umd.cjs",
46
+ "main": "./dist/index.cjs",
44
47
  "module": "./dist/index.js",
45
48
  "peerDependencies": {
46
49
  "@types/ejs": "3.1.3",
@@ -56,7 +59,7 @@
56
59
  "type": "module",
57
60
  "types": "dist/index.d.ts",
58
61
  "scripts": {
59
- "build": "vite build && pnpm run build:template && pnpm types:build && tsc-alias -p tsconfig.build.json",
62
+ "build": "vite build && pnpm run build:template && tsc -p tsconfig.build.json && tsc-alias -p tsconfig.build.json",
60
63
  "build:template": "vite build -c vite.template.config.ts",
61
64
  "lint:check": "eslint .",
62
65
  "lint:fix": "eslint . --fix",
@@ -1,24 +0,0 @@
1
- import ejs from 'ejs';
2
- import fp from 'fastify-plugin';
3
- import fs from 'fs';
4
- import path from 'path';
5
- const fastifyApiReference = async (fastify, options) => {
6
- if (!options.apiReference?.spec && !options.apiReference?.specUrl) {
7
- console.warn('[@scalar/fastify-api-reference] You didn’t provide a spec or specUrl. Please provide one of these options.');
8
- return;
9
- }
10
- fastify.get(options.routePrefix ?? '/', async (_, reply) => {
11
- reply.header('Content-Type', 'text/html; charset=utf-8');
12
- const html = await ejs.renderFile(path.resolve(`${__dirname}/templates/index.ejs`), {
13
- options,
14
- });
15
- reply.send(html);
16
- });
17
- console.log((options.routePrefix ?? '/') + '/fastify-api-reference.js');
18
- fastify.get((options.routePrefix ?? '/') + '/fastify-api-reference.js', async (_, reply) => {
19
- reply.header('Content-Type', 'application/javascript; charset=utf-8');
20
- const content = fs.readFileSync(path.resolve(`${__dirname}/../dist/templates/fastify-api-reference.js`), 'utf8');
21
- reply.send(content);
22
- });
23
- };
24
- export default fp(fastifyApiReference);
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=render.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"render.d.ts","sourceRoot":"","sources":["../../src/templates/render.ts"],"names":[],"mappings":""}
@@ -1,19 +0,0 @@
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
- }