Skip to content

Migrate OCaml petstore to use OAS v3 spec #6348

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

Merged
merged 3 commits into from
May 25, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion bin/ocaml-petstore.sh
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@ fi
# if you've executed sbt assembly previously it will use that instead.
export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties"

args="generate -t modules/openapi-generator/src/main/resources/ocaml -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g ocaml -o samples/client/petstore/ocaml --additional-properties packageName=petstore_client $@"
args="generate -t modules/openapi-generator/src/main/resources/ocaml -i modules/openapi-generator/src/test/resources/3_0/petstore.yaml -g ocaml -o samples/client/petstore/ocaml --additional-properties packageName=petstore_client $@"

echo "java ${JAVA_OPTS} -jar ${executable} ${args}"
java $JAVA_OPTS -jar $executable $args
34 changes: 0 additions & 34 deletions bin/openapi3/ocaml-client-petstore.sh

This file was deleted.

2 changes: 1 addition & 1 deletion bin/windows/ocaml-petstore.bat
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,6 @@ If Not Exist %executable% (
)

REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties
set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g ocaml -o samples\client\petstore\ocaml
set ags=generate -i modules\openapi-generator\src\test\resources\3_0\petstore.yaml -g ocaml -o samples\client\petstore\ocaml

java %JAVA_OPTS% -jar %executable% %ags%
2 changes: 1 addition & 1 deletion samples/client/petstore/ocaml/.openapi-generator/VERSION
Original file line number Diff line number Diff line change
@@ -1 +1 @@
4.2.2-SNAPSHOT
5.0.0-SNAPSHOT
12 changes: 6 additions & 6 deletions samples/client/petstore/ocaml/src/apis/pet_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,13 @@
*
*)

let add_pet ~body =
let add_pet ~pet_t =
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
let body = Request.write_as_json_body Pet.to_yojson pet_t in
Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) ->
Request.handle_unit_response resp
Request.read_json_body_as (JsonSupport.unwrap Pet.of_yojson) resp body

let delete_pet ~pet_id ?api_key () =
let open Lwt in
Expand Down Expand Up @@ -47,13 +47,13 @@ let get_pet_by_id ~pet_id =
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 update_pet ~pet_t =
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
let body = Request.write_as_json_body Pet.to_yojson pet_t in
Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) ->
Request.handle_unit_response resp
Request.read_json_body_as (JsonSupport.unwrap Pet.of_yojson) resp body

let update_pet_with_form ~pet_id ?name ?status () =
let open Lwt in
Expand Down
4 changes: 2 additions & 2 deletions samples/client/petstore/ocaml/src/apis/pet_api.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*
*)

val add_pet : body:Pet.t -> unit Lwt.t
val add_pet : pet_t:Pet.t -> Pet.t 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 : pet_t:Pet.t -> Pet.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
4 changes: 2 additions & 2 deletions samples/client/petstore/ocaml/src/apis/store_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -29,11 +29,11 @@ let get_order_by_id ~order_id =
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 place_order ~order_t =
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
let body = Request.write_as_json_body Order.to_yojson order_t 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

2 changes: 1 addition & 1 deletion samples/client/petstore/ocaml/src/apis/store_api.mli
Original file line number Diff line number Diff line change
Expand Up @@ -8,4 +8,4 @@
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
val place_order : order_t:Order.t -> Order.t Lwt.t
22 changes: 14 additions & 8 deletions samples/client/petstore/ocaml/src/apis/user_api.ml
Original file line number Diff line number Diff line change
Expand Up @@ -5,34 +5,38 @@
*
*)

let create_user ~body =
let create_user ~user_t =
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
let headers = Cohttp.Header.add headers "api_key" Request.api_key in
let body = Request.write_as_json_body User.to_yojson user_t 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 create_users_with_array_input ~user =
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
let headers = Cohttp.Header.add headers "api_key" Request.api_key in
let body = Request.write_as_json_body (JsonSupport.of_list_of User.to_yojson) user 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 create_users_with_list_input ~user =
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
let headers = Cohttp.Header.add headers "api_key" Request.api_key in
let body = Request.write_as_json_body (JsonSupport.of_list_of User.to_yojson) user 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 headers = Cohttp.Header.add headers "api_key" Request.api_key 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
Expand All @@ -58,15 +62,17 @@ let logout_user () =
let open Lwt in
let uri = Request.build_uri "/user/logout" 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.handle_unit_response resp

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

8 changes: 4 additions & 4 deletions samples/client/petstore/ocaml/src/apis/user_api.mli
Original file line number Diff line number Diff line change
Expand Up @@ -5,11 +5,11 @@
*
*)

val create_user : body:User.t -> unit Lwt.t
val create_users_with_array_input : body:User.t list -> unit Lwt.t
val create_users_with_list_input : body:User.t list -> unit Lwt.t
val create_user : user_t:User.t -> unit Lwt.t
val create_users_with_array_input : user:User.t list -> unit Lwt.t
val create_users_with_list_input : user:User.t list -> unit Lwt.t
val delete_user : username:string -> unit Lwt.t
val get_user_by_name : username:string -> User.t Lwt.t
val login_user : username:string -> password:string -> string Lwt.t
val logout_user : unit -> unit Lwt.t
val update_user : username:string -> body:User.t -> unit Lwt.t
val update_user : username:string -> user_t:User.t -> unit Lwt.t
23 changes: 0 additions & 23 deletions samples/openapi3/client/petstore/ocaml/.openapi-generator-ignore

This file was deleted.

This file was deleted.

27 changes: 0 additions & 27 deletions samples/openapi3/client/petstore/ocaml/README.md

This file was deleted.

9 changes: 0 additions & 9 deletions samples/openapi3/client/petstore/ocaml/dune

This file was deleted.

2 changes: 0 additions & 2 deletions samples/openapi3/client/petstore/ocaml/dune-project

This file was deleted.

15 changes: 0 additions & 15 deletions samples/openapi3/client/petstore/ocaml/petstore_client.opam

This file was deleted.

This file was deleted.

This file was deleted.

14 changes: 0 additions & 14 deletions samples/openapi3/client/petstore/ocaml/src/apis/default_api.ml

This file was deleted.

This file was deleted.

Loading