UNPKG

@azure-tools/openapi

Version:
30 lines 1.21 kB
"use strict"; Object.defineProperty(exports, "__esModule", { value: true }); exports.InvalidRefError = void 0; exports.createOpenAPIWorkspace = createOpenAPIWorkspace; const json_1 = require("@azure-tools/json"); const jsonschema_1 = require("@azure-tools/jsonschema"); class InvalidRefError extends Error { } exports.InvalidRefError = InvalidRefError; function createOpenAPIWorkspace(workspace) { const specs = workspace.specs instanceof Map ? workspace.specs : new Map(Object.entries(workspace.specs)); function resolveReference(args) { const ref = parseRef(args); const spec = specs.get(ref.file); if (spec === undefined) { throw new InvalidRefError(`Ref file '${ref.file}' doesn't exists in workspace.`); } const result = ref.path ? (0, json_1.getFromJsonPointer)(spec, ref.path) : spec; return result; } return { specs, resolveReference }; } function parseRef(args) { if ("relativeTo" in args) { const ref = (0, jsonschema_1.parseJsonRef)(args.ref); return ref.file ? { file: ref.file, path: ref.path } : { file: args.relativeTo, path: ref.path }; } return args; } //# sourceMappingURL=workspace.js.map