Skip to content

Commit

Permalink
fix order of argument in request
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtori committed Dec 2, 2024
1 parent 47c9389 commit db0d5df
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 5 deletions.
6 changes: 3 additions & 3 deletions src/ppx/ppx_common.ml
Original file line number Diff line number Diff line change
Expand Up @@ -785,13 +785,13 @@ let request_expr ~meth ~name ?sname ~loc options =
if !global_base && options.nargs = 0 then f [%expr fun ?(base= !ezreq_base) () -> [%e e]]
else if !global_base then f [%expr fun ?(base= !ezreq_base) -> [%e e]]
else f [%expr fun base -> [%e e]] in
let rec args_pat i e =
let rec args_pat n i e =
if i = 0 then e
else [%expr fun [%p pvar ~loc ("arg" ^ string_of_int i)] -> [%e args_pat (i-1) e]] in
else [%expr fun [%p pvar ~loc ("arg" ^ string_of_int (n-i+1))] -> [%e args_pat n (i-1) e]] in
let rec args_expr i =
if i = 0 then [%expr EzAPI.Req.dummy]
else [%expr [%e args_expr (i-1)], [%e evar ~loc ("arg" ^ string_of_int i)]] in
let expr = f @@ args_pat options.nargs @@ [%expr
let expr = f @@ args_pat options.nargs options.nargs @@ [%expr
EzReq_lwt.wrap @@ EzReq_lwt.request ?headers:[%e headers_expr] ?params ?msg ?post:[%e post_expr]
?url_encode:[%e url_encode_expr] ~input:[%e input_expr] base
[%e service] [%e args_expr options.nargs]
Expand Down
2 changes: 1 addition & 1 deletion test/ppx/test_ppx_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ and base = "http://localhost:8080"
type test_derive = {
foo: string;
bar: int;
} [@@get {path="/test/getter/{id: string}"; name="bla"}]
} [@@get {path="/test/getter/{id: string}/{numb: int}"; name="bla"}]

type foo = [ `foo | `bar ] [@@deriving encoding {assoc}]

Expand Down
2 changes: 1 addition & 1 deletion test/ppx/test_ppx_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@ let%param foo = ()
let echo ([%req], s) () =
Format.eprintf "foo: %s@." @@ Option.value ~default:"none" req#foo;
EzAPIServer.return_ok @@ "echo arg: " ^ s
[@@get {path="/echo/{arg : string}"; raw_output=[]; params=[foo]; debug}]
[@@get {path="/echo/{arg : string}"; raw_output=[]; params=[foo]}]

let echo_input s =
EzAPIServer.return_ok @@ "echo input: " ^ s
Expand Down

0 comments on commit db0d5df

Please sign in to comment.