@scalar/fastify-api-reference 0.6.8 → 0.6.12
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/CHANGELOG.md +29 -0
- package/README.md +8 -0
- package/dist/fastifyApiReference.d.ts +1 -1
- package/dist/fastifyApiReference.d.ts.map +1 -1
- package/dist/index.cjs +16 -3
- package/dist/index.js +16 -3
- package/dist/templates/fastify-api-reference.js +23425 -23675
- package/dist/templates/index.ejs +5 -0
- package/package.json +2 -2
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,34 @@
|
|
|
1
1
|
# @scalar/fastify-api-reference
|
|
2
2
|
|
|
3
|
+
## 0.6.12
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- a5eed542: feat: detect @fastify/swagger and load fastify.swagger() automatically
|
|
8
|
+
- @scalar/api-reference@0.6.12
|
|
9
|
+
|
|
10
|
+
## 0.6.11
|
|
11
|
+
|
|
12
|
+
### Patch Changes
|
|
13
|
+
|
|
14
|
+
- Updated dependencies [b76f4d1e]
|
|
15
|
+
- @scalar/api-reference@0.6.11
|
|
16
|
+
|
|
17
|
+
## 0.6.10
|
|
18
|
+
|
|
19
|
+
### Patch Changes
|
|
20
|
+
|
|
21
|
+
- Updated dependencies [07b99141]
|
|
22
|
+
- @scalar/api-reference@0.6.10
|
|
23
|
+
|
|
24
|
+
## 0.6.9
|
|
25
|
+
|
|
26
|
+
### Patch Changes
|
|
27
|
+
|
|
28
|
+
- 386b2941: fix: remove body margin from the fastify template
|
|
29
|
+
- Updated dependencies [4985562c]
|
|
30
|
+
- @scalar/api-reference@0.6.9
|
|
31
|
+
|
|
3
32
|
## 0.6.8
|
|
4
33
|
|
|
5
34
|
### Patch Changes
|
package/README.md
CHANGED
|
@@ -39,6 +39,14 @@ await fastify.register(require('@scalar/fastify-api-reference'), {
|
|
|
39
39
|
})
|
|
40
40
|
```
|
|
41
41
|
|
|
42
|
+
Actually, we’re picking it up automatically, so this would be enough:
|
|
43
|
+
|
|
44
|
+
```ts
|
|
45
|
+
await fastify.register(require('@scalar/fastify-api-reference'), {
|
|
46
|
+
routePrefix: '/reference',
|
|
47
|
+
})
|
|
48
|
+
```
|
|
49
|
+
|
|
42
50
|
Or, if you just have a static OpenAPI spec, you can directly pass it, too:
|
|
43
51
|
|
|
44
52
|
```ts
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAKjD,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,EAAE;
|
|
1
|
+
{"version":3,"file":"fastifyApiReference.d.ts","sourceRoot":"","sources":["../src/fastifyApiReference.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,kBAAkB,EAAE,MAAM,SAAS,CAAA;AAKjD,MAAM,MAAM,mBAAmB,GAAG;IAChC;;;;OAIG;IACH,WAAW,EAAE,MAAM,CAAA;IACnB,YAAY,CAAC,EAAE;QACb,OAAO,CAAC,EAAE,MAAM,CAAA;QAChB,IAAI,CAAC,EAAE,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,GAAG,CAAC,MAAM,MAAM,CAAC,MAAM,EAAE,GAAG,CAAC,CAAC,CAAA;QACxD,KAAK,CAAC,EAAE,MAAM,CAAA;KACf,CAAA;CACF,CAAA;;AAiED,wBAAsC"}
|
package/dist/index.cjs
CHANGED
|
@@ -5,18 +5,31 @@ const fs = require("node:fs");
|
|
|
5
5
|
const path = require("node:path");
|
|
6
6
|
const fastifyApiReference = async (fastify, options) => {
|
|
7
7
|
var _a, _b;
|
|
8
|
-
|
|
8
|
+
const hasSwaggerPlugin = fastify.hasPlugin("@fastify/swagger");
|
|
9
|
+
if (!((_a = options.apiReference) == null ? void 0 : _a.spec) && !((_b = options.apiReference) == null ? void 0 : _b.specUrl) && !hasSwaggerPlugin) {
|
|
9
10
|
console.warn(
|
|
10
|
-
"[@scalar/fastify-api-reference] You didn’t provide a spec or specUrl. Please provide one of these options."
|
|
11
|
+
"[@scalar/fastify-api-reference] You didn’t provide a spec or specUrl and @fastify/swagger could not be find either. Please provide one of these options."
|
|
11
12
|
);
|
|
12
13
|
return;
|
|
13
14
|
}
|
|
14
15
|
fastify.get(options.routePrefix ?? "/", async (_, reply) => {
|
|
16
|
+
var _a2, _b2;
|
|
15
17
|
reply.header("Content-Type", "text/html; charset=utf-8");
|
|
18
|
+
let mergedOptions = options;
|
|
19
|
+
if (!((_a2 = options.apiReference) == null ? void 0 : _a2.spec) && !((_b2 = options.apiReference) == null ? void 0 : _b2.specUrl) && hasSwaggerPlugin) {
|
|
20
|
+
mergedOptions = {
|
|
21
|
+
...options,
|
|
22
|
+
apiReference: {
|
|
23
|
+
...options.apiReference,
|
|
24
|
+
// @ts-ignore
|
|
25
|
+
spec: () => fastify.swagger()
|
|
26
|
+
}
|
|
27
|
+
};
|
|
28
|
+
}
|
|
16
29
|
const html = await ejs.renderFile(
|
|
17
30
|
path.resolve(`${__dirname}/../dist/templates/index.ejs`),
|
|
18
31
|
{
|
|
19
|
-
options
|
|
32
|
+
options: mergedOptions
|
|
20
33
|
}
|
|
21
34
|
);
|
|
22
35
|
reply.send(html);
|
package/dist/index.js
CHANGED
|
@@ -13,18 +13,31 @@ import fs from "node:fs";
|
|
|
13
13
|
import path from "node:path";
|
|
14
14
|
const fastifyApiReference = async (fastify, options) => {
|
|
15
15
|
var _a, _b;
|
|
16
|
-
|
|
16
|
+
const hasSwaggerPlugin = fastify.hasPlugin("@fastify/swagger");
|
|
17
|
+
if (!((_a = options.apiReference) == null ? void 0 : _a.spec) && !((_b = options.apiReference) == null ? void 0 : _b.specUrl) && !hasSwaggerPlugin) {
|
|
17
18
|
console.warn(
|
|
18
|
-
"[@scalar/fastify-api-reference] You didn’t provide a spec or specUrl. Please provide one of these options."
|
|
19
|
+
"[@scalar/fastify-api-reference] You didn’t provide a spec or specUrl and @fastify/swagger could not be find either. Please provide one of these options."
|
|
19
20
|
);
|
|
20
21
|
return;
|
|
21
22
|
}
|
|
22
23
|
fastify.get(options.routePrefix ?? "/", async (_, reply) => {
|
|
24
|
+
var _a2, _b2;
|
|
23
25
|
reply.header("Content-Type", "text/html; charset=utf-8");
|
|
26
|
+
let mergedOptions = options;
|
|
27
|
+
if (!((_a2 = options.apiReference) == null ? void 0 : _a2.spec) && !((_b2 = options.apiReference) == null ? void 0 : _b2.specUrl) && hasSwaggerPlugin) {
|
|
28
|
+
mergedOptions = {
|
|
29
|
+
...options,
|
|
30
|
+
apiReference: {
|
|
31
|
+
...options.apiReference,
|
|
32
|
+
// @ts-ignore
|
|
33
|
+
spec: () => fastify.swagger()
|
|
34
|
+
}
|
|
35
|
+
};
|
|
36
|
+
}
|
|
24
37
|
const html = await ejs.renderFile(
|
|
25
38
|
path.resolve(`${__dirname}/../dist/templates/index.ejs`),
|
|
26
39
|
{
|
|
27
|
-
options
|
|
40
|
+
options: mergedOptions
|
|
28
41
|
}
|
|
29
42
|
);
|
|
30
43
|
reply.send(html);
|