From 242c97d1f1e310476f2159cc7cb69c7bf4728432 Mon Sep 17 00:00:00 2001 From: Pierre Boutillier Date: Tue, 15 Jan 2019 14:27:06 +0100 Subject: [PATCH] ocplib-json-typed: import ' Variable defintion path in json_schema' from upstream It is upstream acfb41f711cbda67680b84d0f8292e2a1849c711 --- .../ocplib-json-typed/src/json_encoding.ml | 12 +++++------ .../ocplib-json-typed/src/json_encoding.mli | 2 +- vendors/ocplib-json-typed/src/json_schema.ml | 20 +++++++++---------- vendors/ocplib-json-typed/src/json_schema.mli | 8 ++++---- 4 files changed, 21 insertions(+), 21 deletions(-) diff --git a/vendors/ocplib-json-typed/src/json_encoding.ml b/vendors/ocplib-json-typed/src/json_encoding.ml index 42a2d1d62..8255818b1 100644 --- a/vendors/ocplib-json-typed/src/json_encoding.ml +++ b/vendors/ocplib-json-typed/src/json_encoding.ml @@ -403,7 +403,7 @@ let patch_description ?title ?description (elt : Json_schema.element) = | None, Some _ -> { elt with description } | Some _, Some _ -> { elt with title ; description } -let schema encoding = +let schema ?definitions_path encoding = let open Json_schema in let sch = ref any in let rec prod l1 l2 = match l1 with @@ -472,7 +472,7 @@ let schema encoding = | Describe { id = name ; title ; description ; encoding } -> let open Json_schema in let schema = patch_description ?title ?description (schema encoding) in - let s, def = add_definition name schema !sch in + let s, def = add_definition ?definitions_path name schema !sch in sch := fst (merge_definitions (!sch, s)) ; def | Custom (_, s) -> @@ -484,10 +484,10 @@ let schema encoding = | Conv (_, _, t, None) -> schema t | Mu { id = name ; title ; description ; self = f } -> let fake_schema = - if definition_exists name !sch then - update (definition_ref name) !sch + if definition_exists ?definitions_path name !sch then + update (definition_ref ?definitions_path name) !sch else - let sch, elt = add_definition name (element Dummy) !sch in + let sch, elt = add_definition ?definitions_path name (element Dummy) !sch in update elt sch in let fake_self = Custom ({ write = (fun _ _ -> assert false) ; @@ -497,7 +497,7 @@ let schema encoding = patch_description ?title ?description (schema (f fake_self)) in - let nsch, def = add_definition name root !sch in + let nsch, def = add_definition ?definitions_path name root !sch in sch := nsch ; def | Array t -> element (Monomorphic_array (schema t, array_specs)) diff --git a/vendors/ocplib-json-typed/src/json_encoding.mli b/vendors/ocplib-json-typed/src/json_encoding.mli index efcc777df..ad4607a8f 100644 --- a/vendors/ocplib-json-typed/src/json_encoding.mli +++ b/vendors/ocplib-json-typed/src/json_encoding.mli @@ -400,7 +400,7 @@ val any_schema : Json_schema.schema encoding (** Describe an encoding in JSON schema format. May raise {!Bad_schema}. *) -val schema : 't encoding -> Json_schema.schema +val schema : ?definitions_path:string -> 't encoding -> Json_schema.schema (** Name a definition so its occurences can be shared in the JSON schema. The first parameter is a path, that must be unique and diff --git a/vendors/ocplib-json-typed/src/json_schema.ml b/vendors/ocplib-json-typed/src/json_schema.ml index 334de2da3..204dac109 100644 --- a/vendors/ocplib-json-typed/src/json_schema.ml +++ b/vendors/ocplib-json-typed/src/json_schema.ml @@ -1113,27 +1113,27 @@ module Make (Repr : Json_repr.Repr) = struct collect schema.root ; { schema with definitions = !res } - let definition_path_of_name name = + let definition_path_of_name ?(definitions_path="/definitions/") name = path_of_json_pointer ~wildcards:false @@ match String.get name 0 with | exception _ -> raise (Bad_reference name) | '/' -> name - | _ -> "/definitions/" ^ name + | _ -> definitions_path ^ name - let find_definition name schema = - let path = definition_path_of_name name in + let find_definition ?definitions_path name schema = + let path = definition_path_of_name ?definitions_path name in find_definition path schema.definitions - let definition_ref name = - let path = definition_path_of_name name in + let definition_ref ?definitions_path name = + let path = definition_path_of_name ?definitions_path name in element (Def_ref path) - let definition_exists name schema = - let path = definition_path_of_name name in + let definition_exists ?definitions_path name schema = + let path = definition_path_of_name ?definitions_path name in definition_exists path schema.definitions - let add_definition name elt schema = - let path = definition_path_of_name name in + let add_definition ?definitions_path name elt schema = + let path = definition_path_of_name ?definitions_path name in (* check inside def *) let definitions = insert_definition path elt schema.definitions in { schema with definitions }, element (Def_ref path) diff --git a/vendors/ocplib-json-typed/src/json_schema.mli b/vendors/ocplib-json-typed/src/json_schema.mli index 08ae8d863..e4fce130e 100644 --- a/vendors/ocplib-json-typed/src/json_schema.mli +++ b/vendors/ocplib-json-typed/src/json_schema.mli @@ -176,19 +176,19 @@ val simplify : schema -> schema error raised by {!Json_repr.path_of_json_pointer} with [~wildcards:false]. Returns the modified schema and the [Def_ref] node that references this definition to be used in the schema. *) -val add_definition : string -> element -> schema -> schema * element +val add_definition : ?definitions_path:string -> string -> element -> schema -> schema * element (** Finds a definition by its path, may raise [Not_found]. See {!add_definition} for the name format.*) -val find_definition : string -> schema -> element +val find_definition : ?definitions_path:string -> string -> schema -> element (** Tells if a path leads to a definition. See {!add_definition} for the name format. *) -val definition_exists : string -> schema -> bool +val definition_exists : ?definitions_path:string -> string -> schema -> bool (** Build a reference to a definition. See {!add_definition} for the name format. *) -val definition_ref : string -> element +val definition_ref : ?definitions_path:string -> string -> element (** {2 Predefined values} *) (***********************************************)