Skip to content

Commit

Permalink
make bindoj_gen omit proper doc string (#394)
Browse files Browse the repository at this point in the history
  • Loading branch information
haochenx authored Dec 17, 2023
1 parent 7349705 commit a60dc47
Show file tree
Hide file tree
Showing 14 changed files with 1,892 additions and 121 deletions.
2 changes: 1 addition & 1 deletion doc/tests_src/ocaml_datatype_basic.md
100755 → 100644
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ module Caml :
sig
module Ppxlib = Ppxlib
module Astlib = Astlib
module Pprintast = Astlib.Pprintast
module Emitter = Bindoj_gen.Emitter
module CommonTypes : sig ... end
type signature_item = CommonTypes.signature_item
type signature = CommonTypes.signature
Expand Down
31 changes: 16 additions & 15 deletions example/ex01/generated/ex01.ml
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type nonrec my_int = int [@@ocaml.doc "definition of my_int type"]
type nonrec my_int = int
(** definition of my_int type *)

let (my_int_reflect : _ Bindoj_runtime.Refl.t) =
lazy
Expand Down Expand Up @@ -52,7 +53,7 @@ and my_int_of_json =
[@@warning "-39"]

type nonrec my_tuple = float * string
[@@ocaml.doc "definition of my_tuple type"]
(** definition of my_tuple type *)

let (my_tuple_reflect : _ Bindoj_runtime.Refl.t) =
lazy
Expand Down Expand Up @@ -149,10 +150,10 @@ and my_tuple_of_json =
[@@warning "-39"]

type student = {
admission_year : int; [@ocaml.doc "addmission_year field"]
name : string; [@ocaml.doc "name field"]
admission_year : int; (** 📅 addmission_year field *)
name : string; (** 📛 name field *)
}
[@@ocaml.doc "definition of student type"]
(** 📝 definition of student type *)

let rec (student_reflect : _ Bindoj_runtime.Refl.t) =
lazy
Expand Down Expand Up @@ -259,19 +260,19 @@ and student_of_json =
: Kxclib.Json.jv -> student option)
[@@warning "-39"]

(** definition of person type *)
type person =
| Anonymous [@ocaml.doc "Anonymous constructor"]
| With_id of int [@ocaml.doc "With_id constructor"]
| Anonymous (** Anonymous constructor *)
| With_id of int (** With_id constructor *)
| Student of {
student_id : int; [@ocaml.doc "student_id field in Student constructor"]
name : string; [@ocaml.doc "name field in Student constructor"]
} [@ocaml.doc "Student constructor"]
student_id : int; (** student_id field in Student constructor *)
name : string; (** name field in Student constructor *)
} (** Student constructor *)
| Teacher of {
faculty_id : int; [@ocaml.doc "faculty_id field in Teacher constructor"]
name : string; [@ocaml.doc "name field in Teacher constructor"]
department : string; [@ocaml.doc "dapartment field in Teacher constructor"]
} [@ocaml.doc "Teacher constructor"]
[@@ocaml.doc "definition of person type"]
faculty_id : int; (** faculty_id field in Teacher constructor *)
name : string; (** name field in Teacher constructor *)
department : string; (** dapartment field in Teacher constructor *)
} (** Teacher constructor *)

let rec (person_reflect : _ Bindoj_runtime.Refl.t) =
lazy
Expand Down
31 changes: 16 additions & 15 deletions example/ex01/generated/ex01.mli
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
type nonrec my_int = int [@@ocaml.doc "definition of my_int type"]
type nonrec my_int = int
(** definition of my_int type *)

val my_int_reflect : my_int Bindoj_runtime.Refl.t
val my_int_json_shape_explanation : Bindoj_runtime.json_shape_explanation
Expand All @@ -7,7 +8,7 @@ val my_int_of_json' : my_int Bindoj_runtime.json_full_decoder
val my_int_of_json : Kxclib.Json.jv -> my_int option

type nonrec my_tuple = float * string
[@@ocaml.doc "definition of my_tuple type"]
(** definition of my_tuple type *)

val my_tuple_reflect : my_tuple Bindoj_runtime.Refl.t
val my_tuple_json_shape_explanation : Bindoj_runtime.json_shape_explanation
Expand All @@ -16,30 +17,30 @@ val my_tuple_of_json' : my_tuple Bindoj_runtime.json_full_decoder
val my_tuple_of_json : Kxclib.Json.jv -> my_tuple option

type student = {
admission_year : int; [@ocaml.doc "addmission_year field"]
name : string; [@ocaml.doc "name field"]
admission_year : int; (** 📅 addmission_year field *)
name : string; (** 📛 name field *)
}
[@@ocaml.doc "definition of student type"]
(** 📝 definition of student type *)

val student_reflect : student Bindoj_runtime.Refl.t
val student_json_shape_explanation : Bindoj_runtime.json_shape_explanation
val student_to_json : student -> Kxclib.Json.jv
val student_of_json' : student Bindoj_runtime.json_full_decoder
val student_of_json : Kxclib.Json.jv -> student option

(** definition of person type *)
type person =
| Anonymous [@ocaml.doc "Anonymous constructor"]
| With_id of int [@ocaml.doc "With_id constructor"]
| Anonymous (** Anonymous constructor *)
| With_id of int (** With_id constructor *)
| Student of {
student_id : int; [@ocaml.doc "student_id field in Student constructor"]
name : string; [@ocaml.doc "name field in Student constructor"]
} [@ocaml.doc "Student constructor"]
student_id : int; (** student_id field in Student constructor *)
name : string; (** name field in Student constructor *)
} (** Student constructor *)
| Teacher of {
faculty_id : int; [@ocaml.doc "faculty_id field in Teacher constructor"]
name : string; [@ocaml.doc "name field in Teacher constructor"]
department : string; [@ocaml.doc "dapartment field in Teacher constructor"]
} [@ocaml.doc "Teacher constructor"]
[@@ocaml.doc "definition of person type"]
faculty_id : int; (** faculty_id field in Teacher constructor *)
name : string; (** name field in Teacher constructor *)
department : string; (** dapartment field in Teacher constructor *)
} (** Teacher constructor *)

val person_reflect : person Bindoj_runtime.Refl.t
val person_json_discriminator_value : person -> string
Expand Down
6 changes: 3 additions & 3 deletions example/ex01/generated/ex01_apidir.json
Original file line number Diff line number Diff line change
Expand Up @@ -187,14 +187,14 @@
"String": { "title": "String", "type": "string" },
"Student": {
"title": "Student",
"description": "definition of student type",
"description": "📝 definition of student type",
"type": "object",
"properties": {
"admissionYear": {
"description": "addmission_year field",
"description": "📅 addmission_year field",
"type": "integer"
},
"name": { "description": "name field", "type": "string" }
"name": { "description": "📛 name field", "type": "string" }
},
"required": ["admissionYear", "name"],
"additionalProperties": false
Expand Down
6 changes: 3 additions & 3 deletions example/ex01/generated/ex01_schema.json
Original file line number Diff line number Diff line change
Expand Up @@ -13,11 +13,11 @@
},
{
"title": "Student",
"description": "definition of student type",
"description": "📝 definition of student type",
"type": "object",
"properties": {
"admissionYear": { "description": "addmission_year field", "type": "integer" },
"name": { "description": "name field", "type": "string" }
"admissionYear": { "description": "📅 addmission_year field", "type": "integer" },
"name": { "description": "📛 name field", "type": "string" }
},
"required": ["admissionYear", "name"],
"additionalProperties": false
Expand Down
6 changes: 3 additions & 3 deletions example/ex01/src/typedesc.ml
Original file line number Diff line number Diff line change
Expand Up @@ -38,10 +38,10 @@ let my_tuple_decl = alias_decl "my_tuple" (

let student_decl = record_decl "student" [
record_field "admission_year" cty_int
~doc:(`docstr "addmission_year field");
~doc:(`docstr "📅 addmission_year field");
record_field "name" cty_string
~doc:( `docstr "name field");
] ~doc:(`docstr "definition of student type")
~doc:( `docstr "📛 name field");
] ~doc:(`docstr "📝 definition of student type")

let person_decl = variant_decl "person" [
variant_constructor "Anonymous" `no_param
Expand Down
69 changes: 32 additions & 37 deletions example/ex02/generated/ex02.ml
Original file line number Diff line number Diff line change
Expand Up @@ -52,12 +52,12 @@ and product_id_of_json =
[@@warning "-39"]

type product_details = {
name : string; [@ocaml.doc "Product name"]
description : string; [@ocaml.doc "Product description"]
price : int; [@ocaml.doc "Product price"]
count : int; [@ocaml.doc "Count of the product"]
name : string; (** Product name *)
description : string; (** Product description *)
price : int; (** Product price *)
count : int; (** Count of the product *)
}
[@@ocaml.doc "Product details"]
(** Product details *)

let rec (product_details_reflect : _ Bindoj_runtime.Refl.t) =
lazy
Expand Down Expand Up @@ -187,11 +187,8 @@ and product_details_of_json =
: Kxclib.Json.jv -> product_details option)
[@@warning "-39"]

type product = {
id : product_id; [@ocaml.doc "Product ID"]
details : product_details;
}
[@@ocaml.doc "Product"]
type product = { id : product_id; (** Product ID *) details : product_details }
(** Product *)

let rec (product_reflect : _ Bindoj_runtime.Refl.t) =
lazy
Expand Down Expand Up @@ -412,19 +409,19 @@ and order_id_of_json =
: Kxclib.Json.jv -> order_id option)
[@@warning "-39"]

(** Payment method of an order *)
type payment_method =
| Credit_card of {
card_number : string; [@ocaml.doc "Card number"]
holder_name : string; [@ocaml.doc "Card holder name"]
expiration_date : int * int; [@ocaml.doc "Expiration date"]
cvv : string; [@ocaml.doc "Card CVV"]
} [@ocaml.doc "Payment by credit card"]
card_number : string; (** Card number *)
holder_name : string; (** Card holder name *)
expiration_date : int * int; (** Expiration date *)
cvv : string; (** Card CVV *)
} (** Payment by credit card *)
| Bank_transfer of {
account_number : string; [@ocaml.doc "Account number"]
bank_name : string; [@ocaml.doc "Bank name"]
holder_name : string; [@ocaml.doc "Account holder name"]
} [@ocaml.doc "Payment by bank transer"]
[@@ocaml.doc "Payment method of an order"]
account_number : string; (** Account number *)
bank_name : string; (** Bank name *)
holder_name : string; (** Account holder name *)
} (** Payment by bank transer *)

let rec (payment_method_reflect : _ Bindoj_runtime.Refl.t) =
lazy
Expand Down Expand Up @@ -709,8 +706,8 @@ and payment_method_of_json =

type order_details = {
products : (product_id * int) list;
[@ocaml.doc "ID and it's count of ordered products"]
payment_method : payment_method; [@ocaml.doc "Payment method"]
(** ID and it's count of ordered products *)
payment_method : payment_method; (** Payment method *)
}

let rec (order_details_reflect : _ Bindoj_runtime.Refl.t) =
Expand Down Expand Up @@ -1050,7 +1047,7 @@ and order_details_of_json =

type nonrec order_status =
[ `Unpaid | `Paid | `Shipped | `Delivered | `Canceled ]
[@@ocaml.doc "Status of an order"]
(** Status of an order *)

let (order_status_reflect : _ Bindoj_runtime.Refl.t) =
lazy
Expand Down Expand Up @@ -1135,7 +1132,7 @@ and order_status_of_json =
[@@warning "-39"]

type order = {
id : order_id; [@ocaml.doc "Order ID"]
id : order_id; (** Order ID *)
total_price : int;
details : order_details;
status : order_status;
Expand Down Expand Up @@ -1587,15 +1584,14 @@ and order_of_json =

type product_query = {
searchQuery : string option;
[@ocaml.doc
"Optional search string to match product names or descriptions"]
(** Optional search string to match product names or descriptions *)
minimum_price : int option;
[@ocaml.doc "Optional minimum price constraint for a product"]
(** Optional minimum price constraint for a product *)
maximum_price : int option;
[@ocaml.doc "Optional maximum price constraint for a product"]
limit : int option; [@ocaml.doc "Number limit of data to be acquired."]
(** Optional maximum price constraint for a product *)
limit : int option; (** Number limit of data to be acquired. *)
}
[@@ocaml.doc "Query to search products"]
(** Query to search products *)

let rec (product_query_reflect : _ Bindoj_runtime.Refl.t) =
lazy
Expand Down Expand Up @@ -1745,16 +1741,15 @@ and product_query_of_json =
[@@warning "-39"]

type order_query = {
products : int list option; [@ocaml.doc "List of product IDs in the order"]
status : order_status list option;
[@ocaml.doc "Optional order status constraint"]
products : int list option; (** List of product IDs in the order *)
status : order_status list option; (** Optional order status constraint *)
minimum_price : int option;
[@ocaml.doc "Optional minimum total price constraint for the order"]
(** Optional minimum total price constraint for the order *)
maximum_price : int option;
[@ocaml.doc "Optional maximum total price constraint for the order"]
limit : int option; [@ocaml.doc "Number limit of data to be acquired."]
(** Optional maximum total price constraint for the order *)
limit : int option; (** Number limit of data to be acquired. *)
}
[@@ocaml.doc "Query to search orders"]
(** Query to search orders *)

let rec (order_query_reflect : _ Bindoj_runtime.Refl.t) =
lazy
Expand Down
Loading

0 comments on commit a60dc47

Please sign in to comment.