@scalar/oas-utils 0.2.125 → 0.2.127

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,21 @@
1
1
  # @scalar/oas-utils
2
2
 
3
+ ## 0.2.127
4
+
5
+ ### Patch Changes
6
+
7
+ - bf961b1: feat: show custom code examples in the API client
8
+ - a176b7e: feat: distinguishes collection and operation servers in import spec
9
+
10
+ ## 0.2.126
11
+
12
+ ### Patch Changes
13
+
14
+ - a571d36: refactor: use central helper fetchDocument to fetch OpenAPI documents
15
+ - Updated dependencies [3783345]
16
+ - @scalar/types@0.1.6
17
+ - @scalar/themes@0.9.84
18
+
3
19
  ## 0.2.125
4
20
 
5
21
  ### Patch Changes
@@ -5,7 +5,7 @@
5
5
  import { type RequestPayload, type Request as RequestType } from './requests.ts';
6
6
  export type Operation = RequestType;
7
7
  export type OperationPayload = RequestPayload;
8
- export declare const operationSchema: import("zod").ZodObject<import("zod").objectUtil.extendShape<import("zod").objectUtil.extendShape<Omit<{
8
+ export declare const operationSchema: import("zod").ZodObject<import("zod").objectUtil.extendShape<import("zod").objectUtil.extendShape<import("zod").objectUtil.extendShape<Omit<{
9
9
  tags: import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodString, "many">>;
10
10
  summary: import("zod").ZodOptional<import("zod").ZodString>;
11
11
  description: import("zod").ZodOptional<import("zod").ZodString>;
@@ -161,6 +161,46 @@ export declare const operationSchema: import("zod").ZodObject<import("zod").obje
161
161
  'x-internal': import("zod").ZodOptional<import("zod").ZodBoolean>;
162
162
  'x-scalar-ignore': import("zod").ZodOptional<import("zod").ZodBoolean>;
163
163
  }, "x-scalar-examples">, {
164
+ 'x-codeSamples': import("zod").ZodCatch<import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
165
+ lang: import("zod").ZodCatch<import("zod").ZodOptional<import("zod").ZodString>>;
166
+ label: import("zod").ZodCatch<import("zod").ZodOptional<import("zod").ZodString>>;
167
+ source: import("zod").ZodString;
168
+ }, "strip", import("zod").ZodTypeAny, {
169
+ source: string;
170
+ label?: string | undefined;
171
+ lang?: string | undefined;
172
+ }, {
173
+ source: string;
174
+ label?: unknown;
175
+ lang?: unknown;
176
+ }>, "many">>>;
177
+ 'x-code-samples': import("zod").ZodCatch<import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
178
+ lang: import("zod").ZodCatch<import("zod").ZodOptional<import("zod").ZodString>>;
179
+ label: import("zod").ZodCatch<import("zod").ZodOptional<import("zod").ZodString>>;
180
+ source: import("zod").ZodString;
181
+ }, "strip", import("zod").ZodTypeAny, {
182
+ source: string;
183
+ label?: string | undefined;
184
+ lang?: string | undefined;
185
+ }, {
186
+ source: string;
187
+ label?: unknown;
188
+ lang?: unknown;
189
+ }>, "many">>>;
190
+ 'x-custom-examples': import("zod").ZodCatch<import("zod").ZodOptional<import("zod").ZodArray<import("zod").ZodObject<{
191
+ lang: import("zod").ZodCatch<import("zod").ZodOptional<import("zod").ZodString>>;
192
+ label: import("zod").ZodCatch<import("zod").ZodOptional<import("zod").ZodString>>;
193
+ source: import("zod").ZodString;
194
+ }, "strip", import("zod").ZodTypeAny, {
195
+ source: string;
196
+ label?: string | undefined;
197
+ lang?: string | undefined;
198
+ }, {
199
+ source: string;
200
+ label?: unknown;
201
+ lang?: unknown;
202
+ }>, "many">>>;
203
+ }>, {
164
204
  'x-scalar-stability': import("zod").ZodCatch<import("zod").ZodOptional<import("zod").ZodEnum<[import("@scalar/types").XScalarStability.Deprecated, import("@scalar/types").XScalarStability.Experimental, import("@scalar/types").XScalarStability.Stable]>>>;
165
205
  }>, {
166
206
  type: import("zod").ZodDefault<import("zod").ZodOptional<import("zod").ZodLiteral<"request">>>;
@@ -209,6 +249,21 @@ export declare const operationSchema: import("zod").ZodObject<import("zod").obje
209
249
  }[] | undefined;
210
250
  requestBody?: any;
211
251
  responses?: Record<string, any> | undefined;
252
+ 'x-codeSamples'?: {
253
+ source: string;
254
+ label?: string | undefined;
255
+ lang?: string | undefined;
256
+ }[] | undefined;
257
+ 'x-code-samples'?: {
258
+ source: string;
259
+ label?: string | undefined;
260
+ lang?: string | undefined;
261
+ }[] | undefined;
262
+ 'x-custom-examples'?: {
263
+ source: string;
264
+ label?: string | undefined;
265
+ lang?: string | undefined;
266
+ }[] | undefined;
212
267
  'x-scalar-stability'?: import("@scalar/types").XScalarStability | undefined;
213
268
  }, {
214
269
  uid?: string | undefined;
@@ -247,6 +302,9 @@ export declare const operationSchema: import("zod").ZodObject<import("zod").obje
247
302
  }[] | undefined;
248
303
  requestBody?: any;
249
304
  responses?: Record<string, any> | undefined;
305
+ 'x-codeSamples'?: unknown;
306
+ 'x-code-samples'?: unknown;
307
+ 'x-custom-examples'?: unknown;
250
308
  'x-scalar-stability'?: unknown;
251
309
  method?: "options" | "connect" | "delete" | "get" | "head" | "patch" | "post" | "put" | "trace" | undefined;
252
310
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/operation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO,IAAI,WAAW,EAAiB,MAAM,eAAe,CAAA;AAE/F,MAAM,MAAM,SAAS,GAAG,WAAW,CAAA;AACnC,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAA;AAC7C,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EAAgB,CAAA"}
1
+ {"version":3,"file":"operation.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/operation.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,OAAO,IAAI,WAAW,EAAiB,MAAM,eAAe,CAAA;AAE/F,MAAM,MAAM,SAAS,GAAG,WAAW,CAAA;AACnC,MAAM,MAAM,gBAAgB,GAAG,cAAc,CAAA;AAC7C,eAAO,MAAM,eAAe;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;aACqV,CAAC;YAAkC,CAAC;;;aAAoE,CAAC;YAAuB,CAAC;;;;;;;;aAAqT,CAAC;YAAkC,CAAC;;;aAAoE,CAAC;YAAuB,CAAC;;;;;;;;aAAwT,CAAC;YAAkC,CAAC;;;aAAoE,CAAC;YAAuB,CAAC;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;EADrzC,CAAA"}
@@ -315,7 +315,7 @@ export declare const oasRequestSchema: z.ZodObject<{
315
315
  }> | undefined;
316
316
  }>;
317
317
  /** Unified request schema for client usage */
318
- export declare const requestSchema: z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<Omit<{
318
+ export declare const requestSchema: z.ZodObject<z.objectUtil.extendShape<z.objectUtil.extendShape<z.objectUtil.extendShape<Omit<{
319
319
  /**
320
320
  * A list of tags for API documentation control. Tags can be used for logical
321
321
  * grouping of operations by resources or any other qualifier.
@@ -506,6 +506,46 @@ export declare const requestSchema: z.ZodObject<z.objectUtil.extendShape<z.objec
506
506
  'x-internal': z.ZodOptional<z.ZodBoolean>;
507
507
  'x-scalar-ignore': z.ZodOptional<z.ZodBoolean>;
508
508
  }, "x-scalar-examples">, {
509
+ 'x-codeSamples': z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodObject<{
510
+ lang: z.ZodCatch<z.ZodOptional<z.ZodString>>;
511
+ label: z.ZodCatch<z.ZodOptional<z.ZodString>>;
512
+ source: z.ZodString;
513
+ }, "strip", z.ZodTypeAny, {
514
+ source: string;
515
+ label?: string | undefined;
516
+ lang?: string | undefined;
517
+ }, {
518
+ source: string;
519
+ label?: unknown;
520
+ lang?: unknown;
521
+ }>, "many">>>;
522
+ 'x-code-samples': z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodObject<{
523
+ lang: z.ZodCatch<z.ZodOptional<z.ZodString>>;
524
+ label: z.ZodCatch<z.ZodOptional<z.ZodString>>;
525
+ source: z.ZodString;
526
+ }, "strip", z.ZodTypeAny, {
527
+ source: string;
528
+ label?: string | undefined;
529
+ lang?: string | undefined;
530
+ }, {
531
+ source: string;
532
+ label?: unknown;
533
+ lang?: unknown;
534
+ }>, "many">>>;
535
+ 'x-custom-examples': z.ZodCatch<z.ZodOptional<z.ZodArray<z.ZodObject<{
536
+ lang: z.ZodCatch<z.ZodOptional<z.ZodString>>;
537
+ label: z.ZodCatch<z.ZodOptional<z.ZodString>>;
538
+ source: z.ZodString;
539
+ }, "strip", z.ZodTypeAny, {
540
+ source: string;
541
+ label?: string | undefined;
542
+ lang?: string | undefined;
543
+ }, {
544
+ source: string;
545
+ label?: unknown;
546
+ lang?: unknown;
547
+ }>, "many">>>;
548
+ }>, {
509
549
  'x-scalar-stability': z.ZodCatch<z.ZodOptional<z.ZodEnum<[XScalarStability.Deprecated, XScalarStability.Experimental, XScalarStability.Stable]>>>;
510
550
  }>, {
511
551
  type: z.ZodDefault<z.ZodOptional<z.ZodLiteral<"request">>>;
@@ -560,6 +600,21 @@ export declare const requestSchema: z.ZodObject<z.objectUtil.extendShape<z.objec
560
600
  }[] | undefined;
561
601
  requestBody?: any;
562
602
  responses?: Record<string, any> | undefined;
603
+ 'x-codeSamples'?: {
604
+ source: string;
605
+ label?: string | undefined;
606
+ lang?: string | undefined;
607
+ }[] | undefined;
608
+ 'x-code-samples'?: {
609
+ source: string;
610
+ label?: string | undefined;
611
+ lang?: string | undefined;
612
+ }[] | undefined;
613
+ 'x-custom-examples'?: {
614
+ source: string;
615
+ label?: string | undefined;
616
+ lang?: string | undefined;
617
+ }[] | undefined;
563
618
  'x-scalar-stability'?: XScalarStability | undefined;
564
619
  }, {
565
620
  uid?: string | undefined;
@@ -598,6 +653,9 @@ export declare const requestSchema: z.ZodObject<z.objectUtil.extendShape<z.objec
598
653
  }[] | undefined;
599
654
  requestBody?: any;
600
655
  responses?: Record<string, any> | undefined;
656
+ 'x-codeSamples'?: unknown;
657
+ 'x-code-samples'?: unknown;
658
+ 'x-custom-examples'?: unknown;
601
659
  'x-scalar-stability'?: unknown;
602
660
  method?: "options" | "connect" | "delete" | "get" | "head" | "patch" | "post" | "put" | "trace" | undefined;
603
661
  }>;
@@ -1 +1 @@
1
- {"version":3,"file":"requests.d.ts","sourceRoot":"","sources":["../../../src/entities/spec/requests.ts"],"names":[],"mappings":"AAEA,OAAO,EAAkB,CAAC,EAAE,MAAM,KAAK,CAAA;AAEvC,OAAO,EAAE,gBAAgB,EAAE,MAAM,eAAe,CAAA;AAGhD,OAAO,EAAE,KAAK,cAAc,EAAwB,MAAM,uBAAuB,CAAA;AAGjF,eAAO,MAAM,cAAc,2FAA4F,CAAA;AAEvH,MAAM,MAAM,aAAa,GAAG,CAAC,OAAO,cAAc,CAAC,CAAC,MAAM,CAAC,CAAA;AAE3D,0DAA0D;AAC1D,MAAM,MAAM,gBAAgB,GAAG,IAAI,CAAC,QAAQ,EAAE,SAAS,CAAC,GAAG;IACzD,iEAAiE;IACjE,OAAO,EAAE,MAAM,CAAC,MAAM,EAAE,MAAM,CAAC,CAAA;IAC/B,wCAAwC;IACxC,gBAAgB,EAAE,MAAM,EAAE,CAAA;IAC1B,kCAAkC;IAClC,QAAQ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ema } from '../shared/utility.js';
2
2
  import { nanoidSchema } from '@scalar/types/utils';
3
3
  import { z } from 'zod';
4
+ import { XCodeSamplesSchema } from '@scalar/openapi-types/schemas/extensions';
4
5
  import { XScalarStability } from '@scalar/types';
5
6
  import { oasSecurityRequirementSchema } from '@scalar/types/entities';
6
7
  import { oasParameterSchema } from './parameters.js';
@@ -100,6 +101,7 @@ const extendedRequestSchema = z.object({
100
101
  /** Unified request schema for client usage */
101
102
  const requestSchema = oasRequestSchema
102
103
  .omit({ 'x-scalar-examples': true })
104
+ .merge(XCodeSamplesSchema)
103
105
  .merge(ScalarStabilitySchema)
104
106
  .merge(extendedRequestSchema);
105
107
 
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Fetches an OpenAPI/Swagger document from a given URL
3
+ *
4
+ * @throws an error if the fetch fails
5
+ */
6
+ export declare function fetchDocument(url: string, proxyUrl?: string, prettyPrint?: boolean): Promise<string>;
7
+ //# sourceMappingURL=fetch-document.d.ts.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"fetch-document.d.ts","sourceRoot":"","sources":["../../src/helpers/fetch-document.ts"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,wBAAsB,aAAa,CAAC,GAAG,EAAE,MAAM,EAAE,QAAQ,CAAC,EAAE,MAAM,EAAE,WAAW,UAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CA4BvG"}
@@ -0,0 +1,35 @@
1
+ import { formatJsonOrYamlString } from './parse.js';
2
+ import { redirectToProxy } from './redirect-to-proxy.js';
3
+
4
+ // Doesn’t work
5
+ const OLD_PROXY_URL = 'https://api.scalar.com/request-proxy';
6
+ // Does work
7
+ const NEW_PROXY_URL = 'https://proxy.scalar.com';
8
+ /**
9
+ * Fetches an OpenAPI/Swagger document from a given URL
10
+ *
11
+ * @throws an error if the fetch fails
12
+ */
13
+ async function fetchDocument(url, proxyUrl, prettyPrint = true) {
14
+ // This replaces the OLD_PROXY_URL with the NEW_PROXY_URL on the fly.
15
+ if (proxyUrl === OLD_PROXY_URL) {
16
+ // biome-ignore lint/style/noParameterAssign: It’s ok, let’s make an exception here.
17
+ proxyUrl = NEW_PROXY_URL;
18
+ }
19
+ const response = await fetch(redirectToProxy(proxyUrl, url));
20
+ // Looks like the request failed
21
+ if (response.status !== 200) {
22
+ console.error(`[fetchDocument] Failed to fetch the OpenAPI document from ${url} (Status: ${response.status})`);
23
+ if (!proxyUrl) {
24
+ console.warn(`[fetchDocument] Tried to fetch the OpenAPI document from ${url} without a proxy. Are the CORS headers configured to allow cross-domain requests? https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS`);
25
+ }
26
+ throw new Error(`Failed to fetch the OpenAPI document from ${url} (Status: ${response.status})`);
27
+ }
28
+ // If it’s JSON, make it pretty
29
+ if (prettyPrint) {
30
+ return formatJsonOrYamlString(await response.text());
31
+ }
32
+ return await response.text();
33
+ }
34
+
35
+ export { fetchDocument };
@@ -1,15 +1,15 @@
1
1
  export type FetchWithProxyFallbackOptions = {
2
- proxy: string | undefined;
2
+ proxyUrl: string | undefined;
3
3
  /**
4
4
  * @see https://developer.mozilla.org/en-US/docs/Web/API/Request/cache
5
5
  */
6
6
  cache?: RequestInit['cache'];
7
7
  };
8
8
  /**
9
- * Fetches an OpenAPI document with a proxy fallback mechanism.
9
+ * Fetches an OpenAPI document with a proxyUrl fallback mechanism.
10
10
  *
11
11
  * If a proxy is provided and the URL requires it, it will first attempt to fetch using the proxy.
12
12
  * If the proxy fetch fails or is not used, it will fall back to a direct fetch.
13
13
  */
14
- export declare function fetchWithProxyFallback(url: string, { proxy, cache }: FetchWithProxyFallbackOptions): Promise<Response>;
14
+ export declare function fetchWithProxyFallback(url: string, { proxyUrl, cache }: FetchWithProxyFallbackOptions): Promise<Response>;
15
15
  //# sourceMappingURL=fetch-with-proxy-fallback.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"fetch-with-proxy-fallback.d.ts","sourceRoot":"","sources":["../../src/helpers/fetch-with-proxy-fallback.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,6BAA6B,GAAG;IAC1C,KAAK,EAAE,MAAM,GAAG,SAAS,CAAA;IACzB;;OAEG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;CAC7B,CAAA;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,KAAK,EAAE,KAAK,EAAE,EAAE,6BAA6B,qBAuBxG"}
1
+ {"version":3,"file":"fetch-with-proxy-fallback.d.ts","sourceRoot":"","sources":["../../src/helpers/fetch-with-proxy-fallback.ts"],"names":[],"mappings":"AAEA,MAAM,MAAM,6BAA6B,GAAG;IAC1C,QAAQ,EAAE,MAAM,GAAG,SAAS,CAAA;IAC5B;;OAEG;IACH,KAAK,CAAC,EAAE,WAAW,CAAC,OAAO,CAAC,CAAA;CAC7B,CAAA;AAED;;;;;GAKG;AACH,wBAAsB,sBAAsB,CAAC,GAAG,EAAE,MAAM,EAAE,EAAE,QAAQ,EAAE,KAAK,EAAE,EAAE,6BAA6B,qBAuB3G"}
@@ -1,28 +1,28 @@
1
1
  import { shouldUseProxy, redirectToProxy } from './redirect-to-proxy.js';
2
2
 
3
3
  /**
4
- * Fetches an OpenAPI document with a proxy fallback mechanism.
4
+ * Fetches an OpenAPI document with a proxyUrl fallback mechanism.
5
5
  *
6
6
  * If a proxy is provided and the URL requires it, it will first attempt to fetch using the proxy.
7
7
  * If the proxy fetch fails or is not used, it will fall back to a direct fetch.
8
8
  */
9
- async function fetchWithProxyFallback(url, { proxy, cache }) {
9
+ async function fetchWithProxyFallback(url, { proxyUrl, cache }) {
10
10
  const fetchOptions = {
11
11
  cache: cache || 'default',
12
12
  };
13
- const shouldTryProxy = shouldUseProxy(proxy, url);
14
- const initialUrl = shouldTryProxy ? redirectToProxy(proxy, url) : url;
13
+ const shouldTryProxy = shouldUseProxy(proxyUrl, url);
14
+ const initialUrl = shouldTryProxy ? redirectToProxy(proxyUrl, url) : url;
15
15
  try {
16
16
  const result = await fetch(initialUrl, fetchOptions);
17
17
  if (result.ok || !shouldTryProxy) {
18
18
  return result;
19
19
  }
20
- // Retry without proxy if the initial request failed
20
+ // Retry without proxyUrl if the initial request failed
21
21
  return await fetch(url, fetchOptions);
22
22
  }
23
23
  catch (error) {
24
24
  if (shouldTryProxy) {
25
- // If proxy failed, try without it
25
+ // If proxyUrl failed, try without it
26
26
  return await fetch(url, fetchOptions);
27
27
  }
28
28
  throw error;
@@ -1,6 +1,6 @@
1
1
  export { createHash } from './create-hash.ts';
2
2
  export { ensureProtocol } from './ensure-protocol.ts';
3
- export { fetchSpecFromUrl } from './fetch-spec-from-url.ts';
3
+ export { fetchDocument } from './fetch-document.ts';
4
4
  export { type FetchWithProxyFallbackOptions, fetchWithProxyFallback } from './fetch-with-proxy-fallback.ts';
5
5
  export { findVariables } from './find-variables.ts';
6
6
  export { canMethodHaveBody, getHttpMethodInfo, isHttpMethod, REQUEST_METHODS } from './http-methods.ts';
@@ -1 +1 @@
1
- {"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/helpers/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,UAAU,EAAE,MAAM,kBAAkB,CAAA;AAC7C,OAAO,EAAE,cAAc,EAAE,MAAM,sBAAsB,CAAA;AACrD,OAAO,EAAE,gBAAgB,EAAE,MAAM,0BAA0B,CAAA;AAC3D,OAAO,EAAE,KAAK,6BAA6B,EAAE,sBAAsB,EAAE,MAAM,gCAAgC,CAAA;AAC3G,OAAO,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AACnD,OAAO,EAAE,iBAAiB,EAAE,iBAAiB,EAAE,YAAY,EAAE,eAAe,EAAE,MAAM,mBAAmB,CAAA;AACvG,OAAO,EAAE,KAAK,cAAc,EAAE,KAAK,eAAe,EAAE,eAAe,EAAE,MAAM,wBAAwB,CAAA;AACnG,OAAO,EAAE,SAAS,EAAE,MAAM,iBAAiB,CAAA;AAC3C,OAAO,EAAE,UAAU,EAAE,MA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cAAc,EAAE,MAAM,wBAAwB,CAAA;AACxF,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAA;AAC1C,OAAO,EAAE,gBAAgB,EAAE,MAAM,wBAAwB,CAAA;AACzD,OAAO,EAAE,WAAW,EAAE,MAAM,mBAAmB,CAAA;AAC/C,OAAO,EAAE,kBAAkB,EAAE,MAAM,2BAA2B,CAAA;AAC9D,OAAO,EAAE,mBAAmB,EAAE,QAAQ,EAAE,MAAM,gBAAgB,CAAA;AAC9D,OAAO,EAAE,iBAAiB,EAAE,UAAU,EAAE,MAAM,aAAa,CAAA"}
@@ -1,6 +1,6 @@
1
1
  export { createHash } from './create-hash.js';
2
2
  export { ensureProtocol } from './ensure-protocol.js';
3
- export { fetchSpecFromUrl } from './fetch-spec-from-url.js';
3
+ export { fetchDocument } from './fetch-document.js';
4
4
  export { fetchWithProxyFallback } from './fetch-with-proxy-fallback.js';
5
5
  export { findVariables } from './find-variables.js';
6
6
  export { REQUEST_METHODS, canMethodHaveBody, getHttpMethodInfo, isHttpMethod } from './http-methods.js';
@@ -1,7 +1,17 @@
1
- /** Redirects the request to a proxy server with a given URL. */
2
- export declare function redirectToProxy(proxy?: string, url?: string): string;
3
- /** Check if the URL is relative or if it's a domain without protocol */
1
+ /**
2
+ * Redirects the request to a proxy server with a given URL. But not for:
3
+ *
4
+ * - Relative URLs
5
+ * - URLs that seem to point to a local IP (except the proxy is on the same domain)
6
+ * - URLs that don’t look like a domain
7
+ **/
8
+ export declare function redirectToProxy(proxyUrl?: string, url?: string): string;
9
+ /**
10
+ * Check if the URL is relative or if it's a domain without protocol
11
+ **/
4
12
  export declare const isRelativePath: (url: string) => boolean;
5
- /** Returns false for requests to localhost, relative URLs, if no proxy is defined … */
6
- export declare function shouldUseProxy(proxy?: string, url?: string): boolean;
13
+ /**
14
+ * Returns false for requests to localhost, relative URLs, if no proxy is defined …
15
+ **/
16
+ export declare function shouldUseProxy(proxyUrl?: string, url?: string): url is string;
7
17
  //# sourceMappingURL=redirect-to-proxy.d.ts.map
@@ -1 +1 @@
1
- {"version":3,"file":"redirect-to-proxy.d.ts","sourceRoot":"","sources":["../../src/helpers/redirect-to-proxy.ts"],"names":[],"mappings":"AAGA,gEAAgE;AAChE,wBAAgB,eAAe,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAepE;AAED,wEAAwE;AACxE,eAAO,MAAM,cAAc,QAAS,MAAM,YAazC,CAAA;AAED,uFAAuF;AACvF,wBAAgB,cAAc,CAAC,KAAK,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,OAAO,CAiBpE"}
1
+ {"version":3,"file":"redirect-to-proxy.d.ts","sourceRoot":"","sources":["../../src/helpers/redirect-to-proxy.ts"],"names":[],"mappings":"AAGA;;;;;;IAMI;AACJ,wBAAgB,eAAe,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,MAAM,CAmCvE;AAED;;IAEI;AACJ,eAAO,MAAM,cAAc,QAAS,MAAM,YAazC,CAAA;AAED;;IAEI;AACJ,wBAAgB,cAAc,CAAC,QAAQ,CAAC,EAAE,MAAM,EAAE,GAAG,CAAC,EAAE,MAAM,GAAG,GAAG,IAAI,MAAM,CAkC7E"}
@@ -1,20 +1,47 @@
1
1
  import { isLocalUrl } from './is-local-url.js';
2
2
  import { REGEX } from './regex-helpers.js';
3
3
 
4
- /** Redirects the request to a proxy server with a given URL. */
5
- function redirectToProxy(proxy, url) {
6
- if (!shouldUseProxy(proxy, url)) {
4
+ /**
5
+ * Redirects the request to a proxy server with a given URL. But not for:
6
+ *
7
+ * - Relative URLs
8
+ * - URLs that seem to point to a local IP (except the proxy is on the same domain)
9
+ * - URLs that don’t look like a domain
10
+ **/
11
+ function redirectToProxy(proxyUrl, url) {
12
+ try {
13
+ if (!shouldUseProxy(proxyUrl, url)) {
14
+ console.log('should not use proxy', proxyUrl, url);
15
+ return url ?? '';
16
+ }
17
+ // Create new URL object from url
18
+ const newUrl = new URL(url);
19
+ // Add temporary domain for relative proxy URLs
20
+ //
21
+ // Q: Why isn’t proxyUrl type guarded?
22
+ // A: Type guarding works for one parameter only (as of now).
23
+ //
24
+ // Q: Why do we need to add http://localhost to relative proxy URLs?
25
+ // A: Because the `new URL()` would otherwise fail.
26
+ //
27
+ const temporaryProxyUrl = isRelativePath(proxyUrl) ? `http://localhost${proxyUrl}` : proxyUrl;
28
+ // Rewrite the URL with the proxy
29
+ newUrl.href = temporaryProxyUrl;
30
+ // Add the original URL as a query parameter
31
+ newUrl.searchParams.append('scalar_url', url);
32
+ // Remove the temporary domain if we added it, but only from the start of the URL
33
+ const result = isRelativePath(proxyUrl)
34
+ ? newUrl.toString().replace(/^http:\/\/localhost/, '')
35
+ : newUrl.toString();
36
+ return result;
37
+ }
38
+ catch {
7
39
  return url ?? '';
8
40
  }
9
- // Create new URL object from url
10
- const newUrl = new URL(url);
11
- // Rewrite the URL with the proxy
12
- newUrl.href = proxy;
13
- // Add the original URL as a query parameter
14
- newUrl.searchParams.append('scalar_url', url);
15
- return newUrl.toString();
16
41
  }
17
- /** Check if the URL is relative or if it's a domain without protocol */
42
+ /**
43
+ * Check if the URL is relative or if it's a domain without protocol
44
+ **/
18
45
  const isRelativePath = (url) => {
19
46
  // Allow http:// https:// and other protocols such as file://
20
47
  if (REGEX.PROTOCOL.test(url)) {
@@ -27,21 +54,39 @@ const isRelativePath = (url) => {
27
54
  }
28
55
  return true;
29
56
  };
30
- /** Returns false for requests to localhost, relative URLs, if no proxy is defined … */
31
- function shouldUseProxy(proxy, url) {
32
- // No proxy or url
33
- if (!proxy || !url) {
34
- return false;
57
+ /**
58
+ * Returns false for requests to localhost, relative URLs, if no proxy is defined …
59
+ **/
60
+ function shouldUseProxy(proxyUrl, url) {
61
+ try {
62
+ // ❌ We don’t have a proxy URL or the URL
63
+ if (!proxyUrl || !url) {
64
+ return false;
65
+ }
66
+ // ❌ Request to relative URLs (won’t be blocked by CORS anyway)
67
+ if (isRelativePath(url)) {
68
+ return false;
69
+ }
70
+ // ✅ Proxy URL is on the same domain (e.g. /proxy)
71
+ // It’s more likely (not guaranteed, though) that the proxy has access to local domains.
72
+ if (isRelativePath(proxyUrl)) {
73
+ return true;
74
+ }
75
+ // ✅ Proxy URL is local
76
+ if (isLocalUrl(proxyUrl)) {
77
+ return true;
78
+ }
79
+ // ❌ Requests to localhost
80
+ // We won’t reach them from a (likely remote) proxy.
81
+ if (isLocalUrl(url)) {
82
+ return false;
83
+ }
84
+ // ✅ Seems fine (e.g. remote proxy + remote URL)
85
+ return true;
35
86
  }
36
- // Relative URLs
37
- if (isRelativePath(url)) {
87
+ catch {
38
88
  return false;
39
89
  }
40
- // Requests to localhost
41
- if (isLocalUrl(url)) {
42
- return false;
43
- }
44
- return true;
45
90
  }
46
91
 
47
92
  export { isRelativePath, redirectToProxy, shouldUseProxy };
@@ -1 +1 @@
1
- {"version":3,"file":"import-spec.d.ts","sourceRoot":"","sources":["../../src/transforms/import-spec.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,WAAW,EAAE,MAAM,uBAAuB,CAAA;AACxD,OAAO,KAAK,EAAE,yBAAyB,EAAE,MAAM,6BAA6B,CAAA;AAE5E,OAAO,KAAK,EAAE,aAAa,EAAE,MAAM,qBAAqB,CAAA;AAGxD,OAAO,KAAK,EAAE,0BAA0B,EAAE,MAAM,8BAA8B,CAAA;AAC9E,OAAO,EAAE,KAAK,UAAU,EAAE,KAAK,iBAAiB,EAAoB,MAAM,+BAA+B,CAAA;AAEzG,OAAO,EAAE,KAAK,cAAc,EAA4B,MAAM,qCAAqC,CAAA;AACnG,OAAO,EAAE,KAAK,OAAO,EAAsC,MAAM,6BAA6B,CAAA;AAC9F,OAAO,EAAE,KAAK,MAAM,EAAgB,MAAM,2BAA2B,CAAA;AACrE,OAAO,EAAE,KAAK,GAAG,EAAa,MAAM,iCAAiC,CAAA;AAKrE,OAAO,EAE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3C,OAAO,EAAE,WAAW,CAAC,YAAY,EAAE,GAAG,SAAS,EAC/C,EAAE,aAAa,EAAE,GAAE,IAAI,CAAC,yBAAyB,EAAE,eAAe,CAAM,GACvE,MAAM,EAAE,CA0CV"}
@@ -86,15 +86,17 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
86
86
  // Some entities will be broken out as individual lists for modification in the workspace
87
87
  const start = performance.now();
88
88
  const requests = [];
89
- // Add the base server url to any relative servers
90
- const servers = getServersFromOpenApiDocument(configuredServers || schema.servers, {
89
+ // Add the base server url to collection servers
90
+ const collectionServers = getServersFromOpenApiDocument(configuredServers || schema.servers, {
91
91
  baseServerURL,
92
92
  });
93
+ // Store operation servers
94
+ const operationServers = [];
93
95
  // Fallback to the current window.location.origin if no servers are provided
94
- if (!servers.length) {
96
+ if (!collectionServers.length) {
95
97
  const fallbackUrl = getFallbackUrl();
96
98
  if (fallbackUrl) {
97
- servers.push(serverSchema.parse({ url: fallbackUrl }));
99
+ collectionServers.push(serverSchema.parse({ url: fallbackUrl }));
98
100
  }
99
101
  }
100
102
  /**
@@ -198,13 +200,17 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
198
200
  }
199
201
  // Path level servers must be saved
200
202
  const pathServers = serverSchema.array().parse(path.servers ?? []);
201
- servers.push(...pathServers);
203
+ for (const server of pathServers) {
204
+ collectionServers.push(server);
205
+ }
202
206
  // Creates a sorted array of methods based on the path object.
203
207
  const methods = Object.keys(path).filter(isHttpMethod);
204
208
  methods.forEach((method) => {
205
209
  const operation = path[method];
206
- const operationServers = serverSchema.array().parse(operation.servers ?? []);
207
- servers.push(...operationServers);
210
+ const operationLevelServers = serverSchema.array().parse(operation.servers ?? []);
211
+ for (const server of operationLevelServers) {
212
+ operationServers.push(server);
213
+ }
208
214
  // We will save a list of all tags to ensure they exists at the top level
209
215
  // TODO: make sure we add any loose requests with no tags to the collection children
210
216
  operation.tags?.forEach((t) => tagNames.add(t));
@@ -234,10 +240,11 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
234
240
  method,
235
241
  path: pathString,
236
242
  security: operationSecurity,
243
+ selectedServerUid: operationLevelServers?.[0]?.uid,
237
244
  selectedSecuritySchemeUids,
238
245
  // Merge path and operation level parameters
239
246
  parameters: [...(path?.parameters ?? []), ...(operation.parameters ?? [])],
240
- servers: [...pathServers, ...operationServers].map((s) => s.uid),
247
+ servers: [...pathServers, ...operationLevelServers].map((s) => s.uid),
241
248
  };
242
249
  // Remove any examples from the request payload as they conflict with our examples property and are not valid
243
250
  if (requestPayload.examples) {
@@ -344,11 +351,11 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
344
351
  documentUrl,
345
352
  useCollectionSecurity,
346
353
  requests: requests.map((r) => r.uid),
347
- servers: servers.map((s) => s.uid),
354
+ servers: collectionServers.map((s) => s.uid),
348
355
  tags: tags.map((t) => t.uid),
349
356
  children: [...collectionChildren],
350
357
  security: schema.security ?? [{}],
351
- selectedServerUid: servers?.[0]?.uid,
358
+ selectedServerUid: collectionServers?.[0]?.uid,
352
359
  selectedSecuritySchemeUids,
353
360
  components: {
354
361
  ...schema.components,
@@ -363,7 +370,7 @@ async function importSpecToWorkspace(spec, { authentication, baseServerURL, docu
363
370
  */
364
371
  return {
365
372
  error: false,
366
- servers,
373
+ servers: [...collectionServers, ...operationServers],
367
374
  schema,
368
375
  requests,
369
376
  examples,
package/package.json CHANGED
@@ -16,7 +16,7 @@
16
16
  "specification",
17
17
  "yaml"
18
18
  ],
19
- "version": "0.2.125",
19
+ "version": "0.2.127",
20
20
  "engines": {
21
21
  "node": ">=18"
22
22
  },
@@ -89,8 +89,8 @@
89
89
  "zod": "^3.23.8",
90
90
  "@scalar/object-utils": "1.1.13",
91
91
  "@scalar/openapi-types": "0.2.0",
92
- "@scalar/themes": "0.9.83",
93
- "@scalar/types": "0.1.5"
92
+ "@scalar/themes": "0.9.84",
93
+ "@scalar/types": "0.1.6"
94
94
  },
95
95
  "devDependencies": {
96
96
  "@types/node": "^20.17.10",
@@ -99,8 +99,8 @@
99
99
  "vitest": "^1.6.0",
100
100
  "zod-to-ts": "github:amritk/zod-to-ts#build",
101
101
  "@scalar/build-tooling": "0.1.17",
102
- "@scalar/openapi-types": "0.2.0",
103
- "@scalar/openapi-parser": "0.10.13"
102
+ "@scalar/openapi-parser": "0.10.14",
103
+ "@scalar/openapi-types": "0.2.0"
104
104
  },
105
105
  "scripts": {
106
106
  "build": "scalar-build-rollup",
@@ -1,7 +0,0 @@
1
- /**
2
- * Fetches an OpenAPI/Swagger specification from a given URL.
3
- *
4
- * @throws an error if the fetch fails
5
- */
6
- export declare function fetchSpecFromUrl(url: string, proxy?: string, beautify?: boolean): Promise<string>;
7
- //# sourceMappingURL=fetch-spec-from-url.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"fetch-spec-from-url.d.ts","sourceRoot":"","sources":["../../src/helpers/fetch-spec-from-url.ts"],"names":[],"mappings":"AAQA;;;;GAIG;AACH,wBAAsB,gBAAgB,CAAC,GAAG,EAAE,MAAM,EAAE,KAAK,CAAC,EAAE,MAAM,EAAE,QAAQ,UAAO,GAAG,OAAO,CAAC,MAAM,CAAC,CA4BpG"}
@@ -1,36 +0,0 @@
1
- import { formatJsonOrYamlString } from './parse.js';
2
- import { redirectToProxy } from './redirect-to-proxy.js';
3
-
4
- // Doesn’t work
5
- const OLD_PROXY_URL = 'https://api.scalar.com/request-proxy';
6
- // Does work
7
- const NEW_PROXY_URL = 'https://proxy.scalar.com';
8
- /**
9
- * Fetches an OpenAPI/Swagger specification from a given URL.
10
- *
11
- * @throws an error if the fetch fails
12
- */
13
- async function fetchSpecFromUrl(url, proxy, beautify = true) {
14
- // This replaces the OLD_PROXY_URL with the NEW_PROXY_URL on the fly.
15
- if (proxy === OLD_PROXY_URL) {
16
- // biome-ignore lint/style/noParameterAssign: It’s ok, let’s make an exception here.
17
- proxy = NEW_PROXY_URL;
18
- }
19
- // To use a proxy or not to use a proxy
20
- const response = await fetch(proxy ? redirectToProxy(proxy, url) : url);
21
- // Looks like the request failed
22
- if (response.status !== 200) {
23
- console.error(`[fetchSpecFromUrl] Failed to fetch the specification at ${url} (Status: ${response.status})`);
24
- if (!proxy) {
25
- console.warn(`[fetchSpecFromUrl] Tried to fetch the specification (url: ${url}) without a proxy. Are the CORS headers configured to allow cross-domain requests? https://developer.mozilla.org/en-US/docs/Web/HTTP/CORS`);
26
- }
27
- throw new Error(`Failed to fetch the specification (Status: ${response.status})`);
28
- }
29
- // If it’s JSON, make it pretty
30
- if (beautify) {
31
- return formatJsonOrYamlString(await response.text());
32
- }
33
- return await response.text();
34
- }
35
-
36
- export { fetchSpecFromUrl };