Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make ppx inline Ppx_deriving_router_runtime #9

Open
davesnx opened this issue Sep 12, 2024 · 5 comments
Open

Make ppx inline Ppx_deriving_router_runtime #9

davesnx opened this issue Sep 12, 2024 · 5 comments

Comments

@davesnx
Copy link
Contributor

davesnx commented Sep 12, 2024

The ppx could generate the full module binding on each case (even when json decoding is used) and avoid users to open the runtime, which is expected to be there in the first place.

module Api = struct
-  open Ppx_deriving_router_runtime.Primitives
-  open Ppx_deriving_json_runtime.Primitives

  type user = { id : int } [@@deriving json]

  type _ t =
    | List_users : user list t [@GET "/"]
    | Create_user : user t [@POST "/"]
    | Get_user : { id : int } -> user t [@GET "/:id"]
    | Raw : Ppx_deriving_router_runtime.response t [@GET "/raw"]
  [@@deriving router]
end
@andreypopp
Copy link
Owner

The open Ppx_deriving_router_runtime.Primitives is needed because ppx cannot know if types like string, _ list or other are the ones from Stdlib or user-defined.

If we make it generate fully qualified names with Primitives in it, then this code would not work:

type string = ...

let x = {a : string} [@@deriving json]

@davesnx
Copy link
Contributor Author

davesnx commented Sep 12, 2024

but that's a good tradeoff, no? If you define your own primitive types... it will def break

@andreypopp
Copy link
Owner

but that's a good tradeoff, no? If you define your own primitive types... it will def break

it won't break if you define/derive to_json/of_json, it'll shadow Primitives

@davesnx
Copy link
Contributor Author

davesnx commented Sep 12, 2024

But why would you define a string type and string_to_json/string_of_json?

@davesnx
Copy link
Contributor Author

davesnx commented Sep 20, 2024

Similar concept/tradeoff from melange-json ppx: melange-community/melange-json#19

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants