From fbb46ed03e3d1a98994a6ee9232d3eba3cfefe86 Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 1 Aug 2025 14:38:59 +0200 Subject: [PATCH 01/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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/20] 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))) From b7414fc9062576976e0b8c50535030f58b6c60e4 Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 22 Aug 2025 09:15:09 +0200 Subject: [PATCH 13/20] Safe Java code cleanup --- .../codegen/languages/OCamlClientCodegen.java | 27 ++++--------------- 1 file changed, 5 insertions(+), 22 deletions(-) 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 4ec76e273497..54e3e7c448b2 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 @@ -51,8 +51,6 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig static final String X_MODEL_MODULE = "x-model-module"; - public static final String CO_HTTP = "cohttp"; - @Setter protected String packageName = "openapi"; @Setter protected String packageVersion = "1.0.0"; protected String apiDocPath = "docs/"; @@ -188,15 +186,6 @@ public OCamlClientCodegen() { typeMapping.put("set", "`Set"); typeMapping.put("password", "string"); typeMapping.put("DateTime", "string"); - -// supportedLibraries.put(CO_HTTP, "HTTP client: CoHttp."); -// -// CliOption libraryOption = new CliOption(CodegenConstants.LIBRARY, "library template (sub-template) to use."); -// libraryOption.setEnum(supportedLibraries); -// // set hyper as the default -// libraryOption.setDefault(CO_HTTP); -// cliOptions.add(libraryOption); -// setLibrary(CO_HTTP); } @Override @@ -210,7 +199,7 @@ public Map postProcessAllModels(Map supero CodegenModel cm = mo.getModel(); // for enum model - if (Boolean.TRUE.equals(cm.isEnum) && cm.allowableValues != null) { + if (cm.isEnum && cm.allowableValues != null) { toRemove.add(modelEntry.getKey()); } else { enrichPropertiesWithEnumDefaultValues(cm.getAllVars()); @@ -244,8 +233,7 @@ private void enrichPropertiesWithEnumDefaultValues(List propert @Override protected void updateDataTypeWithEnumForMap(CodegenProperty property) { CodegenProperty baseItem = property.items; - while (baseItem != null && (Boolean.TRUE.equals(baseItem.isMap) - || Boolean.TRUE.equals(baseItem.isArray))) { + while (baseItem != null && (baseItem.isMap || baseItem.isArray)) { baseItem = baseItem.items; } @@ -262,8 +250,7 @@ protected void updateDataTypeWithEnumForMap(CodegenProperty property) { @Override protected void updateDataTypeWithEnumForArray(CodegenProperty property) { CodegenProperty baseItem = property.items; - while (baseItem != null && (Boolean.TRUE.equals(baseItem.isMap) - || Boolean.TRUE.equals(baseItem.isArray))) { + while (baseItem != null && (baseItem.isMap || baseItem.isArray)) { baseItem = baseItem.items; } if (baseItem != null) { @@ -314,19 +301,17 @@ private void collectEnumSchemas(String parentName, Map schemas) collectEnumSchemas(parentName, sName, schema); + String pName = parentName != null ? parentName + "_" + sName : sName; if (schema.getProperties() != null) { - String pName = parentName != null ? parentName + "_" + sName : sName; collectEnumSchemas(pName, schema.getProperties()); } if (schema.getAdditionalProperties() != null && schema.getAdditionalProperties() instanceof Schema) { - String pName = parentName != null ? parentName + "_" + sName : sName; collectEnumSchemas(pName, (Schema) schema.getAdditionalProperties()); } if (ModelUtils.isArraySchema(schema)) { if (ModelUtils.getSchemaItems(schema) != null) { - String pName = parentName != null ? parentName + "_" + sName : sName; collectEnumSchemas(pName, ModelUtils.getSchemaItems(schema)); } } @@ -679,7 +664,7 @@ private List> buildEnumValues(String valueString) { public String toEnumValueName(String name) { if (reservedWords.contains(name)) { return escapeReservedWord(name); - } else if (((CharSequence) name).chars().anyMatch(character -> specialCharReplacements.keySet().contains(String.valueOf((char) character)))) { + } else if (name.chars().anyMatch(character -> specialCharReplacements.containsKey(String.valueOf((char) character)))) { return escape(name, specialCharReplacements, Collections.singletonList("_"), null); } else { return name; @@ -725,8 +710,6 @@ public OperationsMap postProcessOperationsWithModels(OperationsMap objs, List operations = objectMap.getOperation(); for (CodegenOperation operation : operations) { - // http method verb conversion, depending on client library (e.g. Hyper: PUT => Put, Reqwest: PUT => put) - //if (CO_HTTP.equals(getLibrary())) { for (CodegenParameter param : operation.bodyParams) { if (param.isModel && param.dataType.endsWith(".t")) { param.vendorExtensions.put(X_MODEL_MODULE, param.dataType.substring(0, param.dataType.lastIndexOf('.'))); From 44964bd096b6b6b9304d8a69cf6f3b1ea9f152ef Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 22 Aug 2025 09:52:10 +0200 Subject: [PATCH 14/20] Split into model-record.mustache --- .../resources/ocaml/model-record.mustache | 43 ++++++++++++++++++ .../src/main/resources/ocaml/model.mustache | 44 +------------------ 2 files changed, 44 insertions(+), 43 deletions(-) create mode 100644 modules/openapi-generator/src/main/resources/ocaml/model-record.mustache diff --git a/modules/openapi-generator/src/main/resources/ocaml/model-record.mustache b/modules/openapi-generator/src/main/resources/ocaml/model-record.mustache new file mode 100644 index 000000000000..9eba7813330f --- /dev/null +++ b/modules/openapi-generator/src/main/resources/ocaml/model-record.mustache @@ -0,0 +1,43 @@ +type t = { +{{#vars}} + {{#description}} + (* {{{.}}} *) + {{/description}} + {{#isEnum}} + {{{name}}}: {{^isMap}}Enums.{{/isMap}}{{{datatypeWithEnum}}} + {{^isContainer}} + {{#required}} + {{#defaultValue}}[@default {{{.}}}]{{/defaultValue}} + {{#isNullable}} option [@default + {{#defaultValue}}Some({{{.}}}){{/defaultValue}} + {{^defaultValue}}None{{/defaultValue}} + ] + {{/isNullable}} + {{/required}} + {{^required}} option [@default + {{#defaultValue}}Some({{{.}}}){{/defaultValue}} + {{^defaultValue}}None{{/defaultValue}} + ] + {{/required}} + {{/isContainer}}; [@key "{{{baseName}}}"] + {{/isEnum}} + {{^isEnum}} + {{{name}}}: {{{datatypeWithEnum}}} + {{^isContainer}} + {{#required}}{{#isNullable}} option{{/isNullable}}{{/required}} + {{^required}} option [@default None]{{/required}} + {{/isContainer}} + {{#isArray}}{{^required}} [@default []]{{/required}}{{/isArray}} + ; [@key "{{{baseName}}}"] + {{/isEnum}} +{{/vars}} +} [@@deriving yojson { strict = false }, show, eq ];; + +{{#description}} +(** {{{.}}} *) +{{/description}} +let create {{#requiredVars}}({{{name}}} : {{#isEnum}}Enums.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}} option{{/isNullable}}){{^-last}} {{/-last}}{{/requiredVars}}{{^hasRequired}}(){{/hasRequired}} : t = { + {{#vars}} + {{{name}}} = {{#required}}{{{name}}}{{/required}}{{^required}}{{#isContainer}}[]{{/isContainer}}{{^isContainer}}None{{/isContainer}}{{/required}}; + {{/vars}} +} diff --git a/modules/openapi-generator/src/main/resources/ocaml/model.mustache b/modules/openapi-generator/src/main/resources/ocaml/model.mustache index cbd93f1524b6..a82f5d6db129 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/model.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/model.mustache @@ -10,49 +10,7 @@ {{/description}} {{^isEnum}} -type t = { -{{#vars}} - {{#description}} - (* {{{.}}} *) - {{/description}} - {{#isEnum}} - {{{name}}}: {{^isMap}}Enums.{{/isMap}}{{{datatypeWithEnum}}} - {{^isContainer}} - {{#required}} - {{#defaultValue}}[@default {{{.}}}]{{/defaultValue}} - {{#isNullable}} option [@default - {{#defaultValue}}Some({{{.}}}){{/defaultValue}} - {{^defaultValue}}None{{/defaultValue}} - ] - {{/isNullable}} - {{/required}} - {{^required}} option [@default - {{#defaultValue}}Some({{{.}}}){{/defaultValue}} - {{^defaultValue}}None{{/defaultValue}} - ] - {{/required}} - {{/isContainer}}; [@key "{{{baseName}}}"] - {{/isEnum}} - {{^isEnum}} - {{{name}}}: {{{datatypeWithEnum}}} - {{^isContainer}} - {{#required}}{{#isNullable}} option{{/isNullable}}{{/required}} - {{^required}} option [@default None]{{/required}} - {{/isContainer}} - {{#isArray}}{{^required}} [@default []]{{/required}}{{/isArray}} - ; [@key "{{{baseName}}}"] - {{/isEnum}} -{{/vars}} -} [@@deriving yojson { strict = false }, show, eq ];; - -{{#description}} -(** {{{.}}} *) -{{/description}} -let create {{#requiredVars}}({{{name}}} : {{#isEnum}}Enums.{{{datatypeWithEnum}}}{{/isEnum}}{{^isEnum}}{{{dataType}}}{{/isEnum}}{{#isNullable}} option{{/isNullable}}){{^-last}} {{/-last}}{{/requiredVars}}{{^hasRequired}}(){{/hasRequired}} : t = { - {{#vars}} - {{{name}}} = {{#required}}{{{name}}}{{/required}}{{^required}}{{#isContainer}}[]{{/isContainer}}{{^isContainer}}None{{/isContainer}}{{/required}}; - {{/vars}} -} + {{>model-record}} {{/isEnum}} {{/model}} From f42ba61ec48aa867222fd2cbb72dc7f53b682c80 Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 22 Aug 2025 15:59:28 +0200 Subject: [PATCH 15/20] Add some support for oneOf/anyOf --- .github/workflows/samples-ocaml.yaml | 3 + .gitignore | 1 + bin/configs/ocaml-oneOf.yaml | 6 + .../codegen/languages/OCamlClientCodegen.java | 15 ++- .../resources/ocaml/model-any-of.mustache | 25 ++++ .../resources/ocaml/model-one-of.mustache | 29 +++++ .../src/main/resources/ocaml/model.mustache | 12 +- .../ocaml-oneOf/.openapi-generator-ignore | 23 ++++ .../ocaml-oneOf/.openapi-generator/FILES | 12 ++ .../ocaml-oneOf/.openapi-generator/VERSION | 1 + samples/client/petstore/ocaml-oneOf/README.md | 33 ++++++ samples/client/petstore/ocaml-oneOf/dune | 9 ++ .../client/petstore/ocaml-oneOf/dune-project | 2 + .../petstore/ocaml-oneOf/petstore_client.opam | 24 ++++ .../ocaml-oneOf/src/apis/default_api.ml | 14 +++ .../ocaml-oneOf/src/apis/default_api.mli | 8 ++ .../petstore/ocaml-oneOf/src/models/child.ml | 23 ++++ .../ocaml-oneOf/src/models/example.ml | 39 +++++++ .../petstore/ocaml-oneOf/src/support/enums.ml | 6 + .../ocaml-oneOf/src/support/jsonSupport.ml | 55 +++++++++ .../ocaml-oneOf/src/support/request.ml | 110 ++++++++++++++++++ 21 files changed, 447 insertions(+), 3 deletions(-) create mode 100644 bin/configs/ocaml-oneOf.yaml create mode 100644 modules/openapi-generator/src/main/resources/ocaml/model-any-of.mustache create mode 100644 modules/openapi-generator/src/main/resources/ocaml/model-one-of.mustache create mode 100644 samples/client/petstore/ocaml-oneOf/.openapi-generator-ignore create mode 100644 samples/client/petstore/ocaml-oneOf/.openapi-generator/FILES create mode 100644 samples/client/petstore/ocaml-oneOf/.openapi-generator/VERSION create mode 100644 samples/client/petstore/ocaml-oneOf/README.md create mode 100644 samples/client/petstore/ocaml-oneOf/dune create mode 100644 samples/client/petstore/ocaml-oneOf/dune-project create mode 100644 samples/client/petstore/ocaml-oneOf/petstore_client.opam create mode 100644 samples/client/petstore/ocaml-oneOf/src/apis/default_api.ml create mode 100644 samples/client/petstore/ocaml-oneOf/src/apis/default_api.mli create mode 100644 samples/client/petstore/ocaml-oneOf/src/models/child.ml create mode 100644 samples/client/petstore/ocaml-oneOf/src/models/example.ml create mode 100644 samples/client/petstore/ocaml-oneOf/src/support/enums.ml create mode 100644 samples/client/petstore/ocaml-oneOf/src/support/jsonSupport.ml create mode 100644 samples/client/petstore/ocaml-oneOf/src/support/request.ml diff --git a/.github/workflows/samples-ocaml.yaml b/.github/workflows/samples-ocaml.yaml index 7fbc32364a79..9206c578d893 100644 --- a/.github/workflows/samples-ocaml.yaml +++ b/.github/workflows/samples-ocaml.yaml @@ -5,10 +5,12 @@ on: paths: - 'samples/client/petstore/ocaml/**' - 'samples/client/petstore/ocaml-fake-petstore/**' + - 'samples/client/petstore/ocaml-oneOf/**' pull_request: paths: - 'samples/client/petstore/ocaml/**' - 'samples/client/petstore/ocaml-fake-petstore/**' + - 'samples/client/petstore/ocaml-oneOf/**' jobs: build: @@ -20,6 +22,7 @@ jobs: sample: - 'samples/client/petstore/ocaml/' - 'samples/client/petstore/ocaml-fake-petstore/' + - 'samples/client/petstore/ocaml-oneOf/' steps: - uses: actions/checkout@v5 - name: Set-up OCaml diff --git a/.gitignore b/.gitignore index 9fdd217eabb6..36854746a1f0 100644 --- a/.gitignore +++ b/.gitignore @@ -297,6 +297,7 @@ samples/openapi3/client/petstore/go/privatekey.pem ## OCaml samples/client/petstore/ocaml/_build/ samples/client/petstore/ocaml-fake-petstore/_build/ +samples/client/petstore/ocaml-oneOf/_build/ # jetbrain http client samples/client/jetbrains/adyen/checkout71/http/client/Apis/http-client.private.env.json diff --git a/bin/configs/ocaml-oneOf.yaml b/bin/configs/ocaml-oneOf.yaml new file mode 100644 index 000000000000..7bd6601e2c9f --- /dev/null +++ b/bin/configs/ocaml-oneOf.yaml @@ -0,0 +1,6 @@ +generatorName: ocaml +outputDir: samples/client/petstore/ocaml-oneOf +inputSpec: modules/openapi-generator/src/test/resources/3_0/oneOf_primitive.yaml +templateDir: modules/openapi-generator/src/main/resources/ocaml +additionalProperties: + packageName: petstore_client 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 54e3e7c448b2..b3942140dd53 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 @@ -95,12 +95,15 @@ public OCamlClientCodegen() { .excludeSchemaSupportFeatures( SchemaSupportFeature.Polymorphism ) + .includeSchemaSupportFeatures( + SchemaSupportFeature.oneOf, + SchemaSupportFeature.anyOf + ) .includeClientModificationFeatures( ClientModificationFeature.BasePath ) ); - outputFolder = "generated-code/ocaml"; modelTemplateFiles.put("model.mustache", ".ml"); @@ -193,7 +196,6 @@ public Map postProcessAllModels(Map supero List toRemove = new ArrayList<>(); for (Map.Entry modelEntry : superobjs.entrySet()) { - // process enum in models List models = modelEntry.getValue().getModels(); for (ModelMap mo : models) { CodegenModel cm = mo.getModel(); @@ -210,6 +212,15 @@ public Map postProcessAllModels(Map supero enrichPropertiesWithEnumDefaultValues(cm.getVars()); enrichPropertiesWithEnumDefaultValues(cm.getParentVars()); } + + if (!cm.oneOf.isEmpty()) { + // Add a boolean if it is a `oneOf`, because Mustache does not let us check if a list is non-empty + cm.getVendorExtensions().put("x-ocaml-isOneOf", true); + } + if (!cm.anyOf.isEmpty()) { + // Add a boolean if it is a `anyOf`, because Mustache does not let us check if a list is non-empty + cm.getVendorExtensions().put("x-ocaml-isAnyOf", true); + } } } diff --git a/modules/openapi-generator/src/main/resources/ocaml/model-any-of.mustache b/modules/openapi-generator/src/main/resources/ocaml/model-any-of.mustache new file mode 100644 index 000000000000..2999d6e3100a --- /dev/null +++ b/modules/openapi-generator/src/main/resources/ocaml/model-any-of.mustache @@ -0,0 +1,25 @@ +type t = +{{#composedSchemas.anyOf}} + | {{{nameInPascalCase}}} of {{{dataType}}} +{{/composedSchemas.anyOf}} +[@@deriving show, eq];; + +let to_yojson = function +{{#composedSchemas.anyOf}} + | {{{nameInPascalCase}}} v -> [%to_yojson: {{{ datatypeWithEnum }}}] v +{{/composedSchemas.anyOf}} + +(* Manual implementations because the derived one encodes into a tuple list where the first element is the constructor name. *) + +let of_yojson json = + [ +{{#composedSchemas.anyOf}} + [%of_yojson: {{{ datatypeWithEnum }}}] json + |> Stdlib.Result.to_option + |> Stdlib.Option.map (fun v -> {{{nameInPascalCase}}} v); +{{/composedSchemas.anyOf}} + ] + |> Stdlib.List.filter_map (Fun.id) + |> function + | t :: _ -> Ok t (* Return the first successful parsing. *) + | [] -> Error ("Failed to parse JSON " ^ Yojson.Safe.show json ^ " into a value of type {{{ classname }}}") diff --git a/modules/openapi-generator/src/main/resources/ocaml/model-one-of.mustache b/modules/openapi-generator/src/main/resources/ocaml/model-one-of.mustache new file mode 100644 index 000000000000..6ced87d25291 --- /dev/null +++ b/modules/openapi-generator/src/main/resources/ocaml/model-one-of.mustache @@ -0,0 +1,29 @@ +type t = +{{#composedSchemas.oneOf}} + | {{{nameInPascalCase}}} of {{{dataType}}} +{{/composedSchemas.oneOf}} +[@@deriving show, eq];; + +let to_yojson = function +{{#composedSchemas.oneOf}} + | {{{nameInPascalCase}}} v -> [%to_yojson: {{{ datatypeWithEnum }}}] v +{{/composedSchemas.oneOf}} + +(* Manual implementations because the derived one encodes into a tuple list where the first element is the constructor name. *) + +let of_yojson json = + [ +{{#composedSchemas.oneOf}} + [%of_yojson: {{{ datatypeWithEnum }}}] json + |> Stdlib.Result.to_option + |> Stdlib.Option.map (fun v -> {{{nameInPascalCase}}} v); +{{/composedSchemas.oneOf}} + ] + |> Stdlib.List.filter_map (Fun.id) + |> function + | [t] -> Ok t + | [] -> Error ("Failed to parse JSON " ^ Yojson.Safe.show json ^ " into a value of type {{{ classname }}}") + | ts -> let parsed_ts = ts + |> Stdlib.List.map show + |> Stdlib.String.concat " | " + in Error ("Failed to parse JSON " ^ Yojson.Safe.show json ^ " into a value of type {{{ classname }}}: oneOf should only succeed on one parser, but the JSON was parsed into [" ^ parsed_ts ^ "]") diff --git a/modules/openapi-generator/src/main/resources/ocaml/model.mustache b/modules/openapi-generator/src/main/resources/ocaml/model.mustache index a82f5d6db129..eae441c741d3 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/model.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/model.mustache @@ -10,7 +10,17 @@ {{/description}} {{^isEnum}} - {{>model-record}} + {{#vendorExtensions.x-ocaml-isOneOf}} + {{>model-one-of}} + {{/vendorExtensions.x-ocaml-isOneOf}} + + {{#vendorExtensions.x-ocaml-isAnyOf}} + {{>model-any-of}} + {{/vendorExtensions.x-ocaml-isAnyOf}} + + {{^vendorExtensions.x-ocaml-isOneOf}}{{^vendorExtensions.x-ocaml-isAnyOf}} + {{>model-record}} + {{/vendorExtensions.x-ocaml-isAnyOf}}{{/vendorExtensions.x-ocaml-isOneOf}} {{/isEnum}} {{/model}} diff --git a/samples/client/petstore/ocaml-oneOf/.openapi-generator-ignore b/samples/client/petstore/ocaml-oneOf/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/.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-oneOf/.openapi-generator/FILES b/samples/client/petstore/ocaml-oneOf/.openapi-generator/FILES new file mode 100644 index 000000000000..e6ee03f7ede1 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/.openapi-generator/FILES @@ -0,0 +1,12 @@ +.openapi-generator-ignore +README.md +dune +dune-project +petstore_client.opam +src/apis/default_api.ml +src/apis/default_api.mli +src/models/child.ml +src/models/example.ml +src/support/enums.ml +src/support/jsonSupport.ml +src/support/request.ml diff --git a/samples/client/petstore/ocaml-oneOf/.openapi-generator/VERSION b/samples/client/petstore/ocaml-oneOf/.openapi-generator/VERSION new file mode 100644 index 000000000000..fc74d6ceba8e --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/.openapi-generator/VERSION @@ -0,0 +1 @@ +7.15.0-SNAPSHOT diff --git a/samples/client/petstore/ocaml-oneOf/README.md b/samples/client/petstore/ocaml-oneOf/README.md new file mode 100644 index 000000000000..b9cbd1f3d9a1 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/README.md @@ -0,0 +1,33 @@ +# +No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) + +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-oneOf/dune b/samples/client/petstore/ocaml-oneOf/dune new file mode 100644 index 000000000000..ed1c4d90e3df --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/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-oneOf/dune-project b/samples/client/petstore/ocaml-oneOf/dune-project new file mode 100644 index 000000000000..79d86e3c901a --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/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-oneOf/petstore_client.opam b/samples/client/petstore/ocaml-oneOf/petstore_client.opam new file mode 100644 index 000000000000..7ca31fc5af4f --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/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-oneOf/src/apis/default_api.ml b/samples/client/petstore/ocaml-oneOf/src/apis/default_api.ml new file mode 100644 index 000000000000..93677e4bf1f5 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/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 list () = + let open Lwt.Infix in + let uri = Request.build_uri "/example" 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 Example.of_yojson) resp body + diff --git a/samples/client/petstore/ocaml-oneOf/src/apis/default_api.mli b/samples/client/petstore/ocaml-oneOf/src/apis/default_api.mli new file mode 100644 index 000000000000..2b244b750994 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/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 list : unit -> Example.t Lwt.t diff --git a/samples/client/petstore/ocaml-oneOf/src/models/child.ml b/samples/client/petstore/ocaml-oneOf/src/models/child.ml new file mode 100644 index 000000000000..fd9542253c32 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/src/models/child.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 = { + 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-oneOf/src/models/example.ml b/samples/client/petstore/ocaml-oneOf/src/models/example.ml new file mode 100644 index 000000000000..42162d950c76 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/src/models/example.ml @@ -0,0 +1,39 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + + type t = + | OneOf0 of Child.t + | OneOf1 of int32 + [@@deriving show, eq];; + + let to_yojson = function + | OneOf0 v -> [%to_yojson: Child.t] v + | OneOf1 v -> [%to_yojson: int32] v + + (* Manual implementations because the derived one encodes into a tuple list where the first element is the constructor name. *) + + let of_yojson json = + [ + [%of_yojson: Child.t] json + |> Stdlib.Result.to_option + |> Stdlib.Option.map (fun v -> OneOf0 v); + [%of_yojson: int32] json + |> Stdlib.Result.to_option + |> Stdlib.Option.map (fun v -> OneOf1 v); + ] + |> Stdlib.List.filter_map (Fun.id) + |> function + | [t] -> Ok t + | [] -> Error ("Failed to parse JSON " ^ Yojson.Safe.show json ^ " into a value of type Example.t") + | ts -> let parsed_ts = ts + |> Stdlib.List.map show + |> Stdlib.String.concat " | " + in Error ("Failed to parse JSON " ^ Yojson.Safe.show json ^ " into a value of type Example.t: oneOf should only succeed on one parser, but the JSON was parsed into [" ^ parsed_ts ^ "]") + + + + diff --git a/samples/client/petstore/ocaml-oneOf/src/support/enums.ml b/samples/client/petstore/ocaml-oneOf/src/support/enums.ml new file mode 100644 index 000000000000..b30c42f110c6 --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/src/support/enums.ml @@ -0,0 +1,6 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) diff --git a/samples/client/petstore/ocaml-oneOf/src/support/jsonSupport.ml b/samples/client/petstore/ocaml-oneOf/src/support/jsonSupport.ml new file mode 100644 index 000000000000..061b1be39f8a --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/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-oneOf/src/support/request.ml b/samples/client/petstore/ocaml-oneOf/src/support/request.ml new file mode 100644 index 000000000000..c89862d5d0ea --- /dev/null +++ b/samples/client/petstore/ocaml-oneOf/src/support/request.ml @@ -0,0 +1,110 @@ +let api_key = "" +let base_url = "http://api.example.xyz/v1" +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.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 + +(** 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 = + 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 f5eaf8f69aeda947cd766198b3d251e91eaef1a9 Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 22 Aug 2025 16:13:18 +0200 Subject: [PATCH 16/20] Re-generate all OCaml samples --- .../src/models/additional_properties_class.ml | 28 ++- .../src/models/all_of_with_single_ref.ml | 36 +-- .../ocaml-fake-petstore/src/models/animal.ml | 36 +-- .../src/models/api_response.ml | 48 ++-- .../models/array_of_array_of_number_only.ml | 20 +- .../src/models/array_of_number_only.ml | 20 +- .../src/models/array_test.ml | 36 +-- .../src/models/capitalization.ml | 86 ++++---- .../ocaml-fake-petstore/src/models/cat.ml | 48 ++-- .../src/models/category.ml | 36 +-- .../src/models/child_with_nullable.ml | 50 +++-- .../src/models/class_model.ml | 26 ++- .../ocaml-fake-petstore/src/models/client.ml | 24 +- .../src/models/deprecated_object.ml | 24 +- .../ocaml-fake-petstore/src/models/dog.ml | 48 ++-- .../src/models/enum_arrays.ml | 32 +-- .../src/models/enum_test.ml | 110 ++++----- .../fake_big_decimal_map_200_response.ml | 32 +-- .../ocaml-fake-petstore/src/models/file.ml | 28 ++- .../src/models/file_schema_test_class.ml | 32 +-- .../ocaml-fake-petstore/src/models/foo.ml | 24 +- .../src/models/format_test.ml | 208 +++++++++--------- .../src/models/has_only_read_only.ml | 36 +-- .../src/models/health_check_result.ml | 26 ++- .../ocaml-fake-petstore/src/models/list.ml | 24 +- .../src/models/map_test.ml | 40 ++-- ...perties_and_additional_properties_class.ml | 44 ++-- .../src/models/model_200_response.ml | 38 ++-- .../models/model__foo_get_default_response.ml | 24 +- .../src/models/model__special_model_name_.ml | 24 +- .../ocaml-fake-petstore/src/models/name.ml | 62 +++--- .../src/models/nullable_class.ml | 132 +++++------ .../src/models/number_only.ml | 24 +- .../models/object_with_deprecated_fields.ml | 56 ++--- .../ocaml-fake-petstore/src/models/order.ml | 88 ++++---- .../src/models/outer_composite.ml | 48 ++-- .../models/outer_object_with_enum_property.ml | 24 +- .../src/models/parent_with_nullable.ml | 38 ++-- .../ocaml-fake-petstore/src/models/pet.ml | 80 +++---- .../src/models/read_only_first.ml | 36 +-- .../ocaml-fake-petstore/src/models/return.ml | 26 ++- .../ocaml-fake-petstore/src/models/tag.ml | 36 +-- ..._freeform_additional_properties_request.ml | 24 +- .../ocaml-fake-petstore/src/models/user.ml | 110 ++++----- .../ocaml-oneOf/.openapi-generator/FILES | 1 - .../petstore/ocaml/src/models/api_response.ml | 50 +++-- .../petstore/ocaml/src/models/category.ml | 38 ++-- .../client/petstore/ocaml/src/models/order.ml | 90 ++++---- .../client/petstore/ocaml/src/models/pet.ml | 82 +++---- .../client/petstore/ocaml/src/models/tag.ml | 38 ++-- .../client/petstore/ocaml/src/models/user.ml | 112 +++++----- 51 files changed, 1341 insertions(+), 1142 deletions(-) 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 index e19874830370..098172c86701 100644 --- 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 @@ -5,17 +5,21 @@ * *) -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 = []; -} + + + 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 index 8be4d0ad2ec6..90f73a9a51a1 100644 --- 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 @@ -5,21 +5,25 @@ * *) -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; -} + + + 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 index b851329d1cd9..dbe3537e7aff 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/animal.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/animal.ml @@ -5,21 +5,25 @@ * *) -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; -} + + + 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 index 7fc624a6931f..4d674e397b41 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/api_response.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/api_response.ml @@ -5,27 +5,31 @@ * *) -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; -} + + + 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 index 225845404619..4d2007ce5e65 100644 --- 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 @@ -5,13 +5,17 @@ * *) -type t = { - array_array_number: float list list - [@default []] - ; [@key "ArrayArrayNumber"] -} [@@deriving yojson { strict = false }, show, eq ];; -let create () : t = { - array_array_number = []; -} + + + 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 index fb8fe8aa4135..551bcb295c2e 100644 --- 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 @@ -5,13 +5,17 @@ * *) -type t = { - array_number: float list - [@default []] - ; [@key "ArrayNumber"] -} [@@deriving yojson { strict = false }, show, eq ];; -let create () : t = { - array_number = []; -} + + + 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 index 299adeec039f..7fa6a23a8d34 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/array_test.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/array_test.ml @@ -5,21 +5,25 @@ * *) -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 = []; -} + + + 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 index 7394882bc384..340406d7816c 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/capitalization.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/capitalization.ml @@ -5,46 +5,50 @@ * *) -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; -} + + + 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 index b7fcd26748e0..c0cd2fdcbfa0 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/cat.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/cat.ml @@ -5,27 +5,31 @@ * *) -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; -} + + + 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 index e0ff8244341f..ceecf05c869c 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/category.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/category.ml @@ -5,21 +5,25 @@ * *) -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; -} + + + 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 index 600191eb930b..1ebd5688dc8c 100644 --- 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 @@ -5,28 +5,32 @@ * *) -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; -} + + + 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 index 3f9b3edd4eca..8dd8a9f4c2a2 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/class_model.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/class_model.ml @@ -6,16 +6,20 @@ * 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; -} + + + 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 index 2fdde4fbc305..1cb59540257b 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/client.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/client.ml @@ -5,15 +5,19 @@ * *) -type t = { - client: string - - option [@default None] - - ; [@key "client"] -} [@@deriving yojson { strict = false }, show, eq ];; -let create () : t = { - client = None; -} + + + 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 index f5cf396628b1..fd9542253c32 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/deprecated_object.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/deprecated_object.ml @@ -5,15 +5,19 @@ * *) -type t = { - name: string - - option [@default None] - - ; [@key "name"] -} [@@deriving yojson { strict = false }, show, eq ];; -let create () : t = { - name = None; -} + + + 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 index f7a67f0a5078..65a03e9a0f3e 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/dog.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/dog.ml @@ -5,27 +5,31 @@ * *) -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; -} + + + 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 index c45e282a26ec..612cdf25beba 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/enum_arrays.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/enum_arrays.ml @@ -5,19 +5,23 @@ * *) -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 = []; -} + + + 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 index e82a77d48f50..95e926983e70 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/enum_test.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/enum_test.ml @@ -5,58 +5,62 @@ * *) -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; -} + + + 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 index aa1801f4e06c..14596ab401e9 100644 --- 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 @@ -5,19 +5,23 @@ * *) -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 = []; -} + + + 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 index 9d6d43e2d4f3..7748a36fad58 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/file.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/file.ml @@ -6,17 +6,21 @@ * 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; -} + + + 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 index 423b3f39eef4..7d1c154d72d9 100644 --- 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 @@ -5,19 +5,23 @@ * *) -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 = []; -} + + + 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 index 51cd048e4c53..d656e95273f1 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/foo.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/foo.ml @@ -5,15 +5,19 @@ * *) -type t = { - bar: string - - option [@default None] - - ; [@key "bar"] -} [@@deriving yojson { strict = false }, show, eq ];; -let create () : t = { - bar = None; -} + + + 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 index 0cf0edf0e84d..c5cf24f6de01 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/format_test.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/format_test.ml @@ -5,107 +5,111 @@ * *) -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; -} + + + 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 index 2c9389e7c549..14a6b8232487 100644 --- 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 @@ -5,21 +5,25 @@ * *) -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; -} + + + 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 index 24198f6f73ae..bb898ea1cda6 100644 --- 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 @@ -6,16 +6,20 @@ * 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; -} + + + 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 index f0c267f3d1dd..9e3d16f6752d 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/list.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/list.ml @@ -5,15 +5,19 @@ * *) -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; -} + + + 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 index 2c6430d7d1a7..8900d7da7fd6 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/map_test.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/map_test.ml @@ -5,24 +5,28 @@ * *) -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 + + + + 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 + direct_map: (string * bool) list + + ; [@key "direct_map"] + indirect_map: (string * bool) list + + ; [@key "indirect_map"] + } [@@deriving yojson { strict = false }, show, eq ];; - ; [@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 = []; -} + 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 index e43531cfb964..810fb6c39020 100644 --- 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 @@ -5,25 +5,29 @@ * *) -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 = []; -} + + + 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 index 95ee7727f40d..f30a1381b685 100644 --- 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 @@ -6,22 +6,26 @@ * 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; -} + + + 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 index 6b31b7d74ed4..8efdd9c6247e 100644 --- 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 @@ -5,15 +5,19 @@ * *) -type t = { - string: Foo.t - - option [@default None] - - ; [@key "string"] -} [@@deriving yojson { strict = false }, show, eq ];; -let create () : t = { - string = None; -} + + + 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 index 0495face91a6..2a559b537d1b 100644 --- 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 @@ -5,15 +5,19 @@ * *) -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; -} + + + 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 index 85f14bf15c7d..5e12f053ebd3 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/name.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/name.ml @@ -6,34 +6,38 @@ * 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; -} + + + 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 index 3a01e8875a6d..b639d5b6cfa0 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/nullable_class.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/nullable_class.ml @@ -5,69 +5,73 @@ * *) -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 = []; -} + + + 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 index 1a1310951589..e1746a9c8cb4 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/number_only.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/number_only.ml @@ -5,15 +5,19 @@ * *) -type t = { - just_number: float - - option [@default None] - - ; [@key "JustNumber"] -} [@@deriving yojson { strict = false }, show, eq ];; -let create () : t = { - just_number = None; -} + + + 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 index aa1f4726d0bf..51e400589229 100644 --- 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 @@ -5,31 +5,35 @@ * *) -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 = []; -} + + + 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 index f3ad48c1e3e1..a489aee9b2a4 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/order.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/order.ml @@ -5,47 +5,51 @@ * *) -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; -} + + + 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 index 65184e1b2ab8..30f39f1faf51 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/outer_composite.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/outer_composite.ml @@ -5,27 +5,31 @@ * *) -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; -} + + + 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 index 3c667fbc82fb..5b6a80ba3b55 100644 --- 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 @@ -5,15 +5,19 @@ * *) -type t = { - value: Enums.outerenuminteger - - - - ; [@key "value"] -} [@@deriving yojson { strict = false }, show, eq ];; -let create (value : Enums.outerenuminteger) : t = { - value = value; -} + + + 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 index 9db248d8e6a7..4f39af1c4b9c 100644 --- 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 @@ -5,22 +5,26 @@ * *) -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; -} + + + 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 index c3f0a2e48a10..9b5dcbae4d04 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/pet.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/pet.ml @@ -5,43 +5,47 @@ * *) -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; -} + + + 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 index 782a38a015f7..886c71783e44 100644 --- 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 @@ -5,21 +5,25 @@ * *) -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; -} + + + 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 index f1fe51cdf23d..062d87046af9 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/return.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/return.ml @@ -6,16 +6,20 @@ * 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; -} + + + 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 index c5cdf5113f77..e4badcd31452 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/tag.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/tag.ml @@ -5,21 +5,25 @@ * *) -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; -} + + + 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 index 674eac609d17..3a39d02207c5 100644 --- 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 @@ -5,15 +5,19 @@ * *) -type t = { - some_property: string - - option [@default None] - - ; [@key "someProperty"] -} [@@deriving yojson { strict = false }, show, eq ];; -let create () : t = { - some_property = None; -} + + + 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 index 57f598e3ebda..179354927dbe 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/user.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/user.ml @@ -5,58 +5,62 @@ * *) -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; -} + + + 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-oneOf/.openapi-generator/FILES b/samples/client/petstore/ocaml-oneOf/.openapi-generator/FILES index e6ee03f7ede1..0623f326da70 100644 --- a/samples/client/petstore/ocaml-oneOf/.openapi-generator/FILES +++ b/samples/client/petstore/ocaml-oneOf/.openapi-generator/FILES @@ -1,4 +1,3 @@ -.openapi-generator-ignore README.md dune dune-project diff --git a/samples/client/petstore/ocaml/src/models/api_response.ml b/samples/client/petstore/ocaml/src/models/api_response.ml index 0abc8a37b74a..1a74ae0cebce 100644 --- a/samples/client/petstore/ocaml/src/models/api_response.ml +++ b/samples/client/petstore/ocaml/src/models/api_response.ml @@ -6,28 +6,32 @@ * Schema Api_response.t : Describes the result of uploading an image resource *) -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 ];; -(** Describes the result of uploading an image resource *) -let create () : t = { - code = None; - _type = None; - message = None; -} + + + 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 ];; + + (** Describes the result of uploading an image resource *) + let create () : t = { + code = None; + _type = None; + message = None; + } + diff --git a/samples/client/petstore/ocaml/src/models/category.ml b/samples/client/petstore/ocaml/src/models/category.ml index 47b8f3bee0ea..2d28165f0c24 100644 --- a/samples/client/petstore/ocaml/src/models/category.ml +++ b/samples/client/petstore/ocaml/src/models/category.ml @@ -6,22 +6,26 @@ * Schema Category.t : A category for a pet *) -type t = { - id: int64 - - option [@default None] - - ; [@key "id"] - name: string - - option [@default None] - - ; [@key "name"] -} [@@deriving yojson { strict = false }, show, eq ];; -(** A category for a pet *) -let create () : t = { - id = None; - name = None; -} + + + type t = { + id: int64 + + option [@default None] + + ; [@key "id"] + name: string + + option [@default None] + + ; [@key "name"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** A category for a pet *) + let create () : t = { + id = None; + name = None; + } + diff --git a/samples/client/petstore/ocaml/src/models/order.ml b/samples/client/petstore/ocaml/src/models/order.ml index f88bd155f703..e78086c56454 100644 --- a/samples/client/petstore/ocaml/src/models/order.ml +++ b/samples/client/petstore/ocaml/src/models/order.ml @@ -6,48 +6,52 @@ * Schema Order.t : An order for a pets from the pet store *) -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.status - option [@default - - None - ] - ; [@key "status"] - complete: bool - - option [@default None] - - ; [@key "complete"] -} [@@deriving yojson { strict = false }, show, eq ];; -(** An order for a pets from the pet store *) -let create () : t = { - id = None; - pet_id = None; - quantity = None; - ship_date = None; - status = None; - complete = None; -} + + + 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.status + option [@default + + None + ] + ; [@key "status"] + complete: bool + + option [@default None] + + ; [@key "complete"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** An order for a pets from the pet store *) + let create () : t = { + id = None; + pet_id = None; + quantity = None; + ship_date = None; + status = None; + complete = None; + } + diff --git a/samples/client/petstore/ocaml/src/models/pet.ml b/samples/client/petstore/ocaml/src/models/pet.ml index 34001310d298..9c365d49ddd4 100644 --- a/samples/client/petstore/ocaml/src/models/pet.ml +++ b/samples/client/petstore/ocaml/src/models/pet.ml @@ -6,44 +6,48 @@ * Schema Pet.t : A pet for sale in the pet store *) -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.pet_status - option [@default - - None - ] - ; [@key "status"] -} [@@deriving yojson { strict = false }, show, eq ];; -(** A pet for sale in the pet store *) -let create (name : string) (photo_urls : string list) : t = { - id = None; - category = None; - name = name; - photo_urls = photo_urls; - tags = []; - status = None; -} + + + 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.pet_status + option [@default + + None + ] + ; [@key "status"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** A pet for sale in the pet store *) + 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/src/models/tag.ml b/samples/client/petstore/ocaml/src/models/tag.ml index 9c89a1d1e051..716872196315 100644 --- a/samples/client/petstore/ocaml/src/models/tag.ml +++ b/samples/client/petstore/ocaml/src/models/tag.ml @@ -6,22 +6,26 @@ * Schema Tag.t : A tag for a pet *) -type t = { - id: int64 - - option [@default None] - - ; [@key "id"] - name: string - - option [@default None] - - ; [@key "name"] -} [@@deriving yojson { strict = false }, show, eq ];; -(** A tag for a pet *) -let create () : t = { - id = None; - name = None; -} + + + type t = { + id: int64 + + option [@default None] + + ; [@key "id"] + name: string + + option [@default None] + + ; [@key "name"] + } [@@deriving yojson { strict = false }, show, eq ];; + + (** A tag for a pet *) + let create () : t = { + id = None; + name = None; + } + diff --git a/samples/client/petstore/ocaml/src/models/user.ml b/samples/client/petstore/ocaml/src/models/user.ml index 38ed8cce2dd3..62e4adac58d8 100644 --- a/samples/client/petstore/ocaml/src/models/user.ml +++ b/samples/client/petstore/ocaml/src/models/user.ml @@ -6,59 +6,63 @@ * Schema User.t : A User who is purchasing from the pet store *) -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 ];; -(** A User who is purchasing from the pet store *) -let create () : t = { - id = None; - username = None; - first_name = None; - last_name = None; - email = None; - password = None; - phone = None; - user_status = None; -} + + + 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 ];; + + (** A User who is purchasing from the pet store *) + let create () : t = { + id = None; + username = None; + first_name = None; + last_name = None; + email = None; + password = None; + phone = None; + user_status = None; + } + From ac643b5d430133da73250a6b935c22ce77d403ef Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 22 Aug 2025 16:14:03 +0200 Subject: [PATCH 17/20] Fix: correctly mark non-required maps with default empty list --- .../main/resources/ocaml/model-record.mustache | 1 + .../src/models/additional_properties_class.ml | 2 ++ .../src/models/all_of_with_single_ref.ml | 2 ++ .../ocaml-fake-petstore/src/models/animal.ml | 2 ++ .../src/models/api_response.ml | 3 +++ .../src/models/array_of_array_of_number_only.ml | 1 + .../src/models/array_of_number_only.ml | 1 + .../ocaml-fake-petstore/src/models/array_test.ml | 3 +++ .../src/models/capitalization.ml | 6 ++++++ .../ocaml-fake-petstore/src/models/cat.ml | 3 +++ .../ocaml-fake-petstore/src/models/category.ml | 2 ++ .../src/models/child_with_nullable.ml | 2 ++ .../src/models/class_model.ml | 1 + .../ocaml-fake-petstore/src/models/client.ml | 1 + .../src/models/deprecated_object.ml | 1 + .../ocaml-fake-petstore/src/models/dog.ml | 3 +++ .../ocaml-fake-petstore/src/models/enum_test.ml | 4 ++++ .../models/fake_big_decimal_map_200_response.ml | 2 ++ .../ocaml-fake-petstore/src/models/file.ml | 1 + .../src/models/file_schema_test_class.ml | 2 ++ .../ocaml-fake-petstore/src/models/foo.ml | 1 + .../src/models/format_test.ml | 16 ++++++++++++++++ .../src/models/has_only_read_only.ml | 2 ++ .../src/models/health_check_result.ml | 1 + .../ocaml-fake-petstore/src/models/list.ml | 1 + .../ocaml-fake-petstore/src/models/map_test.ml | 3 +++ ...properties_and_additional_properties_class.ml | 3 +++ .../src/models/model_200_response.ml | 2 ++ .../models/model__foo_get_default_response.ml | 1 + .../src/models/model__special_model_name_.ml | 1 + .../ocaml-fake-petstore/src/models/name.ml | 4 ++++ .../src/models/nullable_class.ml | 12 ++++++++++++ .../src/models/number_only.ml | 1 + .../src/models/object_with_deprecated_fields.ml | 4 ++++ .../ocaml-fake-petstore/src/models/order.ml | 5 +++++ .../src/models/outer_composite.ml | 3 +++ .../models/outer_object_with_enum_property.ml | 1 + .../src/models/parent_with_nullable.ml | 1 + .../ocaml-fake-petstore/src/models/pet.ml | 5 +++++ .../src/models/read_only_first.ml | 2 ++ .../ocaml-fake-petstore/src/models/return.ml | 1 + .../ocaml-fake-petstore/src/models/tag.ml | 2 ++ ...ine_freeform_additional_properties_request.ml | 1 + .../ocaml-fake-petstore/src/models/user.ml | 8 ++++++++ .../petstore/ocaml-oneOf/src/models/child.ml | 1 + .../petstore/ocaml/src/models/api_response.ml | 3 +++ .../client/petstore/ocaml/src/models/category.ml | 2 ++ .../client/petstore/ocaml/src/models/order.ml | 5 +++++ samples/client/petstore/ocaml/src/models/pet.ml | 5 +++++ samples/client/petstore/ocaml/src/models/tag.ml | 2 ++ samples/client/petstore/ocaml/src/models/user.ml | 8 ++++++++ 51 files changed, 150 insertions(+) diff --git a/modules/openapi-generator/src/main/resources/ocaml/model-record.mustache b/modules/openapi-generator/src/main/resources/ocaml/model-record.mustache index 9eba7813330f..a72d3d789d73 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/model-record.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/model-record.mustache @@ -28,6 +28,7 @@ type t = { {{^required}} option [@default None]{{/required}} {{/isContainer}} {{#isArray}}{{^required}} [@default []]{{/required}}{{/isArray}} + {{#isMap}}{{^required}} [@default []]{{/required}}{{/isMap}} ; [@key "{{{baseName}}}"] {{/isEnum}} {{/vars}} 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 index 098172c86701..300288477013 100644 --- 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 @@ -11,9 +11,11 @@ type t = { map_property: (string * string) list + [@default []] ; [@key "map_property"] map_of_map_property: (string * (string * string) list) list + [@default []] ; [@key "map_of_map_property"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 90f73a9a51a1..8824bf45851d 100644 --- 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 @@ -13,11 +13,13 @@ option [@default None] + ; [@key "username"] single_ref_type: Enums.singlereftype option [@default None] + ; [@key "SingleRefType"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/animal.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/animal.ml index dbe3537e7aff..bb9694548e1e 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/animal.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/animal.ml @@ -13,11 +13,13 @@ + ; [@key "className"] color: string option [@default None] + ; [@key "color"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 4d674e397b41..38c83657c392 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/api_response.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/api_response.ml @@ -13,16 +13,19 @@ 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 ];; 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 index 4d2007ce5e65..17d2b550a3dc 100644 --- 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 @@ -11,6 +11,7 @@ type t = { array_array_number: float list list [@default []] + ; [@key "ArrayArrayNumber"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 551bcb295c2e..e4ea0cc597d1 100644 --- 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 @@ -11,6 +11,7 @@ type t = { array_number: float list [@default []] + ; [@key "ArrayNumber"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 7fa6a23a8d34..850e8d6d7197 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/array_test.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/array_test.ml @@ -11,12 +11,15 @@ 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 ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/capitalization.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/capitalization.ml index 340406d7816c..2725a870b917 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/capitalization.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/capitalization.ml @@ -13,32 +13,38 @@ 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 ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/cat.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/cat.ml index c0cd2fdcbfa0..d9dcd55ac0af 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/cat.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/cat.ml @@ -13,16 +13,19 @@ + ; [@key "className"] color: string option [@default None] + ; [@key "color"] declawed: bool option [@default None] + ; [@key "declawed"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/category.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/category.ml index ceecf05c869c..95e0b50ee994 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/category.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/category.ml @@ -13,11 +13,13 @@ option [@default None] + ; [@key "id"] name: string + ; [@key "name"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 1ebd5688dc8c..61eba92d86ce 100644 --- 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 @@ -19,11 +19,13 @@ option [@default None] + ; [@key "nullableProperty"] other_property: string option [@default None] + ; [@key "otherProperty"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 8dd8a9f4c2a2..f63be054b150 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/class_model.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/class_model.ml @@ -14,6 +14,7 @@ option [@default None] + ; [@key "_class"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/client.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/client.ml index 1cb59540257b..d3b578e2509f 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/client.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/client.ml @@ -13,6 +13,7 @@ option [@default None] + ; [@key "client"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index fd9542253c32..ff9a12f2eb4d 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/deprecated_object.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/deprecated_object.ml @@ -13,6 +13,7 @@ option [@default None] + ; [@key "name"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/dog.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/dog.ml index 65a03e9a0f3e..004e9bb56406 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/dog.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/dog.ml @@ -13,16 +13,19 @@ + ; [@key "className"] color: string option [@default None] + ; [@key "color"] breed: string option [@default None] + ; [@key "breed"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 95e926983e70..e9df9f2fec4e 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/enum_test.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/enum_test.ml @@ -34,21 +34,25 @@ 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 ];; 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 index 14596ab401e9..231647487e43 100644 --- 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 @@ -13,9 +13,11 @@ option [@default None] + ; [@key "someId"] some_map: (string * float) list + [@default []] ; [@key "someMap"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/file.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/file.ml index 7748a36fad58..e02dec2b6bde 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/file.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/file.ml @@ -15,6 +15,7 @@ option [@default None] + ; [@key "sourceURI"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 7d1c154d72d9..e9bb0b52c6b6 100644 --- 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 @@ -13,9 +13,11 @@ option [@default None] + ; [@key "file"] files: File.t list [@default []] + ; [@key "files"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/foo.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/foo.ml index d656e95273f1..a3f48385e0d7 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/foo.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/foo.ml @@ -13,6 +13,7 @@ option [@default None] + ; [@key "bar"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index c5cf24f6de01..03631a54e643 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/format_test.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/format_test.ml @@ -13,83 +13,99 @@ 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 ];; 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 index 14a6b8232487..cebf14ba37f9 100644 --- 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 @@ -13,11 +13,13 @@ option [@default None] + ; [@key "bar"] foo: string option [@default None] + ; [@key "foo"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index bb898ea1cda6..b58d7cd6cfeb 100644 --- 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 @@ -14,6 +14,7 @@ option [@default None] + ; [@key "NullableMessage"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/list.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/list.ml index 9e3d16f6752d..13e71de7e641 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/list.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/list.ml @@ -13,6 +13,7 @@ option [@default None] + ; [@key "123-list"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 8900d7da7fd6..c77105c5f280 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/map_test.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/map_test.ml @@ -11,14 +11,17 @@ type t = { map_map_of_string: (string * (string * string) list) list + [@default []] ; [@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 + [@default []] ; [@key "direct_map"] indirect_map: (string * bool) list + [@default []] ; [@key "indirect_map"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 810fb6c39020..ddf696a1ef0d 100644 --- 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 @@ -13,14 +13,17 @@ option [@default None] + ; [@key "uuid"] date_time: string option [@default None] + ; [@key "dateTime"] map: (string * Animal.t) list + [@default []] ; [@key "map"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index f30a1381b685..06031bb76b08 100644 --- 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 @@ -14,11 +14,13 @@ option [@default None] + ; [@key "name"] _class: string option [@default None] + ; [@key "class"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 8efdd9c6247e..3231ca32596c 100644 --- 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 @@ -13,6 +13,7 @@ option [@default None] + ; [@key "string"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 2a559b537d1b..ae3b926c52b1 100644 --- 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 @@ -13,6 +13,7 @@ option [@default None] + ; [@key "$special[property.name]"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/name.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/name.ml index 5e12f053ebd3..4b1861ea51ad 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/name.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/name.ml @@ -14,21 +14,25 @@ + ; [@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 ];; 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 index b639d5b6cfa0..a840a1dce496 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/nullable_class.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/nullable_class.ml @@ -13,49 +13,61 @@ 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 + [@default []] ; [@key "object_nullable_prop"] object_and_items_nullable_prop: (string * Yojson.Safe.t) list + [@default []] ; [@key "object_and_items_nullable_prop"] object_items_nullable: (string * Yojson.Safe.t) list + [@default []] ; [@key "object_items_nullable"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index e1746a9c8cb4..2ca1bb224c58 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/number_only.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/number_only.ml @@ -13,6 +13,7 @@ option [@default None] + ; [@key "JustNumber"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 51e400589229..93bb27889b10 100644 --- 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 @@ -13,19 +13,23 @@ 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 ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/order.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/order.ml index a489aee9b2a4..edeb14daf189 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/order.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/order.ml @@ -13,21 +13,25 @@ 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 @@ -40,6 +44,7 @@ option [@default None] + ; [@key "complete"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 30f39f1faf51..5ab6dc894cfc 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/outer_composite.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/outer_composite.ml @@ -13,16 +13,19 @@ 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 ];; 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 index 5b6a80ba3b55..defddabc9421 100644 --- 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 @@ -13,6 +13,7 @@ + ; [@key "value"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 4f39af1c4b9c..0a82027599dc 100644 --- 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 @@ -19,6 +19,7 @@ option [@default None] + ; [@key "nullableProperty"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/pet.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/pet.ml index 9b5dcbae4d04..bf5b6f289e3c 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/pet.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/pet.ml @@ -13,22 +13,27 @@ 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 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 index 886c71783e44..42764810c586 100644 --- 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 @@ -13,11 +13,13 @@ option [@default None] + ; [@key "bar"] baz: string option [@default None] + ; [@key "baz"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/return.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/return.ml index 062d87046af9..1b27a9c0c5b5 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/return.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/return.ml @@ -14,6 +14,7 @@ option [@default None] + ; [@key "return"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/tag.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/tag.ml index e4badcd31452..01467b5e0745 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/tag.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/tag.ml @@ -13,11 +13,13 @@ option [@default None] + ; [@key "id"] name: string option [@default None] + ; [@key "name"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 3a39d02207c5..9aa631abe7bc 100644 --- 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 @@ -13,6 +13,7 @@ option [@default None] + ; [@key "someProperty"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/models/user.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/user.ml index 179354927dbe..4582d3115276 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/user.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/user.ml @@ -13,42 +13,50 @@ 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 ];; diff --git a/samples/client/petstore/ocaml-oneOf/src/models/child.ml b/samples/client/petstore/ocaml-oneOf/src/models/child.ml index fd9542253c32..ff9a12f2eb4d 100644 --- a/samples/client/petstore/ocaml-oneOf/src/models/child.ml +++ b/samples/client/petstore/ocaml-oneOf/src/models/child.ml @@ -13,6 +13,7 @@ option [@default None] + ; [@key "name"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml/src/models/api_response.ml b/samples/client/petstore/ocaml/src/models/api_response.ml index 1a74ae0cebce..b2a6f6824638 100644 --- a/samples/client/petstore/ocaml/src/models/api_response.ml +++ b/samples/client/petstore/ocaml/src/models/api_response.ml @@ -14,16 +14,19 @@ 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 ];; diff --git a/samples/client/petstore/ocaml/src/models/category.ml b/samples/client/petstore/ocaml/src/models/category.ml index 2d28165f0c24..cb63d1c6ff83 100644 --- a/samples/client/petstore/ocaml/src/models/category.ml +++ b/samples/client/petstore/ocaml/src/models/category.ml @@ -14,11 +14,13 @@ option [@default None] + ; [@key "id"] name: string option [@default None] + ; [@key "name"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml/src/models/order.ml b/samples/client/petstore/ocaml/src/models/order.ml index e78086c56454..3e4e63cda43d 100644 --- a/samples/client/petstore/ocaml/src/models/order.ml +++ b/samples/client/petstore/ocaml/src/models/order.ml @@ -14,21 +14,25 @@ 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.status @@ -41,6 +45,7 @@ option [@default None] + ; [@key "complete"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml/src/models/pet.ml b/samples/client/petstore/ocaml/src/models/pet.ml index 9c365d49ddd4..af5288538870 100644 --- a/samples/client/petstore/ocaml/src/models/pet.ml +++ b/samples/client/petstore/ocaml/src/models/pet.ml @@ -14,22 +14,27 @@ 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.pet_status diff --git a/samples/client/petstore/ocaml/src/models/tag.ml b/samples/client/petstore/ocaml/src/models/tag.ml index 716872196315..8a4cd6418109 100644 --- a/samples/client/petstore/ocaml/src/models/tag.ml +++ b/samples/client/petstore/ocaml/src/models/tag.ml @@ -14,11 +14,13 @@ option [@default None] + ; [@key "id"] name: string option [@default None] + ; [@key "name"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml/src/models/user.ml b/samples/client/petstore/ocaml/src/models/user.ml index 62e4adac58d8..4f79bf2b71c0 100644 --- a/samples/client/petstore/ocaml/src/models/user.ml +++ b/samples/client/petstore/ocaml/src/models/user.ml @@ -14,42 +14,50 @@ 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 ];; From 8f5213dd6e707a193f3a4c8c966d65006b7ff341 Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 22 Aug 2025 17:56:43 +0200 Subject: [PATCH 18/20] Fix: Correctly encode/decode maps --- .../src/main/resources/ocaml/json.mustache | 13 + .../resources/ocaml/model-record.mustache | 2 +- .../src/main/resources/ocaml/to_json.mustache | 53 +-- .../src/apis/another_fake_api.ml | 21 +- .../ocaml-fake-petstore/src/apis/fake_api.ml | 328 +++++++++--------- .../src/apis/fake_classname_tags123_api.ml | 21 +- .../ocaml-fake-petstore/src/apis/pet_api.ml | 42 +-- .../ocaml-fake-petstore/src/apis/store_api.ml | 21 +- .../ocaml-fake-petstore/src/apis/user_api.ml | 102 +++--- .../src/models/additional_properties_class.ml | 4 +- .../fake_big_decimal_map_200_response.ml | 2 +- .../src/models/map_test.ml | 6 +- ...perties_and_additional_properties_class.ml | 2 +- .../src/models/nullable_class.ml | 6 +- .../src/support/jsonSupport.ml | 13 + .../ocaml-oneOf/src/support/jsonSupport.ml | 13 + .../client/petstore/ocaml/src/apis/pet_api.ml | 42 +-- .../petstore/ocaml/src/apis/store_api.ml | 21 +- .../petstore/ocaml/src/apis/user_api.ml | 102 +++--- .../petstore/ocaml/src/support/jsonSupport.ml | 13 + 20 files changed, 425 insertions(+), 402 deletions(-) diff --git a/modules/openapi-generator/src/main/resources/ocaml/json.mustache b/modules/openapi-generator/src/main/resources/ocaml/json.mustache index 061b1be39f8a..0af0c25e759a 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/json.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/json.mustache @@ -53,3 +53,16 @@ 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) + +let to_map_of of_f json = + match json with + | `Assoc l -> + Stdlib.List.fold_right + (fun (k, json) acc -> + match (of_f json, acc) with + | Stdlib.Result.Ok parsed_v, Stdlib.Result.Ok tl -> + Stdlib.Result.Ok ((k, parsed_v) :: tl) + | Stdlib.Result.Error e, _ -> Stdlib.Result.Error e + | _, Stdlib.Result.Error e -> Stdlib.Result.Error e) + l (Stdlib.Result.Ok []) + | _ -> Stdlib.Result.Error "Expected" diff --git a/modules/openapi-generator/src/main/resources/ocaml/model-record.mustache b/modules/openapi-generator/src/main/resources/ocaml/model-record.mustache index a72d3d789d73..6977aed0a4ca 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/model-record.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/model-record.mustache @@ -28,7 +28,7 @@ type t = { {{^required}} option [@default None]{{/required}} {{/isContainer}} {{#isArray}}{{^required}} [@default []]{{/required}}{{/isArray}} - {{#isMap}}{{^required}} [@default []]{{/required}}{{/isMap}} + {{#isMap}}{{^required}} [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: {{{items.datatypeWithEnum}}}]] [@of_yojson JsonSupport.to_map_of [%of_yojson: {{{items.datatypeWithEnum}}}]] {{/required}}{{/isMap}} ; [@key "{{{baseName}}}"] {{/isEnum}} {{/vars}} 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 8bfbaac1fe70..ad7681d20781 100644 --- a/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache +++ b/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache @@ -8,29 +8,32 @@ (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}} +{{^isContainer}} + {{#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}} -{{/isEnum}} -{{^isModel}} - {{^isContainer}} - {{#isEnum}} - Enums.{{{datatypeWithEnum}}}_to_yojson - {{/isEnum}} - {{/isContainer}} -{{/isModel}} -{{#isBinary}}JsonSupport.of_string{{/isBinary}} -{{#isAnyType}}(fun x -> x){{/isAnyType}} + {{#isBinary}}JsonSupport.of_string{{/isBinary}} + {{#isAnyType}}(fun x -> x){{/isAnyType}} + {{#isFreeFormObject}}(fun x -> x){{/isFreeFormObject}} +{{/isContainer}} 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 87b62b8f37af..8e40a663d9be 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,16 +11,17 @@ let call_123_test_special_tags ~client_t = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - - - Client.to_yojson - - + write_as_json_body + + + + + + + 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 0b0fe1568cee..7dd18fe3ceb2 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,16 +55,17 @@ let fake_http_signature_test ~pet_t ?query_1 ?header_1 () = query_1 in let body = Request. - write_as_json_body - - - - - - - Pet.to_yojson - - + write_as_json_body + + + + + + + Pet.to_yojson + + + pet_t in Cohttp_lwt_unix.Client.call `GET uri ~headers ~body >>= fun (resp, body) -> @@ -76,15 +77,16 @@ let fake_outer_boolean_serialize ~body () = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - -JsonSupport.of_bool - - + write_as_json_body + + + + + + JsonSupport.of_bool + + + body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -96,16 +98,17 @@ let fake_outer_composite_serialize ~outer_composite_t () = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - - - Outer_composite.to_yojson - - + write_as_json_body + + + + + + + Outer_composite.to_yojson + + + outer_composite_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -117,15 +120,16 @@ let fake_outer_number_serialize ~body () = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - -JsonSupport.of_float - - - - + write_as_json_body + + + + JsonSupport.of_float + + + + + body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -137,15 +141,16 @@ let fake_outer_string_serialize ~body () = let headers = Request.default_headers in let body = Request. - write_as_json_body JsonSupport.of_string - - - - - - - - + write_as_json_body JsonSupport.of_string + + + + + + + + + body in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -157,16 +162,17 @@ 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 - - - - - - - Outer_object_with_enum_property.to_yojson - - + 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) -> @@ -178,25 +184,17 @@ let test_additional_properties_reference ~request_body = let headers = Request.default_headers in let body = Request. - write_as_json_body (JsonSupport.of_map_of - - - - - - - -(fun x -> x) + 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) -> @@ -208,15 +206,16 @@ let test_body_with_binary ~body = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - - -JsonSupport.of_string - + write_as_json_body + + + + + + + JsonSupport.of_string + + body in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> @@ -228,16 +227,17 @@ let test_body_with_file_schema ~file_schema_test_class_t = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - - - File_schema_test_class.to_yojson - - + 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) -> @@ -264,16 +264,17 @@ let test_body_with_query_params ~query ~user_t = query in let body = Request. - write_as_json_body - - - - - - - User.to_yojson - - + write_as_json_body + + + + + + + User.to_yojson + + + user_t in Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> @@ -285,16 +286,17 @@ let test_client_model ~client_t = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - - - Client.to_yojson - - + write_as_json_body + + + + + + + Client.to_yojson + + + client_t in Cohttp_lwt_unix.Client.call `PATCH uri ~headers ~body >>= fun (resp, body) -> @@ -686,25 +688,17 @@ 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 - - - - - - - - + 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) -> @@ -716,16 +710,17 @@ let test_inline_freeform_additional_properties ~test_inline_freeform_additional_ let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - - - Test_inline_freeform_additional_properties_request.to_yojson - - + 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) -> @@ -776,16 +771,17 @@ let test_nullable ~child_with_nullable_t = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - - - Child_with_nullable.to_yojson - - + 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) -> @@ -988,25 +984,17 @@ 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 - - - - - - - - + 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) -> 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 936bb5092b84..5eb1391914f8 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,16 +12,17 @@ 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 - - - - - - - Client.to_yojson - - + write_as_json_body + + + + + + + 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 ac92862cf1d2..95637700510d 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,16 +11,17 @@ let add_pet ~pet_t = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - - - Pet.to_yojson - - + write_as_json_body + + + + + + + Pet.to_yojson + + + pet_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -138,16 +139,17 @@ let update_pet ~pet_t = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - - - Pet.to_yojson - - + write_as_json_body + + + + + + + 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 6dde02b42a8f..96c52f9b9ed7 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,16 +63,17 @@ let place_order ~order_t = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - - - Order.to_yojson - - + write_as_json_body + + + + + + + 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 ad9b18b360ab..c5f913e57a30 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,16 +11,17 @@ let create_user ~user_t = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - - - User.to_yojson - - + write_as_json_body + + + + + + + User.to_yojson + + + user_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -32,26 +33,18 @@ let create_users_with_array_input ~user = let headers = Request.default_headers in let body = Request. - write_as_json_body (JsonSupport.of_list_of - - - - - - - User.to_yojson - - + 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) -> @@ -63,26 +56,18 @@ let create_users_with_list_input ~user = let headers = Request.default_headers in let body = Request. - write_as_json_body (JsonSupport.of_list_of - - - - - - - User.to_yojson - - + 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) -> @@ -197,16 +182,17 @@ let update_user ~username ~user_t = username in let body = Request. - write_as_json_body - - - - - - - User.to_yojson - - + write_as_json_body + + + + + + + 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-fake-petstore/src/models/additional_properties_class.ml b/samples/client/petstore/ocaml-fake-petstore/src/models/additional_properties_class.ml index 300288477013..1070136f5dec 100644 --- 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 @@ -11,11 +11,11 @@ type t = { map_property: (string * string) list - [@default []] + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: string]] [@of_yojson JsonSupport.to_map_of [%of_yojson: string]] ; [@key "map_property"] map_of_map_property: (string * (string * string) list) list - [@default []] + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: (string * string) list]] [@of_yojson JsonSupport.to_map_of [%of_yojson: (string * string) list]] ; [@key "map_of_map_property"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index 231647487e43..6abba727a131 100644 --- 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 @@ -17,7 +17,7 @@ ; [@key "someId"] some_map: (string * float) list - [@default []] + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: float]] [@of_yojson JsonSupport.to_map_of [%of_yojson: float]] ; [@key "someMap"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index c77105c5f280..22a05cd8e6d1 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/map_test.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/map_test.ml @@ -11,17 +11,17 @@ type t = { map_map_of_string: (string * (string * string) list) list - [@default []] + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: (string * string) list]] [@of_yojson JsonSupport.to_map_of [%of_yojson: (string * string) 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 - [@default []] + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: bool]] [@of_yojson JsonSupport.to_map_of [%of_yojson: bool]] ; [@key "direct_map"] indirect_map: (string * bool) list - [@default []] + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: bool]] [@of_yojson JsonSupport.to_map_of [%of_yojson: bool]] ; [@key "indirect_map"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index ddf696a1ef0d..b3c6cedecc23 100644 --- 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 @@ -23,7 +23,7 @@ ; [@key "dateTime"] map: (string * Animal.t) list - [@default []] + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: Animal.t]] [@of_yojson JsonSupport.to_map_of [%of_yojson: Animal.t]] ; [@key "map"] } [@@deriving yojson { strict = false }, show, eq ];; 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 index a840a1dce496..690eb51db5e7 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/models/nullable_class.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/models/nullable_class.ml @@ -59,15 +59,15 @@ ; [@key "array_items_nullable"] object_nullable_prop: (string * Yojson.Safe.t) list - [@default []] + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: Yojson.Safe.t]] [@of_yojson JsonSupport.to_map_of [%of_yojson: Yojson.Safe.t]] ; [@key "object_nullable_prop"] object_and_items_nullable_prop: (string * Yojson.Safe.t) list - [@default []] + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: Yojson.Safe.t]] [@of_yojson JsonSupport.to_map_of [%of_yojson: Yojson.Safe.t]] ; [@key "object_and_items_nullable_prop"] object_items_nullable: (string * Yojson.Safe.t) list - [@default []] + [@default []] [@to_yojson JsonSupport.of_map_of [%to_yojson: Yojson.Safe.t]] [@of_yojson JsonSupport.to_map_of [%of_yojson: Yojson.Safe.t]] ; [@key "object_items_nullable"] } [@@deriving yojson { strict = false }, show, eq ];; diff --git a/samples/client/petstore/ocaml-fake-petstore/src/support/jsonSupport.ml b/samples/client/petstore/ocaml-fake-petstore/src/support/jsonSupport.ml index 061b1be39f8a..0af0c25e759a 100644 --- a/samples/client/petstore/ocaml-fake-petstore/src/support/jsonSupport.ml +++ b/samples/client/petstore/ocaml-fake-petstore/src/support/jsonSupport.ml @@ -53,3 +53,16 @@ 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) + +let to_map_of of_f json = + match json with + | `Assoc l -> + Stdlib.List.fold_right + (fun (k, json) acc -> + match (of_f json, acc) with + | Stdlib.Result.Ok parsed_v, Stdlib.Result.Ok tl -> + Stdlib.Result.Ok ((k, parsed_v) :: tl) + | Stdlib.Result.Error e, _ -> Stdlib.Result.Error e + | _, Stdlib.Result.Error e -> Stdlib.Result.Error e) + l (Stdlib.Result.Ok []) + | _ -> Stdlib.Result.Error "Expected" diff --git a/samples/client/petstore/ocaml-oneOf/src/support/jsonSupport.ml b/samples/client/petstore/ocaml-oneOf/src/support/jsonSupport.ml index 061b1be39f8a..0af0c25e759a 100644 --- a/samples/client/petstore/ocaml-oneOf/src/support/jsonSupport.ml +++ b/samples/client/petstore/ocaml-oneOf/src/support/jsonSupport.ml @@ -53,3 +53,16 @@ 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) + +let to_map_of of_f json = + match json with + | `Assoc l -> + Stdlib.List.fold_right + (fun (k, json) acc -> + match (of_f json, acc) with + | Stdlib.Result.Ok parsed_v, Stdlib.Result.Ok tl -> + Stdlib.Result.Ok ((k, parsed_v) :: tl) + | Stdlib.Result.Error e, _ -> Stdlib.Result.Error e + | _, Stdlib.Result.Error e -> Stdlib.Result.Error e) + l (Stdlib.Result.Ok []) + | _ -> Stdlib.Result.Error "Expected" diff --git a/samples/client/petstore/ocaml/src/apis/pet_api.ml b/samples/client/petstore/ocaml/src/apis/pet_api.ml index 8f272ccda4bf..386163121bda 100644 --- a/samples/client/petstore/ocaml/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml/src/apis/pet_api.ml @@ -11,16 +11,17 @@ let add_pet ~pet_t = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - - - Pet.to_yojson - - + write_as_json_body + + + + + + + Pet.to_yojson + + + pet_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -138,16 +139,17 @@ let update_pet ~pet_t = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - - - Pet.to_yojson - - + write_as_json_body + + + + + + + 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 68811d326070..510e9ea48325 100644 --- a/samples/client/petstore/ocaml/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml/src/apis/store_api.ml @@ -63,16 +63,17 @@ let place_order ~order_t = let headers = Request.default_headers in let body = Request. - write_as_json_body - - - - - - - Order.to_yojson - - + write_as_json_body + + + + + + + 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 a2e928a71cf4..d034b4b22851 100644 --- a/samples/client/petstore/ocaml/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml/src/apis/user_api.ml @@ -12,16 +12,17 @@ let create_user ~user_t = let headers = Cohttp.Header.add headers "api_key" Request.api_key in let body = Request. - write_as_json_body - - - - - - - User.to_yojson - - + write_as_json_body + + + + + + + User.to_yojson + + + user_t in Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> @@ -34,26 +35,18 @@ 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 - - - - - - - User.to_yojson - - + 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) -> @@ -66,26 +59,18 @@ 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 - - - - - - - User.to_yojson - - + 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) -> @@ -203,16 +188,17 @@ let update_user ~username ~user_t = username in let body = Request. - write_as_json_body - - - - - - - User.to_yojson - - + write_as_json_body + + + + + + + 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/support/jsonSupport.ml b/samples/client/petstore/ocaml/src/support/jsonSupport.ml index 061b1be39f8a..0af0c25e759a 100644 --- a/samples/client/petstore/ocaml/src/support/jsonSupport.ml +++ b/samples/client/petstore/ocaml/src/support/jsonSupport.ml @@ -53,3 +53,16 @@ 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) + +let to_map_of of_f json = + match json with + | `Assoc l -> + Stdlib.List.fold_right + (fun (k, json) acc -> + match (of_f json, acc) with + | Stdlib.Result.Ok parsed_v, Stdlib.Result.Ok tl -> + Stdlib.Result.Ok ((k, parsed_v) :: tl) + | Stdlib.Result.Error e, _ -> Stdlib.Result.Error e + | _, Stdlib.Result.Error e -> Stdlib.Result.Error e) + l (Stdlib.Result.Ok []) + | _ -> Stdlib.Result.Error "Expected" From 2ae3a63a36cbf5675a08d5738368ba6cf19796bc Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 22 Aug 2025 18:15:10 +0200 Subject: [PATCH 19/20] Refresh documentation --- docs/generators/ocaml.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/docs/generators/ocaml.md b/docs/generators/ocaml.md index d2bbfecfa3e0..9f98b06ac073 100644 --- a/docs/generators/ocaml.md +++ b/docs/generators/ocaml.md @@ -209,8 +209,8 @@ These options may be applied as additional-properties (cli) or configOptions (pl |Polymorphism|✗|OAS2,OAS3 |Union|✗|OAS3 |allOf|✗|OAS2,OAS3 -|anyOf|✗|OAS3 -|oneOf|✗|OAS3 +|anyOf|✓|OAS3 +|oneOf|✓|OAS3 |not|✗|OAS3 ### Security Feature From ca6bd1440fcd4532c29b40867c577727dfe30a0f Mon Sep 17 00:00:00 2001 From: Julien Debon Date: Fri, 22 Aug 2025 19:09:43 +0200 Subject: [PATCH 20/20] Refresh after merging master --- .../petstore/ocaml-fake-petstore/.openapi-generator/VERSION | 2 +- samples/client/petstore/ocaml-fake-petstore/README.md | 2 +- samples/client/petstore/ocaml-oneOf/.openapi-generator/VERSION | 2 +- samples/client/petstore/ocaml-oneOf/README.md | 2 +- 4 files changed, 4 insertions(+), 4 deletions(-) diff --git a/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/VERSION b/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/VERSION index fc74d6ceba8e..5e5282953086 100644 --- a/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/VERSION +++ b/samples/client/petstore/ocaml-fake-petstore/.openapi-generator/VERSION @@ -1 +1 @@ -7.15.0-SNAPSHOT +7.16.0-SNAPSHOT diff --git a/samples/client/petstore/ocaml-fake-petstore/README.md b/samples/client/petstore/ocaml-fake-petstore/README.md index 051d999bbf64..d0ad85e9f3cf 100644 --- a/samples/client/petstore/ocaml-fake-petstore/README.md +++ b/samples/client/petstore/ocaml-fake-petstore/README.md @@ -5,7 +5,7 @@ This OCaml package is automatically generated by the [OpenAPI Generator](https:/ - API version: 1.0.0 - Package version: 1.0.0 -- Generator version: 7.15.0-SNAPSHOT +- Generator version: 7.16.0-SNAPSHOT - Build package: org.openapitools.codegen.languages.OCamlClientCodegen ## Requirements. diff --git a/samples/client/petstore/ocaml-oneOf/.openapi-generator/VERSION b/samples/client/petstore/ocaml-oneOf/.openapi-generator/VERSION index fc74d6ceba8e..5e5282953086 100644 --- a/samples/client/petstore/ocaml-oneOf/.openapi-generator/VERSION +++ b/samples/client/petstore/ocaml-oneOf/.openapi-generator/VERSION @@ -1 +1 @@ -7.15.0-SNAPSHOT +7.16.0-SNAPSHOT diff --git a/samples/client/petstore/ocaml-oneOf/README.md b/samples/client/petstore/ocaml-oneOf/README.md index b9cbd1f3d9a1..d33f72445fdf 100644 --- a/samples/client/petstore/ocaml-oneOf/README.md +++ b/samples/client/petstore/ocaml-oneOf/README.md @@ -5,7 +5,7 @@ This OCaml package is automatically generated by the [OpenAPI Generator](https:/ - API version: 1.0.0 - Package version: 1.0.0 -- Generator version: 7.15.0-SNAPSHOT +- Generator version: 7.16.0-SNAPSHOT - Build package: org.openapitools.codegen.languages.OCamlClientCodegen ## Requirements.