@scalar/oas-utils
Advanced tools
Comparing version 0.2.70 to 0.2.71
# @scalar/oas-utils | ||
## 0.2.71 | ||
### Patch Changes | ||
- a40999d: chore: added type safety rule noUncheckedIndexedAccess | ||
- b89da58: fix: ingest base server URL and use it in the api client | ||
- 3300d5b: fix: make the api-client respect the server overload | ||
- Updated dependencies [a40999d] | ||
- @scalar/object-utils@1.1.12 | ||
- @scalar/themes@0.9.47 | ||
- @scalar/openapi-types@0.1.5 | ||
- @scalar/types@0.0.19 | ||
## 0.2.70 | ||
@@ -4,0 +17,0 @@ |
@@ -80,2 +80,4 @@ import { z } from 'zod'; | ||
const schema = param.schema; | ||
const keys = Object.keys(param?.examples ?? {}); | ||
const firstExample = keys.length ? param.examples?.[keys[0]] : null; | ||
/** | ||
@@ -90,3 +92,3 @@ * TODO: | ||
schema?.example ?? | ||
param.examples?.[Object.keys(param.examples)[0]]?.value ?? | ||
firstExample?.value ?? | ||
param.example ?? | ||
@@ -93,0 +95,0 @@ ''); |
@@ -78,3 +78,3 @@ import { schemaModel } from '../../helpers/schema-model.js'; | ||
} | ||
console.warn('[@scalar/oas-utils:security] Invalid schema for oauth example', baseValues); | ||
console.warn('[@scalar/oas-utils:security] Invalid schema for oauth example', scheme, baseValues); | ||
return null; | ||
@@ -81,0 +81,0 @@ } |
@@ -9,5 +9,5 @@ /** | ||
const regex = /(?:\{+)\s*(\w+)\s*(?:\}+)/g; | ||
return [...value.matchAll(regex)].map((match) => match[1].trim()) || []; | ||
return [...value.matchAll(regex)].map((match) => match[1]?.trim()) || []; | ||
}; | ||
export { findVariables }; |
@@ -12,8 +12,8 @@ /** | ||
// Remove any query parameters or hash from the base URL | ||
const cleanBaseUrl = baseUrl.split('?')[0].split('#')[0]; | ||
const cleanBaseUrl = baseUrl.split('?')[0]?.split('#')[0]; | ||
// For base URLs with a path component, we want to remove the last path segment | ||
// if it doesn't end with a slash | ||
const normalizedBaseUrl = cleanBaseUrl.endsWith('/') | ||
const normalizedBaseUrl = cleanBaseUrl?.endsWith('/') | ||
? cleanBaseUrl | ||
: cleanBaseUrl.substring(0, cleanBaseUrl.lastIndexOf('/') + 1); | ||
: cleanBaseUrl?.substring(0, cleanBaseUrl?.lastIndexOf('/') + 1); | ||
return new URL(url, normalizedBaseUrl).toString(); | ||
@@ -20,0 +20,0 @@ }; |
@@ -101,3 +101,3 @@ import { parseLocalStorage } from '../local-storage.js'; | ||
const scheme = oldData.securitySchemes[uid]; | ||
if (scheme.uid) | ||
if (scheme?.uid) | ||
prev[uid] = migrateAuth(scheme); | ||
@@ -143,3 +143,3 @@ return prev; | ||
// Ensure this request can access these schemes | ||
const selectedSecuritySchemeUids = (r.selectedSecuritySchemeUids || []).filter((s) => requestSecurityDict[r.uid].includes(s)); | ||
const selectedSecuritySchemeUids = (r.selectedSecuritySchemeUids || []).filter((s) => requestSecurityDict[r.uid]?.includes(s)); | ||
return { | ||
@@ -146,0 +146,0 @@ ...r, |
@@ -1,5 +0,5 @@ | ||
import { Cookie as Ck } from '../../entities/cookie/index.js'; | ||
import { Environment as E } from '../../entities/environment/index.js'; | ||
import { Collection as Co, Request as R, RequestExample as RE, Server as S, SecurityScheme as SS, Tag as T } from '../../entities/spec/index.js'; | ||
import { Workspace as W } from '../../entities/workspace/index.js'; | ||
import type { Cookie as Ck } from '../../entities/cookie/index.js'; | ||
import type { Environment as E } from '../../entities/environment/index.js'; | ||
import type { Collection as Co, Request as R, RequestExample as RE, Server as S, SecurityScheme as SS, Tag as T } from '../../entities/spec/index.js'; | ||
import type { Workspace as W } from '../../entities/workspace/index.js'; | ||
/** | ||
@@ -6,0 +6,0 @@ * TODO: These types are no longer generated, this was manually grabbed but we must generate them before the next |
@@ -13,3 +13,3 @@ import { type Collection, type CollectionPayload, type Request, type RequestExample, type Server, type Tag } from '../entities/spec/index.js'; | ||
}>; | ||
export type ImportSpecToWorkspaceArgs = Pick<CollectionPayload, 'documentUrl' | 'watchMode'> & Pick<ReferenceConfiguration, 'authentication'> & { | ||
export type ImportSpecToWorkspaceArgs = Pick<CollectionPayload, 'documentUrl' | 'watchMode'> & Pick<ReferenceConfiguration, 'authentication' | 'baseServerURL' | 'servers'> & { | ||
/** Sets the preferred security scheme on the collection instead of the requests */ | ||
@@ -26,3 +26,3 @@ setCollectionSecurity?: boolean; | ||
*/ | ||
export declare function importSpecToWorkspace(spec: string | UnknownObject, { authentication, documentUrl, setCollectionSecurity, watchMode, }?: ImportSpecToWorkspaceArgs): Promise<{ | ||
export declare function importSpecToWorkspace(spec: string | UnknownObject, { authentication, baseServerURL, documentUrl, servers: overloadServers, setCollectionSecurity, watchMode, }?: ImportSpecToWorkspaceArgs): Promise<{ | ||
error: false; | ||
@@ -29,0 +29,0 @@ collection: Collection; |
@@ -98,3 +98,3 @@ import { securitySchemeSchema, authExampleFromSchema } from '../entities/spec/security.js'; | ||
*/ | ||
async function importSpecToWorkspace(spec, { authentication, documentUrl, setCollectionSecurity = false, watchMode = false, } = {}) { | ||
async function importSpecToWorkspace(spec, { authentication, baseServerURL, documentUrl, servers: overloadServers, setCollectionSecurity = false, watchMode = false, } = {}) { | ||
const { schema, errors } = await parseSchema(spec); | ||
@@ -107,10 +107,27 @@ const importWarnings = [...errors.map((e) => e.message)]; | ||
const requests = []; | ||
const servers = serverSchema.array().parse(schema.servers?.map((s) => s ?? [ | ||
{ | ||
url: typeof window !== 'undefined' | ||
? window.location.origin | ||
: 'http://localhost', | ||
description: 'Replace with your API server', | ||
}, | ||
]) ?? []); | ||
// Grab the base server URL for relative servers | ||
const backupBaseServerUrl = typeof window !== 'undefined' ? window.location.origin : 'http://localhost'; | ||
const _baseServerUrl = baseServerURL ?? backupBaseServerUrl; | ||
// Add the base server url to any relative servers | ||
const servers = serverSchema.array().parse((overloadServers ?? schema.servers)?.map((s) => { | ||
// Prepend base server url if relative | ||
if (s?.url?.startsWith('/')) | ||
return { | ||
...s, | ||
// Ensure we only have one slash between | ||
url: [ | ||
_baseServerUrl.replace(/\/$/, ''), | ||
s.url.replace(/^\//, ''), | ||
].join('/'), | ||
}; | ||
// Just return a regular server | ||
if (s.url) | ||
return s; | ||
// Failsafe for no URL, use the base | ||
else | ||
return { | ||
url: _baseServerUrl, | ||
description: 'Replace with your API server', | ||
}; | ||
}) ?? []); | ||
/** | ||
@@ -117,0 +134,0 @@ * List of all tag strings. For non compliant specs we may need to |
@@ -19,3 +19,3 @@ { | ||
], | ||
"version": "0.2.70", | ||
"version": "0.2.71", | ||
"engines": { | ||
@@ -110,5 +110,5 @@ "node": ">=18" | ||
"zod": "^3.23.8", | ||
"@scalar/themes": "0.9.46", | ||
"@scalar/object-utils": "1.1.11", | ||
"@scalar/object-utils": "1.1.12", | ||
"@scalar/openapi-types": "0.1.5", | ||
"@scalar/themes": "0.9.47", | ||
"@scalar/types": "0.0.19" | ||
@@ -121,5 +121,5 @@ }, | ||
"zod-to-ts": "^1.2.0", | ||
"@scalar/build-tooling": "0.1.11", | ||
"@scalar/openapi-types": "0.1.5", | ||
"@scalar/openapi-parser": "0.8.9" | ||
"@scalar/build-tooling": "0.1.12", | ||
"@scalar/openapi-parser": "0.8.9", | ||
"@scalar/openapi-types": "0.1.5" | ||
}, | ||
@@ -126,0 +126,0 @@ "scripts": { |
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
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
384434
8039
+ Added@scalar/object-utils@1.1.12(transitive)
+ Added@scalar/themes@0.9.47(transitive)
- Removed@scalar/object-utils@1.1.11(transitive)
- Removed@scalar/themes@0.9.46(transitive)
Updated@scalar/object-utils@1.1.12
Updated@scalar/themes@0.9.47