Skip to content

Commit

Permalink
turn description into atd doc
Browse files Browse the repository at this point in the history
  • Loading branch information
Khady committed Feb 27, 2024
1 parent 55b7a39 commit 6b41729
Show file tree
Hide file tree
Showing 4 changed files with 94 additions and 82 deletions.
17 changes: 14 additions & 3 deletions lib/generator.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,13 @@ let record_field_name str =
let cleaned_field_name = Utils.sanitize_name str in
if String.equal str cleaned_field_name then str else sprintf {|%s <json name="%s">|} cleaned_field_name str

let define_type name type_ = sprintf "type %s = %s\n" (type_name name) type_
let define_type ?doc name type_ =
let doc =
match doc with
| None -> ""
| Some doc -> sprintf {|<doc text=%S>|} doc
in
sprintf "type %s = %s %s\n" (type_name name) type_ doc

let process_int_type schema =
match schema.format with
Expand Down Expand Up @@ -149,7 +155,7 @@ and process_nested_schema_type ~ancestors schema =
match merge_all_of schema with
| { one_of = Some _; _ } | { typ = Some Object; properties = Some _; _ } | { enum = Some _; _ } ->
let nested_type_name = concat_camelCase (List.rev ancestors) in
let nested = define_type nested_type_name (process_schema_type ~ancestors schema) in
let nested = define_type nested_type_name (process_schema_type ~ancestors schema) ?doc:schema.description in
Buffer.add_string output (nested ^ "\n");
type_name nested_type_name
| _ -> process_schema_type ~ancestors schema
Expand Down Expand Up @@ -200,7 +206,12 @@ and process_enums enums =
let process_schemas (schemas : (string * schema or_ref) list) =
List.fold_left
(fun acc (name, schema_or_ref) ->
define_type name (make_type_from_schema_or_ref ~ancestors:[ name ] schema_or_ref) :: acc
let doc =
match schema_or_ref with
| Ref _ -> None
| Obj schema -> schema.description
in
define_type ?doc name (make_type_from_schema_or_ref ~ancestors:[ name ] schema_or_ref) :: acc
)
[] schemas

Expand Down
Loading

0 comments on commit 6b41729

Please sign in to comment.