Files
klz-cables.com/.pnpm-store/v10/files/6c/7a2bfffaacf7c74bb32e2f3607bb8b068aae4aaf89091cd6ea7c1fc8f37d492cb9dd44fe975bed48b4a41f5ac89a4bbd747bd038830ed0173682ba327132f0
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

53 lines
1.7 KiB
Plaintext

import type {MacroKeywordDefinition, SchemaObject, Schema} from "ajv"
import type {DefinitionOptions} from "./_types"
import {metaSchemaRef} from "./_util"
export default function getDef(opts?: DefinitionOptions): MacroKeywordDefinition {
return {
keyword: "deepProperties",
type: "object",
schemaType: "object",
macro: function (schema: Record<string, SchemaObject>) {
const allOf = []
for (const pointer in schema) allOf.push(getSchema(pointer, schema[pointer]))
return {allOf}
},
metaSchema: {
type: "object",
propertyNames: {type: "string", format: "json-pointer"},
additionalProperties: metaSchemaRef(opts),
},
}
}
function getSchema(jsonPointer: string, schema: SchemaObject): SchemaObject {
const segments = jsonPointer.split("/")
const rootSchema: SchemaObject = {}
let pointerSchema: SchemaObject = rootSchema
for (let i = 1; i < segments.length; i++) {
let segment: string = segments[i]
const isLast = i === segments.length - 1
segment = unescapeJsonPointer(segment)
const properties: Record<string, Schema> = (pointerSchema.properties = {})
let items: SchemaObject[] | undefined
if (/[0-9]+/.test(segment)) {
let count = +segment
items = pointerSchema.items = []
pointerSchema.type = ["object", "array"]
while (count--) items.push({})
} else {
pointerSchema.type = "object"
}
pointerSchema = isLast ? schema : {}
properties[segment] = pointerSchema
if (items) items.push(pointerSchema)
}
return rootSchema
}
function unescapeJsonPointer(str: string): string {
return str.replace(/~1/g, "/").replace(/~0/g, "~")
}
module.exports = getDef