package mcp-kit
Source file kw_conditional.ml
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48(** Keywords: if, then, else (spec §6.6). *) open Jsonschema_core let parent_path path = match List.rev path with [] -> [] | _ :: rest -> List.rev rest let compile_if : Compiler.keyword_compiler = { keyword = "if"; compile = (fun ctx value -> let if_v = ctx.compile_sub value in let then_v = match Schema.keyword "then" (Schema.Obj ctx.schema_obj) with | Some s -> Some (ctx.compile_sub ~schema_path: (Json_pointer.append (parent_path ctx.schema_path) "then") s) | None -> None in let else_v = match Schema.keyword "else" (Schema.Obj ctx.schema_obj) with | Some s -> Some (ctx.compile_sub ~schema_path: (Json_pointer.append (parent_path ctx.schema_path) "else") s) | None -> None in Some (fun instance path -> if if_v instance path = [] then (* if validates → apply then *) match then_v with | Some v -> v instance path | None -> [] else (* if fails → apply else *) match else_v with | Some v -> v instance path | None -> [])); } let compilers = [ compile_if ]