From fbb46ed03e3d1a98994a6ee9232d3eba3cfefe86 Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 1 Aug 2025 14:38:59 +0200 Subject: [PATCH 01/12] Add OCaml fake-petstore to test corner cases --- .gitignore | 1 + bin/configs/ocaml-fake-petstore.yaml | 6 + .../.openapi-generator-ignore | 23 ++ .../.openapi-generator/FILES | 65 +++++ .../.openapi-generator/VERSION | 1 + .../petstore/ocaml-fake-petstore/README.md | 33 +++ .../client/petstore/ocaml-fake-petstore/dune | 9 + .../petstore/ocaml-fake-petstore/dune-project | 2 + .../ocaml-fake-petstore/petstore_client.opam | 24 ++ .../src/apis/another_fake_api.ml | 15 + .../src/apis/another_fake_api.mli | 8 + .../src/apis/default_api.ml | 14 + .../src/apis/default_api.mli | 8 + .../ocaml-fake-petstore/src/apis/fake_api.ml | 274 ++++++++++++++++++ .../ocaml-fake-petstore/src/apis/fake_api.mli | 29 ++ .../src/apis/fake_classname_tags123_api.ml | 16 + .../src/apis/fake_classname_tags123_api.mli | 8 + .../ocaml-fake-petstore/src/apis/pet_api.ml | 109 +++++++ .../ocaml-fake-petstore/src/apis/pet_api.mli | 16 + .../ocaml-fake-petstore/src/apis/store_api.ml | 41 +++ .../src/apis/store_api.mli | 11 + .../ocaml-fake-petstore/src/apis/user_api.ml | 77 +++++ .../ocaml-fake-petstore/src/apis/user_api.mli | 15 + .../src/models/additional_properties_class.ml | 21 ++ .../src/models/all_of_with_single_ref.ml | 25 ++ .../ocaml-fake-petstore/src/models/animal.ml | 25 ++ .../src/models/api_response.ml | 31 ++ .../models/array_of_array_of_number_only.ml | 17 ++ .../src/models/array_of_number_only.ml | 17 ++ .../src/models/array_test.ml | 25 ++ .../src/models/capitalization.ml | 50 ++++ .../ocaml-fake-petstore/src/models/cat.ml | 31 ++ .../src/models/category.ml | 25 ++ .../src/models/child_with_nullable.ml | 32 ++ .../src/models/class_model.ml | 21 ++ .../ocaml-fake-petstore/src/models/client.ml | 19 ++ .../src/models/deprecated_object.ml | 19 ++ .../ocaml-fake-petstore/src/models/dog.ml | 31 ++ .../src/models/enum_arrays.ml | 23 ++ .../src/models/enum_test.ml | 62 ++++ .../fake_big_decimal_map_200_response.ml | 23 ++ .../ocaml-fake-petstore/src/models/file.ml | 22 ++ .../src/models/file_schema_test_class.ml | 23 ++ .../ocaml-fake-petstore/src/models/foo.ml | 19 ++ .../src/models/format_test.ml | 111 +++++++ .../src/models/has_only_read_only.ml | 25 ++ .../src/models/health_check_result.ml | 21 ++ .../ocaml-fake-petstore/src/models/list.ml | 19 ++ .../src/models/map_test.ml | 28 ++ ...perties_and_additional_properties_class.ml | 29 ++ .../src/models/model_200_response.ml | 27 ++ .../models/model__foo_get_default_response.ml | 19 ++ .../src/models/model__special_model_name_.ml | 19 ++ .../ocaml-fake-petstore/src/models/name.ml | 39 +++ .../src/models/nullable_class.ml | 73 +++++ .../src/models/number_only.ml | 19 ++ .../models/object_with_deprecated_fields.ml | 35 +++ .../ocaml-fake-petstore/src/models/order.ml | 51 ++++ .../src/models/outer_composite.ml | 31 ++ .../models/outer_object_with_enum_property.ml | 19 ++ .../src/models/parent_with_nullable.ml | 26 ++ .../ocaml-fake-petstore/src/models/pet.ml | 47 +++ .../src/models/read_only_first.ml | 25 ++ .../ocaml-fake-petstore/src/models/return.ml | 21 ++ .../ocaml-fake-petstore/src/models/tag.ml | 25 ++ ..._freeform_additional_properties_request.ml | 19 ++ .../ocaml-fake-petstore/src/models/user.ml | 62 ++++ .../ocaml-fake-petstore/src/support/enums.ml | 163 +++++++++++ .../src/support/jsonSupport.ml | 55 ++++ .../src/support/request.ml | 97 +++++++ 70 files changed, 2471 insertions(+) create mode 100644 bin/configs/ocaml-fake-petstore.yaml create mode 100644 samples/client/petstore/ocaml-fake-petstore/.openapi-generator-ignore create mode 100644 samples/client/petstore/ocaml-fake-petstore/.openapi-generator/FILES create mode 100644 samples/client/petstore/ocaml-fake-petstore/.openapi-generator/VERSION create mode 100644 samples/client/petstore/ocaml-fake-petstore/README.md create mode 100644 samples/client/petstore/ocaml-fake-petstore/dune create mode 100644 samples/client/petstore/ocaml-fake-petstore/dune-project create mode 100644 samples/client/petstore/ocaml-fake-petstore/petstore_client.opam create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.mli create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/apis/default_api.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/apis/default_api.mli create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.mli create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.mli create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.mli create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.mli create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.mli create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/additional_properties_class.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/all_of_with_single_ref.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/animal.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/api_response.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/array_of_array_of_number_only.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/array_of_number_only.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/array_test.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/capitalization.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/cat.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/category.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/child_with_nullable.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/class_model.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/client.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/deprecated_object.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/dog.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/enum_arrays.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/enum_test.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/fake_big_decimal_map_200_response.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/file.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/file_schema_test_class.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/foo.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/format_test.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/has_only_read_only.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/health_check_result.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/list.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/map_test.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/mixed_properties_and_additional_properties_class.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/model_200_response.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/model__foo_get_default_response.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/model__special_model_name_.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/name.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/nullable_class.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/number_only.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/object_with_deprecated_fields.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/order.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/outer_composite.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/outer_object_with_enum_property.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/parent_with_nullable.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/pet.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/read_only_first.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/return.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/tag.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/test_inline_freeform_additional_properties_request.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/models/user.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/support/enums.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/support/jsonSupport.ml create mode 100644 samples/client/petstore/ocaml-fake-petstore/src/support/request.ml diff --git a/.gitignore b/.gitignore index 5c6df879f35d..9fdd217eabb6 100644 --- a/.gitignore +++ b/.gitignore @@ -296,6 +296,7 @@ samples/openapi3/client/petstore/go/privatekey.pem ## OCaml samples/client/petstore/ocaml/_build/ +samples/client/petstore/ocaml-fake-petstore/_build/ # jetbrain http client samples/client/jetbrains/adyen/checkout71/http/client/Apis/http-client.private.env.json diff --git a/bin/configs/ocaml-fake-petstore.yaml b/bin/configs/ocaml-fake-petstore.yaml new file mode 100644 index 000000000000..dcaf631f34fb --- /dev/null +++ b/bin/configs/ocaml-fake-petstore.yaml @@ -0,0 +1,6 @@ +generatorName: ocaml +outputDir: samples/client/petstore/ocaml-fake-petstore +inputSpec: modules/openapi-generator/src/test/resources/3_0/petstore-with-fake-endpoints-models-for-testing.yaml +templateDir: modules/openapi-generator/src/main/resources/ocaml +additionalProperties: + packageName: petstore_client diff --git a/samples/client/petstore/ocaml-fake-petstore/.openapi-generator-ignore b/samples/client/petstore/ocaml-fake-petstore/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/.openapi-generator-ignore @@ -0,0 +1,23 @@ +# OpenAPI Generator Ignore +# Generated by openapi-generator https://github.com/openapitools/openapi-generator + +# Use this file to prevent files from being overwritten by the generator. +# The patterns follow closely to .gitignore or .dockerignore. + +# As an example, the C# client generator defines ApiClient.cs. +# You can make changes and tell OpenAPI Generator to ignore just this file by uncommenting the following line: +#ApiClient.cs + +# You can match any string of characters against a directory, file or extension with a single asterisk (*): +#foo/*/qux +# The above matches foo/bar/qux and foo/baz/qux, but not foo/bar/baz/qux + +# You can recursively match patterns against a directory, file or extension with a double asterisk (**): +#foo/**/qux +# This matches foo/bar/qux, foo/baz/qux, and foo/bar/baz/qux + +# You can also negate patterns with an exclamation (!). +# For example, you can ignore all files in a docs folder with the file extension .md: +#docs/*.md +# Then explicitly reverse the ignore rule for a single file: +#!docs/README.md diff --git a/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/FILES b/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/FILES new file mode 100644 index 000000000000..d4a1e97f7ede --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/FILES @@ -0,0 +1,65 @@ +README.md +dune +dune-project +petstore_client.opam +src/apis/another_fake_api.ml +src/apis/another_fake_api.mli +src/apis/default_api.ml +src/apis/default_api.mli +src/apis/fake_api.ml +src/apis/fake_api.mli +src/apis/fake_classname_tags123_api.ml +src/apis/fake_classname_tags123_api.mli +src/apis/pet_api.ml +src/apis/pet_api.mli +src/apis/store_api.ml +src/apis/store_api.mli +src/apis/user_api.ml +src/apis/user_api.mli +src/models/additional_properties_class.ml +src/models/all_of_with_single_ref.ml +src/models/animal.ml +src/models/api_response.ml +src/models/array_of_array_of_number_only.ml +src/models/array_of_number_only.ml +src/models/array_test.ml +src/models/capitalization.ml +src/models/cat.ml +src/models/category.ml +src/models/child_with_nullable.ml +src/models/class_model.ml +src/models/client.ml +src/models/deprecated_object.ml +src/models/dog.ml +src/models/enum_arrays.ml +src/models/enum_test.ml +src/models/fake_big_decimal_map_200_response.ml +src/models/file.ml +src/models/file_schema_test_class.ml +src/models/foo.ml +src/models/format_test.ml +src/models/has_only_read_only.ml +src/models/health_check_result.ml +src/models/list.ml +src/models/map_test.ml +src/models/mixed_properties_and_additional_properties_class.ml +src/models/model_200_response.ml +src/models/model__foo_get_default_response.ml +src/models/model__special_model_name_.ml +src/models/name.ml +src/models/nullable_class.ml +src/models/number_only.ml +src/models/object_with_deprecated_fields.ml +src/models/order.ml +src/models/outer_composite.ml +src/models/outer_object_with_enum_property.ml +src/models/parent_with_nullable.ml +src/models/pet.ml +src/models/read_only_first.ml +src/models/return.ml +src/models/tag.ml +src/models/test_inline_freeform_additional_properties_request.ml +src/models/user.ml +src/support/enums.ml +src/support/jsonSupport.ml +src/support/request.ml diff --git a/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/VERSION b/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/VERSION new file mode 100644 index 000000000000..fc74d6ceba8e --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.15.0-SNAPSHOT diff --git a/samples/client/petstore/ocaml-fake-petstore/README.md b/samples/client/petstore/ocaml-fake-petstore/README.md new file mode 100644 index 000000000000..051d999bbf64 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/README.md @@ -0,0 +1,33 @@ +# +This spec is mainly for testing Petstore server and contains fake endpoints, models. Please do not use this for any other purpose. Special characters: \'' \\ + +This OCaml package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: + +- API version: 1.0.0 +- Package version: 1.0.0 +- Generator version: 7.15.0-SNAPSHOT +- Build package: org.openapitools.codegen.languages.OCamlClientCodegen + +## Requirements. + +OCaml 5.x + +## Installation + +Please run the following commands to build the package `petstore_client`: + +```sh +opam install . --deps-only --with-test +eval $(opam env) +dune build +``` + +## Getting Started + +The generated directory structure is: +- `src/apis`: contains several modules, each with several functions. Each function is an API endpoint. +- `src/models`: contains several modules. Each module contains: + - a type `t` representing an input and/or output schema of the OpenAPI spec + - a smart constructor `create` for this type +- `src/support`: various modules used by the generated APIs and Models + diff --git a/samples/client/petstore/ocaml-fake-petstore/dune b/samples/client/petstore/ocaml-fake-petstore/dune new file mode 100644 index 000000000000..ed1c4d90e3df --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/dune @@ -0,0 +1,9 @@ +(include_subdirs unqualified) +(library + (name petstore_client) + (public_name petstore_client) + (flags (:standard -w -27)) + (libraries str cohttp-lwt-unix lwt yojson ppx_deriving_yojson.runtime) + (preprocess (pps ppx_deriving_yojson ppx_deriving.std)) + (wrapped true) +) \ No newline at end of file diff --git a/samples/client/petstore/ocaml-fake-petstore/dune-project b/samples/client/petstore/ocaml-fake-petstore/dune-project new file mode 100644 index 000000000000..79d86e3c901a --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/dune-project @@ -0,0 +1,2 @@ +(lang dune 1.10) +(name petstore_client) \ No newline at end of file diff --git a/samples/client/petstore/ocaml-fake-petstore/petstore_client.opam b/samples/client/petstore/ocaml-fake-petstore/petstore_client.opam new file mode 100644 index 000000000000..7ca31fc5af4f --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/petstore_client.opam @@ -0,0 +1,24 @@ +opam-version: "2.0" +name: "petstore_client" +version: "1.0.0" +synopsis: "" +description: """ +Longer description +""" +maintainer: "Name " +authors: "Name " +license: "" +homepage: "" +bug-reports: "" +dev-repo: "" +depends: [ + "ocaml" + "ocamlfind" + "dune" + "ppx_deriving_yojson" + "conf-libev" + "lwt" + "cohttp-lwt-unix" {< "6.0.0"} + "cohttp-async" {< "6.0.0"} +] +build: ["dune" "build" "-p" name] diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml new file mode 100644 index 000000000000..860d741e0170 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml @@ -0,0 +1,15 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +let call_123_test_special_tags ~client_t = + let open Lwt.Infix in + let uri = Request.build_uri "/another-fake/dummy" in + let headers = Request.default_headers in + let body = Request.write_as_json_body Client.to_yojson client_t in + Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.mli b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.mli new file mode 100644 index 000000000000..3e9e0c80484b --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.mli @@ -0,0 +1,8 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +val call_123_test_special_tags : client_t:Client.t -> Client.t Lwt.t diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/default_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/default_api.ml new file mode 100644 index 000000000000..0184891735dd --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/default_api.ml @@ -0,0 +1,14 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +let foo_get () = + let open Lwt.Infix in + let uri = Request.build_uri "/foo" in + let headers = Request.default_headers in + Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.unwrap Model__foo_get_default_response.of_yojson) resp body + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/default_api.mli b/samples/client/petstore/ocaml-fake-petstore/src/apis/default_api.mli new file mode 100644 index 000000000000..d58454de73ac --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/default_api.mli @@ -0,0 +1,8 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +val foo_get : unit -> Model__foo_get_default_response.t Lwt.t diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml new file mode 100644 index 000000000000..08de0e346f39 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml @@ -0,0 +1,274 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +let fake_big_decimal_map () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/BigDecimalMap" in + let headers = Request.default_headers in + Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.unwrap Fake_big_decimal_map_200_response.of_yojson) resp body + +let fake_health_get () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/health" in + let headers = Request.default_headers in + Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.unwrap Health_check_result.of_yojson) resp body + +let fake_http_signature_test ~pet_t ?query_1 ?header_1 () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/http-signature-test" in + let headers = Request.default_headers in + let headers = Request.maybe_add_header headers "header_1" (fun x -> x) + header_1 in + let uri = Request.maybe_add_query_param uri "query_1" (fun x -> x) + query_1 in + let body = Request.write_as_json_body Pet.to_yojson pet_t in + Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let fake_outer_boolean_serialize ~body () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/outer/boolean" in + let headers = Request.default_headers in + let body = Request.write_as_json_body JsonSupport.of_bool body in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.to_bool) resp body + +let fake_outer_composite_serialize ~outer_composite_t () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/outer/composite" in + let headers = Request.default_headers in + let body = Request.write_as_json_body Outer_composite.to_yojson outer_composite_t in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.unwrap Outer_composite.of_yojson) resp body + +let fake_outer_number_serialize ~body () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/outer/number" in + let headers = Request.default_headers in + let body = Request.write_as_json_body JsonSupport.of_float body in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.to_float) resp body + +let fake_outer_string_serialize ~body () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/outer/string" in + let headers = Request.default_headers in + let body = Request.write_as_json_body JsonSupport.of_string body in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.to_string) resp body + +let fake_property_enum_integer_serialize ~outer_object_with_enum_property_t = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/property/enum-int" in + let headers = Request.default_headers in + let body = Request.write_as_json_body Outer_object_with_enum_property.to_yojson outer_object_with_enum_property_t in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.unwrap Outer_object_with_enum_property.of_yojson) resp body + +let test_additional_properties_reference ~request_body = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/additionalProperties-reference" in + let headers = Request.default_headers in + let body = Request.write_json_body (JsonSupport.of_map_of ) request_body in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let test_body_with_binary ~body = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/body-with-binary" in + let headers = Request.default_headers in + let body = Request.write_as_json_body body in + Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let test_body_with_file_schema ~file_schema_test_class_t = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/body-with-file-schema" in + let headers = Request.default_headers in + let body = Request.write_as_json_body File_schema_test_class.to_yojson file_schema_test_class_t in + Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let test_body_with_query_params ~query ~user_t = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/body-with-query-params" in + let headers = Request.default_headers in + let uri = Request.add_query_param uri "query" (fun x -> x) + query 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 + +let test_client_model ~client_t = + let open Lwt.Infix in + let uri = Request.build_uri "/fake" in + let headers = Request.default_headers in + let body = Request.write_as_json_body Client.to_yojson client_t in + Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body + +let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?integer ?int32 ?int64 ?float ?string ?binary ?date ?date_time ?password ?callback () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake" in + let headers = Request.default_headers in + let body = Request.init_form_encoded_body () in + let body = Request.maybe_add_form_encoded_body_param body "integer" Int32.to_string + integer in + let body = Request.maybe_add_form_encoded_body_param body "int32" Int32.to_string + int32 in + let body = Request.maybe_add_form_encoded_body_param body "int64" Int64.to_string + int64 in + let body = Request.add_form_encoded_body_param body "number" string_of_float + number in + let body = Request.maybe_add_form_encoded_body_param body "float" string_of_float + float in + let body = Request.add_form_encoded_body_param body "double" string_of_float + double in + let body = Request.maybe_add_form_encoded_body_param body "string" (fun x -> x) + string in + let body = Request.add_form_encoded_body_param body "pattern_without_delimiter" (fun x -> x) + pattern_without_delimiter in + let body = Request.add_form_encoded_body_param body "byte" (fun x -> x) + byte in + let body = Request.maybe_add_form_encoded_body_param body "binary" (fun x -> x) + binary in + let body = Request.maybe_add_form_encoded_body_param body "date" (fun x -> x) + date in + let body = Request.maybe_add_form_encoded_body_param body "date_time" (fun x -> x) + date_time in + let body = Request.maybe_add_form_encoded_body_param body "password" (fun x -> x) + password in + let body = Request.maybe_add_form_encoded_body_param body "callback" (fun x -> x) + callback 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 test_enum_parameters ?(enum_header_string_array = []) ?(enum_header_string = `Minusefg) ?(enum_query_string_array = []) ?(enum_query_string = `Minusefg) ?enum_query_integer ?enum_query_double ?(enum_query_model_array = []) ?(enum_form_string_array = [`Dollar]) ?(enum_form_string = `Minusefg) () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake" in + let headers = Request.default_headers in + let headers = Request.add_header_multi headers "enum_header_string_array" (Stdlib.List.map Enums.show_enum_form_string_array +) + enum_header_string_array in + let headers = Request.add_header headers "enum_header_string" Enums.show_enumclass + enum_header_string in + let uri = Request.add_query_param_list uri "enum_query_string_array" (Stdlib.List.map Enums.show_enum_form_string_array +) + enum_query_string_array in + let uri = Request.add_query_param uri "enum_query_string" Enums.show_enumclass + enum_query_string in + let uri = Request.maybe_add_query_param uri "enum_query_integer" Enums.show_enum_query_integer + enum_query_integer in + let uri = Request.maybe_add_query_param uri "enum_query_double" Enums.show_enum_number + enum_query_double in + let uri = Request.add_query_param_list uri "enum_query_model_array" (Stdlib.List.map +) + enum_query_model_array in + let body = Request.init_form_encoded_body () in + let body = Request.add_form_encoded_body_param_list body "enum_form_string_array" (Stdlib.List.map Enums.show_enum_form_string_array +) + enum_form_string_array in + let body = Request.add_form_encoded_body_param body "enum_form_string" Enums.show_enumclass + enum_form_string in + let body = Request.finalize_form_encoded_body body in + Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let test_group_parameters ~required_string_group ~required_boolean_group ~required_int64_group ?string_group ?boolean_group ?int64_group () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake" in + let headers = Request.default_headers in + let headers = Request.add_header headers "required_boolean_group" string_of_bool + required_boolean_group in + let headers = Request.maybe_add_header headers "boolean_group" string_of_bool + boolean_group in + let uri = Request.add_query_param uri "required_string_group" Int32.to_string + required_string_group in + let uri = Request.add_query_param uri "required_int64_group" Int64.to_string + required_int64_group in + let uri = Request.maybe_add_query_param uri "string_group" Int32.to_string + string_group in + let uri = Request.maybe_add_query_param uri "int64_group" Int64.to_string + int64_group in + Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) -> + Request.handle_unit_response resp + +let test_inline_additional_properties ~request_body = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/inline-additionalProperties" in + let headers = Request.default_headers in + let body = Request.write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string) request_body in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let test_inline_freeform_additional_properties ~test_inline_freeform_additional_properties_request_t = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/inline-freeform-additionalProperties" in + let headers = Request.default_headers in + let body = Request.write_as_json_body Test_inline_freeform_additional_properties_request.to_yojson test_inline_freeform_additional_properties_request_t in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let test_json_form_data ~param ~param2 = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/jsonFormData" in + let headers = Request.default_headers in + let body = Request.init_form_encoded_body () in + let body = Request.add_form_encoded_body_param body "param" (fun x -> x) + param in + let body = Request.add_form_encoded_body_param body "param2" (fun x -> x) + param2 in + let body = Request.finalize_form_encoded_body body in + Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let test_nullable ~child_with_nullable_t = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/nullable" in + let headers = Request.default_headers in + let body = Request.write_as_json_body Child_with_nullable.to_yojson child_with_nullable_t in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~allow_empty ?(language = []) () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/test-query-parameters" in + let headers = Request.default_headers in + let uri = Request.add_query_param_list uri "pipe" (Stdlib.List.map (fun x -> x) +) + pipe in + let uri = Request.add_query_param_list uri "ioutil" (Stdlib.List.map (fun x -> x) +) + ioutil in + let uri = Request.add_query_param_list uri "http" (Stdlib.List.map (fun x -> x) +) + http in + let uri = Request.add_query_param_list uri "url" (Stdlib.List.map (fun x -> x) +) + url in + let uri = Request.add_query_param_list uri "context" (Stdlib.List.map (fun x -> x) +) + context in + let uri = Request.add_query_param uri "language" (Stdlib.List.map (fun x -> x) +) + language in + let uri = Request.add_query_param uri "allowEmpty" (fun x -> x) + allow_empty in + Cohttp_lwt_unix.Client.call `PUT uri ~headers >>= fun (resp, body) -> + Request.handle_unit_response resp + +let test_string_map_reference ~request_body = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/stringMap-reference" in + let headers = Request.default_headers in + let body = Request.write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string) request_body in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.mli b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.mli new file mode 100644 index 000000000000..259a66dd29e0 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.mli @@ -0,0 +1,29 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +val fake_big_decimal_map : unit -> Fake_big_decimal_map_200_response.t Lwt.t +val fake_health_get : unit -> Health_check_result.t Lwt.t +val fake_http_signature_test : pet_t:Pet.t -> ?query_1:string -> ?header_1:string -> unit -> unit Lwt.t +val fake_outer_boolean_serialize : body:bool -> unit -> bool Lwt.t +val fake_outer_composite_serialize : outer_composite_t:Outer_composite.t -> unit -> Outer_composite.t Lwt.t +val fake_outer_number_serialize : body:float -> unit -> float Lwt.t +val fake_outer_string_serialize : body:string -> unit -> string Lwt.t +val fake_property_enum_integer_serialize : outer_object_with_enum_property_t:Outer_object_with_enum_property.t -> Outer_object_with_enum_property.t Lwt.t +val test_additional_properties_reference : request_body:(string * Yojson.Safe.t) list -> unit Lwt.t +val test_body_with_binary : body:string -> unit Lwt.t +val test_body_with_file_schema : file_schema_test_class_t:File_schema_test_class.t -> unit Lwt.t +val test_body_with_query_params : query:string -> user_t:User.t -> unit Lwt.t +val test_client_model : client_t:Client.t -> Client.t Lwt.t +val test_endpoint_parameters : number:float -> double:float -> pattern_without_delimiter:string -> byte:string -> ?integer:int32 -> ?int32:int32 -> ?int64:int64 -> ?float:float -> ?string:string -> ?binary:string -> ?date:string -> ?date_time:string -> ?password:string -> ?callback:string -> unit -> unit Lwt.t +val test_enum_parameters : ?enum_header_string_array:Enums.enum_form_string_array list -> ?enum_header_string:Enums.enumclass -> ?enum_query_string_array:Enums.enum_form_string_array list -> ?enum_query_string:Enums.enumclass -> ?enum_query_integer:Enums.enum_query_integer -> ?enum_query_double:Enums.enum_number -> ?enum_query_model_array:Enums.enumclass list -> ?enum_form_string_array:Enums.enum_form_string_array list -> ?enum_form_string:Enums.enumclass -> unit -> unit Lwt.t +val test_group_parameters : required_string_group:int32 -> required_boolean_group:bool -> required_int64_group:int64 -> ?string_group:int32 -> ?boolean_group:bool -> ?int64_group:int64 -> unit -> unit Lwt.t +val test_inline_additional_properties : request_body:(string * string) list -> unit Lwt.t +val test_inline_freeform_additional_properties : test_inline_freeform_additional_properties_request_t:Test_inline_freeform_additional_properties_request.t -> unit Lwt.t +val test_json_form_data : param:string -> param2:string -> unit Lwt.t +val test_nullable : child_with_nullable_t:Child_with_nullable.t -> unit Lwt.t +val test_query_parameter_collection_format : pipe:string list -> ioutil:string list -> http:string list -> url:string list -> context:string list -> allow_empty:string -> ?language:(string * string) list -> unit -> unit Lwt.t +val test_string_map_reference : request_body:(string * string) list -> unit Lwt.t diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml new file mode 100644 index 000000000000..b13297f968cf --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml @@ -0,0 +1,16 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +let test_classname ~client_t = + let open Lwt.Infix in + let uri = Request.build_uri "/fake_classname_test" in + let headers = Request.default_headers in + let uri = Uri.add_query_param' uri ("api_key_query", Request.api_key) in + let body = Request.write_as_json_body Client.to_yojson client_t in + Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.mli b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.mli new file mode 100644 index 000000000000..0f9a292c5073 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.mli @@ -0,0 +1,8 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +val test_classname : client_t:Client.t -> Client.t Lwt.t diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml new file mode 100644 index 000000000000..a45f58ac0e26 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml @@ -0,0 +1,109 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +let add_pet ~pet_t = + let open Lwt.Infix in + let uri = Request.build_uri "/pet" in + let headers = Request.default_headers 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 + +let delete_pet ~pet_id ?api_key () = + let open Lwt.Infix 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.Infix in + let uri = Request.build_uri "/pet/findByStatus" in + let headers = Request.default_headers in + let uri = Request.add_query_param_list uri "status" (Stdlib.List.map Enums.show_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.Infix in + let uri = Request.build_uri "/pet/findByTags" in + let headers = Request.default_headers in + let uri = Request.add_query_param_list uri "tags" (Stdlib.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.Infix 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 ~pet_t = + let open Lwt.Infix in + let uri = Request.build_uri "/pet" in + let headers = Request.default_headers 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 + +let update_pet_with_form ~pet_id ?name ?status () = + let open Lwt.Infix 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.Infix 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 upload_file_with_required_file ~pet_id ~required_file ?additional_metadata () = + let open Lwt.Infix in + let uri = Request.build_uri "/fake/{petId}/uploadImageWithRequiredFile" 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.add_form_encoded_body_param body "required_file" (fun x -> x) + required_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 + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.mli b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.mli new file mode 100644 index 000000000000..f0aa4208b358 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.mli @@ -0,0 +1,16 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +val add_pet : pet_t: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.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 : pet_t: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 upload_file_with_required_file : pet_id:int64 -> required_file:string -> ?additional_metadata:string -> unit -> Api_response.t Lwt.t diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml new file mode 100644 index 000000000000..732d417cc55f --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml @@ -0,0 +1,41 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +let delete_order ~order_id = + let open Lwt.Infix in + let uri = Request.build_uri "/store/order/{order_id}" in + let headers = Request.default_headers in + let uri = Request.replace_path_param uri "order_id" (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.Infix 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.Infix in + let uri = Request.build_uri "/store/order/{order_id}" in + let headers = Request.default_headers in + let uri = Request.replace_path_param uri "order_id" 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 ~order_t = + let open Lwt.Infix 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 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 + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.mli b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.mli new file mode 100644 index 000000000000..63b09db9ca52 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.mli @@ -0,0 +1,11 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +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 : order_t:Order.t -> Order.t Lwt.t diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml new file mode 100644 index 000000000000..1fa4050cf59e --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml @@ -0,0 +1,77 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +let create_user ~user_t = + let open Lwt.Infix in + let uri = Request.build_uri "/user" in + let headers = Request.default_headers 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 ~user = + let open Lwt.Infix 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) 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 ~user = + let open Lwt.Infix 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) 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.Infix 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.Infix 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.Infix 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.Infix 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 ~user_t = + let open Lwt.Infix 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 user_t in + Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.mli b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.mli new file mode 100644 index 000000000000..9a7e8e59c3ac --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.mli @@ -0,0 +1,15 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +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 -> user_t:User.t -> unit Lwt.t diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/additional_properties_class.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/additional_properties_class.ml new file mode 100644 index 000000000000..e19874830370 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/additional_properties_class.ml @@ -0,0 +1,21 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + map_property: (string * string) list + + ; [@key "map_property"] + map_of_map_property: (string * (string * string) list) list + + ; [@key "map_of_map_property"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + map_property = []; + map_of_map_property = []; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/all_of_with_single_ref.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/all_of_with_single_ref.ml new file mode 100644 index 000000000000..8be4d0ad2ec6 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/all_of_with_single_ref.ml @@ -0,0 +1,25 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + username: string + + option [@default None] + + ; [@key "username"] + single_ref_type: Enums.singlereftype + + option [@default None] + + ; [@key "SingleRefType"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + username = None; + single_ref_type = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/animal.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/animal.ml new file mode 100644 index 000000000000..b851329d1cd9 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/animal.ml @@ -0,0 +1,25 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + class_name: string + + + + ; [@key "className"] + color: string + + option [@default None] + + ; [@key "color"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create (class_name : string) : t = { + class_name = class_name; + color = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/api_response.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/api_response.ml new file mode 100644 index 000000000000..7fc624a6931f --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/api_response.ml @@ -0,0 +1,31 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + code: int32 + + option [@default None] + + ; [@key "code"] + _type: string + + option [@default None] + + ; [@key "type"] + message: string + + option [@default None] + + ; [@key "message"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + code = None; + _type = None; + message = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/array_of_array_of_number_only.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/array_of_array_of_number_only.ml new file mode 100644 index 000000000000..225845404619 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/array_of_array_of_number_only.ml @@ -0,0 +1,17 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + array_array_number: float list list + [@default []] + ; [@key "ArrayArrayNumber"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + array_array_number = []; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/array_of_number_only.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/array_of_number_only.ml new file mode 100644 index 000000000000..fb8fe8aa4135 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/array_of_number_only.ml @@ -0,0 +1,17 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + array_number: float list + [@default []] + ; [@key "ArrayNumber"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + array_number = []; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/array_test.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/array_test.ml new file mode 100644 index 000000000000..299adeec039f --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/array_test.ml @@ -0,0 +1,25 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + array_of_string: string list + [@default []] + ; [@key "array_of_string"] + array_array_of_integer: int64 list list + [@default []] + ; [@key "array_array_of_integer"] + array_array_of_model: Read_only_first.t list list + [@default []] + ; [@key "array_array_of_model"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + array_of_string = []; + array_array_of_integer = []; + array_array_of_model = []; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/capitalization.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/capitalization.ml new file mode 100644 index 000000000000..7394882bc384 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/capitalization.ml @@ -0,0 +1,50 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + small_camel: string + + option [@default None] + + ; [@key "smallCamel"] + capital_camel: string + + option [@default None] + + ; [@key "CapitalCamel"] + small_snake: string + + option [@default None] + + ; [@key "small_Snake"] + capital_snake: string + + option [@default None] + + ; [@key "Capital_Snake"] + sca_eth_flow_points: string + + option [@default None] + + ; [@key "SCA_ETH_Flow_Points"] + (* Name of the pet *) + att_name: string + + option [@default None] + + ; [@key "ATT_NAME"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + small_camel = None; + capital_camel = None; + small_snake = None; + capital_snake = None; + sca_eth_flow_points = None; + att_name = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/cat.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/cat.ml new file mode 100644 index 000000000000..b7fcd26748e0 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/cat.ml @@ -0,0 +1,31 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + class_name: string + + + + ; [@key "className"] + color: string + + option [@default None] + + ; [@key "color"] + declawed: bool + + option [@default None] + + ; [@key "declawed"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create (class_name : string) : t = { + class_name = class_name; + color = None; + declawed = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/category.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/category.ml new file mode 100644 index 000000000000..e0ff8244341f --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/category.ml @@ -0,0 +1,25 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + id: int64 + + option [@default None] + + ; [@key "id"] + name: string + + + + ; [@key "name"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create (name : string) : t = { + id = None; + name = name; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/child_with_nullable.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/child_with_nullable.ml new file mode 100644 index 000000000000..600191eb930b --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/child_with_nullable.ml @@ -0,0 +1,32 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + _type: Enums.parentwithnullable_type + option [@default + Some(`ChildWithNullable) + + ] + ; [@key "type"] + nullable_property: string + + option [@default None] + + ; [@key "nullableProperty"] + other_property: string + + option [@default None] + + ; [@key "otherProperty"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + _type = None; + nullable_property = None; + other_property = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/class_model.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/class_model.ml new file mode 100644 index 000000000000..3f9b3edd4eca --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/class_model.ml @@ -0,0 +1,21 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + * Schema Class_model.t : Model for testing model with \''_class\'' property + *) + +type t = { + _class: string + + option [@default None] + + ; [@key "_class"] +} [@@deriving yojson { strict = false }, show, eq ];; + +(** Model for testing model with \''_class\'' property *) +let create () : t = { + _class = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/client.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/client.ml new file mode 100644 index 000000000000..2fdde4fbc305 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/client.ml @@ -0,0 +1,19 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + client: string + + option [@default None] + + ; [@key "client"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + client = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/deprecated_object.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/deprecated_object.ml new file mode 100644 index 000000000000..f5cf396628b1 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/deprecated_object.ml @@ -0,0 +1,19 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + name: string + + option [@default None] + + ; [@key "name"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + name = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/dog.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/dog.ml new file mode 100644 index 000000000000..f7a67f0a5078 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/dog.ml @@ -0,0 +1,31 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + class_name: string + + + + ; [@key "className"] + color: string + + option [@default None] + + ; [@key "color"] + breed: string + + option [@default None] + + ; [@key "breed"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create (class_name : string) : t = { + class_name = class_name; + color = None; + breed = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/enum_arrays.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/enum_arrays.ml new file mode 100644 index 000000000000..c45e282a26ec --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/enum_arrays.ml @@ -0,0 +1,23 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + just_symbol: Enums.just_symbol + option [@default + + None + ] + ; [@key "just_symbol"] + array_enum: Enums.array_enum list +; [@key "array_enum"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + just_symbol = None; + array_enum = []; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/enum_test.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/enum_test.ml new file mode 100644 index 000000000000..e82a77d48f50 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/enum_test.ml @@ -0,0 +1,62 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + enum_string: Enums.enum_string + option [@default + + None + ] + ; [@key "enum_string"] + enum_string_required: Enums.enum_string + + ; [@key "enum_string_required"] + enum_integer: Enums.enum_integer + option [@default + + None + ] + ; [@key "enum_integer"] + enum_number: Enums.enum_number + option [@default + + None + ] + ; [@key "enum_number"] + outer_enum: Enums.order_status + + option [@default None] + + ; [@key "outerEnum"] + outer_enum_integer: Enums.outerenuminteger + + option [@default None] + + ; [@key "outerEnumInteger"] + outer_enum_default_value: Enums.order_status + + option [@default None] + + ; [@key "outerEnumDefaultValue"] + outer_enum_integer_default_value: Enums.outerenuminteger + + option [@default None] + + ; [@key "outerEnumIntegerDefaultValue"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create (enum_string_required : Enums.enum_string) : t = { + enum_string = None; + enum_string_required = enum_string_required; + enum_integer = None; + enum_number = None; + outer_enum = None; + outer_enum_integer = None; + outer_enum_default_value = None; + outer_enum_integer_default_value = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/fake_big_decimal_map_200_response.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/fake_big_decimal_map_200_response.ml new file mode 100644 index 000000000000..aa1801f4e06c --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/fake_big_decimal_map_200_response.ml @@ -0,0 +1,23 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + some_id: float + + option [@default None] + + ; [@key "someId"] + some_map: (string * float) list + + ; [@key "someMap"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + some_id = None; + some_map = []; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/file.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/file.ml new file mode 100644 index 000000000000..9d6d43e2d4f3 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/file.ml @@ -0,0 +1,22 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + * Schema File.t : Must be named `File` for test. + *) + +type t = { + (* Test capitalization *) + source_uri: string + + option [@default None] + + ; [@key "sourceURI"] +} [@@deriving yojson { strict = false }, show, eq ];; + +(** Must be named `File` for test. *) +let create () : t = { + source_uri = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/file_schema_test_class.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/file_schema_test_class.ml new file mode 100644 index 000000000000..423b3f39eef4 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/file_schema_test_class.ml @@ -0,0 +1,23 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + file: File.t + + option [@default None] + + ; [@key "file"] + files: File.t list + [@default []] + ; [@key "files"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + file = None; + files = []; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/foo.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/foo.ml new file mode 100644 index 000000000000..51cd048e4c53 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/foo.ml @@ -0,0 +1,19 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + bar: string + + option [@default None] + + ; [@key "bar"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + bar = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/format_test.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/format_test.ml new file mode 100644 index 000000000000..0cf0edf0e84d --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/format_test.ml @@ -0,0 +1,111 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + integer: int32 + + option [@default None] + + ; [@key "integer"] + int32: int32 + + option [@default None] + + ; [@key "int32"] + int64: int64 + + option [@default None] + + ; [@key "int64"] + number: float + + + + ; [@key "number"] + float: float + + option [@default None] + + ; [@key "float"] + double: float + + option [@default None] + + ; [@key "double"] + decimal: string + + option [@default None] + + ; [@key "decimal"] + string: string + + option [@default None] + + ; [@key "string"] + byte: string + + + + ; [@key "byte"] + binary: string + + option [@default None] + + ; [@key "binary"] + date: string + + + + ; [@key "date"] + date_time: string + + option [@default None] + + ; [@key "dateTime"] + uuid: string + + option [@default None] + + ; [@key "uuid"] + password: string + + + + ; [@key "password"] + (* A string that is a 10 digit number. Can have leading zeros. *) + pattern_with_digits: string + + option [@default None] + + ; [@key "pattern_with_digits"] + (* A string starting with 'image_' (case insensitive) and one to three digits following i.e. Image_01. *) + pattern_with_digits_and_delimiter: string + + option [@default None] + + ; [@key "pattern_with_digits_and_delimiter"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create (number : float) (byte : string) (date : string) (password : string) : t = { + integer = None; + int32 = None; + int64 = None; + number = number; + float = None; + double = None; + decimal = None; + string = None; + byte = byte; + binary = None; + date = date; + date_time = None; + uuid = None; + password = password; + pattern_with_digits = None; + pattern_with_digits_and_delimiter = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/has_only_read_only.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/has_only_read_only.ml new file mode 100644 index 000000000000..2c9389e7c549 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/has_only_read_only.ml @@ -0,0 +1,25 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + bar: string + + option [@default None] + + ; [@key "bar"] + foo: string + + option [@default None] + + ; [@key "foo"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + bar = None; + foo = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/health_check_result.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/health_check_result.ml new file mode 100644 index 000000000000..24198f6f73ae --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/health_check_result.ml @@ -0,0 +1,21 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + * Schema Health_check_result.t : Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. + *) + +type t = { + nullable_message: string + + option [@default None] + + ; [@key "NullableMessage"] +} [@@deriving yojson { strict = false }, show, eq ];; + +(** Just a string to inform instance is up and running. Make it nullable in hope to get it as pointer in generated model. *) +let create () : t = { + nullable_message = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/list.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/list.ml new file mode 100644 index 000000000000..f0c267f3d1dd --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/list.ml @@ -0,0 +1,19 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + var_123_list: string + + option [@default None] + + ; [@key "123-list"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + var_123_list = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/map_test.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/map_test.ml new file mode 100644 index 000000000000..2c6430d7d1a7 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/map_test.ml @@ -0,0 +1,28 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + map_map_of_string: (string * (string * string) list) list + + ; [@key "map_map_of_string"] + map_of_enum_string: (string * Enums.map_of_enum_string) list +; [@key "map_of_enum_string"] + direct_map: (string * bool) list + + ; [@key "direct_map"] + indirect_map: (string * bool) list + + ; [@key "indirect_map"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + map_map_of_string = []; + map_of_enum_string = []; + direct_map = []; + indirect_map = []; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/mixed_properties_and_additional_properties_class.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/mixed_properties_and_additional_properties_class.ml new file mode 100644 index 000000000000..e43531cfb964 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/mixed_properties_and_additional_properties_class.ml @@ -0,0 +1,29 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + uuid: string + + option [@default None] + + ; [@key "uuid"] + date_time: string + + option [@default None] + + ; [@key "dateTime"] + map: (string * Animal.t) list + + ; [@key "map"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + uuid = None; + date_time = None; + map = []; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/model_200_response.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/model_200_response.ml new file mode 100644 index 000000000000..95ee7727f40d --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/model_200_response.ml @@ -0,0 +1,27 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + * Schema Model_200_response.t : Model for testing model name starting with number + *) + +type t = { + name: int32 + + option [@default None] + + ; [@key "name"] + _class: string + + option [@default None] + + ; [@key "class"] +} [@@deriving yojson { strict = false }, show, eq ];; + +(** Model for testing model name starting with number *) +let create () : t = { + name = None; + _class = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/model__foo_get_default_response.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/model__foo_get_default_response.ml new file mode 100644 index 000000000000..6b31b7d74ed4 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/model__foo_get_default_response.ml @@ -0,0 +1,19 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + string: Foo.t + + option [@default None] + + ; [@key "string"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + string = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/model__special_model_name_.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/model__special_model_name_.ml new file mode 100644 index 000000000000..0495face91a6 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/model__special_model_name_.ml @@ -0,0 +1,19 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + special_property_name: int64 + + option [@default None] + + ; [@key "$special[property.name]"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + special_property_name = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/name.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/name.ml new file mode 100644 index 000000000000..85f14bf15c7d --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/name.ml @@ -0,0 +1,39 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + * Schema Name.t : Model for testing model name same as property name + *) + +type t = { + name: int32 + + + + ; [@key "name"] + snake_case: int32 + + option [@default None] + + ; [@key "snake_case"] + property: string + + option [@default None] + + ; [@key "property"] + var_123_number: int32 + + option [@default None] + + ; [@key "123Number"] +} [@@deriving yojson { strict = false }, show, eq ];; + +(** Model for testing model name same as property name *) +let create (name : int32) : t = { + name = name; + snake_case = None; + property = None; + var_123_number = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/nullable_class.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/nullable_class.ml new file mode 100644 index 000000000000..3a01e8875a6d --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/nullable_class.ml @@ -0,0 +1,73 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + integer_prop: int32 + + option [@default None] + + ; [@key "integer_prop"] + number_prop: float + + option [@default None] + + ; [@key "number_prop"] + boolean_prop: bool + + option [@default None] + + ; [@key "boolean_prop"] + string_prop: string + + option [@default None] + + ; [@key "string_prop"] + date_prop: string + + option [@default None] + + ; [@key "date_prop"] + datetime_prop: string + + option [@default None] + + ; [@key "datetime_prop"] + array_nullable_prop: Yojson.Safe.t list + [@default []] + ; [@key "array_nullable_prop"] + array_and_items_nullable_prop: Yojson.Safe.t list + [@default []] + ; [@key "array_and_items_nullable_prop"] + array_items_nullable: Yojson.Safe.t list + [@default []] + ; [@key "array_items_nullable"] + object_nullable_prop: (string * Yojson.Safe.t) list + + ; [@key "object_nullable_prop"] + object_and_items_nullable_prop: (string * Yojson.Safe.t) list + + ; [@key "object_and_items_nullable_prop"] + object_items_nullable: (string * Yojson.Safe.t) list + + ; [@key "object_items_nullable"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + integer_prop = None; + number_prop = None; + boolean_prop = None; + string_prop = None; + date_prop = None; + datetime_prop = None; + array_nullable_prop = []; + array_and_items_nullable_prop = []; + array_items_nullable = []; + object_nullable_prop = []; + object_and_items_nullable_prop = []; + object_items_nullable = []; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/number_only.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/number_only.ml new file mode 100644 index 000000000000..1a1310951589 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/number_only.ml @@ -0,0 +1,19 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + just_number: float + + option [@default None] + + ; [@key "JustNumber"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + just_number = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/object_with_deprecated_fields.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/object_with_deprecated_fields.ml new file mode 100644 index 000000000000..aa1f4726d0bf --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/object_with_deprecated_fields.ml @@ -0,0 +1,35 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + uuid: string + + option [@default None] + + ; [@key "uuid"] + id: float + + option [@default None] + + ; [@key "id"] + deprecated_ref: Deprecated_object.t + + option [@default None] + + ; [@key "deprecatedRef"] + bars: string list + [@default []] + ; [@key "bars"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + uuid = None; + id = None; + deprecated_ref = None; + bars = []; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/order.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/order.ml new file mode 100644 index 000000000000..f3ad48c1e3e1 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/order.ml @@ -0,0 +1,51 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + id: int64 + + option [@default None] + + ; [@key "id"] + pet_id: int64 + + option [@default None] + + ; [@key "petId"] + quantity: int32 + + option [@default None] + + ; [@key "quantity"] + ship_date: string + + option [@default None] + + ; [@key "shipDate"] + (* Order Status *) + status: Enums.order_status + option [@default + + None + ] + ; [@key "status"] + complete: bool + + option [@default None] + + ; [@key "complete"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + id = None; + pet_id = None; + quantity = None; + ship_date = None; + status = None; + complete = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/outer_composite.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/outer_composite.ml new file mode 100644 index 000000000000..65184e1b2ab8 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/outer_composite.ml @@ -0,0 +1,31 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + my_number: float + + option [@default None] + + ; [@key "my_number"] + my_string: string + + option [@default None] + + ; [@key "my_string"] + my_boolean: bool + + option [@default None] + + ; [@key "my_boolean"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + my_number = None; + my_string = None; + my_boolean = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/outer_object_with_enum_property.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/outer_object_with_enum_property.ml new file mode 100644 index 000000000000..3c667fbc82fb --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/outer_object_with_enum_property.ml @@ -0,0 +1,19 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + value: Enums.outerenuminteger + + + + ; [@key "value"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create (value : Enums.outerenuminteger) : t = { + value = value; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/parent_with_nullable.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/parent_with_nullable.ml new file mode 100644 index 000000000000..9db248d8e6a7 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/parent_with_nullable.ml @@ -0,0 +1,26 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + _type: Enums.parentwithnullable_type + option [@default + Some(`ChildWithNullable) + + ] + ; [@key "type"] + nullable_property: string + + option [@default None] + + ; [@key "nullableProperty"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + _type = None; + nullable_property = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/pet.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/pet.ml new file mode 100644 index 000000000000..c3f0a2e48a10 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/pet.ml @@ -0,0 +1,47 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + id: int64 + + option [@default None] + + ; [@key "id"] + category: Category.t + + option [@default None] + + ; [@key "category"] + name: string + + + + ; [@key "name"] + photo_urls: string list + + ; [@key "photoUrls"] + tags: Tag.t list + [@default []] + ; [@key "tags"] + (* pet status in the store *) + status: Enums.status + option [@default + + None + ] + ; [@key "status"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create (name : string) (photo_urls : string list) : t = { + id = None; + category = None; + name = name; + photo_urls = photo_urls; + tags = []; + status = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/read_only_first.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/read_only_first.ml new file mode 100644 index 000000000000..782a38a015f7 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/read_only_first.ml @@ -0,0 +1,25 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + bar: string + + option [@default None] + + ; [@key "bar"] + baz: string + + option [@default None] + + ; [@key "baz"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + bar = None; + baz = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/return.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/return.ml new file mode 100644 index 000000000000..f1fe51cdf23d --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/return.ml @@ -0,0 +1,21 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + * Schema Return.t : Model for testing reserved words + *) + +type t = { + return: int32 + + option [@default None] + + ; [@key "return"] +} [@@deriving yojson { strict = false }, show, eq ];; + +(** Model for testing reserved words *) +let create () : t = { + return = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/tag.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/tag.ml new file mode 100644 index 000000000000..c5cdf5113f77 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/tag.ml @@ -0,0 +1,25 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + id: int64 + + option [@default None] + + ; [@key "id"] + name: string + + option [@default None] + + ; [@key "name"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + id = None; + name = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/test_inline_freeform_additional_properties_request.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/test_inline_freeform_additional_properties_request.ml new file mode 100644 index 000000000000..674eac609d17 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/test_inline_freeform_additional_properties_request.ml @@ -0,0 +1,19 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + some_property: string + + option [@default None] + + ; [@key "someProperty"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + some_property = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/user.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/user.ml new file mode 100644 index 000000000000..57f598e3ebda --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/user.ml @@ -0,0 +1,62 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type t = { + id: int64 + + option [@default None] + + ; [@key "id"] + username: string + + option [@default None] + + ; [@key "username"] + first_name: string + + option [@default None] + + ; [@key "firstName"] + last_name: string + + option [@default None] + + ; [@key "lastName"] + email: string + + option [@default None] + + ; [@key "email"] + password: string + + option [@default None] + + ; [@key "password"] + phone: string + + option [@default None] + + ; [@key "phone"] + (* User Status *) + user_status: int32 + + option [@default None] + + ; [@key "userStatus"] +} [@@deriving yojson { strict = false }, show, eq ];; + +let create () : t = { + id = None; + username = None; + first_name = None; + last_name = None; + email = None; + password = None; + phone = None; + user_status = None; +} + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/support/enums.ml b/samples/client/petstore/ocaml-fake-petstore/src/support/enums.ml new file mode 100644 index 000000000000..38b8eb297499 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/support/enums.ml @@ -0,0 +1,163 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type outerenuminteger = [ +| `_0 [@printer fun fmt _ -> Format.pp_print_string fmt "0"] [@name "0"] +| `_1 [@printer fun fmt _ -> Format.pp_print_string fmt "1"] [@name "1"] +| `_2 [@printer fun fmt _ -> Format.pp_print_string fmt "2"] [@name "2"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let outerenuminteger_of_yojson json = outerenuminteger_of_yojson (`List [json]) +let outerenuminteger_to_yojson e = + match outerenuminteger_to_yojson e with + | `List [json] -> json + | json -> json + +type map_of_enum_string = [ +| `UPPER [@printer fun fmt _ -> Format.pp_print_string fmt "UPPER"] [@name "UPPER"] +| `Lower [@printer fun fmt _ -> Format.pp_print_string fmt "lower"] [@name "lower"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let map_of_enum_string_of_yojson json = map_of_enum_string_of_yojson (`List [json]) +let map_of_enum_string_to_yojson e = + match map_of_enum_string_to_yojson e with + | `List [json] -> json + | json -> json + +type enum_integer = [ +| `_1 [@printer fun fmt _ -> Format.pp_print_string fmt "1"] [@name "1"] +| `Minus1 [@printer fun fmt _ -> Format.pp_print_string fmt "-1"] [@name "-1"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let enum_integer_of_yojson json = enum_integer_of_yojson (`List [json]) +let enum_integer_to_yojson e = + match enum_integer_to_yojson e with + | `List [json] -> json + | json -> json + +type just_symbol = [ +| `Greater_ThanEqual [@printer fun fmt _ -> Format.pp_print_string fmt ">="] [@name ">="] +| `Dollar [@printer fun fmt _ -> Format.pp_print_string fmt "$"] [@name "$"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let just_symbol_of_yojson json = just_symbol_of_yojson (`List [json]) +let just_symbol_to_yojson e = + match just_symbol_to_yojson e with + | `List [json] -> json + | json -> json + +type enumclass = [ +| `_abc [@printer fun fmt _ -> Format.pp_print_string fmt "_abc"] [@name "_abc"] +| `Minusefg [@printer fun fmt _ -> Format.pp_print_string fmt "-efg"] [@name "-efg"] +| `Left_ParenthesisxyzRight_Parenthesis [@printer fun fmt _ -> Format.pp_print_string fmt "(xyz)"] [@name "(xyz)"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let enumclass_of_yojson json = enumclass_of_yojson (`List [json]) +let enumclass_to_yojson e = + match enumclass_to_yojson e with + | `List [json] -> json + | json -> json + +type status = [ +| `Available [@printer fun fmt _ -> Format.pp_print_string fmt "available"] [@name "available"] +| `Pending [@printer fun fmt _ -> Format.pp_print_string fmt "pending"] [@name "pending"] +| `Sold [@printer fun fmt _ -> Format.pp_print_string fmt "sold"] [@name "sold"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let status_of_yojson json = status_of_yojson (`List [json]) +let status_to_yojson e = + match status_to_yojson e with + | `List [json] -> json + | json -> json + +type order_status = [ +| `Placed [@printer fun fmt _ -> Format.pp_print_string fmt "placed"] [@name "placed"] +| `Approved [@printer fun fmt _ -> Format.pp_print_string fmt "approved"] [@name "approved"] +| `Delivered [@printer fun fmt _ -> Format.pp_print_string fmt "delivered"] [@name "delivered"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let order_status_of_yojson json = order_status_of_yojson (`List [json]) +let order_status_to_yojson e = + match order_status_to_yojson e with + | `List [json] -> json + | json -> json + +type enum_query_integer = [ +| `_1 [@printer fun fmt _ -> Format.pp_print_string fmt "1"] [@name "1"] +| `Minus2 [@printer fun fmt _ -> Format.pp_print_string fmt "-2"] [@name "-2"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let enum_query_integer_of_yojson json = enum_query_integer_of_yojson (`List [json]) +let enum_query_integer_to_yojson e = + match enum_query_integer_to_yojson e with + | `List [json] -> json + | json -> json + +type enum_form_string_array = [ +| `Greater_Than [@printer fun fmt _ -> Format.pp_print_string fmt ">"] [@name ">"] +| `Dollar [@printer fun fmt _ -> Format.pp_print_string fmt "$"] [@name "$"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let enum_form_string_array_of_yojson json = enum_form_string_array_of_yojson (`List [json]) +let enum_form_string_array_to_yojson e = + match enum_form_string_array_to_yojson e with + | `List [json] -> json + | json -> json + +type parentwithnullable_type = [ +| `ChildWithNullable [@printer fun fmt _ -> Format.pp_print_string fmt "ChildWithNullable"] [@name "ChildWithNullable"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let parentwithnullable_type_of_yojson json = parentwithnullable_type_of_yojson (`List [json]) +let parentwithnullable_type_to_yojson e = + match parentwithnullable_type_to_yojson e with + | `List [json] -> json + | json -> json + +type enum_number = [ +| `_1Period1 [@printer fun fmt _ -> Format.pp_print_string fmt "1.1"] [@name "1.1"] +| `Minus1Period2 [@printer fun fmt _ -> Format.pp_print_string fmt "-1.2"] [@name "-1.2"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let enum_number_of_yojson json = enum_number_of_yojson (`List [json]) +let enum_number_to_yojson e = + match enum_number_to_yojson e with + | `List [json] -> json + | json -> json + +type array_enum = [ +| `Fish [@printer fun fmt _ -> Format.pp_print_string fmt "fish"] [@name "fish"] +| `Crab [@printer fun fmt _ -> Format.pp_print_string fmt "crab"] [@name "crab"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let array_enum_of_yojson json = array_enum_of_yojson (`List [json]) +let array_enum_to_yojson e = + match array_enum_to_yojson e with + | `List [json] -> json + | json -> json + +type singlereftype = [ +| `Admin [@printer fun fmt _ -> Format.pp_print_string fmt "admin"] [@name "admin"] +| `User [@printer fun fmt _ -> Format.pp_print_string fmt "user"] [@name "user"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let singlereftype_of_yojson json = singlereftype_of_yojson (`List [json]) +let singlereftype_to_yojson e = + match singlereftype_to_yojson e with + | `List [json] -> json + | json -> json + +type enum_string = [ +| `UPPER [@printer fun fmt _ -> Format.pp_print_string fmt "UPPER"] [@name "UPPER"] +| `Lower [@printer fun fmt _ -> Format.pp_print_string fmt "lower"] [@name "lower"] +] [@@deriving yojson, show { with_path = false }, eq];; + +let enum_string_of_yojson json = enum_string_of_yojson (`List [json]) +let enum_string_to_yojson e = + match enum_string_to_yojson e with + | `List [json] -> json + | json -> json diff --git a/samples/client/petstore/ocaml-fake-petstore/src/support/jsonSupport.ml b/samples/client/petstore/ocaml-fake-petstore/src/support/jsonSupport.ml new file mode 100644 index 000000000000..061b1be39f8a --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/support/jsonSupport.ml @@ -0,0 +1,55 @@ +open Ppx_deriving_yojson_runtime + +let unwrap to_json json = + match to_json json with + | Result.Ok json -> json + | Result.Error s -> failwith s + +let to_int json = + match json with + | `Int x -> x + | `Intlit s -> int_of_string s + | _ -> failwith "JsonSupport.to_int" + +let to_bool json = + match json with + | `Bool x -> x + | _ -> failwith "JsonSupport.to_bool" + +let to_float json = + match json with + | `Float x -> x + | _ -> failwith "JsonSupport.to_float" + +let to_string json = + match json with + | `String s -> s + | _ -> failwith "JsonSupport.to_string" + +let to_int32 json : int32 = + match json with + | `Int x -> Int32.of_int x + | `Intlit s -> Int32.of_string s + | _ -> failwith "JsonSupport.to_int32" + +let to_int64 json : int64 = + match json with + | `Int x -> Int64.of_int x + | `Intlit s -> Int64.of_string s + | _ -> failwith "JsonSupport.to_int64" + +let of_int x = `Int x + +let of_bool b = `Bool b + +let of_float x = `Float x + +let of_string s = `String s + +let of_int32 x = `Intlit (Int32.to_string x) + +let of_int64 x = `Intlit (Int64.to_string x) + +let of_list_of of_f l = `List (Stdlib.List.map of_f l) + +let of_map_of of_f l = `Assoc (Stdlib.List.map (fun (k, v) -> (k, of_f v)) l) diff --git a/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml b/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml new file mode 100644 index 000000000000..ca2c139924d8 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml @@ -0,0 +1,97 @@ +let api_key = "" +let base_url = "http://petstore.swagger.io:80/v2" +let default_headers = Cohttp.Header.init_with "Content-Type" "application/json" + +let option_fold f default o = + match o with + | Some v -> f v + | None -> default + +let build_uri operation_path = Uri.of_string (base_url ^ operation_path) + +let add_string_header headers key value = + Cohttp.Header.add headers key value + +let add_string_header_multi headers key values = + Cohttp.Header.add_multi headers key values + +let add_header headers key to_string value = + Cohttp.Header.add headers key (to_string value) + +let add_header_multi headers key to_string value = + Cohttp.Header.add_multi headers key (to_string value) + +let maybe_add_header headers key to_string value = + option_fold (add_header headers key to_string) headers value + +let maybe_add_header_multi headers key to_string value = + option_fold (add_header_multi headers key to_string) headers value + +let write_string_body s = Cohttp_lwt.Body.of_string s + +let write_json_body payload = + Cohttp_lwt.Body.of_string (Yojson.Safe.to_string payload ~std:true) + +let write_as_json_body to_json payload = write_json_body (to_json payload) + +let handle_response resp on_success_handler = + match Cohttp_lwt.Response.status resp with + | #Cohttp.Code.success_status -> on_success_handler () + | s -> failwith ("Server responded with status " ^ Cohttp.Code.(reason_phrase_of_code (code_of_status s))) + +let handle_unit_response resp = handle_response resp (fun () -> Lwt.return ()) + +let read_json_body resp body = + handle_response resp (fun () -> + (Lwt.(Cohttp_lwt.Body.to_string body >|= Yojson.Safe.from_string))) + +let read_json_body_as of_json resp body = + Lwt.(read_json_body resp body >|= of_json) + +let read_json_body_as_list resp body = + Lwt.(read_json_body resp body >|= Yojson.Safe.Util.to_list) + +let read_json_body_as_list_of of_json resp body = + Lwt.(read_json_body_as_list resp body >|= Stdlib.List.map of_json) + +let read_json_body_as_map resp body = + Lwt.(read_json_body resp body >|= Yojson.Safe.Util.to_assoc) + +let read_json_body_as_map_of of_json resp body = + Lwt.(read_json_body_as_map resp body >|= Stdlib.List.map (fun (s, v) -> (s, of_json v))) + +let replace_string_path_param uri param_name param_value = + let regexp = Str.regexp (Str.quote ("{" ^ param_name ^ "}")) in + let path = Str.global_replace regexp param_value (Uri.pct_decode (Uri.path uri)) in + Uri.with_path uri path + +let replace_path_param uri param_name to_string param_value = + replace_string_path_param uri param_name (to_string param_value) + +let maybe_replace_path_param uri param_name to_string param_value = + option_fold (replace_path_param uri param_name to_string) uri param_value + +let add_query_param uri param_name to_string param_value = + Uri.add_query_param' uri (param_name, to_string param_value) + +let add_query_param_list uri param_name to_string param_value = + Uri.add_query_param uri (param_name, to_string param_value) + +let maybe_add_query_param uri param_name to_string param_value = + option_fold (add_query_param uri param_name to_string) uri param_value + +let init_form_encoded_body () = "" + +let add_form_encoded_body_param params param_name to_string param_value = + let new_param_enc = Printf.sprintf {|%s=%s|} (Uri.pct_encode param_name) (Uri.pct_encode (to_string param_value)) in + if params = "" + then new_param_enc + else Printf.sprintf {|%s&%s|} params new_param_enc + +let add_form_encoded_body_param_list params param_name to_string new_params = + add_form_encoded_body_param params param_name (String.concat ",") (to_string new_params) + +let maybe_add_form_encoded_body_param params param_name to_string param_value = + option_fold (add_form_encoded_body_param params param_name to_string) params param_value + +let finalize_form_encoded_body body = Cohttp_lwt.Body.of_string body From 5215f2197c7853be064fde00d12d0d5f034040a1 Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 1 Aug 2025 14:39:29 +0200 Subject: [PATCH 02/12] Prefix List functions with Stdlib as the fake petstore generates a List module --- .../openapi-generator/src/main/resources/ocaml/json.mustache | 4 ++-- .../src/main/resources/ocaml/support.mustache | 4 ++-- .../src/main/resources/ocaml/to_string.mustache | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/ocaml/json.mustache b/modules/openapi-generator/src/main/resources/ocaml/json.mustache index 4b0fac77545a..061b1be39f8a 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/json.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/json.mustache @@ -50,6 +50,6 @@ let of_int32 x = `Intlit (Int32.to_string x) let of_int64 x = `Intlit (Int64.to_string x) -let of_list_of of_f l = `List (List.map of_f l) +let of_list_of of_f l = `List (Stdlib.List.map of_f l) -let of_map_of of_f l = `Assoc (List.map (fun (k, v) -> (k, of_f v)) l) \ No newline at end of file +let of_map_of of_f l = `Assoc (Stdlib.List.map (fun (k, v) -> (k, of_f v)) l) diff --git a/modules/openapi-generator/src/main/resources/ocaml/support.mustache b/modules/openapi-generator/src/main/resources/ocaml/support.mustache index 14d5ba0d5793..65540b46608c 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/support.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/support.mustache @@ -52,13 +52,13 @@ let read_json_body_as_list resp body = Lwt.(read_json_body resp body >|= Yojson.Safe.Util.to_list) let read_json_body_as_list_of of_json resp body = - Lwt.(read_json_body_as_list resp body >|= List.map of_json) + Lwt.(read_json_body_as_list resp body >|= Stdlib.List.map of_json) let read_json_body_as_map resp body = Lwt.(read_json_body resp body >|= Yojson.Safe.Util.to_assoc) let read_json_body_as_map_of of_json resp body = - Lwt.(read_json_body_as_map resp body >|= List.map (fun (s, v) -> (s, of_json v))) + Lwt.(read_json_body_as_map resp body >|= Stdlib.List.map (fun (s, v) -> (s, of_json v))) let replace_string_path_param uri param_name param_value = let regexp = Str.regexp (Str.quote ("{" ^ param_name ^ "}")) in diff --git a/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache b/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache index 3b41569d43d9..4503e98eccf1 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache @@ -1 +1 @@ -{{#isContainer}}{{#items}}(List.map {{> to_string}}){{/items}}{{/isContainer}}{{^isEnum}}{{#isLong}}Int64.to_string{{/isLong}}{{#isInteger}}Int32.to_string{{/isInteger}}{{#isFloat}}string_of_float{{/isFloat}}{{#isNumber}}string_of_float{{/isNumber}}{{#isDouble}}string_of_float{{/isDouble}}{{#isBoolean}}string_of_bool{{/isBoolean}}{{#isFile}}(fun x -> x){{/isFile}}{{#isDate}}(fun x -> x){{/isDate}}{{#isDateTime}}(fun x -> x){{/isDateTime}}{{#isString}}(fun x -> x){{/isString}}{{#isByteArray}}(fun x -> x){{/isByteArray}}{{#isModel}}{{{vendorExtensions.x-model-module}}}.show{{/isModel}}{{/isEnum}}{{^isModel}}{{^isContainer}}{{#isEnum}}Enums.show_{{{datatypeWithEnum}}}{{/isEnum}}{{/isContainer}}{{/isModel}} \ No newline at end of file +{{#isContainer}}{{#items}}(Stdlib.List.map {{> to_string}}){{/items}}{{/isContainer}}{{^isEnum}}{{#isLong}}Int64.to_string{{/isLong}}{{#isInteger}}Int32.to_string{{/isInteger}}{{#isFloat}}string_of_float{{/isFloat}}{{#isNumber}}string_of_float{{/isNumber}}{{#isDouble}}string_of_float{{/isDouble}}{{#isBoolean}}string_of_bool{{/isBoolean}}{{#isFile}}(fun x -> x){{/isFile}}{{#isDate}}(fun x -> x){{/isDate}}{{#isDateTime}}(fun x -> x){{/isDateTime}}{{#isString}}(fun x -> x){{/isString}}{{#isByteArray}}(fun x -> x){{/isByteArray}}{{#isModel}}{{{vendorExtensions.x-model-module}}}.show{{/isModel}}{{/isEnum}}{{^isModel}}{{^isContainer}}{{#isEnum}}Enums.show_{{{datatypeWithEnum}}}{{/isEnum}}{{/isContainer}}{{/isModel}} From a5f098aed194e5218ebae5c6fa9f9b8d410e9c77 Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 1 Aug 2025 14:40:00 +0200 Subject: [PATCH 03/12] Handle decimal and any types --- .../org/openapitools/codegen/languages/OCamlClientCodegen.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/OCamlClientCodegen.java b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/OCamlClientCodegen.java index 2c963f78ce31..4ec76e273497 100644 --- a/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/OCamlClientCodegen.java +++ b/modules/openapi-generator/src/main/java/org/openapitools/codegen/languages/OCamlClientCodegen.java @@ -171,6 +171,7 @@ public OCamlClientCodegen() { typeMapping.put("short", "int"); typeMapping.put("char", "char"); typeMapping.put("float", "float"); + typeMapping.put("decimal", "string"); typeMapping.put("double", "float"); typeMapping.put("integer", "int32"); typeMapping.put("number", "float"); @@ -179,6 +180,7 @@ public OCamlClientCodegen() { typeMapping.put("any", "Yojson.Safe.t"); typeMapping.put("file", "string"); typeMapping.put("ByteArray", "string"); + typeMapping.put("AnyType", "Yojson.Safe.t"); // lib typeMapping.put("string", "string"); typeMapping.put("UUID", "string"); From 675ba3291ec401827d9bdb973242f755058c42ee Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 1 Aug 2025 14:44:37 +0200 Subject: [PATCH 04/12] Indent to_json.mustache for easier maintenance --- .../src/main/resources/ocaml/to_json.mustache | 35 +++- .../src/apis/another_fake_api.ml | 10 +- .../ocaml-fake-petstore/src/apis/fake_api.ml | 167 ++++++++++++++++-- .../src/apis/fake_classname_tags123_api.ml | 10 +- .../ocaml-fake-petstore/src/apis/pet_api.ml | 20 ++- .../ocaml-fake-petstore/src/apis/store_api.ml | 10 +- .../ocaml-fake-petstore/src/apis/user_api.ml | 56 +++++- 7 files changed, 283 insertions(+), 25 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache b/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache index 99e45aafb78e..80872d67ccbc 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache @@ -1 +1,34 @@ -{{#isArray}}{{#items}}(JsonSupport.of_list_of {{> to_json}}){{/items}}{{/isArray}}{{#isMap}}{{#items}}(JsonSupport.of_map_of {{> to_json}}){{/items}}{{/isMap}}{{#isString}}JsonSupport.of_string{{/isString}}{{#isLong}}JsonSupport.of_int64{{/isLong}}{{#isInteger}}JsonSupport.of_int32{{/isInteger}}{{#isFloat}}JsonSupport.of_float{{/isFloat}}{{#isNumber}}JsonSupport.of_float{{/isNumber}}{{#isDouble}}JsonSupport.of_float{{/isDouble}}{{#isBoolean}}JsonSupport.of_bool{{/isBoolean}}{{^isEnum}}{{#isModel}}{{#vendorExtensions.x-model-module}}{{{vendorExtensions.x-model-module}}}.to_yojson{{/vendorExtensions.x-model-module}}{{^vendorExtensions.x-model-module}}{{{baseType}}}.to_yojson{{/vendorExtensions.x-model-module}}{{/isModel}}{{/isEnum}}{{^isModel}}{{^isContainer}}{{#isEnum}}Enums.{{{datatypeWithEnum}}}_to_yojson{{/isEnum}}{{/isContainer}}{{/isModel}} \ No newline at end of file +{{#isArray}} + {{#items}} + (JsonSupport.of_list_of {{> to_json}}) + {{/items}} +{{/isArray}} +{{#isMap}} + {{#items}} + (JsonSupport.of_map_of {{> to_json}}) + {{/items}} +{{/isMap}} +{{#isString}}JsonSupport.of_string{{/isString}} +{{#isLong}}JsonSupport.of_int64{{/isLong}} +{{#isInteger}}JsonSupport.of_int32{{/isInteger}} +{{#isFloat}}JsonSupport.of_float{{/isFloat}} +{{#isNumber}}JsonSupport.of_float{{/isNumber}} +{{#isDouble}}JsonSupport.of_float{{/isDouble}} +{{#isBoolean}}JsonSupport.of_bool{{/isBoolean}} +{{^isEnum}} + {{#isModel}} + {{#vendorExtensions.x-model-module}} + {{{vendorExtensions.x-model-module}}}.to_yojson + {{/vendorExtensions.x-model-module}} + {{^vendorExtensions.x-model-module}} + {{{baseType}}}.to_yojson + {{/vendorExtensions.x-model-module}} + {{/isModel}} +{{/isEnum}} +{{^isModel}} + {{^isContainer}} + {{#isEnum}} + Enums.{{{datatypeWithEnum}}}_to_yojson + {{/isEnum}} + {{/isContainer}} +{{/isModel}} diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml index 860d741e0170..dbab7019427c 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml @@ -9,7 +9,15 @@ let call_123_test_special_tags ~client_t = let open Lwt.Infix in let uri = Request.build_uri "/another-fake/dummy" in let headers = Request.default_headers in - let body = Request.write_as_json_body Client.to_yojson client_t in + let body = Request.write_as_json_body + + + + + + + Client.to_yojson + client_t in Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml index 08de0e346f39..906c912887f3 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml @@ -27,7 +27,15 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () = header_1 in let uri = Request.maybe_add_query_param uri "query_1" (fun x -> x) query_1 in - let body = Request.write_as_json_body Pet.to_yojson pet_t in + let body = Request.write_as_json_body + + + + + + + Pet.to_yojson + pet_t in Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -35,7 +43,14 @@ let fake_outer_boolean_serialize ~body () = let open Lwt.Infix in let uri = Request.build_uri "/fake/outer/boolean" in let headers = Request.default_headers in - let body = Request.write_as_json_body JsonSupport.of_bool body in + let body = Request.write_as_json_body + + + + + +JsonSupport.of_bool + body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.to_bool) resp body @@ -43,7 +58,15 @@ let fake_outer_composite_serialize ~outer_composite_t () = let open Lwt.Infix in let uri = Request.build_uri "/fake/outer/composite" in let headers = Request.default_headers in - let body = Request.write_as_json_body Outer_composite.to_yojson outer_composite_t in + let body = Request.write_as_json_body + + + + + + + Outer_composite.to_yojson + outer_composite_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.unwrap Outer_composite.of_yojson) resp body @@ -51,7 +74,14 @@ let fake_outer_number_serialize ~body () = let open Lwt.Infix in let uri = Request.build_uri "/fake/outer/number" in let headers = Request.default_headers in - let body = Request.write_as_json_body JsonSupport.of_float body in + let body = Request.write_as_json_body + + + +JsonSupport.of_float + + + body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.to_float) resp body @@ -59,7 +89,14 @@ let fake_outer_string_serialize ~body () = let open Lwt.Infix in let uri = Request.build_uri "/fake/outer/string" in let headers = Request.default_headers in - let body = Request.write_as_json_body JsonSupport.of_string body in + let body = Request.write_as_json_body JsonSupport.of_string + + + + + + + body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.to_string) resp body @@ -67,7 +104,15 @@ let fake_property_enum_integer_serialize ~outer_object_with_enum_property_t = let open Lwt.Infix in let uri = Request.build_uri "/fake/property/enum-int" in let headers = Request.default_headers in - let body = Request.write_as_json_body Outer_object_with_enum_property.to_yojson outer_object_with_enum_property_t in + let body = Request.write_as_json_body + + + + + + + Outer_object_with_enum_property.to_yojson + outer_object_with_enum_property_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.unwrap Outer_object_with_enum_property.of_yojson) resp body @@ -75,7 +120,22 @@ let test_additional_properties_reference ~request_body = let open Lwt.Infix in let uri = Request.build_uri "/fake/additionalProperties-reference" in let headers = Request.default_headers in - let body = Request.write_json_body (JsonSupport.of_map_of ) request_body in + let body = Request.write_json_body (JsonSupport.of_map_of + + + + + + +) + + + + + + + + request_body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -83,7 +143,14 @@ let test_body_with_binary ~body = let open Lwt.Infix in let uri = Request.build_uri "/fake/body-with-binary" in let headers = Request.default_headers in - let body = Request.write_as_json_body body in + let body = Request.write_as_json_body + + + + + + + body in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -91,7 +158,15 @@ let test_body_with_file_schema ~file_schema_test_class_t = let open Lwt.Infix in let uri = Request.build_uri "/fake/body-with-file-schema" in let headers = Request.default_headers in - let body = Request.write_as_json_body File_schema_test_class.to_yojson file_schema_test_class_t in + let body = Request.write_as_json_body + + + + + + + File_schema_test_class.to_yojson + file_schema_test_class_t in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -101,7 +176,15 @@ let test_body_with_query_params ~query ~user_t = let headers = Request.default_headers in let uri = Request.add_query_param uri "query" (fun x -> x) query in - let body = Request.write_as_json_body User.to_yojson user_t 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 @@ -109,7 +192,15 @@ let test_client_model ~client_t = let open Lwt.Infix in let uri = Request.build_uri "/fake" in let headers = Request.default_headers in - let body = Request.write_as_json_body Client.to_yojson client_t in + let body = Request.write_as_json_body + + + + + + + Client.to_yojson + client_t in Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body @@ -204,7 +295,22 @@ let test_inline_additional_properties ~request_body = let open Lwt.Infix in let uri = Request.build_uri "/fake/inline-additionalProperties" in let headers = Request.default_headers in - let body = Request.write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string) request_body in + let body = Request.write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string + + + + + + +) + + + + + + + + request_body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -212,7 +318,15 @@ let test_inline_freeform_additional_properties ~test_inline_freeform_additional_ let open Lwt.Infix in let uri = Request.build_uri "/fake/inline-freeform-additionalProperties" in let headers = Request.default_headers in - let body = Request.write_as_json_body Test_inline_freeform_additional_properties_request.to_yojson test_inline_freeform_additional_properties_request_t in + let body = Request.write_as_json_body + + + + + + + Test_inline_freeform_additional_properties_request.to_yojson + test_inline_freeform_additional_properties_request_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -233,7 +347,15 @@ let test_nullable ~child_with_nullable_t = let open Lwt.Infix in let uri = Request.build_uri "/fake/nullable" in let headers = Request.default_headers in - let body = Request.write_as_json_body Child_with_nullable.to_yojson child_with_nullable_t in + let body = Request.write_as_json_body + + + + + + + Child_with_nullable.to_yojson + child_with_nullable_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -268,7 +390,22 @@ let test_string_map_reference ~request_body = let open Lwt.Infix in let uri = Request.build_uri "/fake/stringMap-reference" in let headers = Request.default_headers in - let body = Request.write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string) request_body in + let body = Request.write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string + + + + + + +) + + + + + + + + request_body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml index b13297f968cf..cf87b671d7a2 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml @@ -10,7 +10,15 @@ let test_classname ~client_t = let uri = Request.build_uri "/fake_classname_test" in let headers = Request.default_headers in let uri = Uri.add_query_param' uri ("api_key_query", Request.api_key) in - let body = Request.write_as_json_body Client.to_yojson client_t in + let body = Request.write_as_json_body + + + + + + + Client.to_yojson + client_t in Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml index a45f58ac0e26..f14daf0e525a 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml @@ -9,7 +9,15 @@ let add_pet ~pet_t = let open Lwt.Infix in let uri = Request.build_uri "/pet" in let headers = Request.default_headers in - let body = Request.write_as_json_body Pet.to_yojson pet_t 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 @@ -58,7 +66,15 @@ let update_pet ~pet_t = let open Lwt.Infix in let uri = Request.build_uri "/pet" in let headers = Request.default_headers in - let body = Request.write_as_json_body Pet.to_yojson pet_t 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 diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml index 732d417cc55f..8dcba73d2c81 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml @@ -35,7 +35,15 @@ let place_order ~order_t = let open Lwt.Infix 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 order_t 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 diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml index 1fa4050cf59e..384a6f749e64 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml @@ -9,7 +9,15 @@ let create_user ~user_t = let open Lwt.Infix in let uri = Request.build_uri "/user" in let headers = Request.default_headers in - let body = Request.write_as_json_body User.to_yojson user_t 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 @@ -17,7 +25,23 @@ let create_users_with_array_input ~user = let open Lwt.Infix 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) user 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 @@ -25,7 +49,23 @@ let create_users_with_list_input ~user = let open Lwt.Infix 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) user 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 @@ -71,7 +111,15 @@ let update_user ~username ~user_t = 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 user_t 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 From 3ea004ad5667410967d5bcc377652486ae3e33e4 Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 1 Aug 2025 15:02:43 +0200 Subject: [PATCH 05/12] Indent api-impl.mustache a bit more for readability before fix --- .../main/resources/ocaml/api-impl.mustache | 6 +- .../src/apis/another_fake_api.ml | 6 +- .../ocaml-fake-petstore/src/apis/fake_api.ml | 90 +++++++++++++++---- .../src/apis/fake_classname_tags123_api.ml | 6 +- .../ocaml-fake-petstore/src/apis/pet_api.ml | 12 ++- .../ocaml-fake-petstore/src/apis/store_api.ml | 6 +- .../ocaml-fake-petstore/src/apis/user_api.ml | 24 ++++- .../client/petstore/ocaml/src/apis/pet_api.ml | 63 ++++++++++--- .../petstore/ocaml/src/apis/store_api.ml | 20 ++++- .../petstore/ocaml/src/apis/user_api.ml | 87 ++++++++++++++++-- .../petstore/ocaml/src/support/jsonSupport.ml | 4 +- .../petstore/ocaml/src/support/request.ml | 4 +- 12 files changed, 274 insertions(+), 54 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache b/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache index f29964db21b3..4ddc9f8145e0 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache @@ -42,7 +42,11 @@ let {{{operationId}}} {{^hasParams}}(){{/hasParams}}{{#allParams}}{{> to_param}} {{/authMethods}} {{/hasAuthMethods}} {{#bodyParams}} - let body = Request.{{#isFreeFormObject}}write_json_body{{/isFreeFormObject}}{{#isByteArray}}write_string_body{{/isByteArray}}{{^isFreeFormObject}}{{^isByteArray}}write_as_json_body{{/isByteArray}}{{/isFreeFormObject}} {{> to_json}} {{{paramName}}} in + let body = Request. + {{#isFreeFormObject}}write_json_body{{/isFreeFormObject}} + {{#isByteArray}}write_string_body{{/isByteArray}} + {{^isFreeFormObject}}{{^isByteArray}}write_as_json_body{{/isByteArray}}{{/isFreeFormObject}} + {{> to_json}} {{{paramName}}} in {{/bodyParams}} {{^hasBodyParam}} {{#hasFormParams}} diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml index dbab7019427c..1fa27116a2bf 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml @@ -9,7 +9,11 @@ let call_123_test_special_tags ~client_t = let open Lwt.Infix in let uri = Request.build_uri "/another-fake/dummy" in let headers = Request.default_headers in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml index 906c912887f3..403b9a53575a 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml @@ -27,7 +27,11 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () = header_1 in let uri = Request.maybe_add_query_param uri "query_1" (fun x -> x) query_1 in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + @@ -43,7 +47,11 @@ let fake_outer_boolean_serialize ~body () = let open Lwt.Infix in let uri = Request.build_uri "/fake/outer/boolean" in let headers = Request.default_headers in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + @@ -58,7 +66,11 @@ let fake_outer_composite_serialize ~outer_composite_t () = let open Lwt.Infix in let uri = Request.build_uri "/fake/outer/composite" in let headers = Request.default_headers in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + @@ -74,7 +86,11 @@ let fake_outer_number_serialize ~body () = let open Lwt.Infix in let uri = Request.build_uri "/fake/outer/number" in let headers = Request.default_headers in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + @@ -89,7 +105,11 @@ let fake_outer_string_serialize ~body () = let open Lwt.Infix in let uri = Request.build_uri "/fake/outer/string" in let headers = Request.default_headers in - let body = Request.write_as_json_body JsonSupport.of_string + let body = Request. + + + write_as_json_body + JsonSupport.of_string @@ -104,7 +124,11 @@ let fake_property_enum_integer_serialize ~outer_object_with_enum_property_t = let open Lwt.Infix in let uri = Request.build_uri "/fake/property/enum-int" in let headers = Request.default_headers in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + @@ -120,7 +144,11 @@ let test_additional_properties_reference ~request_body = let open Lwt.Infix in let uri = Request.build_uri "/fake/additionalProperties-reference" in let headers = Request.default_headers in - let body = Request.write_json_body (JsonSupport.of_map_of + let body = Request. + write_json_body + + + (JsonSupport.of_map_of @@ -143,7 +171,11 @@ let test_body_with_binary ~body = let open Lwt.Infix in let uri = Request.build_uri "/fake/body-with-binary" in let headers = Request.default_headers in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + @@ -158,7 +190,11 @@ let test_body_with_file_schema ~file_schema_test_class_t = let open Lwt.Infix in let uri = Request.build_uri "/fake/body-with-file-schema" in let headers = Request.default_headers in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + @@ -176,7 +212,11 @@ let test_body_with_query_params ~query ~user_t = let headers = Request.default_headers in let uri = Request.add_query_param uri "query" (fun x -> x) query in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + @@ -192,7 +232,11 @@ let test_client_model ~client_t = let open Lwt.Infix in let uri = Request.build_uri "/fake" in let headers = Request.default_headers in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + @@ -295,7 +339,11 @@ let test_inline_additional_properties ~request_body = let open Lwt.Infix in let uri = Request.build_uri "/fake/inline-additionalProperties" in let headers = Request.default_headers in - let body = Request.write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string + let body = Request. + + + write_as_json_body + (JsonSupport.of_map_of JsonSupport.of_string @@ -318,7 +366,11 @@ let test_inline_freeform_additional_properties ~test_inline_freeform_additional_ let open Lwt.Infix in let uri = Request.build_uri "/fake/inline-freeform-additionalProperties" in let headers = Request.default_headers in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + @@ -347,7 +399,11 @@ let test_nullable ~child_with_nullable_t = let open Lwt.Infix in let uri = Request.build_uri "/fake/nullable" in let headers = Request.default_headers in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + @@ -390,7 +446,11 @@ let test_string_map_reference ~request_body = let open Lwt.Infix in let uri = Request.build_uri "/fake/stringMap-reference" in let headers = Request.default_headers in - let body = Request.write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string + let body = Request. + + + write_as_json_body + (JsonSupport.of_map_of JsonSupport.of_string diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml index cf87b671d7a2..a39666ef47ed 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml @@ -10,7 +10,11 @@ let test_classname ~client_t = let uri = Request.build_uri "/fake_classname_test" in let headers = Request.default_headers in let uri = Uri.add_query_param' uri ("api_key_query", Request.api_key) in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml index f14daf0e525a..2347d539a5a1 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml @@ -9,7 +9,11 @@ let add_pet ~pet_t = let open Lwt.Infix in let uri = Request.build_uri "/pet" in let headers = Request.default_headers in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + @@ -66,7 +70,11 @@ let update_pet ~pet_t = let open Lwt.Infix in let uri = Request.build_uri "/pet" in let headers = Request.default_headers in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml index 8dcba73d2c81..f1baa934b2ed 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml @@ -35,7 +35,11 @@ let place_order ~order_t = let open Lwt.Infix in let uri = Request.build_uri "/store/order" in let headers = Request.default_headers in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml index 384a6f749e64..6dc6dc3f597e 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml @@ -9,7 +9,11 @@ let create_user ~user_t = let open Lwt.Infix in let uri = Request.build_uri "/user" in let headers = Request.default_headers in - let body = Request.write_as_json_body + let body = Request. + + + write_as_json_body + @@ -25,7 +29,11 @@ let create_users_with_array_input ~user = let open Lwt.Infix 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 + let body = Request. + + + write_as_json_body + (JsonSupport.of_list_of @@ -49,7 +57,11 @@ let create_users_with_list_input ~user = let open Lwt.Infix 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 + let body = Request. + + + write_as_json_body + (JsonSupport.of_list_of @@ -111,7 +123,11 @@ let update_user ~username ~user_t = 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 + let body = Request. + + + write_as_json_body + diff --git a/samples/client/petstore/ocaml/src/apis/pet_api.ml b/samples/client/petstore/ocaml/src/apis/pet_api.ml index 9df027a393cb..a338ef5befe2 100644 --- a/samples/client/petstore/ocaml/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml/src/apis/pet_api.ml @@ -9,7 +9,19 @@ let add_pet ~pet_t = let open Lwt.Infix in let uri = Request.build_uri "/pet" in let headers = Request.default_headers in - let body = Request.write_as_json_body Pet.to_yojson pet_t 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.read_json_body_as (JsonSupport.unwrap Pet.of_yojson) resp body @@ -17,8 +29,10 @@ let delete_pet ~pet_id ?api_key () = let open Lwt.Infix 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 + 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 @@ -26,7 +40,9 @@ let find_pets_by_status ~status = let open Lwt.Infix 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 + let uri = Request.add_query_param_list uri "status" (Stdlib.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 @@ -34,7 +50,9 @@ let find_pets_by_tags ~tags = let open Lwt.Infix 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 + let uri = Request.add_query_param_list uri "tags" (Stdlib.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 @@ -43,7 +61,8 @@ let get_pet_by_id ~pet_id = 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 + 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 @@ -51,7 +70,19 @@ let update_pet ~pet_t = let open Lwt.Infix in let uri = Request.build_uri "/pet" in let headers = Request.default_headers in - let body = Request.write_as_json_body Pet.to_yojson pet_t 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.read_json_body_as (JsonSupport.unwrap Pet.of_yojson) resp body @@ -59,10 +90,13 @@ let update_pet_with_form ~pet_id ?name ?status () = let open Lwt.Infix 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 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.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 @@ -71,10 +105,13 @@ let upload_file ~pet_id ?additional_metadata ?file () = let open Lwt.Infix 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 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.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 diff --git a/samples/client/petstore/ocaml/src/apis/store_api.ml b/samples/client/petstore/ocaml/src/apis/store_api.ml index 2fafcfd77eb7..828d1d7dd147 100644 --- a/samples/client/petstore/ocaml/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml/src/apis/store_api.ml @@ -9,7 +9,8 @@ let delete_order ~order_id = let open Lwt.Infix 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 + 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 @@ -25,7 +26,8 @@ let get_order_by_id ~order_id = let open Lwt.Infix 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 + 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 @@ -33,7 +35,19 @@ let place_order ~order_t = let open Lwt.Infix 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 order_t 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 diff --git a/samples/client/petstore/ocaml/src/apis/user_api.ml b/samples/client/petstore/ocaml/src/apis/user_api.ml index b0b45d12095f..5434ad7fa223 100644 --- a/samples/client/petstore/ocaml/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml/src/apis/user_api.ml @@ -10,7 +10,19 @@ let create_user ~user_t = let uri = Request.build_uri "/user" in let headers = Request.default_headers 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 + 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 @@ -19,7 +31,27 @@ let create_users_with_array_input ~user = let uri = Request.build_uri "/user/createWithArray" in let headers = Request.default_headers 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 + 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 @@ -28,7 +60,27 @@ let create_users_with_list_input ~user = let uri = Request.build_uri "/user/createWithList" in let headers = Request.default_headers 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 + 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 @@ -37,7 +89,8 @@ let delete_user ~username = 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 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 @@ -45,7 +98,8 @@ let get_user_by_name ~username = let open Lwt.Infix 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 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 @@ -53,8 +107,10 @@ let login_user ~username ~password = let open Lwt.Infix 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 + 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 @@ -71,8 +127,21 @@ let update_user ~username ~user_t = 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 user_t in + let uri = Request.replace_path_param uri "username" (fun x -> x) + username 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 diff --git a/samples/client/petstore/ocaml/src/support/jsonSupport.ml b/samples/client/petstore/ocaml/src/support/jsonSupport.ml index 4b0fac77545a..061b1be39f8a 100644 --- a/samples/client/petstore/ocaml/src/support/jsonSupport.ml +++ b/samples/client/petstore/ocaml/src/support/jsonSupport.ml @@ -50,6 +50,6 @@ let of_int32 x = `Intlit (Int32.to_string x) let of_int64 x = `Intlit (Int64.to_string x) -let of_list_of of_f l = `List (List.map of_f l) +let of_list_of of_f l = `List (Stdlib.List.map of_f l) -let of_map_of of_f l = `Assoc (List.map (fun (k, v) -> (k, of_f v)) l) \ No newline at end of file +let of_map_of of_f l = `Assoc (Stdlib.List.map (fun (k, v) -> (k, of_f v)) l) diff --git a/samples/client/petstore/ocaml/src/support/request.ml b/samples/client/petstore/ocaml/src/support/request.ml index dde0e723e481..60d15587384b 100644 --- a/samples/client/petstore/ocaml/src/support/request.ml +++ b/samples/client/petstore/ocaml/src/support/request.ml @@ -52,13 +52,13 @@ let read_json_body_as_list resp body = Lwt.(read_json_body resp body >|= Yojson.Safe.Util.to_list) let read_json_body_as_list_of of_json resp body = - Lwt.(read_json_body_as_list resp body >|= List.map of_json) + Lwt.(read_json_body_as_list resp body >|= Stdlib.List.map of_json) let read_json_body_as_map resp body = Lwt.(read_json_body resp body >|= Yojson.Safe.Util.to_assoc) let read_json_body_as_map_of of_json resp body = - Lwt.(read_json_body_as_map resp body >|= List.map (fun (s, v) -> (s, of_json v))) + Lwt.(read_json_body_as_map resp body >|= Stdlib.List.map (fun (s, v) -> (s, of_json v))) let replace_string_path_param uri param_name param_value = let regexp = Str.regexp (Str.quote ("{" ^ param_name ^ "}")) in From 38060f918198347e8ac2ea20698aaad768fd8c43 Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 1 Aug 2025 15:09:54 +0200 Subject: [PATCH 06/12] Fix: do not call `to_json` for free forms and byte arrays Fixes https://github.com/OpenAPITools/openapi-generator/issues/21312 --- .../main/resources/ocaml/api-impl.mustache | 8 +- .../src/apis/another_fake_api.ml | 6 +- .../ocaml-fake-petstore/src/apis/fake_api.ml | 103 ++++++++---------- .../src/apis/fake_classname_tags123_api.ml | 6 +- .../ocaml-fake-petstore/src/apis/pet_api.ml | 12 +- .../ocaml-fake-petstore/src/apis/store_api.ml | 6 +- .../ocaml-fake-petstore/src/apis/user_api.ml | 24 ++-- .../client/petstore/ocaml/src/apis/pet_api.ml | 12 +- .../petstore/ocaml/src/apis/store_api.ml | 6 +- .../petstore/ocaml/src/apis/user_api.ml | 24 ++-- 10 files changed, 96 insertions(+), 111 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache b/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache index 4ddc9f8145e0..e2996207b917 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache @@ -43,10 +43,10 @@ let {{{operationId}}} {{^hasParams}}(){{/hasParams}}{{#allParams}}{{> to_param}} {{/hasAuthMethods}} {{#bodyParams}} let body = Request. - {{#isFreeFormObject}}write_json_body{{/isFreeFormObject}} - {{#isByteArray}}write_string_body{{/isByteArray}} - {{^isFreeFormObject}}{{^isByteArray}}write_as_json_body{{/isByteArray}}{{/isFreeFormObject}} - {{> to_json}} {{{paramName}}} in + {{#isFreeFormObject}}write_json_body {{{paramName}}}{{/isFreeFormObject}} + {{#isByteArray}}write_string_body {{{paramName}}}{{/isByteArray}} + {{^isFreeFormObject}}{{^isByteArray}}write_as_json_body {{> to_json}} {{{paramName}}}{{/isByteArray}}{{/isFreeFormObject}} + in {{/bodyParams}} {{^hasBodyParam}} {{#hasFormParams}} diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml index 1fa27116a2bf..95c1cad4e6c9 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml @@ -12,8 +12,7 @@ let call_123_test_special_tags ~client_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -21,7 +20,8 @@ let call_123_test_special_tags ~client_t = Client.to_yojson - client_t in + client_t + in Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml index 403b9a53575a..86fa851e8233 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml @@ -30,8 +30,7 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () = let body = Request. - write_as_json_body - + write_as_json_body @@ -39,7 +38,8 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () = Pet.to_yojson - pet_t in + pet_t + in Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -50,15 +50,15 @@ let fake_outer_boolean_serialize ~body () = let body = Request. - write_as_json_body - + write_as_json_body JsonSupport.of_bool - body in + body + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.to_bool) resp body @@ -69,8 +69,7 @@ let fake_outer_composite_serialize ~outer_composite_t () = let body = Request. - write_as_json_body - + write_as_json_body @@ -78,7 +77,8 @@ let fake_outer_composite_serialize ~outer_composite_t () = Outer_composite.to_yojson - outer_composite_t in + outer_composite_t + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.unwrap Outer_composite.of_yojson) resp body @@ -89,15 +89,15 @@ let fake_outer_number_serialize ~body () = let body = Request. - write_as_json_body - + write_as_json_body JsonSupport.of_float - body in + body + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.to_float) resp body @@ -108,15 +108,15 @@ let fake_outer_string_serialize ~body () = let body = Request. - write_as_json_body - JsonSupport.of_string + write_as_json_body JsonSupport.of_string - body in + body + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.to_string) resp body @@ -127,8 +127,7 @@ let fake_property_enum_integer_serialize ~outer_object_with_enum_property_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -136,7 +135,8 @@ let fake_property_enum_integer_serialize ~outer_object_with_enum_property_t = Outer_object_with_enum_property.to_yojson - outer_object_with_enum_property_t in + outer_object_with_enum_property_t + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.unwrap Outer_object_with_enum_property.of_yojson) resp body @@ -145,25 +145,10 @@ let test_additional_properties_reference ~request_body = let uri = Request.build_uri "/fake/additionalProperties-reference" in let headers = Request.default_headers in let body = Request. - write_json_body + write_json_body request_body - (JsonSupport.of_map_of - - - - - - -) - - - - - - - - request_body in + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -174,15 +159,15 @@ let test_body_with_binary ~body = let body = Request. - write_as_json_body - + write_as_json_body - body in + body + in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -193,8 +178,7 @@ let test_body_with_file_schema ~file_schema_test_class_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -202,7 +186,8 @@ let test_body_with_file_schema ~file_schema_test_class_t = File_schema_test_class.to_yojson - file_schema_test_class_t in + file_schema_test_class_t + in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -215,8 +200,7 @@ let test_body_with_query_params ~query ~user_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -224,7 +208,8 @@ let test_body_with_query_params ~query ~user_t = User.to_yojson - user_t in + user_t + in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -235,8 +220,7 @@ let test_client_model ~client_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -244,7 +228,8 @@ let test_client_model ~client_t = Client.to_yojson - client_t in + client_t + in Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body @@ -342,8 +327,7 @@ let test_inline_additional_properties ~request_body = let body = Request. - write_as_json_body - (JsonSupport.of_map_of JsonSupport.of_string + write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string @@ -358,7 +342,8 @@ let test_inline_additional_properties ~request_body = - request_body in + request_body + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -369,8 +354,7 @@ let test_inline_freeform_additional_properties ~test_inline_freeform_additional_ let body = Request. - write_as_json_body - + write_as_json_body @@ -378,7 +362,8 @@ let test_inline_freeform_additional_properties ~test_inline_freeform_additional_ Test_inline_freeform_additional_properties_request.to_yojson - test_inline_freeform_additional_properties_request_t in + test_inline_freeform_additional_properties_request_t + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -402,8 +387,7 @@ let test_nullable ~child_with_nullable_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -411,7 +395,8 @@ let test_nullable ~child_with_nullable_t = Child_with_nullable.to_yojson - child_with_nullable_t in + child_with_nullable_t + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -449,8 +434,7 @@ let test_string_map_reference ~request_body = let body = Request. - write_as_json_body - (JsonSupport.of_map_of JsonSupport.of_string + write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string @@ -465,7 +449,8 @@ let test_string_map_reference ~request_body = - request_body in + request_body + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml index a39666ef47ed..a0d5c5d157d8 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml @@ -13,8 +13,7 @@ let test_classname ~client_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -22,7 +21,8 @@ let test_classname ~client_t = Client.to_yojson - client_t in + client_t + in Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.unwrap Client.of_yojson) resp body diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml index 2347d539a5a1..47080b667036 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml @@ -12,8 +12,7 @@ let add_pet ~pet_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -21,7 +20,8 @@ let add_pet ~pet_t = Pet.to_yojson - pet_t in + pet_t + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -73,8 +73,7 @@ let update_pet ~pet_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -82,7 +81,8 @@ let update_pet ~pet_t = Pet.to_yojson - pet_t in + pet_t + in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml index f1baa934b2ed..18ef029805ec 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml @@ -38,8 +38,7 @@ let place_order ~order_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -47,7 +46,8 @@ let place_order ~order_t = Order.to_yojson - order_t in + 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 diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml index 6dc6dc3f597e..930731724ef0 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml @@ -12,8 +12,7 @@ let create_user ~user_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -21,7 +20,8 @@ let create_user ~user_t = User.to_yojson - user_t in + user_t + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -32,8 +32,7 @@ let create_users_with_array_input ~user = let body = Request. - write_as_json_body - (JsonSupport.of_list_of + write_as_json_body (JsonSupport.of_list_of @@ -49,7 +48,8 @@ let create_users_with_array_input ~user = - user in + user + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -60,8 +60,7 @@ let create_users_with_list_input ~user = let body = Request. - write_as_json_body - (JsonSupport.of_list_of + write_as_json_body (JsonSupport.of_list_of @@ -77,7 +76,8 @@ let create_users_with_list_input ~user = - user in + user + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -126,8 +126,7 @@ let update_user ~username ~user_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -135,7 +134,8 @@ let update_user ~username ~user_t = User.to_yojson - user_t in + user_t + in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp diff --git a/samples/client/petstore/ocaml/src/apis/pet_api.ml b/samples/client/petstore/ocaml/src/apis/pet_api.ml index a338ef5befe2..8b12a7e2a984 100644 --- a/samples/client/petstore/ocaml/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml/src/apis/pet_api.ml @@ -12,8 +12,7 @@ let add_pet ~pet_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -21,7 +20,8 @@ let add_pet ~pet_t = Pet.to_yojson - pet_t in + pet_t + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.unwrap Pet.of_yojson) resp body @@ -73,8 +73,7 @@ let update_pet ~pet_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -82,7 +81,8 @@ let update_pet ~pet_t = Pet.to_yojson - pet_t in + pet_t + in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.unwrap Pet.of_yojson) resp body diff --git a/samples/client/petstore/ocaml/src/apis/store_api.ml b/samples/client/petstore/ocaml/src/apis/store_api.ml index 828d1d7dd147..1ceca3d50481 100644 --- a/samples/client/petstore/ocaml/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml/src/apis/store_api.ml @@ -38,8 +38,7 @@ let place_order ~order_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -47,7 +46,8 @@ let place_order ~order_t = Order.to_yojson - order_t in + 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 diff --git a/samples/client/petstore/ocaml/src/apis/user_api.ml b/samples/client/petstore/ocaml/src/apis/user_api.ml index 5434ad7fa223..b321e8ece693 100644 --- a/samples/client/petstore/ocaml/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml/src/apis/user_api.ml @@ -13,8 +13,7 @@ let create_user ~user_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -22,7 +21,8 @@ let create_user ~user_t = User.to_yojson - user_t in + user_t + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -34,8 +34,7 @@ let create_users_with_array_input ~user = let body = Request. - write_as_json_body - (JsonSupport.of_list_of + write_as_json_body (JsonSupport.of_list_of @@ -51,7 +50,8 @@ let create_users_with_array_input ~user = - user in + user + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -63,8 +63,7 @@ let create_users_with_list_input ~user = let body = Request. - write_as_json_body - (JsonSupport.of_list_of + write_as_json_body (JsonSupport.of_list_of @@ -80,7 +79,8 @@ let create_users_with_list_input ~user = - user in + user + in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -132,8 +132,7 @@ let update_user ~username ~user_t = let body = Request. - write_as_json_body - + write_as_json_body @@ -141,7 +140,8 @@ let update_user ~username ~user_t = User.to_yojson - user_t in + user_t + in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp From 2d298390bf970a34a8d016b8d4c5613f86e892aa Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 1 Aug 2025 15:23:01 +0200 Subject: [PATCH 07/12] Fix compilation for binary types The implementation may not be correct, but at least it compiles. To be checked if someday someone actually uses it/complains. --- .../src/main/resources/ocaml/to_json.mustache | 1 + .../src/apis/another_fake_api.ml | 1 + .../ocaml-fake-petstore/src/apis/fake_api.ml | 16 ++++++++++++++++ .../src/apis/fake_classname_tags123_api.ml | 1 + .../ocaml-fake-petstore/src/apis/pet_api.ml | 2 ++ .../ocaml-fake-petstore/src/apis/store_api.ml | 1 + .../ocaml-fake-petstore/src/apis/user_api.ml | 6 ++++++ .../client/petstore/ocaml/src/apis/pet_api.ml | 2 ++ .../client/petstore/ocaml/src/apis/store_api.ml | 1 + .../client/petstore/ocaml/src/apis/user_api.ml | 6 ++++++ 10 files changed, 37 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache b/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache index 80872d67ccbc..b8d059157fd4 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache @@ -32,3 +32,4 @@ {{/isEnum}} {{/isContainer}} {{/isModel}} +{{#isBinary}}JsonSupport.of_string{{/isBinary}} diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml index 95c1cad4e6c9..2e61acda9e3e 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml @@ -20,6 +20,7 @@ let call_123_test_special_tags ~client_t = Client.to_yojson + client_t in Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml index 86fa851e8233..62f50c4459b2 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml @@ -38,6 +38,7 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () = Pet.to_yojson + pet_t in Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) -> @@ -57,6 +58,7 @@ let fake_outer_boolean_serialize ~body () = JsonSupport.of_bool + body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -77,6 +79,7 @@ let fake_outer_composite_serialize ~outer_composite_t () = Outer_composite.to_yojson + outer_composite_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -96,6 +99,7 @@ let fake_outer_number_serialize ~body () = JsonSupport.of_float + body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -115,6 +119,7 @@ let fake_outer_string_serialize ~body () = + body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -135,6 +140,7 @@ let fake_property_enum_integer_serialize ~outer_object_with_enum_property_t = Outer_object_with_enum_property.to_yojson + outer_object_with_enum_property_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -166,6 +172,7 @@ let test_body_with_binary ~body = +JsonSupport.of_string body in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> @@ -186,6 +193,7 @@ let test_body_with_file_schema ~file_schema_test_class_t = File_schema_test_class.to_yojson + file_schema_test_class_t in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> @@ -208,6 +216,7 @@ let test_body_with_query_params ~query ~user_t = User.to_yojson + user_t in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> @@ -228,6 +237,7 @@ let test_client_model ~client_t = Client.to_yojson + client_t in Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> @@ -334,6 +344,7 @@ let test_inline_additional_properties ~request_body = + ) @@ -342,6 +353,7 @@ let test_inline_additional_properties ~request_body = + request_body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -362,6 +374,7 @@ let test_inline_freeform_additional_properties ~test_inline_freeform_additional_ Test_inline_freeform_additional_properties_request.to_yojson + test_inline_freeform_additional_properties_request_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -395,6 +408,7 @@ let test_nullable ~child_with_nullable_t = Child_with_nullable.to_yojson + child_with_nullable_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -441,6 +455,7 @@ let test_string_map_reference ~request_body = + ) @@ -449,6 +464,7 @@ let test_string_map_reference ~request_body = + request_body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml index a0d5c5d157d8..2a4c458deea1 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml @@ -21,6 +21,7 @@ let test_classname ~client_t = Client.to_yojson + client_t in Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml index 47080b667036..c9c389c02910 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml @@ -20,6 +20,7 @@ let add_pet ~pet_t = Pet.to_yojson + pet_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -81,6 +82,7 @@ let update_pet ~pet_t = Pet.to_yojson + pet_t in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml index 18ef029805ec..8ecf51a54077 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml @@ -46,6 +46,7 @@ let place_order ~order_t = Order.to_yojson + order_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml index 930731724ef0..79acf69c0a42 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml @@ -20,6 +20,7 @@ let create_user ~user_t = User.to_yojson + user_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -40,6 +41,7 @@ let create_users_with_array_input ~user = User.to_yojson + ) @@ -48,6 +50,7 @@ let create_users_with_array_input ~user = + user in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -68,6 +71,7 @@ let create_users_with_list_input ~user = User.to_yojson + ) @@ -76,6 +80,7 @@ let create_users_with_list_input ~user = + user in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -134,6 +139,7 @@ let update_user ~username ~user_t = User.to_yojson + user_t in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml/src/apis/pet_api.ml b/samples/client/petstore/ocaml/src/apis/pet_api.ml index 8b12a7e2a984..5ccc0f5663f6 100644 --- a/samples/client/petstore/ocaml/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml/src/apis/pet_api.ml @@ -20,6 +20,7 @@ let add_pet ~pet_t = Pet.to_yojson + pet_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -81,6 +82,7 @@ let update_pet ~pet_t = Pet.to_yojson + pet_t in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml/src/apis/store_api.ml b/samples/client/petstore/ocaml/src/apis/store_api.ml index 1ceca3d50481..e7c9ac0caa71 100644 --- a/samples/client/petstore/ocaml/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml/src/apis/store_api.ml @@ -46,6 +46,7 @@ let place_order ~order_t = Order.to_yojson + order_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml/src/apis/user_api.ml b/samples/client/petstore/ocaml/src/apis/user_api.ml index b321e8ece693..a22c1f36503e 100644 --- a/samples/client/petstore/ocaml/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml/src/apis/user_api.ml @@ -21,6 +21,7 @@ let create_user ~user_t = User.to_yojson + user_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -42,6 +43,7 @@ let create_users_with_array_input ~user = User.to_yojson + ) @@ -50,6 +52,7 @@ let create_users_with_array_input ~user = + user in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -71,6 +74,7 @@ let create_users_with_list_input ~user = User.to_yojson + ) @@ -79,6 +83,7 @@ let create_users_with_list_input ~user = + user in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -140,6 +145,7 @@ let update_user ~username ~user_t = User.to_yojson + user_t in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> From 2bc64f73762d8e6fa13dfe57df04bcda3ffab064 Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 1 Aug 2025 15:31:43 +0200 Subject: [PATCH 08/12] Indent to_string.mustache --- .../main/resources/ocaml/to_string.mustache | 23 +- .../ocaml-fake-petstore/src/apis/fake_api.ml | 562 ++++++++++++++++-- .../ocaml-fake-petstore/src/apis/pet_api.ml | 196 +++++- .../ocaml-fake-petstore/src/apis/store_api.ml | 28 +- .../ocaml-fake-petstore/src/apis/user_api.ml | 70 ++- .../client/petstore/ocaml/src/apis/pet_api.ml | 154 ++++- .../petstore/ocaml/src/apis/store_api.ml | 28 +- .../petstore/ocaml/src/apis/user_api.ml | 70 ++- 8 files changed, 1050 insertions(+), 81 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache b/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache index 4503e98eccf1..bbb370598f68 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache @@ -1 +1,22 @@ -{{#isContainer}}{{#items}}(Stdlib.List.map {{> to_string}}){{/items}}{{/isContainer}}{{^isEnum}}{{#isLong}}Int64.to_string{{/isLong}}{{#isInteger}}Int32.to_string{{/isInteger}}{{#isFloat}}string_of_float{{/isFloat}}{{#isNumber}}string_of_float{{/isNumber}}{{#isDouble}}string_of_float{{/isDouble}}{{#isBoolean}}string_of_bool{{/isBoolean}}{{#isFile}}(fun x -> x){{/isFile}}{{#isDate}}(fun x -> x){{/isDate}}{{#isDateTime}}(fun x -> x){{/isDateTime}}{{#isString}}(fun x -> x){{/isString}}{{#isByteArray}}(fun x -> x){{/isByteArray}}{{#isModel}}{{{vendorExtensions.x-model-module}}}.show{{/isModel}}{{/isEnum}}{{^isModel}}{{^isContainer}}{{#isEnum}}Enums.show_{{{datatypeWithEnum}}}{{/isEnum}}{{/isContainer}}{{/isModel}} +{{#isContainer}} + {{#items}}(Stdlib.List.map {{> to_string}}){{/items}} +{{/isContainer}} +{{^isEnum}} + {{#isLong}}Int64.to_string{{/isLong}} + {{#isInteger}}Int32.to_string{{/isInteger}} + {{#isFloat}}string_of_float{{/isFloat}} + {{#isNumber}}string_of_float{{/isNumber}} + {{#isDouble}}string_of_float{{/isDouble}} + {{#isBoolean}}string_of_bool{{/isBoolean}} + {{#isFile}}(fun x -> x){{/isFile}} + {{#isDate}}(fun x -> x){{/isDate}} + {{#isDateTime}}(fun x -> x){{/isDateTime}} + {{#isString}}(fun x -> x){{/isString}} + {{#isByteArray}}(fun x -> x){{/isByteArray}} + {{#isModel}}{{{vendorExtensions.x-model-module}}}.show{{/isModel}} +{{/isEnum}} +{{^isModel}} + {{^isContainer}} + {{#isEnum}}Enums.show_{{{datatypeWithEnum}}}{{/isEnum}} + {{/isContainer}} +{{/isModel}} diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml index 62f50c4459b2..304e8c54ef6b 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml @@ -23,9 +23,33 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () = let open Lwt.Infix in let uri = Request.build_uri "/fake/http-signature-test" in let headers = Request.default_headers in - let headers = Request.maybe_add_header headers "header_1" (fun x -> x) + let headers = Request.maybe_add_header headers "header_1" + + + + + + + + + (fun x -> x) + + + header_1 in - let uri = Request.maybe_add_query_param uri "query_1" (fun x -> x) + let uri = Request.maybe_add_query_param uri "query_1" + + + + + + + + + (fun x -> x) + + + query_1 in let body = Request. @@ -203,7 +227,19 @@ let test_body_with_query_params ~query ~user_t = let open Lwt.Infix in let uri = Request.build_uri "/fake/body-with-query-params" in let headers = Request.default_headers in - let uri = Request.add_query_param uri "query" (fun x -> x) + let uri = Request.add_query_param uri "query" + + + + + + + + + (fun x -> x) + + + query in let body = Request. @@ -248,33 +284,201 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i let uri = Request.build_uri "/fake" in let headers = Request.default_headers in let body = Request.init_form_encoded_body () in - let body = Request.maybe_add_form_encoded_body_param body "integer" Int32.to_string + let body = Request.maybe_add_form_encoded_body_param body "integer" + Int32.to_string + + + + + + + + + + + integer in - let body = Request.maybe_add_form_encoded_body_param body "int32" Int32.to_string + let body = Request.maybe_add_form_encoded_body_param body "int32" + Int32.to_string + + + + + + + + + + + int32 in - let body = Request.maybe_add_form_encoded_body_param body "int64" Int64.to_string + let body = Request.maybe_add_form_encoded_body_param body "int64" Int64.to_string + + + + + + + + + + + + int64 in - let body = Request.add_form_encoded_body_param body "number" string_of_float + let body = Request.add_form_encoded_body_param body "number" + + + string_of_float + + + + + + + + + number in - let body = Request.maybe_add_form_encoded_body_param body "float" string_of_float + let body = Request.maybe_add_form_encoded_body_param body "float" + + string_of_float + + + + + + + + + + float in - let body = Request.add_form_encoded_body_param body "double" string_of_float + let body = Request.add_form_encoded_body_param body "double" + + + + string_of_float + + + + + + + + double in - let body = Request.maybe_add_form_encoded_body_param body "string" (fun x -> x) + let body = Request.maybe_add_form_encoded_body_param body "string" + + + + + + + + + (fun x -> x) + + + string in - let body = Request.add_form_encoded_body_param body "pattern_without_delimiter" (fun x -> x) + let body = Request.add_form_encoded_body_param body "pattern_without_delimiter" + + + + + + + + + (fun x -> x) + + + pattern_without_delimiter in - let body = Request.add_form_encoded_body_param body "byte" (fun x -> x) + let body = Request.add_form_encoded_body_param body "byte" + + + + + + + + + + (fun x -> x) + + byte in - let body = Request.maybe_add_form_encoded_body_param body "binary" (fun x -> x) + let body = Request.maybe_add_form_encoded_body_param body "binary" + + + + + + (fun x -> x) + + + + + + binary in - let body = Request.maybe_add_form_encoded_body_param body "date" (fun x -> x) + let body = Request.maybe_add_form_encoded_body_param body "date" + + + + + + + (fun x -> x) + + + + + date in - let body = Request.maybe_add_form_encoded_body_param body "date_time" (fun x -> x) + let body = Request.maybe_add_form_encoded_body_param body "date_time" + + + + + + + + (fun x -> x) + + + + date_time in - let body = Request.maybe_add_form_encoded_body_param body "password" (fun x -> x) + let body = Request.maybe_add_form_encoded_body_param body "password" + + + + + + + + + (fun x -> x) + + + password in - let body = Request.maybe_add_form_encoded_body_param body "callback" (fun x -> x) + let body = Request.maybe_add_form_encoded_body_param body "callback" + + + + + + + + + (fun x -> x) + + + callback in let body = Request.finalize_form_encoded_body body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -284,28 +488,52 @@ let test_enum_parameters ?(enum_header_string_array = []) ?(enum_header_string = let open Lwt.Infix in let uri = Request.build_uri "/fake" in let headers = Request.default_headers in - let headers = Request.add_header_multi headers "enum_header_string_array" (Stdlib.List.map Enums.show_enum_form_string_array + let headers = Request.add_header_multi headers "enum_header_string_array" (Stdlib.List.map Enums.show_enum_form_string_array ) enum_header_string_array in - let headers = Request.add_header headers "enum_header_string" Enums.show_enumclass + let headers = Request.add_header headers "enum_header_string" Enums.show_enumclass enum_header_string in - let uri = Request.add_query_param_list uri "enum_query_string_array" (Stdlib.List.map Enums.show_enum_form_string_array + let uri = Request.add_query_param_list uri "enum_query_string_array" (Stdlib.List.map Enums.show_enum_form_string_array ) enum_query_string_array in - let uri = Request.add_query_param uri "enum_query_string" Enums.show_enumclass + let uri = Request.add_query_param uri "enum_query_string" Enums.show_enumclass enum_query_string in - let uri = Request.maybe_add_query_param uri "enum_query_integer" Enums.show_enum_query_integer + let uri = Request.maybe_add_query_param uri "enum_query_integer" Enums.show_enum_query_integer enum_query_integer in - let uri = Request.maybe_add_query_param uri "enum_query_double" Enums.show_enum_number + let uri = Request.maybe_add_query_param uri "enum_query_double" Enums.show_enum_number enum_query_double in - let uri = Request.add_query_param_list uri "enum_query_model_array" (Stdlib.List.map + let uri = Request.add_query_param_list uri "enum_query_model_array" (Stdlib.List.map + + + + + + + + + + + + ) + + + + + + + + + + + + enum_query_model_array in let body = Request.init_form_encoded_body () in - let body = Request.add_form_encoded_body_param_list body "enum_form_string_array" (Stdlib.List.map Enums.show_enum_form_string_array + let body = Request.add_form_encoded_body_param_list body "enum_form_string_array" (Stdlib.List.map Enums.show_enum_form_string_array ) enum_form_string_array in - let body = Request.add_form_encoded_body_param body "enum_form_string" Enums.show_enumclass + let body = Request.add_form_encoded_body_param body "enum_form_string" Enums.show_enumclass enum_form_string in let body = Request.finalize_form_encoded_body body in Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) -> @@ -315,17 +543,89 @@ let test_group_parameters ~required_string_group ~required_boolean_group ~requir let open Lwt.Infix in let uri = Request.build_uri "/fake" in let headers = Request.default_headers in - let headers = Request.add_header headers "required_boolean_group" string_of_bool + let headers = Request.add_header headers "required_boolean_group" + + + + + string_of_bool + + + + + + + required_boolean_group in - let headers = Request.maybe_add_header headers "boolean_group" string_of_bool + let headers = Request.maybe_add_header headers "boolean_group" + + + + + string_of_bool + + + + + + + boolean_group in - let uri = Request.add_query_param uri "required_string_group" Int32.to_string + let uri = Request.add_query_param uri "required_string_group" + Int32.to_string + + + + + + + + + + + required_string_group in - let uri = Request.add_query_param uri "required_int64_group" Int64.to_string + let uri = Request.add_query_param uri "required_int64_group" Int64.to_string + + + + + + + + + + + + required_int64_group in - let uri = Request.maybe_add_query_param uri "string_group" Int32.to_string + let uri = Request.maybe_add_query_param uri "string_group" + Int32.to_string + + + + + + + + + + + string_group in - let uri = Request.maybe_add_query_param uri "int64_group" Int64.to_string + let uri = Request.maybe_add_query_param uri "int64_group" Int64.to_string + + + + + + + + + + + + int64_group in Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) -> Request.handle_unit_response resp @@ -385,9 +685,33 @@ let test_json_form_data ~param ~param2 = let uri = Request.build_uri "/fake/jsonFormData" in let headers = Request.default_headers in let body = Request.init_form_encoded_body () in - let body = Request.add_form_encoded_body_param body "param" (fun x -> x) + let body = Request.add_form_encoded_body_param body "param" + + + + + + + + + (fun x -> x) + + + param in - let body = Request.add_form_encoded_body_param body "param2" (fun x -> x) + let body = Request.add_form_encoded_body_param body "param2" + + + + + + + + + (fun x -> x) + + + param2 in let body = Request.finalize_form_encoded_body body in Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) -> @@ -418,25 +742,181 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al let open Lwt.Infix in let uri = Request.build_uri "/fake/test-query-parameters" in let headers = Request.default_headers in - let uri = Request.add_query_param_list uri "pipe" (Stdlib.List.map (fun x -> x) + let uri = Request.add_query_param_list uri "pipe" (Stdlib.List.map + + + + + + + + + (fun x -> x) + + + ) + + + + + + + + + + + + pipe in - let uri = Request.add_query_param_list uri "ioutil" (Stdlib.List.map (fun x -> x) + let uri = Request.add_query_param_list uri "ioutil" (Stdlib.List.map + + + + + + + + + (fun x -> x) + + + ) + + + + + + + + + + + + ioutil in - let uri = Request.add_query_param_list uri "http" (Stdlib.List.map (fun x -> x) + let uri = Request.add_query_param_list uri "http" (Stdlib.List.map + + + + + + + + + (fun x -> x) + + + ) + + + + + + + + + + + + http in - let uri = Request.add_query_param_list uri "url" (Stdlib.List.map (fun x -> x) + let uri = Request.add_query_param_list uri "url" (Stdlib.List.map + + + + + + + + + (fun x -> x) + + + ) + + + + + + + + + + + + url in - let uri = Request.add_query_param_list uri "context" (Stdlib.List.map (fun x -> x) + let uri = Request.add_query_param_list uri "context" (Stdlib.List.map + + + + + + + + + (fun x -> x) + + + ) + + + + + + + + + + + + context in - let uri = Request.add_query_param uri "language" (Stdlib.List.map (fun x -> x) + let uri = Request.add_query_param uri "language" (Stdlib.List.map + + + + + + + + + (fun x -> x) + + + ) + + + + + + + + + + + + language in - let uri = Request.add_query_param uri "allowEmpty" (fun x -> x) + let uri = Request.add_query_param uri "allowEmpty" + + + + + + + + + (fun x -> x) + + + allow_empty in Cohttp_lwt_unix.Client.call `PUT uri ~headers >>= fun (resp, body) -> Request.handle_unit_response resp diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml index c9c389c02910..2fec93c5ac53 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml @@ -30,9 +30,33 @@ let delete_pet ~pet_id ?api_key () = let open Lwt.Infix 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) + 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 + 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 @@ -41,7 +65,7 @@ let find_pets_by_status ~status = let open Lwt.Infix in let uri = Request.build_uri "/pet/findByStatus" in let headers = Request.default_headers in - let uri = Request.add_query_param_list uri "status" (Stdlib.List.map Enums.show_status + let uri = Request.add_query_param_list uri "status" (Stdlib.List.map Enums.show_status ) status in Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> @@ -51,8 +75,32 @@ let find_pets_by_tags ~tags = let open Lwt.Infix in let uri = Request.build_uri "/pet/findByTags" in let headers = Request.default_headers in - let uri = Request.add_query_param_list uri "tags" (Stdlib.List.map (fun x -> x) + let uri = Request.add_query_param_list uri "tags" (Stdlib.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 @@ -62,7 +110,19 @@ let get_pet_by_id ~pet_id = 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 + 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 @@ -92,12 +152,48 @@ let update_pet_with_form ~pet_id ?name ?status () = let open Lwt.Infix 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 + 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) + 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) + 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) -> @@ -107,12 +203,48 @@ let upload_file ~pet_id ?additional_metadata ?file () = let open Lwt.Infix 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 + 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) + 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) + 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) -> @@ -122,12 +254,48 @@ let upload_file_with_required_file ~pet_id ~required_file ?additional_metadata ( let open Lwt.Infix in let uri = Request.build_uri "/fake/{petId}/uploadImageWithRequiredFile" in let headers = Request.default_headers in - let uri = Request.replace_path_param uri "petId" Int64.to_string + 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) + let body = Request.maybe_add_form_encoded_body_param body "additional_metadata" + + + + + + + + + (fun x -> x) + + + additional_metadata in - let body = Request.add_form_encoded_body_param body "required_file" (fun x -> x) + let body = Request.add_form_encoded_body_param body "required_file" + + + + + + (fun x -> x) + + + + + + required_file in let body = Request.finalize_form_encoded_body body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml index 8ecf51a54077..f9d83d35683d 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml @@ -9,7 +9,19 @@ let delete_order ~order_id = let open Lwt.Infix in let uri = Request.build_uri "/store/order/{order_id}" in let headers = Request.default_headers in - let uri = Request.replace_path_param uri "order_id" (fun x -> x) + let uri = Request.replace_path_param uri "order_id" + + + + + + + + + (fun x -> x) + + + order_id in Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) -> Request.handle_unit_response resp @@ -26,7 +38,19 @@ let get_order_by_id ~order_id = let open Lwt.Infix in let uri = Request.build_uri "/store/order/{order_id}" in let headers = Request.default_headers in - let uri = Request.replace_path_param uri "order_id" Int64.to_string + let uri = Request.replace_path_param uri "order_id" 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 diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml index 79acf69c0a42..2d02d4f1660a 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml @@ -90,7 +90,19 @@ let delete_user ~username = let open Lwt.Infix 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) + 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 @@ -99,7 +111,19 @@ let get_user_by_name ~username = let open Lwt.Infix 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) + 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 @@ -108,9 +132,33 @@ let login_user ~username ~password = let open Lwt.Infix 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) + let uri = Request.add_query_param uri "username" + + + + + + + + + (fun x -> x) + + + username in - let uri = Request.add_query_param uri "password" (fun x -> x) + 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 @@ -126,7 +174,19 @@ let update_user ~username ~user_t = let open Lwt.Infix 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) + let uri = Request.replace_path_param uri "username" + + + + + + + + + (fun x -> x) + + + username in let body = Request. diff --git a/samples/client/petstore/ocaml/src/apis/pet_api.ml b/samples/client/petstore/ocaml/src/apis/pet_api.ml index 5ccc0f5663f6..6094b4ceb729 100644 --- a/samples/client/petstore/ocaml/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml/src/apis/pet_api.ml @@ -30,9 +30,33 @@ let delete_pet ~pet_id ?api_key () = let open Lwt.Infix 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) + 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 + 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 @@ -41,7 +65,7 @@ let find_pets_by_status ~status = let open Lwt.Infix in let uri = Request.build_uri "/pet/findByStatus" in let headers = Request.default_headers in - let uri = Request.add_query_param_list uri "status" (Stdlib.List.map Enums.show_pet_status + let uri = Request.add_query_param_list uri "status" (Stdlib.List.map Enums.show_pet_status ) status in Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> @@ -51,8 +75,32 @@ let find_pets_by_tags ~tags = let open Lwt.Infix in let uri = Request.build_uri "/pet/findByTags" in let headers = Request.default_headers in - let uri = Request.add_query_param_list uri "tags" (Stdlib.List.map (fun x -> x) + let uri = Request.add_query_param_list uri "tags" (Stdlib.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 @@ -62,7 +110,19 @@ let get_pet_by_id ~pet_id = 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 + 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 @@ -92,12 +152,48 @@ let update_pet_with_form ~pet_id ?name ?status () = let open Lwt.Infix 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 + 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) + 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) + 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) -> @@ -107,12 +203,48 @@ let upload_file ~pet_id ?additional_metadata ?file () = let open Lwt.Infix 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 + 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) + 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) + 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) -> diff --git a/samples/client/petstore/ocaml/src/apis/store_api.ml b/samples/client/petstore/ocaml/src/apis/store_api.ml index e7c9ac0caa71..8b3077eac03a 100644 --- a/samples/client/petstore/ocaml/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml/src/apis/store_api.ml @@ -9,7 +9,19 @@ let delete_order ~order_id = let open Lwt.Infix 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) + 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 @@ -26,7 +38,19 @@ let get_order_by_id ~order_id = let open Lwt.Infix 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 + 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 diff --git a/samples/client/petstore/ocaml/src/apis/user_api.ml b/samples/client/petstore/ocaml/src/apis/user_api.ml index a22c1f36503e..e7fe2ee5ee37 100644 --- a/samples/client/petstore/ocaml/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml/src/apis/user_api.ml @@ -94,7 +94,19 @@ let delete_user ~username = 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) + 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 @@ -103,7 +115,19 @@ let get_user_by_name ~username = let open Lwt.Infix 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) + 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 @@ -112,9 +136,33 @@ let login_user ~username ~password = let open Lwt.Infix 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) + let uri = Request.add_query_param uri "username" + + + + + + + + + (fun x -> x) + + + username in - let uri = Request.add_query_param uri "password" (fun x -> x) + 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 @@ -132,7 +180,19 @@ let update_user ~username ~user_t = 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) + let uri = Request.replace_path_param uri "username" + + + + + + + + + (fun x -> x) + + + username in let body = Request. From 74c8e30bdf67389b9f6b71a6b702438a04c46749 Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Mon, 18 Aug 2025 12:18:48 +0200 Subject: [PATCH 09/12] Add support for exploded form-style object query params Fixes https://github.com/OpenAPITools/openapi-generator/issues/21307 --- .../main/resources/ocaml/api-impl.mustache | 2 +- .../src/main/resources/ocaml/support.mustache | 13 ++++++ .../main/resources/ocaml/to_string.mustache | 8 +++- .../ocaml-fake-petstore/src/apis/fake_api.ml | 46 ++++++++++++++++++- .../ocaml-fake-petstore/src/apis/pet_api.ml | 14 ++++++ .../ocaml-fake-petstore/src/apis/store_api.ml | 2 + .../ocaml-fake-petstore/src/apis/user_api.ml | 5 ++ .../src/support/request.ml | 13 ++++++ .../client/petstore/ocaml/src/apis/pet_api.ml | 11 +++++ .../petstore/ocaml/src/apis/store_api.ml | 2 + .../petstore/ocaml/src/apis/user_api.ml | 5 ++ .../petstore/ocaml/src/support/request.ml | 13 ++++++ 12 files changed, 129 insertions(+), 5 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache b/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache index e2996207b917..32c9b12bca12 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache @@ -30,7 +30,7 @@ let {{{operationId}}} {{^hasParams}}(){{/hasParams}}{{#allParams}}{{> to_param}} let uri = Request.{{> to_optional_prefix}}replace_path_param uri "{{{baseName}}}" {{> to_string}} {{{paramName}}} in {{/pathParams}} {{#queryParams}} - let uri = Request.{{> to_optional_prefix}}add_query_param{{#isArray}}_list{{/isArray}} uri "{{{baseName}}}" {{> to_string}} {{{paramName}}} in + let uri = Request.{{> to_optional_prefix}}add_query_param{{#isArray}}_list{{/isArray}}{{#isExplode}}{{#isFormStyle}}{{#isMap}}_exploded_form_object{{/isMap}}{{/isFormStyle}}{{/isExplode}} uri "{{{baseName}}}" {{> to_string}} {{{paramName}}} in {{/queryParams}} {{#hasAuthMethods}} {{#authMethods}} diff --git a/modules/openapi-generator/src/main/resources/ocaml/support.mustache b/modules/openapi-generator/src/main/resources/ocaml/support.mustache index 65540b46608c..0c02b13be726 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/support.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/support.mustache @@ -80,6 +80,19 @@ let add_query_param_list uri param_name to_string param_value = let maybe_add_query_param uri param_name to_string param_value = option_fold (add_query_param uri param_name to_string) uri param_value +(** Corresponds to: + - [style = form] + - [explode = true] + - type [object] + + See https://swagger.io/docs/specification/v3_0/serialization/#query-parameters +*) +let add_query_param_exploded_form_object uri _param_name to_string param_value = +Stdlib.List.fold_left + (fun uri (param_name, param_value) -> add_query_param uri param_name to_string param_value) + uri + param_value + let init_form_encoded_body () = "" let add_form_encoded_body_param params param_name to_string param_value = diff --git a/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache b/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache index bbb370598f68..9dc1968f0c4e 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache @@ -1,6 +1,9 @@ -{{#isContainer}} +{{#isArray}} {{#items}}(Stdlib.List.map {{> to_string}}){{/items}} -{{/isContainer}} +{{/isArray}} +{{#isMap}}{{! For maps, only transform the value, the call site will take care of properly transforming the key-value pairs since it depends on the context. }} + {{#items}}{{> to_string}}{{/items}} +{{/isMap}} {{^isEnum}} {{#isLong}}Int64.to_string{{/isLong}} {{#isInteger}}Int32.to_string{{/isInteger}} @@ -18,5 +21,6 @@ {{^isModel}} {{^isContainer}} {{#isEnum}}Enums.show_{{{datatypeWithEnum}}}{{/isEnum}} + {{#isEnumRef}}(failwith "Unsupported: enum reference"){{/isEnumRef}} {{/isContainer}} {{/isModel}} diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml index 304e8c54ef6b..c373775bbd69 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml @@ -36,6 +36,7 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () = + header_1 in let uri = Request.maybe_add_query_param uri "query_1" @@ -50,6 +51,7 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () = + query_1 in let body = Request. @@ -240,6 +242,7 @@ let test_body_with_query_params ~query ~user_t = + query in let body = Request. @@ -297,6 +300,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i + integer in let body = Request.maybe_add_form_encoded_body_param body "int32" Int32.to_string @@ -311,6 +315,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i + int32 in let body = Request.maybe_add_form_encoded_body_param body "int64" Int64.to_string @@ -325,6 +330,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i + int64 in let body = Request.add_form_encoded_body_param body "number" @@ -339,6 +345,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i + number in let body = Request.maybe_add_form_encoded_body_param body "float" @@ -353,6 +360,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i + float in let body = Request.add_form_encoded_body_param body "double" @@ -367,6 +375,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i + double in let body = Request.maybe_add_form_encoded_body_param body "string" @@ -381,6 +390,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i + string in let body = Request.add_form_encoded_body_param body "pattern_without_delimiter" @@ -395,6 +405,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i + pattern_without_delimiter in let body = Request.add_form_encoded_body_param body "byte" @@ -409,6 +420,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i (fun x -> x) + byte in let body = Request.maybe_add_form_encoded_body_param body "binary" @@ -423,6 +435,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i + binary in let body = Request.maybe_add_form_encoded_body_param body "date" @@ -437,6 +450,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i + date in let body = Request.maybe_add_form_encoded_body_param body "date_time" @@ -451,6 +465,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i + date_time in let body = Request.maybe_add_form_encoded_body_param body "password" @@ -465,6 +480,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i + password in let body = Request.maybe_add_form_encoded_body_param body "callback" @@ -479,6 +495,7 @@ let test_endpoint_parameters ~number ~double ~pattern_without_delimiter ~byte ?i + callback in let body = Request.finalize_form_encoded_body body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -489,18 +506,24 @@ let test_enum_parameters ?(enum_header_string_array = []) ?(enum_header_string = let uri = Request.build_uri "/fake" in let headers = Request.default_headers in let headers = Request.add_header_multi headers "enum_header_string_array" (Stdlib.List.map Enums.show_enum_form_string_array + ) enum_header_string_array in let headers = Request.add_header headers "enum_header_string" Enums.show_enumclass + enum_header_string in let uri = Request.add_query_param_list uri "enum_query_string_array" (Stdlib.List.map Enums.show_enum_form_string_array + ) enum_query_string_array in let uri = Request.add_query_param uri "enum_query_string" Enums.show_enumclass + enum_query_string in let uri = Request.maybe_add_query_param uri "enum_query_integer" Enums.show_enum_query_integer + enum_query_integer in let uri = Request.maybe_add_query_param uri "enum_query_double" Enums.show_enum_number + enum_query_double in let uri = Request.add_query_param_list uri "enum_query_model_array" (Stdlib.List.map @@ -515,6 +538,7 @@ let test_enum_parameters ?(enum_header_string_array = []) ?(enum_header_string = + (failwith "Unsupported: enum reference") ) @@ -531,9 +555,11 @@ let test_enum_parameters ?(enum_header_string_array = []) ?(enum_header_string = enum_query_model_array in let body = Request.init_form_encoded_body () in let body = Request.add_form_encoded_body_param_list body "enum_form_string_array" (Stdlib.List.map Enums.show_enum_form_string_array + ) enum_form_string_array in let body = Request.add_form_encoded_body_param body "enum_form_string" Enums.show_enumclass + enum_form_string in let body = Request.finalize_form_encoded_body body in Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) -> @@ -556,6 +582,7 @@ let test_group_parameters ~required_string_group ~required_boolean_group ~requir + required_boolean_group in let headers = Request.maybe_add_header headers "boolean_group" @@ -570,6 +597,7 @@ let test_group_parameters ~required_string_group ~required_boolean_group ~requir + boolean_group in let uri = Request.add_query_param uri "required_string_group" Int32.to_string @@ -584,6 +612,7 @@ let test_group_parameters ~required_string_group ~required_boolean_group ~requir + required_string_group in let uri = Request.add_query_param uri "required_int64_group" Int64.to_string @@ -598,6 +627,7 @@ let test_group_parameters ~required_string_group ~required_boolean_group ~requir + required_int64_group in let uri = Request.maybe_add_query_param uri "string_group" Int32.to_string @@ -612,6 +642,7 @@ let test_group_parameters ~required_string_group ~required_boolean_group ~requir + string_group in let uri = Request.maybe_add_query_param uri "int64_group" Int64.to_string @@ -626,6 +657,7 @@ let test_group_parameters ~required_string_group ~required_boolean_group ~requir + int64_group in Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) -> Request.handle_unit_response resp @@ -698,6 +730,7 @@ let test_json_form_data ~param ~param2 = + param in let body = Request.add_form_encoded_body_param body "param2" @@ -712,6 +745,7 @@ let test_json_form_data ~param ~param2 = + param2 in let body = Request.finalize_form_encoded_body body in Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) -> @@ -755,6 +789,7 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al + ) @@ -782,6 +817,7 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al + ) @@ -809,6 +845,7 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al + ) @@ -836,6 +873,7 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al + ) @@ -863,6 +901,7 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al + ) @@ -877,7 +916,8 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al context in - let uri = Request.add_query_param uri "language" (Stdlib.List.map + let uri = Request.add_query_param_exploded_form_object uri "language" + @@ -890,7 +930,8 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al -) + + @@ -917,6 +958,7 @@ let test_query_parameter_collection_format ~pipe ~ioutil ~http ~url ~context ~al + allow_empty in Cohttp_lwt_unix.Client.call `PUT uri ~headers >>= fun (resp, body) -> Request.handle_unit_response resp diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml index 2fec93c5ac53..923e54b7fdbb 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml @@ -43,6 +43,7 @@ let delete_pet ~pet_id ?api_key () = + api_key in let uri = Request.replace_path_param uri "petId" Int64.to_string @@ -57,6 +58,7 @@ let delete_pet ~pet_id ?api_key () = + pet_id in Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) -> Request.handle_unit_response resp @@ -66,6 +68,7 @@ let find_pets_by_status ~status = let uri = Request.build_uri "/pet/findByStatus" in let headers = Request.default_headers in let uri = Request.add_query_param_list uri "status" (Stdlib.List.map Enums.show_status + ) status in Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> @@ -88,6 +91,7 @@ let find_pets_by_tags ~tags = + ) @@ -123,6 +127,7 @@ let get_pet_by_id ~pet_id = + 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 @@ -165,6 +170,7 @@ let update_pet_with_form ~pet_id ?name ?status () = + pet_id in let body = Request.init_form_encoded_body () in let body = Request.maybe_add_form_encoded_body_param body "name" @@ -180,6 +186,7 @@ let update_pet_with_form ~pet_id ?name ?status () = + name in let body = Request.maybe_add_form_encoded_body_param body "status" @@ -194,6 +201,7 @@ let update_pet_with_form ~pet_id ?name ?status () = + status in let body = Request.finalize_form_encoded_body body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -216,6 +224,7 @@ let upload_file ~pet_id ?additional_metadata ?file () = + pet_id in let body = Request.init_form_encoded_body () in let body = Request.maybe_add_form_encoded_body_param body "additional_metadata" @@ -231,6 +240,7 @@ let upload_file ~pet_id ?additional_metadata ?file () = + additional_metadata in let body = Request.maybe_add_form_encoded_body_param body "file" @@ -245,6 +255,7 @@ let upload_file ~pet_id ?additional_metadata ?file () = + file in let body = Request.finalize_form_encoded_body body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -267,6 +278,7 @@ let upload_file_with_required_file ~pet_id ~required_file ?additional_metadata ( + pet_id in let body = Request.init_form_encoded_body () in let body = Request.maybe_add_form_encoded_body_param body "additional_metadata" @@ -282,6 +294,7 @@ let upload_file_with_required_file ~pet_id ~required_file ?additional_metadata ( + additional_metadata in let body = Request.add_form_encoded_body_param body "required_file" @@ -296,6 +309,7 @@ let upload_file_with_required_file ~pet_id ~required_file ?additional_metadata ( + required_file in let body = Request.finalize_form_encoded_body body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml index f9d83d35683d..7846df005fcd 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml @@ -22,6 +22,7 @@ let delete_order ~order_id = + order_id in Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) -> Request.handle_unit_response resp @@ -51,6 +52,7 @@ let get_order_by_id ~order_id = + 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 diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml index 2d02d4f1660a..8fe7ba35cbe4 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml @@ -103,6 +103,7 @@ let delete_user ~username = + username in Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) -> Request.handle_unit_response resp @@ -124,6 +125,7 @@ let get_user_by_name ~username = + 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 @@ -145,6 +147,7 @@ let login_user ~username ~password = + username in let uri = Request.add_query_param uri "password" @@ -159,6 +162,7 @@ let login_user ~username ~password = + password in Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.to_string) resp body @@ -187,6 +191,7 @@ let update_user ~username ~user_t = + username in let body = Request. diff --git a/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml b/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml index ca2c139924d8..3e1ac69536e5 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml @@ -80,6 +80,19 @@ let add_query_param_list uri param_name to_string param_value = let maybe_add_query_param uri param_name to_string param_value = option_fold (add_query_param uri param_name to_string) uri param_value +(** Corresponds to: + - [style = form] + - [explode = true] + - type [object] + + See https://swagger.io/docs/specification/v3_0/serialization/#query-parameters +*) +let add_query_param_exploded_form_object uri _param_name to_string param_value = +Stdlib.List.fold_left + (fun uri (param_name, param_value) -> add_query_param uri param_name to_string param_value) + uri + param_value + let init_form_encoded_body () = "" let add_form_encoded_body_param params param_name to_string param_value = diff --git a/samples/client/petstore/ocaml/src/apis/pet_api.ml b/samples/client/petstore/ocaml/src/apis/pet_api.ml index 6094b4ceb729..0122d157703e 100644 --- a/samples/client/petstore/ocaml/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml/src/apis/pet_api.ml @@ -43,6 +43,7 @@ let delete_pet ~pet_id ?api_key () = + api_key in let uri = Request.replace_path_param uri "petId" Int64.to_string @@ -57,6 +58,7 @@ let delete_pet ~pet_id ?api_key () = + pet_id in Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) -> Request.handle_unit_response resp @@ -66,6 +68,7 @@ let find_pets_by_status ~status = let uri = Request.build_uri "/pet/findByStatus" in let headers = Request.default_headers in let uri = Request.add_query_param_list uri "status" (Stdlib.List.map Enums.show_pet_status + ) status in Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> @@ -88,6 +91,7 @@ let find_pets_by_tags ~tags = + ) @@ -123,6 +127,7 @@ let get_pet_by_id ~pet_id = + 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 @@ -165,6 +170,7 @@ let update_pet_with_form ~pet_id ?name ?status () = + pet_id in let body = Request.init_form_encoded_body () in let body = Request.maybe_add_form_encoded_body_param body "name" @@ -180,6 +186,7 @@ let update_pet_with_form ~pet_id ?name ?status () = + name in let body = Request.maybe_add_form_encoded_body_param body "status" @@ -194,6 +201,7 @@ let update_pet_with_form ~pet_id ?name ?status () = + status in let body = Request.finalize_form_encoded_body body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -216,6 +224,7 @@ let upload_file ~pet_id ?additional_metadata ?file () = + pet_id in let body = Request.init_form_encoded_body () in let body = Request.maybe_add_form_encoded_body_param body "additional_metadata" @@ -231,6 +240,7 @@ let upload_file ~pet_id ?additional_metadata ?file () = + additional_metadata in let body = Request.maybe_add_form_encoded_body_param body "file" @@ -245,6 +255,7 @@ let upload_file ~pet_id ?additional_metadata ?file () = + file in let body = Request.finalize_form_encoded_body body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml/src/apis/store_api.ml b/samples/client/petstore/ocaml/src/apis/store_api.ml index 8b3077eac03a..56738e68c297 100644 --- a/samples/client/petstore/ocaml/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml/src/apis/store_api.ml @@ -22,6 +22,7 @@ let delete_order ~order_id = + order_id in Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) -> Request.handle_unit_response resp @@ -51,6 +52,7 @@ let get_order_by_id ~order_id = + 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 diff --git a/samples/client/petstore/ocaml/src/apis/user_api.ml b/samples/client/petstore/ocaml/src/apis/user_api.ml index e7fe2ee5ee37..831bfbd11cb6 100644 --- a/samples/client/petstore/ocaml/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml/src/apis/user_api.ml @@ -107,6 +107,7 @@ let delete_user ~username = + username in Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) -> Request.handle_unit_response resp @@ -128,6 +129,7 @@ let get_user_by_name ~username = + 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 @@ -149,6 +151,7 @@ let login_user ~username ~password = + username in let uri = Request.add_query_param uri "password" @@ -163,6 +166,7 @@ let login_user ~username ~password = + password in Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> Request.read_json_body_as (JsonSupport.to_string) resp body @@ -193,6 +197,7 @@ let update_user ~username ~user_t = + username in let body = Request. diff --git a/samples/client/petstore/ocaml/src/support/request.ml b/samples/client/petstore/ocaml/src/support/request.ml index 60d15587384b..db22779198c5 100644 --- a/samples/client/petstore/ocaml/src/support/request.ml +++ b/samples/client/petstore/ocaml/src/support/request.ml @@ -80,6 +80,19 @@ let add_query_param_list uri param_name to_string param_value = let maybe_add_query_param uri param_name to_string param_value = option_fold (add_query_param uri param_name to_string) uri param_value +(** Corresponds to: + - [style = form] + - [explode = true] + - type [object] + + See https://swagger.io/docs/specification/v3_0/serialization/#query-parameters +*) +let add_query_param_exploded_form_object uri _param_name to_string param_value = +Stdlib.List.fold_left + (fun uri (param_name, param_value) -> add_query_param uri param_name to_string param_value) + uri + param_value + let init_form_encoded_body () = "" let add_form_encoded_body_param params param_name to_string param_value = From 847d2c5920fdcf60791351a7bffc0c8f899d5e8d Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Mon, 18 Aug 2025 12:20:50 +0200 Subject: [PATCH 10/12] Add ocaml-fake-petstore to CI --- .github/workflows/samples-ocaml.yaml | 3 +++ 1 file changed, 3 insertions(+) diff --git a/.github/workflows/samples-ocaml.yaml b/.github/workflows/samples-ocaml.yaml index 884ecc4a4c5f..7fbc32364a79 100644 --- a/.github/workflows/samples-ocaml.yaml +++ b/.github/workflows/samples-ocaml.yaml @@ -4,9 +4,11 @@ on: push: paths: - 'samples/client/petstore/ocaml/**' + - 'samples/client/petstore/ocaml-fake-petstore/**' pull_request: paths: - 'samples/client/petstore/ocaml/**' + - 'samples/client/petstore/ocaml-fake-petstore/**' jobs: build: @@ -17,6 +19,7 @@ jobs: matrix: sample: - 'samples/client/petstore/ocaml/' + - 'samples/client/petstore/ocaml-fake-petstore/' steps: - uses: actions/checkout@v5 - name: Set-up OCaml From a9e6ca2a75b888f7a0443fec1d2a1e26a55c6113 Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Mon, 18 Aug 2025 13:51:06 +0200 Subject: [PATCH 11/12] Fix free-form body params --- .../main/resources/ocaml/api-impl.mustache | 3 +- .../src/main/resources/ocaml/to_json.mustache | 1 + .../src/apis/another_fake_api.ml | 2 +- .../ocaml-fake-petstore/src/apis/fake_api.ml | 52 +++++++++++++------ .../src/apis/fake_classname_tags123_api.ml | 2 +- .../ocaml-fake-petstore/src/apis/pet_api.ml | 4 +- .../ocaml-fake-petstore/src/apis/store_api.ml | 2 +- .../ocaml-fake-petstore/src/apis/user_api.ml | 10 ++-- .../client/petstore/ocaml/src/apis/pet_api.ml | 4 +- .../petstore/ocaml/src/apis/store_api.ml | 2 +- .../petstore/ocaml/src/apis/user_api.ml | 10 ++-- 11 files changed, 58 insertions(+), 34 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache b/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache index 32c9b12bca12..b2a5a9037a4d 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache @@ -43,9 +43,8 @@ let {{{operationId}}} {{^hasParams}}(){{/hasParams}}{{#allParams}}{{> to_param}} {{/hasAuthMethods}} {{#bodyParams}} let body = Request. - {{#isFreeFormObject}}write_json_body {{{paramName}}}{{/isFreeFormObject}} {{#isByteArray}}write_string_body {{{paramName}}}{{/isByteArray}} - {{^isFreeFormObject}}{{^isByteArray}}write_as_json_body {{> to_json}} {{{paramName}}}{{/isByteArray}}{{/isFreeFormObject}} + {{^isByteArray}}write_as_json_body {{> to_json}} {{{paramName}}}{{/isByteArray}} in {{/bodyParams}} {{^hasBodyParam}} diff --git a/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache b/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache index b8d059157fd4..8bfbaac1fe70 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache @@ -33,3 +33,4 @@ {{/isContainer}} {{/isModel}} {{#isBinary}}JsonSupport.of_string{{/isBinary}} +{{#isAnyType}}(fun x -> x){{/isAnyType}} diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml index 2e61acda9e3e..87b62b8f37af 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml @@ -11,7 +11,6 @@ let call_123_test_special_tags ~client_t = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -21,6 +20,7 @@ let call_123_test_special_tags ~client_t = Client.to_yojson + client_t in Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml index c373775bbd69..0b0fe1568cee 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml @@ -55,7 +55,6 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () = query_1 in let body = Request. - write_as_json_body @@ -65,6 +64,7 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () = Pet.to_yojson + pet_t in Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) -> @@ -76,7 +76,6 @@ let fake_outer_boolean_serialize ~body () = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -85,6 +84,7 @@ let fake_outer_boolean_serialize ~body () = JsonSupport.of_bool + body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -96,7 +96,6 @@ let fake_outer_composite_serialize ~outer_composite_t () = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -106,6 +105,7 @@ let fake_outer_composite_serialize ~outer_composite_t () = Outer_composite.to_yojson + outer_composite_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -117,7 +117,6 @@ let fake_outer_number_serialize ~body () = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -126,6 +125,7 @@ JsonSupport.of_float + body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -137,7 +137,6 @@ let fake_outer_string_serialize ~body () = let headers = Request.default_headers in let body = Request. - write_as_json_body JsonSupport.of_string @@ -146,6 +145,7 @@ let fake_outer_string_serialize ~body () = + body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -157,7 +157,6 @@ let fake_property_enum_integer_serialize ~outer_object_with_enum_property_t = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -167,6 +166,7 @@ let fake_property_enum_integer_serialize ~outer_object_with_enum_property_t = Outer_object_with_enum_property.to_yojson + outer_object_with_enum_property_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -177,9 +177,27 @@ let test_additional_properties_reference ~request_body = let uri = Request.build_uri "/fake/additionalProperties-reference" in let headers = Request.default_headers in let body = Request. - write_json_body request_body - + write_as_json_body (JsonSupport.of_map_of + + + + + + + +(fun x -> x) +) + + + + + + + + + + request_body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> Request.handle_unit_response resp @@ -190,7 +208,6 @@ let test_body_with_binary ~body = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -199,6 +216,7 @@ let test_body_with_binary ~body = JsonSupport.of_string + body in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> @@ -210,7 +228,6 @@ let test_body_with_file_schema ~file_schema_test_class_t = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -220,6 +237,7 @@ let test_body_with_file_schema ~file_schema_test_class_t = File_schema_test_class.to_yojson + file_schema_test_class_t in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> @@ -246,7 +264,6 @@ let test_body_with_query_params ~query ~user_t = query in let body = Request. - write_as_json_body @@ -256,6 +273,7 @@ let test_body_with_query_params ~query ~user_t = User.to_yojson + user_t in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> @@ -267,7 +285,6 @@ let test_client_model ~client_t = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -277,6 +294,7 @@ let test_client_model ~client_t = Client.to_yojson + client_t in Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> @@ -668,7 +686,6 @@ let test_inline_additional_properties ~request_body = let headers = Request.default_headers in let body = Request. - write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string @@ -677,6 +694,7 @@ let test_inline_additional_properties ~request_body = + ) @@ -686,6 +704,7 @@ let test_inline_additional_properties ~request_body = + request_body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -697,7 +716,6 @@ let test_inline_freeform_additional_properties ~test_inline_freeform_additional_ let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -707,6 +725,7 @@ let test_inline_freeform_additional_properties ~test_inline_freeform_additional_ Test_inline_freeform_additional_properties_request.to_yojson + test_inline_freeform_additional_properties_request_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -757,7 +776,6 @@ let test_nullable ~child_with_nullable_t = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -767,6 +785,7 @@ let test_nullable ~child_with_nullable_t = Child_with_nullable.to_yojson + child_with_nullable_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -969,7 +988,6 @@ let test_string_map_reference ~request_body = let headers = Request.default_headers in let body = Request. - write_as_json_body (JsonSupport.of_map_of JsonSupport.of_string @@ -978,6 +996,7 @@ let test_string_map_reference ~request_body = + ) @@ -987,6 +1006,7 @@ let test_string_map_reference ~request_body = + request_body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml index 2a4c458deea1..936bb5092b84 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml @@ -12,7 +12,6 @@ let test_classname ~client_t = let uri = Uri.add_query_param' uri ("api_key_query", Request.api_key) in let body = Request. - write_as_json_body @@ -22,6 +21,7 @@ let test_classname ~client_t = Client.to_yojson + client_t in Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml index 923e54b7fdbb..ac92862cf1d2 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml @@ -11,7 +11,6 @@ let add_pet ~pet_t = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -21,6 +20,7 @@ let add_pet ~pet_t = Pet.to_yojson + pet_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -138,7 +138,6 @@ let update_pet ~pet_t = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -148,6 +147,7 @@ let update_pet ~pet_t = Pet.to_yojson + pet_t in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml index 7846df005fcd..6dde02b42a8f 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml @@ -63,7 +63,6 @@ let place_order ~order_t = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -73,6 +72,7 @@ let place_order ~order_t = Order.to_yojson + order_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml index 8fe7ba35cbe4..ad9b18b360ab 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml @@ -11,7 +11,6 @@ let create_user ~user_t = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -21,6 +20,7 @@ let create_user ~user_t = User.to_yojson + user_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -32,7 +32,6 @@ let create_users_with_array_input ~user = let headers = Request.default_headers in let body = Request. - write_as_json_body (JsonSupport.of_list_of @@ -42,6 +41,7 @@ let create_users_with_array_input ~user = User.to_yojson + ) @@ -51,6 +51,7 @@ let create_users_with_array_input ~user = + user in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -62,7 +63,6 @@ let create_users_with_list_input ~user = let headers = Request.default_headers in let body = Request. - write_as_json_body (JsonSupport.of_list_of @@ -72,6 +72,7 @@ let create_users_with_list_input ~user = User.to_yojson + ) @@ -81,6 +82,7 @@ let create_users_with_list_input ~user = + user in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -195,7 +197,6 @@ let update_user ~username ~user_t = username in let body = Request. - write_as_json_body @@ -205,6 +206,7 @@ let update_user ~username ~user_t = User.to_yojson + user_t in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml/src/apis/pet_api.ml b/samples/client/petstore/ocaml/src/apis/pet_api.ml index 0122d157703e..8f272ccda4bf 100644 --- a/samples/client/petstore/ocaml/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml/src/apis/pet_api.ml @@ -11,7 +11,6 @@ let add_pet ~pet_t = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -21,6 +20,7 @@ let add_pet ~pet_t = Pet.to_yojson + pet_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -138,7 +138,6 @@ let update_pet ~pet_t = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -148,6 +147,7 @@ let update_pet ~pet_t = Pet.to_yojson + pet_t in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml/src/apis/store_api.ml b/samples/client/petstore/ocaml/src/apis/store_api.ml index 56738e68c297..68811d326070 100644 --- a/samples/client/petstore/ocaml/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml/src/apis/store_api.ml @@ -63,7 +63,6 @@ let place_order ~order_t = let headers = Request.default_headers in let body = Request. - write_as_json_body @@ -73,6 +72,7 @@ let place_order ~order_t = Order.to_yojson + order_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> diff --git a/samples/client/petstore/ocaml/src/apis/user_api.ml b/samples/client/petstore/ocaml/src/apis/user_api.ml index 831bfbd11cb6..a2e928a71cf4 100644 --- a/samples/client/petstore/ocaml/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml/src/apis/user_api.ml @@ -12,7 +12,6 @@ let create_user ~user_t = let headers = Cohttp.Header.add headers "api_key" Request.api_key in let body = Request. - write_as_json_body @@ -22,6 +21,7 @@ let create_user ~user_t = User.to_yojson + user_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -34,7 +34,6 @@ let create_users_with_array_input ~user = let headers = Cohttp.Header.add headers "api_key" Request.api_key in let body = Request. - write_as_json_body (JsonSupport.of_list_of @@ -44,6 +43,7 @@ let create_users_with_array_input ~user = User.to_yojson + ) @@ -53,6 +53,7 @@ let create_users_with_array_input ~user = + user in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -65,7 +66,6 @@ let create_users_with_list_input ~user = let headers = Cohttp.Header.add headers "api_key" Request.api_key in let body = Request. - write_as_json_body (JsonSupport.of_list_of @@ -75,6 +75,7 @@ let create_users_with_list_input ~user = User.to_yojson + ) @@ -84,6 +85,7 @@ let create_users_with_list_input ~user = + user in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -201,7 +203,6 @@ let update_user ~username ~user_t = username in let body = Request. - write_as_json_body @@ -211,6 +212,7 @@ let update_user ~username ~user_t = User.to_yojson + user_t in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> From cad4d184fd7f89b7e348cb1de34dbdc17c57fc46 Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Mon, 18 Aug 2025 15:14:39 +0200 Subject: [PATCH 12/12] Cohttp_lwt.Response is deprecated, use Cohttp.Response instead --- .../openapi-generator/src/main/resources/ocaml/support.mustache | 2 +- .../client/petstore/ocaml-fake-petstore/src/support/request.ml | 2 +- samples/client/petstore/ocaml/src/support/request.ml | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/ocaml/support.mustache b/modules/openapi-generator/src/main/resources/ocaml/support.mustache index 0c02b13be726..ee134b87198b 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/support.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/support.mustache @@ -35,7 +35,7 @@ let write_json_body payload = let write_as_json_body to_json payload = write_json_body (to_json payload) let handle_response resp on_success_handler = - match Cohttp_lwt.Response.status resp with + match Cohttp.Response.status resp with | #Cohttp.Code.success_status -> on_success_handler () | s -> failwith ("Server responded with status " ^ Cohttp.Code.(reason_phrase_of_code (code_of_status s))) diff --git a/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml b/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml index 3e1ac69536e5..cbb1a71ea697 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml @@ -35,7 +35,7 @@ let write_json_body payload = let write_as_json_body to_json payload = write_json_body (to_json payload) let handle_response resp on_success_handler = - match Cohttp_lwt.Response.status resp with + match Cohttp.Response.status resp with | #Cohttp.Code.success_status -> on_success_handler () | s -> failwith ("Server responded with status " ^ Cohttp.Code.(reason_phrase_of_code (code_of_status s))) diff --git a/samples/client/petstore/ocaml/src/support/request.ml b/samples/client/petstore/ocaml/src/support/request.ml index db22779198c5..fea945d04cf3 100644 --- a/samples/client/petstore/ocaml/src/support/request.ml +++ b/samples/client/petstore/ocaml/src/support/request.ml @@ -35,7 +35,7 @@ let write_json_body payload = let write_as_json_body to_json payload = write_json_body (to_json payload) let handle_response resp on_success_handler = - match Cohttp_lwt.Response.status resp with + match Cohttp.Response.status resp with | #Cohttp.Code.success_status -> on_success_handler () | s -> failwith ("Server responded with status " ^ Cohttp.Code.(reason_phrase_of_code (code_of_status s)))