UNPKG

@redocly/openapi-core

Version:

See https://github.com/Redocly/redocly-cli

55 lines 1.76 kB
// Specialized OAS only bundle export for vite bundle import { BaseResolver } from '../resolve.js'; import { detectSpec } from '../detect-spec.js'; import { bundleDocument } from './bundle-document.js'; import { Oas2Types } from '../types/oas2.js'; import { Oas3Types } from '../types/oas3.js'; import { Oas3_1Types } from '../types/oas3_1.js'; import { Oas3_2Types } from '../types/oas3_2.js'; import { Config } from '../config/config.js'; export { Source } from '../resolve.js'; export async function bundleOas(opts) { const { ref, doc, externalRefResolver = new BaseResolver(opts.config.resolve), base = null, } = opts; if (!(ref || doc)) { throw new Error('Document or reference is required.\n'); } const document = doc === undefined ? await externalRefResolver.resolveDocument(base, ref, true) : doc; if (document instanceof Error) { throw document; } const version = detectSpec(document.parsed); let types; switch (version) { case 'oas2': types = Oas2Types; break; case 'oas3_0': types = Oas3Types; break; case 'oas3_1': types = Oas3_1Types; break; case 'oas3_2': types = Oas3_2Types; break; default: throw new Error(`Unsupported OpenAPI version: ${version}`); } return bundleDocument({ document, ...opts, externalRefResolver, types, }); } export function createEmptyRedoclyConfig(options = {}) { return new Config({ rules: {}, preprocessors: {}, decorators: {}, plugins: [], }, { configPath: options.configPath, }); } //# sourceMappingURL=bundle-oas.js.map