openapi-ts-json-schema
Version:
OpenAPI to JSON schema generator with TypeScript in mind
24 lines (23 loc) • 644 B
JavaScript
;
Object.defineProperty(exports, "__esModule", { value: true });
exports.refToId = void 0;
/**
* Parses OpenApi ref:
* "#/components/schema/Foo" --> "components/schema/Foo"
*/
function parseRef(ref) {
if (!ref.startsWith('#/')) {
throw new Error(`[openapi-ts-json-schema] Unsupported ref value: "${ref}"`);
}
const refPath = ref.replace('#/', '');
return refPath;
}
/**
* Generate an internal schema ID from a given schema ref:
* "#/components/schema/Foo" --> "/components/schema/Foo"
*/
function refToId(ref) {
const refPath = parseRef(ref);
return `/${refPath}`;
}
exports.refToId = refToId;