@scalar/api-reference 1.24.15 → 1.24.16

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 CHANGED
@@ -1,5 +1,23 @@
1
1
  # @scalar/api-reference
2
2
 
3
+ ## 1.24.16
4
+
5
+ ### Patch Changes
6
+
7
+ - 716811f: fix: HTML API does not work with YAML content inside script tag
8
+ - 5812c2f: feat: allow custom headers
9
+ - ee5fdee: fix: api reference allof items merge objects
10
+ - Updated dependencies [e4419ce]
11
+ - Updated dependencies [e5ac3e1]
12
+ - Updated dependencies [f2c1019]
13
+ - Updated dependencies [fd0c93d]
14
+ - Updated dependencies [7b87b8c]
15
+ - Updated dependencies [512c815]
16
+ - @scalar/components@0.12.0
17
+ - @scalar/use-tooltip@1.0.0
18
+ - @scalar/api-client@1.3.15
19
+ - @scalar/api-client-modal@0.0.12
20
+
3
21
  ## 1.24.15
4
22
 
5
23
  ### Patch Changes
package/README.md CHANGED
@@ -29,284 +29,119 @@ import '@scalar/api-reference/style.css'
29
29
  </template>
30
30
  ```
31
31
 
32
- You can even [mount the component in React](https://github.com/scalar/scalar/blob/main/examples/react/src/App.tsx).
33
-
34
- ## OpenAPI Specification
35
-
36
- We’re expecting the passed specification to adhere to [the Swagger 2.0, OpenAPI 3.0 or OpenAPI 3.1 specification](https://github.com/OAI/OpenAPI-Specification).
37
-
38
- On top of that, we’ve added a few things for your convenience:
39
-
40
- ### x-displayName
41
-
42
- You can overwrite tag names with `x-displayName`.
43
-
44
- ```diff
45
- openapi: 3.1.0
46
- info:
47
- title: Example
48
- version: "1.0"
49
- tags:
50
- - name: pl4n3t5
51
- + x-displayName: planets
52
- paths:
53
- '/planets':
54
- get:
55
- summary: Get all planets
56
- tags:
57
- - pl4n3t5
58
- ```
59
-
60
- ### x-tagGroup
61
-
62
- You can group your tags with `x-tagGroup`.
63
-
64
- ```diff
65
- openapi: 3.1.0
66
- info:
67
- title: Example
68
- version: "1.0"
69
- tags:
70
- - name: planets
71
- +x-tagGroups:
72
- + - name: galaxy
73
- + tags:
74
- + - planets
75
- paths:
76
- '/planets':
77
- get:
78
- summary: Get all planets
79
- tags:
80
- - planets
81
- ```
82
-
83
- ### x-internal
84
-
85
- You can hide operations from the reference with `x-internal`.
86
-
87
- ```diff
88
- openapi: 3.1.0
89
- info:
90
- title: Example
91
- version: "1.0"
92
- paths:
93
- '/planets':
94
- get:
95
- summary: Get all planets
96
- post:
97
- summary: Create a new planet
98
- + x-internal: true
99
- ```
100
-
101
- ## Configuration
102
-
103
- There’s a configuration object that can be used on all platforms. In Vue.js, you use it like this:
104
-
105
- #### isEditable?: boolean
106
-
107
- Whether the Swagger editor should be shown.
108
-
109
- ```vue
110
- <ApiReference :configuration="{ isEditable: true }" />
111
- ```
112
-
113
- #### spec.content?: string
114
-
115
- Directly pass an OpenAPI/Swagger spec.
32
+ ### CDN
33
+
34
+ ```html
35
+ <!doctype html>
36
+ <html>
37
+ <head>
38
+ <title>Scalar API Reference</title>
39
+ <meta charset="utf-8" />
40
+ <meta
41
+ name="viewport"
42
+ content="width=device-width, initial-scale=1" />
43
+ </head>
44
+ <body>
45
+ <!-- Add your own OpenAPI/Swagger specification URL here: -->
46
+ <!-- Note: The example is our public proxy (to avoid CORS issues). You can remove the `data-proxy-url` attribute if you don’t need it. -->
47
+ <script
48
+ id="api-reference"
49
+ data-url="https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml"
50
+ data-proxy-url="https://proxy.scalar.com"></script>
51
+
52
+ <!-- Optional: You can set a full configuration object like this: -->
53
+ <script>
54
+ var configuration = {
55
+ theme: 'purple',
56
+ }
116
57
 
117
- ```vue
118
- <ApiReference :configuration="{ spec: { content: '{ … }' } }" />
58
+ document.getElementById('api-reference').dataset.configuration =
59
+ JSON.stringify(configuration)
60
+ </script>
61
+ <script src="https://cdn.jsdelivr.net/npm/@scalar/api-reference"></script>
62
+ </body>
63
+ </html>
119
64
  ```
120
65
 
121
- #### spec.url?: string
66
+ You can also use the following syntax to directly pass an OpenAPI specification:
122
67
 
123
- Pass the URL of a spec file (JSON or Yaml).
124
-
125
- ```vue
126
- <ApiReference :configuration="{ spec: { url: '/openapi.json' } }" />
68
+ ```html
69
+ <script
70
+ id="api-reference"
71
+ type="application/json">
72
+ { … }
73
+ </script>
127
74
  ```
128
75
 
129
- #### proxyUrl?: string
76
+ If you’d like to add a request proxy for the API client (to avoid CORS issues):
130
77
 
131
- Making requests to other domains is restricted in the browser and requires [CORS headers](https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS). It’s recommended to use a proxy to send requests to other origins.
132
-
133
- ```vue
134
- <ApiReference :configuration="{ proxy: 'https://proxy.example.com' }" />
78
+ ```html
79
+ <script
80
+ id="api-reference"
81
+ type="application/json"
82
+ data-proxy-url="https://proxy.scalar.com">
83
+ { … }
84
+ </script>
135
85
  ```
136
86
 
137
- You can use our hosted proxy:
87
+ #### Events [beta]
138
88
 
139
- ```vue
140
- <ApiReference :configuration="{ proxy: 'https://proxy.scalar.com' }" />
141
- ```
142
-
143
- If you like to run your own, check out our [example proxy written in Go](https://github.com/scalar/scalar/tree/main/examples/proxy-server).
89
+ We have recently added two events to the standalone CDN build only.
144
90
 
145
- #### showSidebar?: boolean
91
+ ##### scalar:reload-references
146
92
 
147
- Whether the sidebar should be shown.
93
+ Reload the references, this will re-mount the app in case you have switched pages or the dom
94
+ elements have been removed.
148
95
 
149
- ```vue
150
- <ApiReference :configuration="{ showSidebar: true } />
96
+ ```ts
97
+ document.dispatchEvent(new Event('scalar:reload-references'))
151
98
  ```
152
99
 
153
- #### hideModels?: boolean
100
+ ##### scalar:update-references-config
154
101
 
155
- Whether models (`components.schemas` or `definitions`) should be shown in the sidebar, search and content.
102
+ If you have updated the config or spec, you can trigger this event with the new payload to update
103
+ the app. It should update reactively so you do not need to trigger the reload event above after.
156
104
 
157
- `@default false`
105
+ ```ts
106
+ import { type ReferenceProps } from './types'
158
107
 
159
- ```vue
160
- <ApiReference :configuration="{ hideModels: true } />
108
+ const ev = new CustomEvent('scalar:update-references-config', {
109
+ detail: {
110
+ configuration: {
111
+ spec: {
112
+ url: 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml',
113
+ },
114
+ },
115
+ } satisfies ReferenceProps,
116
+ })
117
+ document.dispatchEvent(ev)
161
118
  ```
162
119
 
163
- #### hideDownloadButton?: boolean
120
+ ## Vue.js
164
121
 
165
- Whether to show the "Download OpenAPI Specification" button
122
+ The API Reference is built in Vue.js. If you’re working in Vue.js, too, you can directly use our Vue components.
123
+ Install them via `npm`:
166
124
 
167
- `@default false`
168
-
169
- ```vue
170
- <ApiReference :configuration="{ hideDownloadButton: true } />
125
+ ```bash
126
+ npm install @scalar/api-reference
171
127
  ```
172
128
 
173
- ### customCss?: string
174
-
175
- You can pass custom CSS directly to the component. This is helpful for the integrations for Fastify, Express, Hono and others where you it’s easier to add CSS to the configuration.
176
-
177
- In Vue or React you’d probably use other ways to add custom CSS.
129
+ And import the `ApiReference` component and style to your app:
178
130
 
179
131
  ```vue
180
- <script setup>
181
- const customCss = `* { font-family: "Comic Sans MS", cursive, sans-serif; }`
132
+ <script setup lang="ts">
133
+ import { ApiReference } from '@scalar/api-reference'
134
+ import '@scalar/api-reference/style.css'
182
135
  </script>
183
136
 
184
137
  <template>
185
- <ApiReference :configuration="{ customCss }" />
186
- </template>
187
- ```
188
-
189
- #### searchHotKey?: string
190
-
191
- Key used with CTRL/CMD to open the search modal (defaults to 'k' e.g. CMD+k)
192
-
193
- ```vue
194
- <ApiReference :configuration="{ searchHotKey: 'l'} />
195
- ```
196
-
197
- #### servers?: Server[]
198
-
199
- List of servers to override the openapi spec servers
200
-
201
- @default undefined
202
- @example [{ url: 'https://api.scalar.com', description: 'Production server' }]
203
-
204
- ```vue
205
- <ApiReference :configuration="{ servers: [{ url: 'https://api.scalar.com', description: 'Production server' }] } />
206
- ```
207
-
208
- #### metaData?: object
209
-
210
- You can pass information to the config object to configure meta information out of the box.
211
-
212
- ```vue
213
- <ApiReference :configuration="{
214
- metaData: {
215
- title: 'Page title',
216
- description: 'My page page',
217
- ogDescription: 'Still about my my page',
218
- ogTitle: 'Page title',
219
- ogImage: 'https://example.com/image.png',
220
- twitterCard: 'summary_large_image',
221
- //Add more...
222
- }
223
- } />
224
- ```
225
-
226
- #### hiddenClients?: array | true
227
-
228
- You can pass an array of [httpsnippet clients](https://github.com/Kong/httpsnippet/wiki/Targets) to hide from the clients menu.
229
-
230
- ```vue
231
- <ApiReference :configuration="{
232
- hiddenClients: ['fetch']
233
- } />
234
- ```
235
-
236
- By default hides Unirest, pass `[]` to **show** all clients or `true` to **hide** all clients:
237
-
238
- ```vue
239
- <ApiReference :configuration="{
240
- hiddenClients: true
241
- } />
242
- ```
243
-
244
- #### onSpecUpdate?: (spec: string) => void
245
-
246
- You can listen to spec changes with onSpecUpdate that runs on spec/swagger content change
247
-
248
- ```vue
249
- <ApiReference :configuration="{
250
- onSpecUpdate: (value: string) => {
251
- console.log('Content updated:', value)
252
- }
253
- } />
254
- ```
255
-
256
- #### authentication?: Partial<AuthenticationState>
257
-
258
- To make authentication easier you can prefill the credentials for your users:
259
-
260
- ```vue
261
- <ApiReference :configuration="{
262
- authentication: {
263
- // The OpenAPI file has keys for all security schemes:
264
- // Which one should be used by default?
265
- preferredSecurityScheme: 'my_custom_security_scheme',
266
- // The `my_custom_security_scheme` security scheme is of type `apiKey`, so prefill the token:
267
- apiKey: {
268
- token: 'super-secret-token',
269
- },
270
- },
271
- } />
272
- ```
273
-
274
- For OpenAuth2 it’s more looking like this:
275
-
276
- ```vue
277
- <ApiReference :configuration="{
278
- authentication: {
279
- // The OpenAPI file has keys for all security schemes
280
- // Which one should be used by default?
281
- preferredSecurityScheme: 'oauth2',
282
- // The `oauth2` security scheme is of type `oAuth2`, so prefill the client id and the scopes:
283
- oAuth2: {
284
- clientId: 'foobar123',
285
- // optional:
286
- scopes: ['read:planets', 'write:planets'],
138
+ <ApiReference
139
+ :configuration="{
140
+ spec: {
141
+ url: 'https://cdn.jsdelivr.net/npm/@scalar/galaxy/dist/latest.yaml',
287
142
  },
288
- },
289
- } />
290
- ```
291
-
292
- #### withDefaultFonts?: boolean
293
-
294
- By default we’re using Inter and JetBrains Mono, served by Google Fonts. If you use a different font or just don’t want to use Google Fonts, pass `withDefaultFonts: false` to the configuration.
295
-
296
- ```vue
297
- <ApiReference :configuration="{
298
- withDefaultFonts: false
299
- } />
143
+ }" />
144
+ </template>
300
145
  ```
301
146
 
302
- #### theme?: string
303
-
304
- You don’t like the color scheme? We’ve prepared some themes for you:
305
-
306
- Can be one of: **alternate**, **default**, **moon**, **purple**, **solarized**, **bluePlanet**, **saturn**, **kepler**, **mars**, **deepSpace**, **none**
307
-
308
- ```vue
309
- <ApiReference :configuration="{
310
- theme: default
311
- } />
312
- ```
147
+ You can [pass props to customize the API reference](https://github.com/scalar/scalar/tree/main/documentation/configuration.md).