From a8dd9b6e3c26a664231cf7e17c1dfbc97c6201ca Mon Sep 17 00:00:00 2001 From: Maxime Levillain Date: Fri, 8 Dec 2023 11:00:40 +0100 Subject: [PATCH 1/2] fix service name in ppx --- src/ppx/ppx_common.ml | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/src/ppx/ppx_common.ml b/src/ppx/ppx_common.ml index 1340309..d93dc43 100644 --- a/src/ppx/ppx_common.ml +++ b/src/ppx/ppx_common.ml @@ -57,13 +57,16 @@ let json e = let loc = e.pexp_loc in pexp_construct ~loc (llid ~loc "EzAPI.Json") @@ Some e -let options ?register loc = +let options ?register ?name loc = let register = match register with | None -> pexp_construct ~loc (llid ~loc "true") None - | Some register -> register in { + | Some register -> register in + let name = match name with + | None -> enone ~loc + | Some name -> esome (estring ~loc name) in { path = pexp_ident ~loc (llid ~loc "EzAPI.Path.root"); input = empty ~loc; output = empty ~loc; errors = enone ~loc; params = enone ~loc; - section = enone ~loc; name = enone ~loc; descr = enone ~loc; + section = enone ~loc; name; descr = enone ~loc; security = enone ~loc; register; input_example = enone ~loc; hide = enone ~loc; output_example = enone ~loc; error_type = ptyp_constr ~loc (llid ~loc "exn") []; security_type = ptyp_constr ~loc (llid ~loc "EzAPI.no_security") []; @@ -149,8 +152,8 @@ let get_options ~loc ?name ?(client=false) p = end | "service" -> name, { acc with service = Some e; error_type = ptyp_any ~loc; security_type = ptyp_any ~loc } - | _ -> name, acc) (name, options ?register loc) l - | _ -> name, options ?register loc + | _ -> name, acc) (name, options ?register ?name loc) l + | _ -> name, options ?register ?name loc let service_value ?name ?client ~meth ~loc p = let meth = pexp_variant ~loc (String.uppercase_ascii meth) None in From e4d626140a84b9a02df32a1a89b733e7426ee3c0 Mon Sep 17 00:00:00 2001 From: Maxime Levillain Date: Fri, 8 Dec 2023 13:27:18 +0100 Subject: [PATCH 2/2] possibility to link only service --- src/ppx/ppx_common.ml | 10 +++++++++- 1 file changed, 9 insertions(+), 1 deletion(-) diff --git a/src/ppx/ppx_common.ml b/src/ppx/ppx_common.ml index d93dc43..a00d6db 100644 --- a/src/ppx/ppx_common.ml +++ b/src/ppx/ppx_common.ml @@ -153,7 +153,15 @@ let get_options ~loc ?name ?(client=false) p = | "service" -> name, { acc with service = Some e; error_type = ptyp_any ~loc; security_type = ptyp_any ~loc } | _ -> name, acc) (name, options ?register ?name loc) l - | _ -> name, options ?register ?name loc + | PStr [ {pstr_desc=Pstr_eval ({pexp_desc=Pexp_ident _; _} as e, _); _} ] -> + let o = options ?register ?name loc in + name, { o with service = Some e; error_type = ptyp_any ~loc; security_type = ptyp_any ~loc } + | PStr s -> + Format.eprintf "attribute not understood %a@." Pprintast.structure s; + name, options ?register ?name loc + | _ -> + Format.eprintf "attribute not understood@."; + name, options ?register ?name loc let service_value ?name ?client ~meth ~loc p = let meth = pexp_variant ~loc (String.uppercase_ascii meth) None in