@scalar/oas-utils
Advanced tools
Comparing version 0.2.65 to 0.2.66
# @scalar/oas-utils | ||
## 0.2.66 | ||
### Patch Changes | ||
- c929284: fix: add default redirectURI and prefix relative redirectURIs with activeServer | ||
- 2275977: feat: import from way more sources, leverage the proxy more | ||
- 3a0c367: fix: improve handling of non-string enums in parameter schema | ||
- 89a2cc7: fix: preselect auth in the modal | ||
## 0.2.65 | ||
@@ -4,0 +13,0 @@ |
@@ -92,3 +92,6 @@ import { z } from 'zod'; | ||
''); | ||
const parseEnum = schema?.type === 'number' ? schema?.enum?.map(String) : schema?.enum; | ||
// Handle non-string enums | ||
const parseEnum = schema?.enum && schema?.type !== 'string' | ||
? schema.enum?.map(String) | ||
: schema?.enum; | ||
// safe parse the example | ||
@@ -95,0 +98,0 @@ const example = schemaModel({ |
@@ -172,2 +172,6 @@ import { schemaModel } from '../../helpers/schema-model.js'; | ||
}); | ||
/** Setup a default redirect uri if we can */ | ||
const defaultRedirectUri = typeof window !== 'undefined' | ||
? window.location.origin + window.location.pathname | ||
: ''; | ||
const oasOauthFlowSchema = z | ||
@@ -179,3 +183,6 @@ .discriminatedUnion('type', [ | ||
authorizationUrl, | ||
'x-scalar-redirect-uri': z.string().optional().default(''), | ||
'x-scalar-redirect-uri': z | ||
.string() | ||
.optional() | ||
.default(defaultRedirectUri), | ||
}), | ||
@@ -196,3 +203,6 @@ /** Configuration for the OAuth Resource Owner Password flow */ | ||
authorizationUrl, | ||
'x-scalar-redirect-uri': z.string().optional().default(''), | ||
'x-scalar-redirect-uri': z | ||
.string() | ||
.optional() | ||
.default(defaultRedirectUri), | ||
tokenUrl, | ||
@@ -199,0 +209,0 @@ }), |
@@ -0,1 +1,8 @@ | ||
export type FetchWithProxyFallbackOptions = { | ||
proxy?: string; | ||
/** | ||
* @see https://developer.mozilla.org/en-US/docs/Web/API/Request/cache | ||
*/ | ||
cache?: RequestInit['cache']; | ||
}; | ||
/** | ||
@@ -6,6 +13,4 @@ * Fetches an OpenAPI document with a proxy fallback mechanism. | ||
* If the proxy fetch fails or is not used, it will fall back to a direct fetch. | ||
* | ||
* Also handles cases where the input is a JSON object instead of a URL. | ||
*/ | ||
export declare function fetchWithProxyFallback(value: string, proxy?: string): Promise<Response>; | ||
export declare function fetchWithProxyFallback(url: string, { proxy, cache }: FetchWithProxyFallbackOptions): Promise<Response>; | ||
//# sourceMappingURL=fetchWithProxyFallback.d.ts.map |
@@ -1,2 +0,1 @@ | ||
import { resolve } from '@scalar/import'; | ||
import { shouldUseProxy, redirectToProxy } from './redirectToProxy.js'; | ||
@@ -9,24 +8,11 @@ | ||
* If the proxy fetch fails or is not used, it will fall back to a direct fetch. | ||
* | ||
* Also handles cases where the input is a JSON object instead of a URL. | ||
*/ | ||
async function fetchWithProxyFallback(value, proxy) { | ||
// Maybe it’s not an OpenAPI document URL, but we can still find the actual URL | ||
const url = await resolve(value); | ||
// If the value is an object, mock a fetch response with beautified JSON | ||
if (typeof value === 'object' && value !== null) { | ||
const json = JSON.stringify(value, null, 2); | ||
return { | ||
ok: true, | ||
status: 200, | ||
text: async () => json, | ||
}; | ||
} | ||
if (typeof url !== 'string') { | ||
throw new Error(`[fetchWithProxyFallback] Can’t fetch URL: ${url}`); | ||
} | ||
async function fetchWithProxyFallback(url, { proxy, cache }) { | ||
const fetchOptions = { | ||
cache: cache || 'default', | ||
}; | ||
const shouldTryProxy = shouldUseProxy(proxy, url); | ||
const initialUrl = shouldTryProxy ? redirectToProxy(proxy, url) : url; | ||
try { | ||
const result = await fetch(initialUrl, { cache: 'no-cache' }); | ||
const result = await fetch(initialUrl, fetchOptions); | ||
if (result.ok || !shouldTryProxy) { | ||
@@ -36,3 +22,3 @@ return result; | ||
// Retry without proxy if the initial request failed | ||
return await fetch(url, { cache: 'no-cache' }); | ||
return await fetch(url, fetchOptions); | ||
} | ||
@@ -42,3 +28,3 @@ catch (error) { | ||
// If proxy failed, try without it | ||
return await fetch(url, { cache: 'no-cache' }); | ||
return await fetch(url, fetchOptions); | ||
} | ||
@@ -45,0 +31,0 @@ throw error; |
@@ -271,6 +271,8 @@ import { securitySchemeSchema, authExampleFromSchema } from '../entities/spec/security.js'; | ||
}, {}); | ||
/** Selected security scheme UIDs for the collection */ | ||
const securityKeys = Object.keys(security); | ||
let selectedSecuritySchemeUids = []; | ||
if (setCollectionSecurity && authentication?.preferredSecurityScheme) { | ||
const uid = securitySchemeMap[authentication.preferredSecurityScheme]; | ||
/** Selected security scheme UIDs for the collection, defaults to the first key */ | ||
if (setCollectionSecurity && securityKeys.length) { | ||
const preferred = authentication?.preferredSecurityScheme || securityKeys[0]; | ||
const uid = securitySchemeMap[preferred]; | ||
selectedSecuritySchemeUids = [uid]; | ||
@@ -277,0 +279,0 @@ } |
@@ -19,3 +19,3 @@ { | ||
], | ||
"version": "0.2.65", | ||
"version": "0.2.66", | ||
"engines": { | ||
@@ -110,7 +110,6 @@ "node": ">=18" | ||
"zod": "^3.23.8", | ||
"@scalar/import": "0.0.3", | ||
"@scalar/openapi-types": "0.1.4", | ||
"@scalar/object-utils": "1.1.11", | ||
"@scalar/types": "0.0.18", | ||
"@scalar/themes": "0.9.45" | ||
"@scalar/themes": "0.9.45", | ||
"@scalar/types": "0.0.18" | ||
}, | ||
@@ -117,0 +116,0 @@ "devDependencies": { |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
379861
10
7964
- Removed@scalar/import@0.0.3
- Removed@scalar/import@0.0.3(transitive)
- Removed@scalar/openapi-parser@0.8.8(transitive)
- Removedajv@8.17.1(transitive)
- Removedajv-draft-04@1.0.0(transitive)
- Removedajv-formats@3.0.1(transitive)
- Removedfast-deep-equal@3.1.3(transitive)
- Removedfast-uri@3.0.6(transitive)
- Removedjson-schema-traverse@1.0.0(transitive)
- Removedjsonpointer@5.0.1(transitive)
- Removedleven@4.0.0(transitive)
- Removedrequire-from-string@2.0.2(transitive)