diff --git a/packages/cli/src/utils.ts b/packages/cli/src/utils.ts index 1c8aa36f52..87b897a07e 100644 --- a/packages/cli/src/utils.ts +++ b/packages/cli/src/utils.ts @@ -17,14 +17,12 @@ import { stringifyYaml, isAbsoluteUrl, loadConfig, - Document, Region, Config, Oas3Definition, Oas2Definition, RedoclyClient, } from '@redocly/openapi-core'; -import { ConfigValidationError } from '@redocly/openapi-core/lib/config'; import { Totals, outputExtensions, @@ -37,7 +35,7 @@ import { isEmptyObject } from '@redocly/openapi-core/lib/utils'; import { Arguments } from 'yargs'; import { version } from './update-version-notifier'; import { DESTINATION_REGEX } from './commands/push'; -import type { ResolvedRefMap } from '@redocly/openapi-core/lib/resolve'; +import type { ConfigValidationError, RawConfigProcessor } from '@redocly/openapi-core/lib/config'; export async function getFallbackApisOrExit( argsApis: string[] | undefined, @@ -426,7 +424,7 @@ export async function loadConfigAndHandleErrors( options: { configPath?: string; customExtends?: string[]; - processRawConfig?: (rawConfig: Document, resolvedRefMap: ResolvedRefMap) => void | Promise; + processRawConfig?: RawConfigProcessor; files?: string[]; region?: Region; } = {} diff --git a/packages/core/src/bundle.ts b/packages/core/src/bundle.ts index fe208783b2..6d745f290c 100755 --- a/packages/core/src/bundle.ts +++ b/packages/core/src/bundle.ts @@ -51,7 +51,7 @@ export async function resolveConfigFile(opts: { } & BundleOptions) { const { ref, - externalRefResolver = new BaseResolver(/* opts.config.resolve */), + externalRefResolver = new BaseResolver(), base = null, } = opts; diff --git a/packages/core/src/config/load.ts b/packages/core/src/config/load.ts index 3cb9320b8c..d53dc6627f 100644 --- a/packages/core/src/config/load.ts +++ b/packages/core/src/config/load.ts @@ -10,7 +10,7 @@ import type { RawConfig, RawUniversalConfig, Region } from './types'; import { RegionalTokenWithValidity } from '../redocly/redocly-client-types'; import {bundleConfig, resolveConfigFile} from '../bundle'; import { Document } from '../resolve'; -import type { ResolvedRefMap } from '../resolve'; +import type { BaseResolver, ResolvedRefMap } from '../resolve'; async function addConfigMetadata({ rawConfig, @@ -69,20 +69,23 @@ async function addConfigMetadata({ ); } +export type RawConfigProcessor = ( + rawConfig: Document, + resolvedRefMap: ResolvedRefMap +) => void | Promise + export async function loadConfig( options: { configPath?: string; customExtends?: string[]; - processRawConfig?: ( - rawConfig: Document, - resolvedRefMap: ResolvedRefMap - ) => void | Promise; + processRawConfig?: RawConfigProcessor; + externalRefResolver?: BaseResolver; files?: string[]; region?: Region; } = {} ): Promise { - const { configPath = findConfig(), customExtends, processRawConfig, files, region } = options; - const rawConfig = await getConfig(configPath, processRawConfig); + const { configPath = findConfig(), customExtends, processRawConfig, files, region , externalRefResolver} = options; + const rawConfig = await getConfig({configPath, processRawConfig, externalRefResolver}); const redoclyClient = new RedoclyClient(); const tokens = await redoclyClient.getTokens(); @@ -114,15 +117,17 @@ export function findConfig(dir?: string): string | undefined { return existingConfigFiles[0]; } -export async function getConfig( - configPath: string | undefined = findConfig(), - processRawConfig?: (rawConfig: Document, resolvedRefMap: ResolvedRefMap) => void | Promise -): Promise { +export async function getConfig(options: { + configPath: string | undefined ; + processRawConfig?: RawConfigProcessor; +externalRefResolver?: BaseResolver; +}): Promise { + const { configPath = findConfig(), processRawConfig, externalRefResolver } = options; if (!configPath || !doesYamlFileExist(configPath)) return {}; try { // const rawConfig = // (await loadYaml(configPath)) || {}; - const { document, resolvedRefMap } = await resolveConfigFile({ ref: configPath, config: {} as any }); + const { document, resolvedRefMap } = await resolveConfigFile({ ref: configPath, config: {} as any, externalRefResolver }); if (typeof processRawConfig === 'function') { await processRawConfig(document, resolvedRefMap); }