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
25 lines
671 B
Plaintext
25 lines
671 B
Plaintext
import type {MacroKeywordDefinition} from "ajv"
|
|
import type {GetDefinition} from "./_types"
|
|
|
|
type RequiredKwd = "anyRequired" | "oneRequired"
|
|
|
|
export default function getRequiredDef(
|
|
keyword: RequiredKwd
|
|
): GetDefinition<MacroKeywordDefinition> {
|
|
return () => ({
|
|
keyword,
|
|
type: "object",
|
|
schemaType: "array",
|
|
macro(schema: string[]) {
|
|
if (schema.length === 0) return true
|
|
if (schema.length === 1) return {required: schema}
|
|
const comb = keyword === "anyRequired" ? "anyOf" : "oneOf"
|
|
return {[comb]: schema.map((p) => ({required: [p]}))}
|
|
},
|
|
metaSchema: {
|
|
type: "array",
|
|
items: {type: "string"},
|
|
},
|
|
})
|
|
}
|