INNER CODE UNIT · TypeScript

migrateSchema

x-cmd/x-cmd · mod/ajv/lib/ajv.ts:211

function migrateSchema(input: Record<string, unknown>): Record<string, unknown> {
    const schema = JSON.parse(JSON.stringify(input)) as Record<string, unknown>;

    const cur = (typeof schema.$schema === "string")
        ? DRAFTS.findIndex((d) => (schema.$schema as string).includes(d.replace(/^https?:/, "")))
        : -1;

    // draft-04/06 → 07+: rename `id` to `$id`.
    if (cur >= 0 && cur < 2 && "id" in schema && !("$id" in schema)) {
        schema.$id = schema.id;
        delete schema.id;
    }

    // Set target $schema (2020-12).
    schema.$schema = DRAFTS[DRAFTS.length - 1];

    return schema;
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…