99(* *************************************************************************)
1010
1111type t = {
12- doc_id : int ; (* uniq service identifier *)
12+ mutable doc_id : int ; (* uniq service identifier *)
1313 doc_name : string option ;
1414 doc_descr : string option ;
1515 doc_path : string ;
1616 doc_args : Arg .descr list ;
1717 doc_params : Param .t list ;
18- mutable doc_registered : bool ;
1918 doc_section : section ;
2019 doc_input : Json_schema .schema Lazy .t option ;
2120 doc_output : Json_schema .schema Lazy .t option ;
@@ -25,29 +24,24 @@ type t = {
2524 doc_security : Security .scheme list ;
2625 doc_input_example : Json_repr .any option ;
2726 doc_output_example : Json_repr .any option ;
27+ doc_hide : bool ;
28+ doc_register : bool ;
2829}
2930
3031and section = {
3132 section_name : string ;
3233 mutable section_docs : t list ;
3334}
3435
35- let services = ref []
36- let nservices = ref 0
3736let default_section = { section_name = " Misc" ; section_docs = [] }
3837let sections = ref [ default_section ]
3938
4039let definitions_path = " /components/schemas/"
4140
42- let rec update_service_list services doc = match services with
43- | [] -> [ doc ]
44- | h :: t when h.doc_path = doc.doc_path -> doc :: t
45- | h :: t -> h :: (update_service_list t doc)
46-
4741let make :
48- type i . ?name :string -> ?descr :string -> ?register :bool -> ?section :section ->
42+ type i . ?name :string -> ?descr :string -> ?register :bool -> ?hide : bool -> ? section :section ->
4943 ?input_example :i -> ?output_example:'o -> (_, i, 'o, _, _) Service.t -> t =
50- fun ?name ?descr ?(register =true ) ?(section =default_section) ?input_example ?output_example s ->
44+ fun ?name ?descr ?(register =true ) ?(hide = false ) ?( section =default_section) ?input_example ?output_example s ->
5145 let path = Service. path s in
5246 let input = Service. input s in
5347 let output = Service. output s in
@@ -67,29 +61,35 @@ let make :
6761 let doc_output_example = match output_example, output with
6862 | Some ex , Service.IO. Json enc -> Some (Json_repr. to_any @@ Json_encoding. construct enc ex)
6963 | _ -> None in
70- let doc_id = if register then (
71- let id = ! nservices in
72- incr nservices;
73- id)
74- else - 1 in
75- let doc = {
64+ {
7665 doc_path = Path. to_string path;
7766 doc_args = Path. args path;
7867 doc_params = Service. params s;
79- doc_registered = false ;
80- doc_name = name; doc_descr = descr; doc_id;
68+ doc_name = name; doc_descr = descr; doc_id = - 1 ;
8169 doc_section = section;
8270 doc_input; doc_mime;
8371 doc_output;
8472 doc_errors = Err. merge_errs_same_code ~definitions_path (Service. errors s);
8573 doc_meth = Service. meth s;
8674 doc_security = (Service. security s :> Security.scheme list );
87- doc_input_example; doc_output_example
88- } in
89- if register then (
90- section.section_docs < - update_service_list section.section_docs doc;
91- services := update_service_list ! services doc);
92- doc
75+ doc_input_example; doc_output_example;
76+ doc_hide = hide;
77+ doc_register = register
78+ }
79+
80+ let rec update_service_list services doc = match services with
81+ | [] -> [ doc ]
82+ | h :: t when h.doc_path = doc.doc_path -> doc :: t
83+ | h :: t -> h :: (update_service_list t doc)
84+
85+ let services = ref []
86+ let nservices = ref 0
87+
88+ let register doc =
89+ doc.doc_id < - ! nservices;
90+ incr nservices;
91+ doc.doc_section.section_docs < - update_service_list doc.doc_section.section_docs doc;
92+ services := update_service_list ! services doc
9393
9494let section section_name =
9595 let s = { section_name; section_docs = [] } in
@@ -98,7 +98,7 @@ let section section_name =
9898
9999let all_services_registered () =
100100 let s = List. fold_left (fun acc doc ->
101- if not doc.doc_registered then
101+ if doc.doc_id = - 1 && doc.doc_register then
102102 Printf. sprintf " %s%s is not registered\n " acc doc.doc_path
103103 else acc
104104 ) " " ! services in
0 commit comments