@scalar/hono-api-reference 0.9.3 → 0.9.5
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 +2 -125
- package/package.json +4 -4
package/README.md
CHANGED
|
@@ -9,132 +9,9 @@ This middleware provides an easy way to render a beautiful API reference based o
|
|
|
9
9
|
|
|
10
10
|

|
|
11
11
|
|
|
12
|
-
##
|
|
12
|
+
## Documentation
|
|
13
13
|
|
|
14
|
-
|
|
15
|
-
npm install @scalar/hono-api-reference
|
|
16
|
-
```
|
|
17
|
-
|
|
18
|
-
## Usage
|
|
19
|
-
|
|
20
|
-
Set up [Zod OpenAPI Hono](https://github.com/honojs/middleware/tree/main/packages/zod-openapi) or [Hono OpenAPI](https://github.com/rhinobase/hono-openapi) and pass the configured URL to the `Scalar` middleware:
|
|
21
|
-
|
|
22
|
-
```ts
|
|
23
|
-
import { Hono } from 'hono'
|
|
24
|
-
import { Scalar } from '@scalar/hono-api-reference'
|
|
25
|
-
|
|
26
|
-
const app = new Hono()
|
|
27
|
-
|
|
28
|
-
// Use the middleware to serve the Scalar API Reference at /scalar
|
|
29
|
-
app.get('/scalar', Scalar({ url: '/doc' }))
|
|
30
|
-
|
|
31
|
-
// Or with dynamic configuration
|
|
32
|
-
app.get('/scalar', Scalar((c) => {
|
|
33
|
-
return {
|
|
34
|
-
url: '/doc',
|
|
35
|
-
proxyUrl: c.env.ENVIRONMENT === 'development' ? 'https://proxy.scalar.com' : undefined,
|
|
36
|
-
}
|
|
37
|
-
}))
|
|
38
|
-
|
|
39
|
-
export default app
|
|
40
|
-
```
|
|
41
|
-
|
|
42
|
-
The Hono middleware takes our universal configuration object, [read more about configuration](https://github.com/scalar/scalar/blob/main/documentation/configuration.md) in the core package README.
|
|
43
|
-
|
|
44
|
-
### Themes
|
|
45
|
-
|
|
46
|
-
The middleware comes with a custom theme for Hono. You can use one of [the other predefined themes](https://github.com/scalar/scalar/blob/main/packages/themes/src/index.ts#L15) (`alternate`, `default`, `moon`, `purple`, `solarized`) or overwrite it with `none`. All themes come with a light and dark color scheme.
|
|
47
|
-
|
|
48
|
-
```ts
|
|
49
|
-
import { Scalar } from '@scalar/hono-api-reference'
|
|
50
|
-
|
|
51
|
-
// Switch the theme (or pass other options)
|
|
52
|
-
app.get('/scalar', Scalar({
|
|
53
|
-
url: '/doc',
|
|
54
|
-
theme: 'purple',
|
|
55
|
-
}))
|
|
56
|
-
```
|
|
57
|
-
|
|
58
|
-
### Custom page title
|
|
59
|
-
|
|
60
|
-
There’s one additional option to set the page title:
|
|
61
|
-
|
|
62
|
-
```ts
|
|
63
|
-
import { Scalar } from '@scalar/hono-api-reference'
|
|
64
|
-
|
|
65
|
-
// Set a page title
|
|
66
|
-
app.get('/scalar', Scalar({
|
|
67
|
-
url: '/doc',
|
|
68
|
-
pageTitle: 'Awesome API',
|
|
69
|
-
}))
|
|
70
|
-
```
|
|
71
|
-
|
|
72
|
-
### Custom CDN
|
|
73
|
-
|
|
74
|
-
You can use a custom CDN, default is `https://cdn.jsdelivr.net/npm/@scalar/api-reference`.
|
|
75
|
-
|
|
76
|
-
You can also pin the CDN to a specific version by specifying it in the CDN string like `https://cdn.jsdelivr.net/npm/@scalar/api-reference@1.25.28`
|
|
77
|
-
|
|
78
|
-
You can find all available CDN versions [here](https://www.jsdelivr.com/package/npm/@scalar/api-reference?tab=files)
|
|
79
|
-
|
|
80
|
-
```ts
|
|
81
|
-
import { Scalar } from '@scalar/hono-api-reference'
|
|
82
|
-
|
|
83
|
-
app.get('/scalar', Scalar({ url: '/doc', pageTitle: 'Awesome API' }))
|
|
84
|
-
|
|
85
|
-
app.get('/scalar', Scalar({
|
|
86
|
-
url: '/doc',
|
|
87
|
-
cdn: 'https://cdn.jsdelivr.net/npm/@scalar/api-reference@latest',
|
|
88
|
-
}))
|
|
89
|
-
```
|
|
90
|
-
|
|
91
|
-
### Markdown for LLMs
|
|
92
|
-
|
|
93
|
-
If you want to create a Markdown version of the API reference (for LLMs), install `@scalar/openapi-to-markdown`:
|
|
94
|
-
|
|
95
|
-
```bash
|
|
96
|
-
npm install @scalar/openapi-to-markdown
|
|
97
|
-
```
|
|
98
|
-
|
|
99
|
-
And add an additional route for it:
|
|
100
|
-
|
|
101
|
-
```ts
|
|
102
|
-
import { Hono } from 'hono'
|
|
103
|
-
import { createMarkdownFromOpenApi } from '@scalar/openapi-to-markdown'
|
|
104
|
-
|
|
105
|
-
const app = new Hono()
|
|
106
|
-
|
|
107
|
-
// Generate Markdown from your OpenAPI document
|
|
108
|
-
const markdown = await createMarkdownFromOpenApi(content)
|
|
109
|
-
|
|
110
|
-
/**
|
|
111
|
-
* Register a route to serve the Markdown for LLMs
|
|
112
|
-
*
|
|
113
|
-
* Q: Why /llms.txt?
|
|
114
|
-
* A: It's a proposal to standardise on using an /llms.txt file.
|
|
115
|
-
*
|
|
116
|
-
* @see https://llmstxt.org/
|
|
117
|
-
*/
|
|
118
|
-
app.get('/llms.txt', (c) => c.text(markdown))
|
|
119
|
-
|
|
120
|
-
export default app
|
|
121
|
-
```
|
|
122
|
-
|
|
123
|
-
Or, if you are using Zod OpenAPI Hono:
|
|
124
|
-
|
|
125
|
-
```ts
|
|
126
|
-
// Get the OpenAPI document
|
|
127
|
-
const content = app.getOpenAPI31Document({
|
|
128
|
-
openapi: '3.1.0',
|
|
129
|
-
info: { title: 'Example', version: 'v1' },
|
|
130
|
-
})
|
|
131
|
-
|
|
132
|
-
const markdown = await createMarkdownFromOpenApi(JSON.stringify(content))
|
|
133
|
-
|
|
134
|
-
app.get('/llms.txt', async (c) => {
|
|
135
|
-
return c.text(markdown)
|
|
136
|
-
})
|
|
137
|
-
```
|
|
14
|
+
[Read the documentation here](https://guides.scalar.com/scalar/scalar-api-references/integrations/hono)
|
|
138
15
|
|
|
139
16
|
## Community
|
|
140
17
|
|
package/package.json
CHANGED
|
@@ -10,7 +10,7 @@
|
|
|
10
10
|
"url": "git+https://github.com/scalar/scalar.git",
|
|
11
11
|
"directory": "integrations/hono"
|
|
12
12
|
},
|
|
13
|
-
"version": "0.9.
|
|
13
|
+
"version": "0.9.5",
|
|
14
14
|
"engines": {
|
|
15
15
|
"node": ">=20"
|
|
16
16
|
},
|
|
@@ -29,7 +29,7 @@
|
|
|
29
29
|
],
|
|
30
30
|
"module": "dist/index.js",
|
|
31
31
|
"dependencies": {
|
|
32
|
-
"@scalar/core": "0.3.
|
|
32
|
+
"@scalar/core": "0.3.3"
|
|
33
33
|
},
|
|
34
34
|
"devDependencies": {
|
|
35
35
|
"@hono/node-server": "^1.11.0",
|
|
@@ -37,8 +37,8 @@
|
|
|
37
37
|
"hono": "^4.6.5",
|
|
38
38
|
"vite": "5.4.19",
|
|
39
39
|
"vitest": "^1.6.0",
|
|
40
|
-
"@scalar/
|
|
41
|
-
"@scalar/
|
|
40
|
+
"@scalar/build-tooling": "0.2.3",
|
|
41
|
+
"@scalar/openapi-to-markdown": "0.2.13"
|
|
42
42
|
},
|
|
43
43
|
"peerDependencies": {
|
|
44
44
|
"hono": "^4.0.0"
|