UNPKG

openapi-ts-json-schema

Version:

Generate TypeScript-first JSON schemas from OpenAPI definitions

20 lines (19 loc) 521 B
/** * 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" */ export function refToId(ref) { const refPath = parseRef(ref); return `/${refPath}`; }