UNPKG

openapi-ts-json-schema

Version:

Generate TypeScript-first JSON schemas from OpenAPI definitions

12 lines (11 loc) 420 B
import { PLACEHOLDER_REGEX } from '../index.js'; /** * Replace id placeholders with their relevant $ref object */ export function replacePlaceholdersWithRefs({ schemaAsText, refMapper, }) { // Replace placeholder occurrences with a JSON schema $ref object let output = schemaAsText.replaceAll(PLACEHOLDER_REGEX, (_match, id) => { return `{ $ref: "${refMapper({ id })}" }`; }); return output; }