source: imaps-frontend/node_modules/ajv-keywords/src/definitions/_required.ts@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 4 days ago

F4 Finalna Verzija

  • Property mode set to 100644
File size: 671 bytes
Line 
1import type {MacroKeywordDefinition} from "ajv"
2import type {GetDefinition} from "./_types"
3
4type RequiredKwd = "anyRequired" | "oneRequired"
5
6export default function getRequiredDef(
7 keyword: RequiredKwd
8): GetDefinition<MacroKeywordDefinition> {
9 return () => ({
10 keyword,
11 type: "object",
12 schemaType: "array",
13 macro(schema: string[]) {
14 if (schema.length === 0) return true
15 if (schema.length === 1) return {required: schema}
16 const comb = keyword === "anyRequired" ? "anyOf" : "oneOf"
17 return {[comb]: schema.map((p) => ({required: [p]}))}
18 },
19 metaSchema: {
20 type: "array",
21 items: {type: "string"},
22 },
23 })
24}
Note: See TracBrowser for help on using the repository browser.