UNPKG

openapi-ts-json-schema

Version:

OpenAPI to JSON schema generator with TypeScript in mind

23 lines (22 loc) 854 B
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.parseId = void 0; const node_path_1 = __importDefault(require("node:path")); /** * Parses internal schema ids (/components/schema/Foo) to the derive the expected schema output path * this library saves generated JSON schemas to (...outputPath/components.schema/Foo) */ function parseId(id) { if (!id.startsWith('/')) { throw new Error(`[openapi-ts-json-schema] Unsupported id value: "${id}"`); } const idPath = id.replace('/', ''); return { schemaRelativeDirName: node_path_1.default.dirname(idPath), schemaName: node_path_1.default.basename(idPath), }; } exports.parseId = parseId;