123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181(**************************************************************************)(* resto *)(* Copyright (C) 2016, OCamlPro. *)(* *)(* All rights reserved. This file is distributed under the terms *)(* of the GNU Lesser General Public License version 2.1, with the *)(* special exception on linking described in the file LICENSE. *)(* *)(**************************************************************************)moduleEncoding=structincludeJson_encodingtype'at='aencodingtypeschema=Json_schema.schemaletuntyped=obj1(req"untyped"string)letconvfgt=conv~schema:(schemat)fgtmoduleStringMap=Map.Make(String)letarg_encoding=letopenJson_encodinginconv(fun{Resto.Arg.name;descr}->(name,descr))(fun(name,descr)->{name;descr})(obj2(req"name"string)(opt"descr"string))openResto.Descriptionletmeth_encoding=Json_encoding.string_enum["GET",`GET;"POST",`POST;"DELETE",`DELETE;"PUT",`PUT;"PATCH",`PATCH]letpath_item_encoding=letopenJson_encodinginunion[casestring(functionPStatics->Somes|_->None)(funs->PStatics);casearg_encoding(functionPDynamics->Somes|_->None)(funs->PDynamics);]letquery_kind_encoding=letopenJson_encodinginunion[case(obj1(req"single"arg_encoding))(functionSingles->Somes|_->None)(funs->Singles);case(obj1(req"optional"arg_encoding))(functionOptionals->Somes|_->None)(funs->Optionals);case(obj1(req"flag"empty))(functionFlag->Some()|_->None)(fun()->Flag);case(obj1(req"multi"arg_encoding))(functionMultis->Somes|_->None)(funs->Multis);]letquery_item_encoding=letopenJson_encodinginconv(fun{name;description;kind}->(name,description,kind))(fun(name,description,kind)->{name;description;kind})(obj3(req"name"string)(opt"description"string)(req"kind"query_kind_encoding))letservice_descr_encoding=letopenJson_encodinginconv(fun{meth;path;description;query;input;output;error}->(meth,path,description,query,input,output,error))(fun(meth,path,description,query,input,output,error)->{meth;path;description;query;input;output;error})(obj7(req"meth"meth_encoding)(req"path"(listpath_item_encoding))(opt"description"string)(req"query"(listquery_item_encoding))(opt"input"any_schema)(req"output"any_schema)(req"erro"any_schema))letdirectory_descr_encoding=letopenJson_encodinginmu"service_tree"@@fundirectory_descr_encoding->letstatic_subdirectories_descr_encoding=union[case(obj1(req"suffixes"(list(obj2(req"name"string)(req"tree"directory_descr_encoding)))))(functionSuffixesmap->Some(Resto.StringMap.bindingsmap)|_->None)(funm->letaddacc(n,t)=Resto.StringMap.addntaccinSuffixes(List.fold_leftaddResto.StringMap.emptym));case(obj1(req"dynamic_dispatch"(obj2(req"arg"arg_encoding)(req"tree"directory_descr_encoding))))(functionArg(ty,tree)->Some(ty,tree)|_->None)(fun(ty,tree)->Arg(ty,tree))]inletstatic_directory_descr_encoding=conv(fun{services;subdirs}->letfinds=trySome(Resto.MethMap.findsservices)withNot_found->Nonein(find`GET,find`POST,find`DELETE,find`PUT,find`PATCH,subdirs))(fun(get,post,delete,put,patch,subdirs)->letaddmethsservices=matchswith|None->services|Somes->Resto.MethMap.addmethsservicesinletservices=Resto.MethMap.empty|>add`GETget|>add`POSTpost|>add`DELETEdelete|>add`PUTput|>add`PATCHpatchin{services;subdirs})(obj6(opt"get_service"service_descr_encoding)(opt"post_service"service_descr_encoding)(opt"delete_service"service_descr_encoding)(opt"put_service"service_descr_encoding)(opt"patch_service"service_descr_encoding)(opt"subdirs"static_subdirectories_descr_encoding))inunion[case(obj1(req"static"static_directory_descr_encoding))(functionStaticdescr->Somedescr|_->None)(fundescr->Staticdescr);case(obj1(req"dynamic"(optionstring)))(functionDynamicdescr->Somedescr|_->None)(fundescr->Dynamicdescr);]letdescription_request_encoding=conv(fun{recurse}->recurse)(functionrecurse->{recurse})(obj1(dft"recursive"boolfalse))letdescription_answer_encoding=directory_descr_encodingendmoduletypeVALUE=sigtypettype'aencodingvalconstruct:'aencoding->'a->tvaldestruct:'aencoding->t->'aendmoduleEzjsonm=structtypet=Json_repr.Ezjsonm.valueletconstruct=Json_encoding.constructletdestruct=Json_encoding.destructendmoduleBson=structopenJson_repr_bsontypet=Repr.valueletconstruct=Json_encoding.constructletdestruct=Json_encoding.destructend