Skip to content

Commit

Permalink
more derivers
Browse files Browse the repository at this point in the history
  • Loading branch information
maxtori committed Oct 9, 2024
1 parent 85f123a commit 25ffc33
Show file tree
Hide file tree
Showing 8 changed files with 153 additions and 63 deletions.
9 changes: 9 additions & 0 deletions src/ppx/dune
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@
(libraries ppx_common)
(ppx_runtime_libraries ezAPIServer))

(library
(name ppx_req)
(public_name ez_api.ppx_req)
(optional)
(modules ppx_req)
(kind ppx_rewriter)
(libraries ppx_common)
(ppx_runtime_libraries ezReq_lwt))

(library
(name ppx_deriving_err_case)
(public_name ez_api.ppx_err_case)
Expand Down
2 changes: 1 addition & 1 deletion src/ppx/ppx.ml
Original file line number Diff line number Diff line change
Expand Up @@ -10,4 +10,4 @@

let () =
Ppxlib.Driver.register_transformation "ez_api" ~impl:Ppx_common.impl;
Ppx_common.derivers ()
Ppx_common.derivers None
5 changes: 3 additions & 2 deletions src/ppx/ppx_client.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
(**************************************************************************)

let () =
Ppxlib.Driver.register_transformation "ez_api_client" ~impl:(Ppx_common.impl ~kind:`client);
Ppx_common.derivers ()
let kind = Some `client in
Ppxlib.Driver.register_transformation "ez_api_client" ~impl:(Ppx_common.impl ?kind);
Ppx_common.derivers kind
172 changes: 119 additions & 53 deletions src/ppx/ppx_common.ml

Large diffs are not rendered by default.

14 changes: 14 additions & 0 deletions src/ppx/ppx_req.ml
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
(**************************************************************************)
(* *)
(* Copyright 2018-2023 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. *)
(* *)
(**************************************************************************)

let () =
let kind = Some `request in
Ppxlib.Driver.register_transformation "ez_api_req" ~impl:(Ppx_common.impl ?kind);
Ppx_common.derivers kind
5 changes: 3 additions & 2 deletions src/ppx/ppx_server.ml
Original file line number Diff line number Diff line change
Expand Up @@ -9,5 +9,6 @@
(**************************************************************************)

let () =
Ppxlib.Driver.register_transformation "ez_api_server" ~impl:(Ppx_common.impl ~kind:`server);
Ppx_common.derivers ()
let kind = Some `server in
Ppxlib.Driver.register_transformation "ez_api_server" ~impl:(Ppx_common.impl ?kind);
Ppx_common.derivers kind
2 changes: 1 addition & 1 deletion test/ppx/dune
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
(library
(name test_ppx_lib)
(modules test_ppx_lib)
(preprocess (pps ez_api.ppx ppx_deriving_encoding)))
(preprocess (pps ppx_deriving_encoding ez_api.ppx_req)))

(executable
(name test_ppx_server)
Expand Down
7 changes: 3 additions & 4 deletions test/ppx/test_ppx_lib.ml
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,12 @@ let%service errors = [
EzAPI.Err.make ~code:400 ~name:"Error" ~encoding:error_enc ~select:Option.some ~deselect:Fun.id
]
and security : EzAPI.Security.bearer list = [ `Bearer {EzAPI.Security.bearer_name="Bearer"; format=None} ]
and base = "http://localhost:8080"

type nonrec test_derive_input = {
type test_derive = {
foo: string;
bar: int;
}
and test_derive_output = int
[@@post {path="/test/getter"}]
} [@@get {path="/test/getter"; debug}]

let%post echo_input = {
path="/echo_input"; raw_input=["text/plain"];
Expand Down

0 comments on commit 25ffc33

Please sign in to comment.