@scalar/hono-api-reference 0.7.5 → 0.8.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.
package/README.md CHANGED
@@ -17,48 +17,34 @@ npm install @scalar/hono-api-reference
17
17
 
18
18
  ## Usage
19
19
 
20
- Set up [Zod OpenAPI Hono](https://github.com/honojs/middleware/tree/main/packages/zod-openapi) and pass the configured URL to the `apiReference` middleware:
20
+ Set up [Zod OpenAPI Hono](https://github.com/honojs/middleware/tree/main/packages/zod-openapi) and pass the configured URL to the `Scalar` middleware:
21
21
 
22
22
  ```ts
23
- import { apiReference } from '@scalar/hono-api-reference'
24
-
25
- app.get(
26
- '/reference',
27
- apiReference({
28
- url: '/doc',
29
- }),
30
- )
31
- ```
32
-
33
- 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.
23
+ import { Hono } from 'hono'
24
+ import { Scalar } from '@scalar/hono-api-reference'
34
25
 
35
- ### CORS middleware
26
+ const app = new Hono()
36
27
 
37
- We recommend to allow requests from other domains to your API definition. That makes it easier to use your API with [our free web client](https://client.scalar.com/) for example.
38
-
39
- You just need to add the official Hono CORS middleware to the route of your OpenAPI document:
40
-
41
- ```ts
42
- import { cors } from 'hono/cors'
28
+ // Use the middleware to serve the Scalar API Reference at /scalar
29
+ app.get('/scalar', Scalar({ url: '/doc' }))
43
30
 
44
- // Recommended: Allows cross-origin requests (from other domains) to your OpenAPI document
45
- app.use('/doc', cors())
31
+ export default app
46
32
  ```
47
33
 
34
+ 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.
35
+
48
36
  ### Themes
49
37
 
50
38
  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.
51
39
 
52
40
  ```ts
53
- import { apiReference } from '@scalar/hono-api-reference'
54
-
55
- app.get(
56
- '/reference',
57
- apiReference({
58
- theme: 'purple',
59
- url: '/doc',
60
- }),
61
- )
41
+ import { Scalar } from '@scalar/hono-api-reference'
42
+
43
+ // Switch the theme (or pass other options)
44
+ app.get('/scalar', Scalar({
45
+ url: '/doc',
46
+ theme: 'purple',
47
+ }))
62
48
  ```
63
49
 
64
50
  ### Custom page title
@@ -66,15 +52,13 @@ app.get(
66
52
  There’s one additional option to set the page title:
67
53
 
68
54
  ```ts
69
- import { apiReference } from '@scalar/hono-api-reference'
70
-
71
- app.get(
72
- '/reference',
73
- apiReference({
74
- pageTitle: 'Hono API Reference',
75
- url: '/doc',
76
- }),
77
- )
55
+ import { Scalar } from '@scalar/hono-api-reference'
56
+
57
+ // Set a page title
58
+ app.get('/scalar', Scalar({
59
+ url: '/doc',
60
+ pageTitle: 'Awesome API',
61
+ }))
78
62
  ```
79
63
 
80
64
  ### Custom CDN
@@ -86,15 +70,14 @@ You can also pin the CDN to a specific version by specifying it in the CDN strin
86
70
  You can find all available CDN versions [here](https://www.jsdelivr.com/package/npm/@scalar/api-reference?tab=files)
87
71
 
88
72
  ```ts
89
- import { apiReference } from '@scalar/hono-api-reference'
90
-
91
- app.use(
92
- '/reference',
93
- apiReference({
94
- cdn: 'https://cdn.jsdelivr.net/npm/@scalar/api-reference@latest',
95
- url: '/doc',
96
- }),
97
- )
73
+ import { Scalar } from '@scalar/hono-api-reference'
74
+
75
+ app.get('/scalar', Scalar({ url: '/doc', pageTitle: 'Awesome API' }))
76
+
77
+ app.get('/scalar', Scalar({
78
+ url: '/doc',
79
+ cdn: 'https://cdn.jsdelivr.net/npm/@scalar/api-reference@latest',
80
+ }))
98
81
  ```
99
82
 
100
83
  ## Community
package/dist/index.d.ts CHANGED
@@ -1,3 +1,3 @@
1
- export { apiReference } from './honoApiReference.ts';
1
+ export { apiReference, Scalar } from './scalar.ts';
2
2
  export type { ApiReferenceConfiguration } from './types.ts';
3
3
  //# sourceMappingURL=index.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,uBAAuB,CAAA;AACpD,YAAY,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA"}
1
+ {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../src/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,EAAE,MAAM,aAAa,CAAA;AAClD,YAAY,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA"}
package/dist/index.js CHANGED
@@ -1 +1 @@
1
- export { apiReference } from './honoApiReference.js';
1
+ export { Scalar, apiReference } from './scalar.js';
@@ -7,5 +7,9 @@ export declare const customTheme = "\n.light-mode {\n color-scheme: light;\n -
7
7
  /**
8
8
  * The Hono middleware for the Scalar API Reference.
9
9
  */
10
+ export declare const Scalar: <E extends Env>(givenConfiguration: Partial<ApiReferenceConfiguration>) => MiddlewareHandler<E>;
11
+ /**
12
+ * @deprecated Use `Scalar` instead.
13
+ */
10
14
  export declare const apiReference: <E extends Env>(givenConfiguration: Partial<ApiReferenceConfiguration>) => MiddlewareHandler<E>;
11
- //# sourceMappingURL=honoApiReference.d.ts.map
15
+ //# sourceMappingURL=scalar.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalar.d.ts","sourceRoot":"","sources":["../src/scalar.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAElD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAS3D;;GAEG;AACH,eAAO,MAAM,WAAW,mtHAoGvB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,MAAM,GAAI,CAAC,SAAS,GAAG,sBAAsB,OAAO,CAAC,yBAAyB,CAAC,KAAG,iBAAiB,CAAC,CAAC,CASjH,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,GAdF,CAAC,SAAS,GAAG,sBAAsB,OAAO,CAAC,yBAAyB,CAAC,KAAG,iBAAiB,CAAC,CAAC,CAchF,CAAA"}
@@ -113,7 +113,7 @@ const customTheme = `
113
113
  /**
114
114
  * The Hono middleware for the Scalar API Reference.
115
115
  */
116
- const apiReference = (givenConfiguration) => {
116
+ const Scalar = (givenConfiguration) => {
117
117
  // Merge the defaults
118
118
  const configuration = {
119
119
  ...DEFAULT_CONFIGURATION,
@@ -122,5 +122,9 @@ const apiReference = (givenConfiguration) => {
122
122
  // Respond with the HTML document
123
123
  return async (c) => c.html(/* html */ `${getHtmlDocument(configuration, customTheme)}`);
124
124
  };
125
+ /**
126
+ * @deprecated Use `Scalar` instead.
127
+ */
128
+ const apiReference = Scalar;
125
129
 
126
- export { apiReference, customTheme };
130
+ export { Scalar, apiReference, customTheme };
@@ -0,0 +1,2 @@
1
+ export {};
2
+ //# sourceMappingURL=scalar.test.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"scalar.test.d.ts","sourceRoot":"","sources":["../src/scalar.test.ts"],"names":[],"mappings":""}
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.7.5",
13
+ "version": "0.8.1",
14
14
  "engines": {
15
15
  "node": ">=18"
16
16
  },
@@ -29,7 +29,7 @@
29
29
  ],
30
30
  "module": "dist/index.js",
31
31
  "dependencies": {
32
- "@scalar/core": "0.2.5"
32
+ "@scalar/core": "0.2.7"
33
33
  },
34
34
  "devDependencies": {
35
35
  "@hono/node-server": "^1.11.0",
@@ -1 +0,0 @@
1
- {"version":3,"file":"honoApiReference.d.ts","sourceRoot":"","sources":["../src/honoApiReference.ts"],"names":[],"mappings":"AACA,OAAO,KAAK,EAAE,GAAG,EAAE,iBAAiB,EAAE,MAAM,MAAM,CAAA;AAElD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,YAAY,CAAA;AAS3D;;GAEG;AACH,eAAO,MAAM,WAAW,mtHAoGvB,CAAA;AAED;;GAEG;AACH,eAAO,MAAM,YAAY,GAAI,CAAC,SAAS,GAAG,sBACpB,OAAO,CAAC,yBAAyB,CAAC,KACrD,iBAAiB,CAAC,CAAC,CASrB,CAAA"}
@@ -1,2 +0,0 @@
1
- export {};
2
- //# sourceMappingURL=honoApiReference.test.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"honoApiReference.test.d.ts","sourceRoot":"","sources":["../src/honoApiReference.test.ts"],"names":[],"mappings":""}