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 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/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"); 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..b2a5a9037a4d 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}} @@ -42,7 +42,10 @@ 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. + {{#isByteArray}}write_string_body {{{paramName}}}{{/isByteArray}} + {{^isByteArray}}write_as_json_body {{> to_json}} {{{paramName}}}{{/isByteArray}} + in {{/bodyParams}} {{^hasBodyParam}} {{#hasFormParams}} 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..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))) @@ -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 @@ -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_json.mustache b/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache index 99e45aafb78e..8bfbaac1fe70 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,36 @@ -{{#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}} +{{#isBinary}}JsonSupport.of_string{{/isBinary}} +{{#isAnyType}}(fun x -> x){{/isAnyType}} 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..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 +1,26 @@ -{{#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 +{{#isArray}} + {{#items}}(Stdlib.List.map {{> to_string}}){{/items}} +{{/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}} + {{#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}} + {{#isEnumRef}}(failwith "Unsupported: enum reference"){{/isEnumRef}} + {{/isContainer}} +{{/isModel}} 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..87b62b8f37af --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/another_fake_api.ml @@ -0,0 +1,28 @@ +(* + * 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..0b0fe1568cee --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_api.ml @@ -0,0 +1,1014 @@ +(* + * 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_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 + +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 + + + + + + +JsonSupport.of_string + + 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 + + + + + + + + + + + + + (failwith "Unsupported: enum reference") +) + + + + + + + + + + + + + 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_exploded_form_object uri "language" + + + + + + + + + + (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..936bb5092b84 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/fake_classname_tags123_api.ml @@ -0,0 +1,29 @@ +(* + * 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..ac92862cf1d2 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/pet_api.ml @@ -0,0 +1,317 @@ +(* + * 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..6dde02b42a8f --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/store_api.ml @@ -0,0 +1,80 @@ +(* + * 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..ad9b18b360ab --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/apis/user_api.ml @@ -0,0 +1,214 @@ +(* + * 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..cbb1a71ea697 --- /dev/null +++ b/samples/client/petstore/ocaml-fake-petstore/src/support/request.ml @@ -0,0 +1,110 @@ +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.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 diff --git a/samples/client/petstore/ocaml/src/apis/pet_api.ml b/samples/client/petstore/ocaml/src/apis/pet_api.ml index 9df027a393cb..8f272ccda4bf 100644 --- a/samples/client/petstore/ocaml/src/apis/pet_api.ml +++ b/samples/client/petstore/ocaml/src/apis/pet_api.ml @@ -9,7 +9,20 @@ 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 +30,36 @@ 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 +67,10 @@ 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 +78,34 @@ 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 +114,21 @@ 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 +136,20 @@ 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 +157,52 @@ 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 +211,52 @@ 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..68811d326070 100644 --- a/samples/client/petstore/ocaml/src/apis/store_api.ml +++ b/samples/client/petstore/ocaml/src/apis/store_api.ml @@ -9,7 +9,21 @@ 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 +39,21 @@ 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 +61,20 @@ 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..a2e928a71cf4 100644 --- a/samples/client/petstore/ocaml/src/apis/user_api.ml +++ b/samples/client/petstore/ocaml/src/apis/user_api.ml @@ -10,7 +10,20 @@ 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 +32,30 @@ 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 +64,30 @@ 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 +96,21 @@ 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 +118,21 @@ 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 +140,36 @@ 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 +186,35 @@ 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..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))) @@ -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 @@ -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 =