Skip to content

Commit

Permalink
auto-format ocaml petstore
Browse files Browse the repository at this point in the history
  • Loading branch information
wing328 committed Aug 8, 2019
1 parent 760d0ed commit 2a44261
Show file tree
Hide file tree
Showing 15 changed files with 333 additions and 282 deletions.
145 changes: 86 additions & 59 deletions samples/client/petstore/ocaml/src/apis/pet_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,76 +6,103 @@
*)

let add_pet ~body =
let open Lwt in
let uri = Request.build_uri "/pet" in
let headers = Request.default_headers in
let body = Request.write_as_json_body Pet.to_yojson body in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
Request.handle_unit_response resp
let open Lwt in
let uri = Request.build_uri "/pet" in
let headers = Request.default_headers in
let body = Request.write_as_json_body Pet.to_yojson body in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body
>>= fun (resp, body) -> Request.handle_unit_response resp

let delete_pet ~pet_id ?api_key () =
let open Lwt in
let uri = Request.build_uri "/pet/{petId}" in
let headers = Request.default_headers in
let headers = Request.maybe_add_header headers "api_key" (fun x -> x) api_key in
let uri = Request.replace_path_param uri "petId" Int64.to_string pet_id in
Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) ->
Request.handle_unit_response resp
let open Lwt in
let uri = Request.build_uri "/pet/{petId}" in
let headers = Request.default_headers in
let headers =
Request.maybe_add_header headers "api_key" (fun x -> x) api_key
in
let uri = Request.replace_path_param uri "petId" Int64.to_string pet_id in
Cohttp_lwt_unix.Client.call `DELETE uri ~headers
>>= fun (resp, body) -> Request.handle_unit_response resp

let find_pets_by_status ~status =
let open Lwt in
let uri = Request.build_uri "/pet/findByStatus" in
let headers = Request.default_headers in
let uri = Request.add_query_param_list uri "status" (List.map Enums.show_pet_status) status in
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
Request.read_json_body_as_list_of (JsonSupport.unwrap Pet.of_yojson) resp body
let open Lwt in
let uri = Request.build_uri "/pet/findByStatus" in
let headers = Request.default_headers in
let uri =
Request.add_query_param_list uri "status"
(List.map Enums.show_pet_status)
status
in
Cohttp_lwt_unix.Client.call `GET uri ~headers
>>= fun (resp, body) ->
Request.read_json_body_as_list_of
(JsonSupport.unwrap Pet.of_yojson)
resp body

let find_pets_by_tags ~tags =
let open Lwt in
let uri = Request.build_uri "/pet/findByTags" in
let headers = Request.default_headers in
let uri = Request.add_query_param_list uri "tags" (List.map (fun x -> x)) tags in
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
Request.read_json_body_as_list_of (JsonSupport.unwrap Pet.of_yojson) resp body
let open Lwt in
let uri = Request.build_uri "/pet/findByTags" in
let headers = Request.default_headers in
let uri =
Request.add_query_param_list uri "tags" (List.map (fun x -> x)) tags
in
Cohttp_lwt_unix.Client.call `GET uri ~headers
>>= fun (resp, body) ->
Request.read_json_body_as_list_of
(JsonSupport.unwrap Pet.of_yojson)
resp body

let get_pet_by_id ~pet_id =
let open Lwt in
let uri = Request.build_uri "/pet/{petId}" in
let headers = Request.default_headers in
let headers = Cohttp.Header.add headers "api_key" Request.api_key in
let uri = Request.replace_path_param uri "petId" Int64.to_string pet_id in
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap Pet.of_yojson) resp body
let open Lwt in
let uri = Request.build_uri "/pet/{petId}" in
let headers = Request.default_headers in
let headers = Cohttp.Header.add headers "api_key" Request.api_key in
let uri = Request.replace_path_param uri "petId" Int64.to_string pet_id in
Cohttp_lwt_unix.Client.call `GET uri ~headers
>>= fun (resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap Pet.of_yojson) resp body

let update_pet ~body =
let open Lwt in
let uri = Request.build_uri "/pet" in
let headers = Request.default_headers in
let body = Request.write_as_json_body Pet.to_yojson body in
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
Request.handle_unit_response resp
let open Lwt in
let uri = Request.build_uri "/pet" in
let headers = Request.default_headers in
let body = Request.write_as_json_body Pet.to_yojson body in
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body
>>= fun (resp, body) -> Request.handle_unit_response resp

let update_pet_with_form ~pet_id ?name ?status () =
let open Lwt in
let uri = Request.build_uri "/pet/{petId}" in
let headers = Request.default_headers in
let uri = Request.replace_path_param uri "petId" Int64.to_string pet_id in
let body = Request.init_form_encoded_body () in
let body = Request.maybe_add_form_encoded_body_param body "name" (fun x -> x) name in
let body = Request.maybe_add_form_encoded_body_param body "status" (fun x -> x) status in
let body = Request.finalize_form_encoded_body body in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
Request.handle_unit_response resp
let open Lwt in
let uri = Request.build_uri "/pet/{petId}" in
let headers = Request.default_headers in
let uri = Request.replace_path_param uri "petId" Int64.to_string pet_id in
let body = Request.init_form_encoded_body () in
let body =
Request.maybe_add_form_encoded_body_param body "name" (fun x -> x) name
in
let body =
Request.maybe_add_form_encoded_body_param body "status" (fun x -> x) status
in
let body = Request.finalize_form_encoded_body body in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body
>>= fun (resp, body) -> Request.handle_unit_response resp

let upload_file ~pet_id ?additional_metadata ?file () =
let open Lwt in
let uri = Request.build_uri "/pet/{petId}/uploadImage" in
let headers = Request.default_headers in
let uri = Request.replace_path_param uri "petId" Int64.to_string pet_id in
let body = Request.init_form_encoded_body () in
let body = Request.maybe_add_form_encoded_body_param body "additional_metadata" (fun x -> x) additional_metadata in
let body = Request.maybe_add_form_encoded_body_param body "file" (fun x -> x) file in
let body = Request.finalize_form_encoded_body body in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap Api_response.of_yojson) resp body

let open Lwt in
let uri = Request.build_uri "/pet/{petId}/uploadImage" in
let headers = Request.default_headers in
let uri = Request.replace_path_param uri "petId" Int64.to_string pet_id in
let body = Request.init_form_encoded_body () in
let body =
Request.maybe_add_form_encoded_body_param body "additional_metadata"
(fun x -> x)
additional_metadata
in
let body =
Request.maybe_add_form_encoded_body_param body "file" (fun x -> x) file
in
let body = Request.finalize_form_encoded_body body in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body
>>= fun (resp, body) ->
Request.read_json_body_as
(JsonSupport.unwrap Api_response.of_yojson)
resp body
17 changes: 15 additions & 2 deletions samples/client/petstore/ocaml/src/apis/pet_api.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,10 +6,23 @@
*)

val add_pet : body:Pet.t -> unit Lwt.t

val delete_pet : pet_id:int64 -> ?api_key:string -> unit -> unit Lwt.t

val find_pets_by_status : status:Enums.pet_status list -> Pet.t list Lwt.t

val find_pets_by_tags : tags:string list -> Pet.t list Lwt.t

val get_pet_by_id : pet_id:int64 -> Pet.t Lwt.t

val update_pet : body:Pet.t -> unit Lwt.t
val update_pet_with_form : pet_id:int64 -> ?name:string -> ?status:string -> unit -> unit Lwt.t
val upload_file : pet_id:int64 -> ?additional_metadata:string -> ?file:string -> unit -> Api_response.t Lwt.t

val update_pet_with_form :
pet_id:int64 -> ?name:string -> ?status:string -> unit -> unit Lwt.t

val upload_file :
pet_id:int64
-> ?additional_metadata:string
-> ?file:string
-> unit
-> Api_response.t Lwt.t
54 changes: 29 additions & 25 deletions samples/client/petstore/ocaml/src/apis/store_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,34 +6,38 @@
*)

let delete_order ~order_id =
let open Lwt in
let uri = Request.build_uri "/store/order/{orderId}" in
let headers = Request.default_headers in
let uri = Request.replace_path_param uri "orderId" (fun x -> x) order_id in
Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) ->
Request.handle_unit_response resp
let open Lwt in
let uri = Request.build_uri "/store/order/{orderId}" in
let headers = Request.default_headers in
let uri = Request.replace_path_param uri "orderId" (fun x -> x) order_id in
Cohttp_lwt_unix.Client.call `DELETE uri ~headers
>>= fun (resp, body) -> Request.handle_unit_response resp

let get_inventory () =
let open Lwt in
let uri = Request.build_uri "/store/inventory" in
let headers = Request.default_headers in
let headers = Cohttp.Header.add headers "api_key" Request.api_key in
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
Request.read_json_body_as_map_of (JsonSupport.to_int32) resp body
let open Lwt in
let uri = Request.build_uri "/store/inventory" in
let headers = Request.default_headers in
let headers = Cohttp.Header.add headers "api_key" Request.api_key in
Cohttp_lwt_unix.Client.call `GET uri ~headers
>>= fun (resp, body) ->
Request.read_json_body_as_map_of JsonSupport.to_int32 resp body

let get_order_by_id ~order_id =
let open Lwt in
let uri = Request.build_uri "/store/order/{orderId}" in
let headers = Request.default_headers in
let uri = Request.replace_path_param uri "orderId" Int64.to_string order_id in
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap Order.of_yojson) resp body
let open Lwt in
let uri = Request.build_uri "/store/order/{orderId}" in
let headers = Request.default_headers in
let uri =
Request.replace_path_param uri "orderId" Int64.to_string order_id
in
Cohttp_lwt_unix.Client.call `GET uri ~headers
>>= fun (resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap Order.of_yojson) resp body

let place_order ~body =
let open Lwt in
let uri = Request.build_uri "/store/order" in
let headers = Request.default_headers in
let body = Request.write_as_json_body Order.to_yojson body in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap Order.of_yojson) resp body

let open Lwt in
let uri = Request.build_uri "/store/order" in
let headers = Request.default_headers in
let body = Request.write_as_json_body Order.to_yojson body in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body
>>= fun (resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap Order.of_yojson) resp body
3 changes: 3 additions & 0 deletions samples/client/petstore/ocaml/src/apis/store_api.mli
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,9 @@
*)

val delete_order : order_id:string -> unit Lwt.t

val get_inventory : unit -> (string * int32) list Lwt.t

val get_order_by_id : order_id:int64 -> Order.t Lwt.t

val place_order : body:Order.t -> Order.t Lwt.t
105 changes: 55 additions & 50 deletions samples/client/petstore/ocaml/src/apis/user_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -6,67 +6,72 @@
*)

let create_user ~body =
let open Lwt in
let uri = Request.build_uri "/user" in
let headers = Request.default_headers in
let body = Request.write_as_json_body User.to_yojson body in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
Request.handle_unit_response resp
let open Lwt in
let uri = Request.build_uri "/user" in
let headers = Request.default_headers in
let body = Request.write_as_json_body User.to_yojson body in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body
>>= fun (resp, body) -> Request.handle_unit_response resp

let create_users_with_array_input ~body =
let open Lwt in
let uri = Request.build_uri "/user/createWithArray" in
let headers = Request.default_headers in
let body = Request.write_as_json_body (JsonSupport.of_list_of User.to_yojson) body in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
Request.handle_unit_response resp
let open Lwt in
let uri = Request.build_uri "/user/createWithArray" in
let headers = Request.default_headers in
let body =
Request.write_as_json_body (JsonSupport.of_list_of User.to_yojson) body
in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body
>>= fun (resp, body) -> Request.handle_unit_response resp

let create_users_with_list_input ~body =
let open Lwt in
let uri = Request.build_uri "/user/createWithList" in
let headers = Request.default_headers in
let body = Request.write_as_json_body (JsonSupport.of_list_of User.to_yojson) body in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
Request.handle_unit_response resp
let open Lwt in
let uri = Request.build_uri "/user/createWithList" in
let headers = Request.default_headers in
let body =
Request.write_as_json_body (JsonSupport.of_list_of User.to_yojson) body
in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body
>>= fun (resp, body) -> Request.handle_unit_response resp

let delete_user ~username =
let open Lwt in
let uri = Request.build_uri "/user/{username}" in
let headers = Request.default_headers in
let uri = Request.replace_path_param uri "username" (fun x -> x) username in
Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) ->
Request.handle_unit_response resp
let open Lwt in
let uri = Request.build_uri "/user/{username}" in
let headers = Request.default_headers in
let uri = Request.replace_path_param uri "username" (fun x -> x) username in
Cohttp_lwt_unix.Client.call `DELETE uri ~headers
>>= fun (resp, body) -> Request.handle_unit_response resp

let get_user_by_name ~username =
let open Lwt in
let uri = Request.build_uri "/user/{username}" in
let headers = Request.default_headers in
let uri = Request.replace_path_param uri "username" (fun x -> x) username in
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap User.of_yojson) resp body
let open Lwt in
let uri = Request.build_uri "/user/{username}" in
let headers = Request.default_headers in
let uri = Request.replace_path_param uri "username" (fun x -> x) username in
Cohttp_lwt_unix.Client.call `GET uri ~headers
>>= fun (resp, body) ->
Request.read_json_body_as (JsonSupport.unwrap User.of_yojson) resp body

let login_user ~username ~password =
let open Lwt in
let uri = Request.build_uri "/user/login" in
let headers = Request.default_headers in
let uri = Request.add_query_param uri "username" (fun x -> x) username in
let uri = Request.add_query_param uri "password" (fun x -> x) password in
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
Request.read_json_body_as (JsonSupport.to_string) resp body
let open Lwt in
let uri = Request.build_uri "/user/login" in
let headers = Request.default_headers in
let uri = Request.add_query_param uri "username" (fun x -> x) username in
let uri = Request.add_query_param uri "password" (fun x -> x) password in
Cohttp_lwt_unix.Client.call `GET uri ~headers
>>= fun (resp, body) ->
Request.read_json_body_as JsonSupport.to_string resp body

let logout_user () =
let open Lwt in
let uri = Request.build_uri "/user/logout" in
let headers = Request.default_headers in
Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) ->
Request.handle_unit_response resp
let open Lwt in
let uri = Request.build_uri "/user/logout" in
let headers = Request.default_headers in
Cohttp_lwt_unix.Client.call `GET uri ~headers
>>= fun (resp, body) -> Request.handle_unit_response resp

let update_user ~username ~body =
let open Lwt in
let uri = Request.build_uri "/user/{username}" in
let headers = Request.default_headers in
let uri = Request.replace_path_param uri "username" (fun x -> x) username in
let body = Request.write_as_json_body User.to_yojson body in
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
Request.handle_unit_response resp

let open Lwt in
let uri = Request.build_uri "/user/{username}" in
let headers = Request.default_headers in
let uri = Request.replace_path_param uri "username" (fun x -> x) username in
let body = Request.write_as_json_body User.to_yojson body in
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body
>>= fun (resp, body) -> Request.handle_unit_response resp
Loading

0 comments on commit 2a44261

Please sign in to comment.