@scalar/types 0.7.2 → 0.7.4

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.
Files changed (46) hide show
  1. package/CHANGELOG.md +15 -0
  2. package/dist/api-reference/api-client-configuration.js +3 -7
  3. package/dist/api-reference/api-client-plugin.js +32 -30
  4. package/dist/api-reference/api-reference-configuration.js +404 -361
  5. package/dist/api-reference/api-reference-plugin.js +43 -47
  6. package/dist/api-reference/authentication-configuration.js +1 -1
  7. package/dist/api-reference/authentication-configuration.test-d.js +41 -42
  8. package/dist/api-reference/base-configuration.js +150 -146
  9. package/dist/api-reference/html-api.js +1 -1
  10. package/dist/api-reference/html-rendering-configuration.js +19 -20
  11. package/dist/api-reference/index.js +5 -26
  12. package/dist/api-reference/source-configuration.js +105 -96
  13. package/dist/entities/index.js +1 -21
  14. package/dist/entities/security-scheme.js +179 -140
  15. package/dist/index.js +6 -6
  16. package/dist/legacy/index.js +1 -5
  17. package/dist/legacy/reference-config.js +6 -10
  18. package/dist/snippetz/index.js +1 -6
  19. package/dist/snippetz/snippetz.js +35 -31
  20. package/dist/snippetz/snippetz.test-d.js +30 -27
  21. package/dist/utils/index.js +1 -5
  22. package/dist/utils/nanoid.js +7 -7
  23. package/dist/utils/utility-types.js +1 -1
  24. package/package.json +5 -9
  25. package/dist/api-reference/api-client-configuration.js.map +0 -7
  26. package/dist/api-reference/api-client-plugin.js.map +0 -7
  27. package/dist/api-reference/api-reference-configuration.js.map +0 -7
  28. package/dist/api-reference/api-reference-plugin.js.map +0 -7
  29. package/dist/api-reference/authentication-configuration.js.map +0 -7
  30. package/dist/api-reference/authentication-configuration.test-d.js.map +0 -7
  31. package/dist/api-reference/base-configuration.js.map +0 -7
  32. package/dist/api-reference/html-api.js.map +0 -7
  33. package/dist/api-reference/html-rendering-configuration.js.map +0 -7
  34. package/dist/api-reference/index.js.map +0 -7
  35. package/dist/api-reference/source-configuration.js.map +0 -7
  36. package/dist/entities/index.js.map +0 -7
  37. package/dist/entities/security-scheme.js.map +0 -7
  38. package/dist/index.js.map +0 -7
  39. package/dist/legacy/index.js.map +0 -7
  40. package/dist/legacy/reference-config.js.map +0 -7
  41. package/dist/snippetz/index.js.map +0 -7
  42. package/dist/snippetz/snippetz.js.map +0 -7
  43. package/dist/snippetz/snippetz.test-d.js.map +0 -7
  44. package/dist/utils/index.js.map +0 -7
  45. package/dist/utils/nanoid.js.map +0 -7
  46. package/dist/utils/utility-types.js.map +0 -7
@@ -1,367 +1,410 @@
1
- import { z } from "zod";
2
- import { apiReferencePluginSchema } from "./api-reference-plugin.js";
3
- import { NEW_PROXY_URL, OLD_PROXY_URL, baseConfigurationSchema } from "./base-configuration.js";
4
- import { sourceConfigurationSchema } from "./source-configuration.js";
1
+ import { z } from 'zod';
2
+ import { apiReferencePluginSchema } from './api-reference-plugin.js';
3
+ import { NEW_PROXY_URL, OLD_PROXY_URL, baseConfigurationSchema } from './base-configuration.js';
4
+ import { sourceConfigurationSchema } from './source-configuration.js';
5
+ // Zod Schemas don't work well with async functions, so we use a custom type instead.
5
6
  const fetchLikeSchema = z.custom();
6
- const apiReferenceConfigurationSchema = baseConfigurationSchema.extend({
7
- /**
8
- * The layout to use for the references
9
- * @default 'modern'
10
- */
11
- layout: z.enum(["modern", "classic"]).optional().default("modern").catch("modern"),
12
- /**
13
- * URL to a request proxy for the API client
14
- * @deprecated Use proxyUrl instead
15
- */
16
- proxy: z.string().optional(),
17
- /**
18
- * Custom fetch function for custom logic
19
- *
20
- * Can be used to add custom headers, handle auth, etc.
21
- */
22
- fetch: fetchLikeSchema.optional(),
23
- /**
24
- * Plugins for the API reference
25
- */
26
- plugins: z.array(apiReferencePluginSchema).optional(),
27
- /**
28
- * Allows the user to inject an editor for the spec
29
- * @default false
30
- */
31
- isEditable: z.boolean().optional().default(false).catch(false),
32
- /**
33
- * Controls whether the references show a loading state in the intro
34
- * @default false
35
- */
36
- isLoading: z.boolean().optional().default(false).catch(false),
37
- /**
38
- * Whether to show models in the sidebar, search, and content.
39
- * @default false
40
- */
41
- hideModels: z.boolean().optional().default(false).catch(false),
42
- /**
43
- * Sets the file type of the document to download, set to `none` to hide the download button
44
- * @default 'both'
45
- */
46
- documentDownloadType: z.enum(["yaml", "json", "both", "direct", "none"]).optional().default("both").catch("both"),
47
- /**
48
- * Whether to show the "Download OpenAPI Document" button
49
- * @default false
50
- * @deprecated Use `documentDownloadType: 'none'` instead
51
- */
52
- hideDownloadButton: z.boolean().optional(),
53
- /**
54
- * Whether to show the "Test Request" button
55
- * @default false
56
- */
57
- hideTestRequestButton: z.boolean().optional().default(false).catch(false),
58
- /**
59
- * Whether to show the sidebar search bar
60
- * @default false
61
- */
62
- hideSearch: z.boolean().optional().default(false).catch(false),
63
- /**
64
- * Whether to show the operationId
65
- *
66
- * @default false
67
- */
68
- showOperationId: z.boolean().optional().default(false).catch(false),
69
- /** Whether dark mode is on or off initially (light mode) */
70
- darkMode: z.boolean().optional(),
71
- /** forceDarkModeState makes it always this state no matter what */
72
- forceDarkModeState: z.enum(["dark", "light"]).optional(),
73
- /**
74
- * Whether to show the dark mode toggle
75
- * @default false
76
- */
77
- hideDarkModeToggle: z.boolean().optional().default(false).catch(false),
78
- /**
79
- * If used, passed data will be added to the HTML header
80
- * @see https://unhead.unjs.io/usage/composables/use-seo-meta
81
- */
82
- metaData: z.any().optional(),
83
- // Using any for UseSeoMetaInput since it's an external type
84
- /**
85
- * Path to a favicon image
86
- * @default undefined
87
- * @example '/favicon.svg'
88
- */
89
- favicon: z.string().optional(),
90
- /**
91
- * List of httpsnippet clients to hide from the clients menu
92
- * By default hides Unirest, pass `[]` to show all clients
93
- */
94
- hiddenClients: z.union([z.record(z.string(), z.union([z.boolean(), z.array(z.string())])), z.array(z.string()), z.literal(true)]).optional(),
95
- /** Determine the HTTP client that's selected by default */
96
- defaultHttpClient: z.object({
97
- targetKey: z.custom(),
98
- clientKey: z.string()
99
- }).optional(),
100
- /** Custom CSS to be added to the page */
101
- customCss: z.string().optional(),
102
- /** onSpecUpdate is fired on spec/swagger content change */
103
- onSpecUpdate: z.function({
104
- input: [z.string()],
105
- output: z.void()
106
- }).optional(),
107
- /** onServerChange is fired on selected server change */
108
- onServerChange: z.function({
109
- input: [z.string()],
110
- output: z.void()
111
- }).optional(),
112
- /** onDocumentSelect is fired when the config is selected */
113
- onDocumentSelect: z.function({
114
- input: []
115
- // Why no output? https://github.com/scalar/scalar/pull/7047
116
- // output: z.union([z.void(), z.promise(z.void())]),
117
- }).optional(),
118
- /** Callback fired when the reference is fully loaded */
119
- onLoaded: z.function().optional(),
120
- /** onBeforeRequest is fired before the request is sent. You can modify the request here. */
121
- onBeforeRequest: z.function({
122
- input: [z.object({ request: z.instanceof(Request) })]
123
- // Why no output? https://github.com/scalar/scalar/pull/7047
124
- // output: z.union([z.void(), z.promise(z.void())]),
125
- }).optional(),
126
- /**
127
- * onShowMore is fired when the user clicks the "Show more" button on the references
128
- * @param tagId - The ID of the tag that was clicked
129
- */
130
- onShowMore: z.function({
131
- input: [z.string()]
132
- // Why no output? https://github.com/scalar/scalar/pull/7047
133
- // output: z.union([z.void(), z.promise(z.void())]),
134
- }).optional(),
135
- /**
136
- * onSidebarClick is fired when the user clicks on a sidebar item
137
- * @param href - The href of the sidebar item that was clicked
138
- */
139
- onSidebarClick: z.function({
140
- input: [z.string()]
141
- // Why no output? https://github.com/scalar/scalar/pull/7047
142
- // output: z.union([z.void(), z.promise(z.void())]),
143
- }).optional(),
144
- /**
145
- * Route using paths instead of hashes, your server MUST support this
146
- * @example '/standalone-api-reference/:custom(.*)?'
147
- * @experimental
148
- * @default undefined
149
- */
150
- pathRouting: z.object({
151
- basePath: z.string()
152
- }).optional(),
153
- /**
154
- * MCP (Model Context Protocol) configuration
155
- * Optional. When provided, enables MCP integration with the given name and url.
156
- */
157
- mcp: z.object({
158
- /** Display name for the MCP server */
159
- name: z.string().optional(),
160
- /** URL of the MCP server */
161
- url: z.string().optional(),
162
- /** When true, disables the MCP integration */
163
- disabled: z.boolean().optional()
164
- }).optional(),
165
- /**
166
- * Customize the heading portion of the hash
167
- * @param heading - The heading object
168
- * @returns A string ID used to generate the URL hash
169
- * @default (heading) => `#description/${heading.slug}`
170
- */
171
- generateHeadingSlug: z.function({
172
- input: [z.object({ slug: z.string().default("headingSlug") })],
173
- output: z.string()
174
- }).optional(),
175
- /**
176
- * Customize the model portion of the hash
177
- * @param model - The model object with a name property
178
- * @returns A string ID used to generate the URL hash
179
- * @default (model) => slug(model.name)
180
- */
181
- generateModelSlug: z.function({
182
- input: [z.object({ name: z.string().default("modelName") })],
183
- output: z.string()
184
- }).optional(),
185
- /**
186
- * Customize the tag portion of the hash
187
- * @param tag - The tag object
188
- * @returns A string ID used to generate the URL hash
189
- * @default (tag) => slug(tag.name)
190
- */
191
- generateTagSlug: z.function({
192
- input: [z.object({ name: z.string().default("tagName") })],
193
- output: z.string()
194
- }).optional(),
195
- /**
196
- * Customize the operation portion of the hash
197
- * @param operation - The operation object
198
- * @returns A string ID used to generate the URL hash
199
- * @default (operation) => `${operation.method}${operation.path}`
200
- */
201
- generateOperationSlug: z.function({
202
- input: [
203
- z.object({
204
- path: z.string(),
205
- operationId: z.string().optional(),
206
- method: z.string(),
207
- summary: z.string().optional()
208
- })
209
- ],
210
- output: z.string()
211
- }).optional(),
212
- /**
213
- * Customize the webhook portion of the hash
214
- * @param webhook - The webhook object
215
- * @returns A string ID used to generate the URL hash
216
- * @default (webhook) => slug(webhook.name)
217
- */
218
- generateWebhookSlug: z.function({
219
- input: [
220
- z.object({
221
- name: z.string(),
222
- method: z.string().optional()
223
- })
224
- ],
225
- output: z.string()
226
- }).optional(),
227
- /**
228
- * To handle redirects, pass a function that will receive:
229
- * - The current path with hash if pathRouting is enabled
230
- * - The current hash if hashRouting (default)
231
- * And then passes that to history.replaceState
232
- *
233
- * @example hashRouting (default)
234
- * ```ts
235
- * redirect: (hash: string) => hash.replace('#v1/old-path', '#v2/new-path')
236
- * ```
237
- * @example pathRouting
238
- * ```ts
239
- * redirect: (pathWithHash: string) => {
240
- * if (pathWithHash.includes('#')) {
241
- * return pathWithHash.replace('/v1/tags/user#operation/get-user', '/v1/tags/user/operation/get-user')
242
- * }
243
- * return null
244
- * }
245
- * ```
246
- */
247
- redirect: z.function({
248
- input: [z.string()],
249
- output: z.string().nullable().optional()
250
- }).optional(),
251
- /**
252
- * Whether to include default fonts
253
- * @default true
254
- */
255
- withDefaultFonts: z.boolean().optional().default(true).catch(true),
256
- /**
257
- * Whether to expand the first tag in the sidebar when no specific URL target is present
258
- * @default true
259
- */
260
- defaultOpenFirstTag: z.boolean().optional().default(true).catch(true),
261
- /**
262
- * Whether to expand all tags by default
263
- *
264
- * Warning this can cause performance issues on big documents
265
- * @default false
266
- */
267
- defaultOpenAllTags: z.boolean().optional().default(false).catch(false),
268
- /**
269
- * Whether to expand all models by default
270
- *
271
- * Warning this can cause performance issues on big documents
272
- * @default false
273
- */
274
- expandAllModelSections: z.boolean().optional().default(false).catch(false),
275
- /**
276
- * Whether to expand all responses by default
277
- *
278
- * Warning this can cause performance issues on big documents
279
- * @default false
280
- */
281
- expandAllResponses: z.boolean().optional().default(false).catch(false),
282
- /**
283
- * Function to sort tags
284
- * @default 'alpha' for alphabetical sorting
285
- */
286
- tagsSorter: z.union([
287
- z.literal("alpha"),
288
- z.function({
289
- input: [z.any(), z.any()],
290
- output: z.number()
7
+ /**
8
+ * Standard configuration for the Api Reference.
9
+ *
10
+ * This is used internally to the configure the applications and does not include the sources.
11
+ *
12
+ * Sources should only be specified in the user facing configurations.
13
+ *
14
+ * In the the future it is likely sources will be removed completely from the configuration and instead
15
+ * specified through a separate addDocument interface.
16
+ */
17
+ export const apiReferenceConfigurationSchema = baseConfigurationSchema.extend({
18
+ /**
19
+ * The layout to use for the references
20
+ * @default 'modern'
21
+ */
22
+ layout: z.enum(['modern', 'classic']).optional().default('modern').catch('modern'),
23
+ /**
24
+ * URL to a request proxy for the API client
25
+ * @deprecated Use proxyUrl instead
26
+ */
27
+ proxy: z.string().optional(),
28
+ /**
29
+ * Custom fetch function for custom logic
30
+ *
31
+ * Can be used to add custom headers, handle auth, etc.
32
+ */
33
+ fetch: fetchLikeSchema.optional(),
34
+ /**
35
+ * Plugins for the API reference
36
+ */
37
+ plugins: z.array(apiReferencePluginSchema).optional(),
38
+ /**
39
+ * Allows the user to inject an editor for the spec
40
+ * @default false
41
+ */
42
+ isEditable: z.boolean().optional().default(false).catch(false),
43
+ /**
44
+ * Controls whether the references show a loading state in the intro
45
+ * @default false
46
+ */
47
+ isLoading: z.boolean().optional().default(false).catch(false),
48
+ /**
49
+ * Whether to show models in the sidebar, search, and content.
50
+ * @default false
51
+ */
52
+ hideModels: z.boolean().optional().default(false).catch(false),
53
+ /**
54
+ * Sets the file type of the document to download, set to `none` to hide the download button
55
+ * @default 'both'
56
+ */
57
+ documentDownloadType: z.enum(['yaml', 'json', 'both', 'direct', 'none']).optional().default('both').catch('both'),
58
+ /**
59
+ * Whether to show the "Download OpenAPI Document" button
60
+ * @default false
61
+ * @deprecated Use `documentDownloadType: 'none'` instead
62
+ */
63
+ hideDownloadButton: z.boolean().optional(),
64
+ /**
65
+ * Whether to show the "Test Request" button
66
+ * @default false
67
+ */
68
+ hideTestRequestButton: z.boolean().optional().default(false).catch(false),
69
+ /**
70
+ * Whether to show the sidebar search bar
71
+ * @default false
72
+ */
73
+ hideSearch: z.boolean().optional().default(false).catch(false),
74
+ /**
75
+ * Whether to show the operationId
76
+ *
77
+ * @default false
78
+ */
79
+ showOperationId: z.boolean().optional().default(false).catch(false),
80
+ /** Whether dark mode is on or off initially (light mode) */
81
+ darkMode: z.boolean().optional(),
82
+ /** forceDarkModeState makes it always this state no matter what */
83
+ forceDarkModeState: z.enum(['dark', 'light']).optional(),
84
+ /**
85
+ * Whether to show the dark mode toggle
86
+ * @default false
87
+ */
88
+ hideDarkModeToggle: z.boolean().optional().default(false).catch(false),
89
+ /**
90
+ * If used, passed data will be added to the HTML header
91
+ * @see https://unhead.unjs.io/usage/composables/use-seo-meta
92
+ */
93
+ metaData: z.any().optional(), // Using any for UseSeoMetaInput since it's an external type
94
+ /**
95
+ * Path to a favicon image
96
+ * @default undefined
97
+ * @example '/favicon.svg'
98
+ */
99
+ favicon: z.string().optional(),
100
+ /**
101
+ * List of httpsnippet clients to hide from the clients menu
102
+ * By default hides Unirest, pass `[]` to show all clients
103
+ */
104
+ hiddenClients: z
105
+ .union([z.record(z.string(), z.union([z.boolean(), z.array(z.string())])), z.array(z.string()), z.literal(true)])
106
+ .optional(),
107
+ /** Determine the HTTP client that's selected by default */
108
+ defaultHttpClient: z
109
+ .object({
110
+ targetKey: z.custom(),
111
+ clientKey: z.string(),
291
112
  })
292
- ]).optional(),
293
- /**
294
- * Function to sort operations
295
- * @default 'alpha' for alphabetical sorting
296
- */
297
- operationsSorter: z.union([
298
- z.literal("alpha"),
299
- z.literal("method"),
300
- z.function({
301
- input: [z.any(), z.any()],
302
- output: z.number()
113
+ .optional(),
114
+ /** Custom CSS to be added to the page */
115
+ customCss: z.string().optional(),
116
+ /** onSpecUpdate is fired on spec/swagger content change */
117
+ onSpecUpdate: z
118
+ .function({
119
+ input: [z.string()],
120
+ output: z.void(),
303
121
  })
304
- ]).optional(),
305
- /**
306
- * Order the schema properties by
307
- * @default 'alpha' for alphabetical sorting
308
- */
309
- orderSchemaPropertiesBy: z.union([z.literal("alpha"), z.literal("preserve")]).optional().default("alpha").catch("alpha"),
310
- /**
311
- * Sort the schema properties by required ones first
312
- * @default true
313
- */
314
- orderRequiredPropertiesFirst: z.boolean().optional().default(true).catch(true)
122
+ .optional(),
123
+ /** onServerChange is fired on selected server change */
124
+ onServerChange: z
125
+ .function({
126
+ input: [z.string()],
127
+ output: z.void(),
128
+ })
129
+ .optional(),
130
+ /** onDocumentSelect is fired when the config is selected */
131
+ onDocumentSelect: z
132
+ .function({
133
+ input: [],
134
+ // Why no output? https://github.com/scalar/scalar/pull/7047
135
+ // output: z.union([z.void(), z.promise(z.void())]),
136
+ })
137
+ .optional(),
138
+ /** Callback fired when the reference is fully loaded */
139
+ onLoaded: z.function().optional(),
140
+ /** onBeforeRequest is fired before the request is sent. You can modify the request here. */
141
+ onBeforeRequest: z
142
+ .function({
143
+ input: [z.object({ request: z.instanceof(Request) })],
144
+ // Why no output? https://github.com/scalar/scalar/pull/7047
145
+ // output: z.union([z.void(), z.promise(z.void())]),
146
+ })
147
+ .optional(),
148
+ /**
149
+ * onShowMore is fired when the user clicks the "Show more" button on the references
150
+ * @param tagId - The ID of the tag that was clicked
151
+ */
152
+ onShowMore: z
153
+ .function({
154
+ input: [z.string()],
155
+ // Why no output? https://github.com/scalar/scalar/pull/7047
156
+ // output: z.union([z.void(), z.promise(z.void())]),
157
+ })
158
+ .optional(),
159
+ /**
160
+ * onSidebarClick is fired when the user clicks on a sidebar item
161
+ * @param href - The href of the sidebar item that was clicked
162
+ */
163
+ onSidebarClick: z
164
+ .function({
165
+ input: [z.string()],
166
+ // Why no output? https://github.com/scalar/scalar/pull/7047
167
+ // output: z.union([z.void(), z.promise(z.void())]),
168
+ })
169
+ .optional(),
170
+ /**
171
+ * Route using paths instead of hashes, your server MUST support this
172
+ * @example '/standalone-api-reference/:custom(.*)?'
173
+ * @experimental
174
+ * @default undefined
175
+ */
176
+ pathRouting: z
177
+ .object({
178
+ basePath: z.string(),
179
+ })
180
+ .optional(),
181
+ /**
182
+ * MCP (Model Context Protocol) configuration
183
+ * Optional. When provided, enables MCP integration with the given name and url.
184
+ */
185
+ mcp: z
186
+ .object({
187
+ /** Display name for the MCP server */
188
+ name: z.string().optional(),
189
+ /** URL of the MCP server */
190
+ url: z.string().optional(),
191
+ /** When true, disables the MCP integration */
192
+ disabled: z.boolean().optional(),
193
+ })
194
+ .optional(),
195
+ /**
196
+ * Customize the heading portion of the hash
197
+ * @param heading - The heading object
198
+ * @returns A string ID used to generate the URL hash
199
+ * @default (heading) => `#description/${heading.slug}`
200
+ */
201
+ generateHeadingSlug: z
202
+ .function({
203
+ input: [z.object({ slug: z.string().default('headingSlug') })],
204
+ output: z.string(),
205
+ })
206
+ .optional(),
207
+ /**
208
+ * Customize the model portion of the hash
209
+ * @param model - The model object with a name property
210
+ * @returns A string ID used to generate the URL hash
211
+ * @default (model) => slug(model.name)
212
+ */
213
+ generateModelSlug: z
214
+ .function({
215
+ input: [z.object({ name: z.string().default('modelName') })],
216
+ output: z.string(),
217
+ })
218
+ .optional(),
219
+ /**
220
+ * Customize the tag portion of the hash
221
+ * @param tag - The tag object
222
+ * @returns A string ID used to generate the URL hash
223
+ * @default (tag) => slug(tag.name)
224
+ */
225
+ generateTagSlug: z
226
+ .function({
227
+ input: [z.object({ name: z.string().default('tagName') })],
228
+ output: z.string(),
229
+ })
230
+ .optional(),
231
+ /**
232
+ * Customize the operation portion of the hash
233
+ * @param operation - The operation object
234
+ * @returns A string ID used to generate the URL hash
235
+ * @default (operation) => `${operation.method}${operation.path}`
236
+ */
237
+ generateOperationSlug: z
238
+ .function({
239
+ input: [
240
+ z.object({
241
+ path: z.string(),
242
+ operationId: z.string().optional(),
243
+ method: z.string(),
244
+ summary: z.string().optional(),
245
+ }),
246
+ ],
247
+ output: z.string(),
248
+ })
249
+ .optional(),
250
+ /**
251
+ * Customize the webhook portion of the hash
252
+ * @param webhook - The webhook object
253
+ * @returns A string ID used to generate the URL hash
254
+ * @default (webhook) => slug(webhook.name)
255
+ */
256
+ generateWebhookSlug: z
257
+ .function({
258
+ input: [
259
+ z.object({
260
+ name: z.string(),
261
+ method: z.string().optional(),
262
+ }),
263
+ ],
264
+ output: z.string(),
265
+ })
266
+ .optional(),
267
+ /**
268
+ * To handle redirects, pass a function that will receive:
269
+ * - The current path with hash if pathRouting is enabled
270
+ * - The current hash if hashRouting (default)
271
+ * And then passes that to history.replaceState
272
+ *
273
+ * @example hashRouting (default)
274
+ * ```ts
275
+ * redirect: (hash: string) => hash.replace('#v1/old-path', '#v2/new-path')
276
+ * ```
277
+ * @example pathRouting
278
+ * ```ts
279
+ * redirect: (pathWithHash: string) => {
280
+ * if (pathWithHash.includes('#')) {
281
+ * return pathWithHash.replace('/v1/tags/user#operation/get-user', '/v1/tags/user/operation/get-user')
282
+ * }
283
+ * return null
284
+ * }
285
+ * ```
286
+ */
287
+ redirect: z
288
+ .function({
289
+ input: [z.string()],
290
+ output: z.string().nullable().optional(),
291
+ })
292
+ .optional(),
293
+ /**
294
+ * Whether to include default fonts
295
+ * @default true
296
+ */
297
+ withDefaultFonts: z.boolean().optional().default(true).catch(true),
298
+ /**
299
+ * Whether to expand the first tag in the sidebar when no specific URL target is present
300
+ * @default true
301
+ */
302
+ defaultOpenFirstTag: z.boolean().optional().default(true).catch(true),
303
+ /**
304
+ * Whether to expand all tags by default
305
+ *
306
+ * Warning this can cause performance issues on big documents
307
+ * @default false
308
+ */
309
+ defaultOpenAllTags: z.boolean().optional().default(false).catch(false),
310
+ /**
311
+ * Whether to expand all models by default
312
+ *
313
+ * Warning this can cause performance issues on big documents
314
+ * @default false
315
+ */
316
+ expandAllModelSections: z.boolean().optional().default(false).catch(false),
317
+ /**
318
+ * Whether to expand all responses by default
319
+ *
320
+ * Warning this can cause performance issues on big documents
321
+ * @default false
322
+ */
323
+ expandAllResponses: z.boolean().optional().default(false).catch(false),
324
+ /**
325
+ * Function to sort tags
326
+ * @default 'alpha' for alphabetical sorting
327
+ */
328
+ tagsSorter: z
329
+ .union([
330
+ z.literal('alpha'),
331
+ z.function({
332
+ input: [z.any(), z.any()],
333
+ output: z.number(),
334
+ }),
335
+ ])
336
+ .optional(),
337
+ /**
338
+ * Function to sort operations
339
+ * @default 'alpha' for alphabetical sorting
340
+ */
341
+ operationsSorter: z
342
+ .union([
343
+ z.literal('alpha'),
344
+ z.literal('method'),
345
+ z.function({
346
+ input: [z.any(), z.any()],
347
+ output: z.number(),
348
+ }),
349
+ ])
350
+ .optional(),
351
+ /**
352
+ * Order the schema properties by
353
+ * @default 'alpha' for alphabetical sorting
354
+ */
355
+ orderSchemaPropertiesBy: z
356
+ .union([z.literal('alpha'), z.literal('preserve')])
357
+ .optional()
358
+ .default('alpha')
359
+ .catch('alpha'),
360
+ /**
361
+ * Sort the schema properties by required ones first
362
+ * @default true
363
+ */
364
+ orderRequiredPropertiesFirst: z.boolean().optional().default(true).catch(true),
315
365
  });
316
- const apiReferenceConfigurationWithSourceSchema = apiReferenceConfigurationSchema.extend(sourceConfigurationSchema.shape).transform((configuration) => {
317
- if (configuration.hideDownloadButton) {
318
- console.warn(
319
- `[DEPRECATED] You're using the deprecated 'hideDownloadButton' attribute. Use 'documentDownloadType: 'none'' instead.`
320
- );
321
- configuration.documentDownloadType = "none";
322
- }
323
- if (configuration.spec?.url) {
324
- console.warn(
325
- `[DEPRECATED] You're using the deprecated 'spec.url' attribute. Remove the spec prefix and move the 'url' attribute to the top level.`
326
- );
327
- configuration.url = configuration.spec.url;
328
- delete configuration.spec;
329
- }
330
- if (configuration.spec?.content) {
331
- console.warn(
332
- `[DEPRECATED] You're using the deprecated 'spec.content' attribute. Remove the spec prefix and move the 'content' attribute to the top level.`
333
- );
334
- configuration.content = configuration.spec.content;
335
- delete configuration.spec;
336
- }
337
- if (configuration.proxy) {
338
- console.warn(
339
- `[DEPRECATED] You're using the deprecated 'proxy' attribute, rename it to 'proxyUrl' or update the package.`
340
- );
341
- if (!configuration.proxyUrl) {
342
- configuration.proxyUrl = configuration.proxy;
366
+ /** Migrate the configuration through a transform */
367
+ // const migrateConfiguration = <T extends z.infer<typeof _apiReferenceConfigurationSchema>>
368
+ /** Configuration for the Api Reference */
369
+ export const apiReferenceConfigurationWithSourceSchema = apiReferenceConfigurationSchema.extend(sourceConfigurationSchema.shape).transform((configuration) => {
370
+ // Migrate hideDownloadButton to documentDownloadType
371
+ if (configuration.hideDownloadButton) {
372
+ console.warn(`[DEPRECATED] You're using the deprecated 'hideDownloadButton' attribute. Use 'documentDownloadType: 'none'' instead.`);
373
+ configuration.documentDownloadType = 'none';
374
+ }
375
+ // Remove the spec prefix
376
+ if (configuration.spec?.url) {
377
+ console.warn(`[DEPRECATED] You're using the deprecated 'spec.url' attribute. Remove the spec prefix and move the 'url' attribute to the top level.`);
378
+ configuration.url = configuration.spec.url;
379
+ delete configuration.spec;
380
+ }
381
+ if (configuration.spec?.content) {
382
+ console.warn(`[DEPRECATED] You're using the deprecated 'spec.content' attribute. Remove the spec prefix and move the 'content' attribute to the top level.`);
383
+ configuration.content = configuration.spec.content;
384
+ delete configuration.spec;
385
+ }
386
+ // Migrate proxy URL
387
+ if (configuration.proxy) {
388
+ console.warn(`[DEPRECATED] You're using the deprecated 'proxy' attribute, rename it to 'proxyUrl' or update the package.`);
389
+ if (!configuration.proxyUrl) {
390
+ configuration.proxyUrl = configuration.proxy;
391
+ }
392
+ delete configuration.proxy;
393
+ }
394
+ if (configuration.proxyUrl === OLD_PROXY_URL) {
395
+ console.warn(`[DEPRECATED] Warning: configuration.proxyUrl points to our old proxy (${OLD_PROXY_URL}).`);
396
+ console.warn(`[DEPRECATED] We are overwriting the value and use the new proxy URL (${NEW_PROXY_URL}) instead.`);
397
+ console.warn(`[DEPRECATED] Action Required: You should manually update your configuration to use the new URL (${NEW_PROXY_URL}). Read more: https://github.com/scalar/scalar`);
398
+ configuration.proxyUrl = NEW_PROXY_URL;
399
+ }
400
+ // Migrate showToolbar to showDeveloperTools
401
+ if (configuration.showToolbar && configuration.showToolbar !== 'localhost') {
402
+ console.warn(`[DEPRECATED] You're using the deprecated 'showToolbar' attribute. Use 'showDeveloperTools' instead.`);
403
+ configuration.showDeveloperTools = configuration.showToolbar;
404
+ // @ts-expect-error - We're deleting the deprecated attribute
405
+ delete configuration.showToolbar;
343
406
  }
344
- delete configuration.proxy;
345
- }
346
- if (configuration.proxyUrl === OLD_PROXY_URL) {
347
- console.warn(`[DEPRECATED] Warning: configuration.proxyUrl points to our old proxy (${OLD_PROXY_URL}).`);
348
- console.warn(`[DEPRECATED] We are overwriting the value and use the new proxy URL (${NEW_PROXY_URL}) instead.`);
349
- console.warn(
350
- `[DEPRECATED] Action Required: You should manually update your configuration to use the new URL (${NEW_PROXY_URL}). Read more: https://github.com/scalar/scalar`
351
- );
352
- configuration.proxyUrl = NEW_PROXY_URL;
353
- }
354
- if (configuration.showToolbar && configuration.showToolbar !== "localhost") {
355
- console.warn(`[DEPRECATED] You're using the deprecated 'showToolbar' attribute. Use 'showDeveloperTools' instead.`);
356
- configuration.showDeveloperTools = configuration.showToolbar;
357
- delete configuration.showToolbar;
358
- }
359
- return configuration;
407
+ return configuration;
360
408
  });
361
- const isConfigurationWithSources = (config) => Boolean(!Array.isArray(config) && config && "sources" in config && Array.isArray(config.sources));
362
- export {
363
- apiReferenceConfigurationSchema,
364
- apiReferenceConfigurationWithSourceSchema,
365
- isConfigurationWithSources
366
- };
367
- //# sourceMappingURL=api-reference-configuration.js.map
409
+ /** Typeguard to check to narrow the configs to the one with sources */
410
+ export const isConfigurationWithSources = (config) => Boolean(!Array.isArray(config) && config && 'sources' in config && Array.isArray(config.sources));