Skip to content

Commit

Permalink
Make "additionalProperties" “boolable”
Browse files Browse the repository at this point in the history
  • Loading branch information
smondet committed Nov 24, 2024
1 parent fb9dfd8 commit 14c74a3
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
7 changes: 6 additions & 1 deletion lib/json_schema.atd
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,11 @@ type 'a or_ref = [
| Ref of ref_
] <ocaml repr="classic"> <json adapter.ocaml="Json_schema_adapters.Or_ref">

type 'a or_bool = [
| Obj of 'a
| Bool of bool
] <ocaml repr="classic"> <json adapter.ocaml="Json_schema_adapters.Or_bool">

type typ = [
| Integer <json name="integer">
| Number <json name="number">
Expand Down Expand Up @@ -58,7 +63,7 @@ type schema = {

(* 10.3.2 keywords for applying subschemas to objects *)
~properties : (string * schema or_ref) list <json repr="object"> nullable;
~additional_properties <json name="additionalProperties">: schema nullable;
~additional_properties <json name="additionalProperties">: schema or_bool nullable;

(* fields from Json Schema Validation https://json-schema.org/draft/2020-12/json-schema-validation.html *)

Expand Down
11 changes: 11 additions & 0 deletions lib/json_schema_adapters.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,4 +9,15 @@ module Or_ref = struct
| x -> x
end

module Or_bool = struct
let normalize : Yojson.Safe.t -> Yojson.Safe.t = function
| `Bool b -> `List [ `String "Bool"; `Bool b ]
| obj -> `List [ `String "Obj"; obj ]

let restore = function
| `List [ `String "Bool"; `Bool b ] -> `Bool b
| `List [ `String "Obj"; obj ] -> obj
| x -> x
end

module Ref = Utils.Fresh (String) ()

0 comments on commit 14c74a3

Please sign in to comment.