Files
klz-cables.com/.pnpm-store/v10/files/a7/69eaa3b708457390f8f29a1a7a963ebfc9489352d6a2c712a4254fdcb113c69560e2d3648ee387d15016db208144753c23086b07f7877086d70cac020c0a2c
Marc Mintel 5397309103
Some checks failed
Build & Deploy / 🔍 Prepare (push) Successful in 20s
Build & Deploy / 🧪 QA (push) Failing after 34s
Build & Deploy / 🏗️ Build (push) Has started running
Build & Deploy / 🚀 Deploy (push) Has been cancelled
Build & Deploy / 🧪 Smoke Test (push) Has been cancelled
Build & Deploy / ⚡ Lighthouse (push) Has been cancelled
Build & Deploy / 🔔 Notify (push) Has been cancelled
fix(products): fix breadcrumbs and product filtering (backport from main)
2026-02-24 16:04:21 +01:00

52 lines
1.4 KiB
Plaintext

import type {LinkedJSONSchema} from './types/JSONSchema'
import {Intersection, Parent, Types} from './types/JSONSchema'
import {typesOfSchema} from './typesOfSchema'
export function applySchemaTyping(schema: LinkedJSONSchema) {
const types = typesOfSchema(schema)
Object.defineProperty(schema, Types, {
enumerable: false,
value: types,
writable: false,
})
if (types.size === 1) {
return
}
// Some schemas can be understood as multiple possible types (see related
// comment in `typesOfSchema.ts`). In such cases, we generate an `ALL_OF`
// intersection that will ultimately be used to generate a union type.
//
// The original schema's name, title, and description are hoisted to the
// new intersection schema to prevent duplication.
//
// If the original schema also contained its own `ALL_OF` property, it is
// also hoiested to the new intersection schema.
const intersection = {
[Parent]: schema,
[Types]: new Set(['ALL_OF']),
$id: schema.$id,
description: schema.description,
name: schema.name,
title: schema.title,
allOf: schema.allOf ?? [],
required: [],
additionalProperties: false,
}
types.delete('ALL_OF')
delete schema.allOf
delete schema.$id
delete schema.description
delete schema.name
delete schema.title
Object.defineProperty(schema, Intersection, {
enumerable: false,
value: intersection,
writable: false,
})
}