diff --git a/README.md b/README.md index 0aaf86e953b1..065ec69d340e 100644 --- a/README.md +++ b/README.md @@ -59,7 +59,7 @@ OpenAPI Generator allows generation of API client libraries (SDK generation), se | | Languages/Frameworks | |-|-| -**API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later), **C++** (cpp-restsdk, Qt5, Tizen), **Clojure**, **Dart (1.x, 2.x)**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client), **Kotlin**, **Lua**, **Node.js/JavaScript** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types) **Objective-C**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (rust, rust-server), **Scala** (akka, http4s, scalaz, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x), **Typescript** (AngularJS, Angular (2.x - 7.x), Aurelia, Axios, Fetch, Inversify, jQuery, Node, Rxjs) +**API clients** | **ActionScript**, **Ada**, **Apex**, **Bash**, **C**, **C#** (.net 2.0, 3.5 or later), **C++** (cpp-restsdk, Qt5, Tizen), **Clojure**, **Dart (1.x, 2.x)**, **Elixir**, **Elm**, **Eiffel**, **Erlang**, **Go**, **Groovy**, **Haskell** (http-client, Servant), **Java** (Jersey1.x, Jersey2.x, OkHttp, Retrofit1.x, Retrofit2.x, Feign, RestTemplate, RESTEasy, Vertx, Google API Client Library for Java, Rest-assured, Spring 5 Web Client), **Kotlin**, **Lua**, **Node.js/JavaScript** (ES5, ES6, AngularJS with Google Closure Compiler annotations, Flow types), **Objective-C**, **OCaml**, **Perl**, **PHP**, **PowerShell**, **Python**, **R**, **Ruby**, **Rust** (rust, rust-server), **Scala** (akka, http4s, scalaz, swagger-async-httpclient), **Swift** (2.x, 3.x, 4.x), **Typescript** (AngularJS, Angular (2.x - 7.x), Aurelia, Axios, Fetch, Inversify, jQuery, Node, Rxjs) **Server stubs** | **Ada**, **C#** (ASP.NET Core, NancyFx), **C++** (Pistache, Restbed, Qt5 QHTTPEngine), **Erlang**, **F#** (Giraffe), **Go** (net/http, Gin), **Haskell** (Servant), **Java** (MSF4J, Spring, Undertow, JAX-RS: CDI, CXF, Inflector, RestEasy, Play Framework, [PKMST](https://github.com/ProKarma-Inc/pkmst-getting-started-examples)), **Kotlin** (Spring Boot, Ktor), **PHP** (Laravel, Lumen, Slim, Silex, [Symfony](https://symfony.com/), [Zend Expressive](https://github.com/zendframework/zend-expressive)), **Python** (Flask), **NodeJS**, **Ruby** (Sinatra, Rails5), **Rust** (rust-server), **Scala** ([Finch](https://github.com/finagle/finch), [Lagom](https://github.com/lagom/lagom), [Play](https://www.playframework.com/), Scalatra) **API documentation generators** | **HTML**, **Confluence Wiki** **Configuration files** | [**Apache2**](https://httpd.apache.org/) @@ -680,6 +680,7 @@ Here is a list of template creators: * JMeter: @davidkiss * Kotlin: @jimschubert [:heart:](https://www.patreon.com/jimschubert) * Lua: @daurnimator + * OCaml: @cgensoul * Perl: @wing328 [:heart:](https://www.patreon.com/wing328) * PHP (Guzzle): @baartosz * PowerShell: @beatcracker diff --git a/bin/ocaml-client-petstore.sh b/bin/ocaml-petstore.sh similarity index 71% rename from bin/ocaml-client-petstore.sh rename to bin/ocaml-petstore.sh index d124ad74b0a6..9b3cb70990eb 100755 --- a/bin/ocaml-client-petstore.sh +++ b/bin/ocaml-petstore.sh @@ -26,9 +26,9 @@ then fi # if you've executed sbt assembly previously it will use that instead. -export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DdebugOperations -DloggerPath=conf/log4j.properties" +export JAVA_OPTS="${JAVA_OPTS} -Xmx1024M -DloggerPath=conf/log4j.properties" -args="generate -t modules/openapi-generator/src/main/resources/ocaml-client -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g ocaml-client -o samples/client/petstore/ocaml-client --additional-properties packageName=petstore_client $@" +args="generate -t modules/openapi-generator/src/main/resources/ocaml -i modules/openapi-generator/src/test/resources/2_0/petstore.yaml -g ocaml -o samples/client/petstore/ocaml --additional-properties packageName=petstore_client $@" echo "java ${JAVA_OPTS} -jar ${executable} ${args}" java $JAVA_OPTS -jar $executable $args diff --git a/bin/windows/ocaml-petstore.bat b/bin/windows/ocaml-petstore.bat new file mode 100755 index 000000000000..aa59c18b8278 --- /dev/null +++ b/bin/windows/ocaml-petstore.bat @@ -0,0 +1,10 @@ +set executable=.\modules\openapi-generator-cli\target\openapi-generator-cli.jar + +If Not Exist %executable% ( + mvn clean package +) + +REM set JAVA_OPTS=%JAVA_OPTS% -Xmx1024M -DloggerPath=conf/log4j.properties +set ags=generate -i modules\openapi-generator\src\test\resources\2_0\petstore.yaml -g ocaml -o samples\client\petstore\ocaml + +java %JAVA_OPTS% -jar %executable% %ags% diff --git a/docs/generators.md b/docs/generators.md index 12c7ecdfedc6..46a9c92365fd 100644 --- a/docs/generators.md +++ b/docs/generators.md @@ -39,7 +39,7 @@ The following generators are available: - [kotlin](generators/kotlin.md) - [lua](generators/lua.md) - [objc](generators/objc.md) - - [ocaml-client](generators/ocaml-client.md) + - [ocaml](generators/ocaml.md) - [perl](generators/perl.md) - [php](generators/php.md) - [powershell](generators/powershell.md) diff --git a/docs/generators/ocaml.md b/docs/generators/ocaml.md new file mode 100644 index 000000000000..7397b1c31bf9 --- /dev/null +++ b/docs/generators/ocaml.md @@ -0,0 +1,13 @@ + +--- +id: generator-opts-client-ocaml +title: Config Options for ocaml +sidebar_label: ocaml +--- + +| Option | Description | Values | Default | +| ------ | ----------- | ------ | ------- | +|sortParamsByRequiredFlag|Sort method arguments to place required parameters before optional parameters.| |true| +|ensureUniqueParams|Whether to ensure parameter names are unique in an operation (rename parameters that are not).| |true| +|allowUnicodeIdentifiers|boolean, toggles whether unicode identifiers are allowed in names or not, default is false| |false| +|prependFormOrBodyParameters|Add form or body parameters to the beginning of the parameter list.| |false| 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 5df13a046b13..2ad91492b2e0 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 @@ -59,7 +59,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig } public String getName() { - return "ocaml-client"; + return "ocaml"; } public String getHelp() { @@ -68,13 +68,13 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig public OCamlClientCodegen() { super(); - outputFolder = "generated-code/ocaml-client"; + outputFolder = "generated-code/ocaml"; modelTemplateFiles.put("model.mustache", ".ml"); // default HIDE_GENERATION_TIMESTAMP to true hideGenerationTimestamp = Boolean.TRUE; - embeddedTemplateDir = templateDir = "ocaml-client"; + embeddedTemplateDir = templateDir = "ocaml"; setReservedWordsLowerCase( Arrays.asList( @@ -95,6 +95,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig supportingFiles.add(new SupportingFile("dune.mustache", "", "dune")); supportingFiles.add(new SupportingFile("dune-project.mustache", "", "dune-project")); + supportingFiles.add(new SupportingFile("readme.mustache", "", "README.md")); defaultIncludes = new HashSet<>( Arrays.asList( @@ -106,7 +107,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig "char", "string", "list" - ) + ) ); languageSpecificPrimitives = new HashSet<>( @@ -249,7 +250,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig private void collectEnumSchemas(String parentName, String sName, Schema schema) { if (schema instanceof ArraySchema) { - collectEnumSchemas(parentName, sName, ((ArraySchema)schema).getItems()); + collectEnumSchemas(parentName, sName, ((ArraySchema) schema).getItems()); } else if (schema instanceof MapSchema && schema.getAdditionalProperties() instanceof Schema) { collectEnumSchemas(parentName, sName, (Schema) schema.getAdditionalProperties()); } else if (isEnumSchema(schema)) { @@ -348,7 +349,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig } if (!hasDefName) { int i = 0; - String candidate;; + String candidate; while (definitiveNames.containsKey(candidate = sanitizeOCamlTypeName(nameCandidates.get(0) + "_" + i))) { i++; } @@ -361,7 +362,7 @@ public class OCamlClientCodegen extends DefaultCodegen implements CodegenConfig private void collectEnumSchemas(OpenAPI openAPI) { Components components = openAPI.getComponents(); - if (components != null && components.getSchemas() != null && !components.getSchemas().isEmpty()) { + if (components != null && components.getSchemas() != null && !components.getSchemas().isEmpty()) { collectEnumSchemas(null, components.getSchemas()); } diff --git a/modules/openapi-generator/src/main/resources/ocaml-client/api-impl.mustache b/modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/ocaml-client/api-impl.mustache rename to modules/openapi-generator/src/main/resources/ocaml/api-impl.mustache diff --git a/modules/openapi-generator/src/main/resources/ocaml-client/api-intf.mustache b/modules/openapi-generator/src/main/resources/ocaml/api-intf.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/ocaml-client/api-intf.mustache rename to modules/openapi-generator/src/main/resources/ocaml/api-intf.mustache diff --git a/modules/openapi-generator/src/main/resources/ocaml-client/dune-project.mustache b/modules/openapi-generator/src/main/resources/ocaml/dune-project.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/ocaml-client/dune-project.mustache rename to modules/openapi-generator/src/main/resources/ocaml/dune-project.mustache diff --git a/modules/openapi-generator/src/main/resources/ocaml-client/dune.mustache b/modules/openapi-generator/src/main/resources/ocaml/dune.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/ocaml-client/dune.mustache rename to modules/openapi-generator/src/main/resources/ocaml/dune.mustache diff --git a/modules/openapi-generator/src/main/resources/ocaml-client/enums.mustache b/modules/openapi-generator/src/main/resources/ocaml/enums.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/ocaml-client/enums.mustache rename to modules/openapi-generator/src/main/resources/ocaml/enums.mustache diff --git a/modules/openapi-generator/src/main/resources/ocaml-client/json.mustache b/modules/openapi-generator/src/main/resources/ocaml/json.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/ocaml-client/json.mustache rename to modules/openapi-generator/src/main/resources/ocaml/json.mustache diff --git a/modules/openapi-generator/src/main/resources/ocaml-client/lib.mustache b/modules/openapi-generator/src/main/resources/ocaml/lib.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/ocaml-client/lib.mustache rename to modules/openapi-generator/src/main/resources/ocaml/lib.mustache diff --git a/modules/openapi-generator/src/main/resources/ocaml-client/model.mustache b/modules/openapi-generator/src/main/resources/ocaml/model.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/ocaml-client/model.mustache rename to modules/openapi-generator/src/main/resources/ocaml/model.mustache diff --git a/modules/openapi-generator/src/main/resources/ocaml-client/of_json.mustache b/modules/openapi-generator/src/main/resources/ocaml/of_json.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/ocaml-client/of_json.mustache rename to modules/openapi-generator/src/main/resources/ocaml/of_json.mustache diff --git a/modules/openapi-generator/src/main/resources/ocaml-client/partial_header.mustache b/modules/openapi-generator/src/main/resources/ocaml/partial_header.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/ocaml-client/partial_header.mustache rename to modules/openapi-generator/src/main/resources/ocaml/partial_header.mustache diff --git a/modules/openapi-generator/src/main/resources/ocaml/readme.mustache b/modules/openapi-generator/src/main/resources/ocaml/readme.mustache new file mode 100644 index 000000000000..2ecff7daa88b --- /dev/null +++ b/modules/openapi-generator/src/main/resources/ocaml/readme.mustache @@ -0,0 +1,35 @@ +# {{{projectName}}} +{{#appDescription}} +{{{appDescription}}} +{{/appDescription}} + +This OCaml package is automatically generated by the [OpenAPI Generator](https://openapi-generator.tech) project: + +- API version: {{appVersion}} +- Package version: {{packageVersion}} +{{^hideGenerationTimestamp}} +- Build date: {{generatedDate}} +{{/hideGenerationTimestamp}} +- Build package: {{generatorClass}} +{{#infoUrl}} +For more information, please visit [{{{infoUrl}}}]({{{infoUrl}}}) +{{/infoUrl}} + +## Requirements. + +OCaml 4.x + +## Installation + +Please run the following commands to build the package `{{{packageName}}}`: + +```sh +opam install ppx_deriving_yojson cohttp ppx_deriving cohttp-lwt-unix +eval $(opam env) +dune build +``` + +## Getting Started + +TODO + diff --git a/modules/openapi-generator/src/main/resources/ocaml-client/support.mustache b/modules/openapi-generator/src/main/resources/ocaml/support.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/ocaml-client/support.mustache rename to modules/openapi-generator/src/main/resources/ocaml/support.mustache diff --git a/modules/openapi-generator/src/main/resources/ocaml-client/to_json.mustache b/modules/openapi-generator/src/main/resources/ocaml/to_json.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/ocaml-client/to_json.mustache rename to modules/openapi-generator/src/main/resources/ocaml/to_json.mustache diff --git a/modules/openapi-generator/src/main/resources/ocaml-client/to_string.mustache b/modules/openapi-generator/src/main/resources/ocaml/to_string.mustache similarity index 100% rename from modules/openapi-generator/src/main/resources/ocaml-client/to_string.mustache rename to modules/openapi-generator/src/main/resources/ocaml/to_string.mustache diff --git a/samples/client/petstore/ocaml/.openapi-generator-ignore b/samples/client/petstore/ocaml/.openapi-generator-ignore new file mode 100644 index 000000000000..7484ee590a38 --- /dev/null +++ b/samples/client/petstore/ocaml/.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/.openapi-generator/VERSION b/samples/client/petstore/ocaml/.openapi-generator/VERSION new file mode 100644 index 000000000000..83a328a9227e --- /dev/null +++ b/samples/client/petstore/ocaml/.openapi-generator/VERSION @@ -0,0 +1 @@ +4.1.0-SNAPSHOT \ No newline at end of file diff --git a/samples/client/petstore/ocaml/README.md b/samples/client/petstore/ocaml/README.md new file mode 100644 index 000000000000..165b35333586 --- /dev/null +++ b/samples/client/petstore/ocaml/README.md @@ -0,0 +1,26 @@ +# +This is a sample server Petstore server. For this sample, you can use the api key `special-key` to test the authorization filters. + +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 +- Build package: org.openapitools.codegen.languages.OCamlClientCodegen + +## Requirements. + +OCaml 4.x + +## Installation + +Please run the following commands to build the package `petstore_client`: + +```sh +opam install ppx_deriving_yojson cohttp ppx_deriving cohttp-lwt-unix +dune build +``` + +## Getting Started + +TODO + diff --git a/samples/client/petstore/ocaml/dune b/samples/client/petstore/ocaml/dune new file mode 100644 index 000000000000..ed1c4d90e3df --- /dev/null +++ b/samples/client/petstore/ocaml/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/dune-project b/samples/client/petstore/ocaml/dune-project new file mode 100644 index 000000000000..79d86e3c901a --- /dev/null +++ b/samples/client/petstore/ocaml/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/petstore_client.opam b/samples/client/petstore/ocaml/petstore_client.opam new file mode 100644 index 000000000000..3c3603c2f14c --- /dev/null +++ b/samples/client/petstore/ocaml/petstore_client.opam @@ -0,0 +1,15 @@ +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" ] +build: ["dune" "build" "-p" name] \ No newline at end of file diff --git a/samples/client/petstore/ocaml/src/apis/pet_api.ml b/samples/client/petstore/ocaml/src/apis/pet_api.ml new file mode 100644 index 000000000000..207503b9061a --- /dev/null +++ b/samples/client/petstore/ocaml/src/apis/pet_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 add_pet body = + let open Lwt in + let uri = Request.build_uri "/pet" in + let headers = Request.default_headers in + let body = Request.write_json_body Pet.to_yojson body in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let delete_pet pet_id api_key = + let open Lwt in + let uri = Request.build_uri "/pet/{petId}" in + let headers = Request.default_headers in + let headers = Cohttp.Header.add headers "api_key" (api_key) in + let uri = Request.replace_path_param uri "petId" (Int64.to_string pet_id) in + Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) -> + Request.handle_unit_response resp + +let find_pets_by_status status = + let open Lwt in + let uri = Request.build_uri "/pet/findByStatus" in + let headers = Request.default_headers in + let uri = Uri.add_query_param uri ("status", List.map Enums.show_pet_status status) in + Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> + Request.read_json_body_as_list_of (JsonSupport.unwrap Pet.of_yojson) resp body + +let find_pets_by_tags tags = + let open Lwt in + let uri = Request.build_uri "/pet/findByTags" in + let headers = Request.default_headers in + let uri = Uri.add_query_param uri ("tags", tags) in + Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> + Request.read_json_body_as_list_of (JsonSupport.unwrap Pet.of_yojson) resp body + +let get_pet_by_id pet_id = + let open Lwt in + let uri = Request.build_uri "/pet/{petId}" in + let headers = Request.default_headers in + let uri = Request.replace_path_param uri "petId" (Int64.to_string pet_id) in + Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.unwrap Pet.of_yojson) resp body + +let update_pet body = + let open Lwt in + let uri = Request.build_uri "/pet" in + let headers = Request.default_headers in + let body = Request.write_json_body Pet.to_yojson body in + Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let update_pet_with_form pet_id name status = + let open Lwt in + let uri = Request.build_uri "/pet/{petId}" in + let headers = Request.default_headers in + let uri = Request.replace_path_param uri "petId" (Int64.to_string pet_id) in + let body = Request.init_form_encoded_body () in + let body = Request.add_form_encoded_body_param body ("name", name) in + let body = Request.add_form_encoded_body_param body ("status", status) in + let body = Request.finalize_form_encoded_body body in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let upload_file pet_id additional_metadata file = + let open Lwt in + let uri = Request.build_uri "/pet/{petId}/uploadImage" in + let headers = Request.default_headers in + let uri = Request.replace_path_param uri "petId" (Int64.to_string pet_id) in + let body = Request.init_form_encoded_body () in + let body = Request.add_form_encoded_body_param body ("additional_metadata", additional_metadata) in + let body = Request.add_form_encoded_body_param body ("file", 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/pet_api.mli b/samples/client/petstore/ocaml/src/apis/pet_api.mli new file mode 100644 index 000000000000..0cc31e085cf7 --- /dev/null +++ b/samples/client/petstore/ocaml/src/apis/pet_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 add_pet : Pet.t -> unit Lwt.t +val delete_pet : int64 -> string -> unit Lwt.t +val find_pets_by_status : Enums.pet_status list -> Pet.t list Lwt.t +val find_pets_by_tags : string list -> Pet.t list Lwt.t +val get_pet_by_id : int64 -> Pet.t Lwt.t +val update_pet : Pet.t -> unit Lwt.t +val update_pet_with_form : int64 -> string -> string -> unit Lwt.t +val upload_file : int64 -> string -> string -> Api_response.t Lwt.t diff --git a/samples/client/petstore/ocaml/src/apis/store_api.ml b/samples/client/petstore/ocaml/src/apis/store_api.ml new file mode 100644 index 000000000000..cebccabdd853 --- /dev/null +++ b/samples/client/petstore/ocaml/src/apis/store_api.ml @@ -0,0 +1,38 @@ +(* + * 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 in + let uri = Request.build_uri "/store/order/{orderId}" in + let headers = Request.default_headers in + let uri = Request.replace_path_param uri "orderId" (order_id) in + Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) -> + Request.handle_unit_response resp + +let get_inventory () = + let open Lwt in + let uri = Request.build_uri "/store/inventory" in + let headers = Request.default_headers in + Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> + Request.read_json_body_as_map_of (JsonSupport.to_int32) resp body + +let get_order_by_id order_id = + let open Lwt in + let uri = Request.build_uri "/store/order/{orderId}" in + let headers = Request.default_headers in + let uri = Request.replace_path_param uri "orderId" (Int64.to_string order_id) in + Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.unwrap Order.of_yojson) resp body + +let place_order body = + let open Lwt in + let uri = Request.build_uri "/store/order" in + let headers = Request.default_headers in + let body = Request.write_json_body Order.to_yojson body in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.unwrap Order.of_yojson) resp body + diff --git a/samples/client/petstore/ocaml/src/apis/store_api.mli b/samples/client/petstore/ocaml/src/apis/store_api.mli new file mode 100644 index 000000000000..bc3c93eb494c --- /dev/null +++ b/samples/client/petstore/ocaml/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 : string -> unit Lwt.t +val get_inventory : unit -> (string * int32) list Lwt.t +val get_order_by_id : int64 -> Order.t Lwt.t +val place_order : Order.t -> Order.t Lwt.t diff --git a/samples/client/petstore/ocaml/src/apis/user_api.ml b/samples/client/petstore/ocaml/src/apis/user_api.ml new file mode 100644 index 000000000000..d05d71682a3d --- /dev/null +++ b/samples/client/petstore/ocaml/src/apis/user_api.ml @@ -0,0 +1,72 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +let create_user body = + let open Lwt in + let uri = Request.build_uri "/user" in + let headers = Request.default_headers in + let body = Request.write_json_body User.to_yojson body in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let create_users_with_array_input body = + let open Lwt in + let uri = Request.build_uri "/user/createWithArray" in + let headers = Request.default_headers in + let body = Request.write_json_body (JsonSupport.of_list_of User.to_yojson) body in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let create_users_with_list_input body = + let open Lwt in + let uri = Request.build_uri "/user/createWithList" in + let headers = Request.default_headers in + let body = Request.write_json_body (JsonSupport.of_list_of User.to_yojson) body in + Cohttp_lwt_unix.Client.call `POST uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + +let delete_user username = + let open Lwt in + let uri = Request.build_uri "/user/{username}" in + let headers = Request.default_headers in + let uri = Request.replace_path_param uri "username" (username) in + Cohttp_lwt_unix.Client.call `DELETE uri ~headers >>= fun (resp, body) -> + Request.handle_unit_response resp + +let get_user_by_name username = + let open Lwt in + let uri = Request.build_uri "/user/{username}" in + let headers = Request.default_headers in + let uri = Request.replace_path_param uri "username" (username) in + Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.unwrap User.of_yojson) resp body + +let login_user username password = + let open Lwt in + let uri = Request.build_uri "/user/login" in + let headers = Request.default_headers in + let uri = Uri.add_query_param' uri ("username", username) in + let uri = Uri.add_query_param' uri ("password", password) in + Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> + Request.read_json_body_as (JsonSupport.to_string) resp body + +let logout_user () = + let open Lwt in + let uri = Request.build_uri "/user/logout" in + let headers = Request.default_headers in + Cohttp_lwt_unix.Client.call `GET uri ~headers >>= fun (resp, body) -> + Request.handle_unit_response resp + +let update_user username body = + let open Lwt in + let uri = Request.build_uri "/user/{username}" in + let headers = Request.default_headers in + let uri = Request.replace_path_param uri "username" (username) in + let body = Request.write_json_body User.to_yojson body in + Cohttp_lwt_unix.Client.call `PUT uri ~headers ~body >>= fun (resp, body) -> + Request.handle_unit_response resp + diff --git a/samples/client/petstore/ocaml/src/apis/user_api.mli b/samples/client/petstore/ocaml/src/apis/user_api.mli new file mode 100644 index 000000000000..5191a2ea41bb --- /dev/null +++ b/samples/client/petstore/ocaml/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 -> unit Lwt.t +val create_users_with_array_input : User.t list -> unit Lwt.t +val create_users_with_list_input : User.t list -> unit Lwt.t +val delete_user : string -> unit Lwt.t +val get_user_by_name : string -> User.t Lwt.t +val login_user : string -> string -> string Lwt.t +val logout_user : unit -> unit Lwt.t +val update_user : string -> User.t -> unit Lwt.t diff --git a/samples/client/petstore/ocaml/src/models/api_response.ml b/samples/client/petstore/ocaml/src/models/api_response.ml new file mode 100644 index 000000000000..f1b960d14496 --- /dev/null +++ b/samples/client/petstore/ocaml/src/models/api_response.ml @@ -0,0 +1,21 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + * Schema Api_response.t : Describes the result of uploading an image resource + *) + +type t = { + code: int32 option [@default None]; + _type: string option [@default None]; + message: string option [@default None]; +} [@@deriving yojson, show ];; + +(** Describes the result of uploading an image resource *) +let create () : t = { + code = None; + _type = None; + message = None; +} + diff --git a/samples/client/petstore/ocaml/src/models/category.ml b/samples/client/petstore/ocaml/src/models/category.ml new file mode 100644 index 000000000000..31b9c3aab1dd --- /dev/null +++ b/samples/client/petstore/ocaml/src/models/category.ml @@ -0,0 +1,19 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + * Schema Category.t : A category for a pet + *) + +type t = { + id: int64 option [@default None]; + name: string option [@default None]; +} [@@deriving yojson, show ];; + +(** A category for a pet *) +let create () : t = { + id = None; + name = None; +} + diff --git a/samples/client/petstore/ocaml/src/models/order.ml b/samples/client/petstore/ocaml/src/models/order.ml new file mode 100644 index 000000000000..6130f88fd956 --- /dev/null +++ b/samples/client/petstore/ocaml/src/models/order.ml @@ -0,0 +1,28 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + * Schema Order.t : An order for a pets from the pet store + *) + +type t = { + id: int64 option [@default None]; + pet_id: int64 option [@default None]; + quantity: int32 option [@default None]; + ship_date: string option [@default None]; + (* Order Status *) + status: Enums.status option [@default None]; + complete: bool option [@default None]; +} [@@deriving yojson, show ];; + +(** An order for a pets from the pet store *) +let create () : t = { + id = None; + pet_id = None; + quantity = None; + ship_date = None; + status = None; + complete = None; +} + diff --git a/samples/client/petstore/ocaml/src/models/pet.ml b/samples/client/petstore/ocaml/src/models/pet.ml new file mode 100644 index 000000000000..5d267ef32db0 --- /dev/null +++ b/samples/client/petstore/ocaml/src/models/pet.ml @@ -0,0 +1,28 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + * Schema Pet.t : A pet for sale in the pet store + *) + +type t = { + id: int64 option [@default None]; + category: Category.t option [@default None]; + name: string; + photo_urls: string list; + tags: Tag.t list; + (* pet status in the store *) + status: Enums.pet_status option [@default None]; +} [@@deriving yojson, show ];; + +(** A pet for sale in the pet store *) +let create (name : string) (photo_urls : string list) : t = { + id = None; + category = None; + name = name; + photo_urls = photo_urls; + tags = []; + status = None; +} + diff --git a/samples/client/petstore/ocaml/src/models/tag.ml b/samples/client/petstore/ocaml/src/models/tag.ml new file mode 100644 index 000000000000..5570d9c8eafd --- /dev/null +++ b/samples/client/petstore/ocaml/src/models/tag.ml @@ -0,0 +1,19 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + * Schema Tag.t : A tag for a pet + *) + +type t = { + id: int64 option [@default None]; + name: string option [@default None]; +} [@@deriving yojson, show ];; + +(** A tag for a pet *) +let create () : t = { + id = None; + name = None; +} + diff --git a/samples/client/petstore/ocaml/src/models/user.ml b/samples/client/petstore/ocaml/src/models/user.ml new file mode 100644 index 000000000000..a9483d728890 --- /dev/null +++ b/samples/client/petstore/ocaml/src/models/user.ml @@ -0,0 +1,32 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + * Schema User.t : A User who is purchasing from the pet store + *) + +type t = { + id: int64 option [@default None]; + username: string option [@default None]; + first_name: string option [@default None]; + last_name: string option [@default None]; + email: string option [@default None]; + password: string option [@default None]; + phone: string option [@default None]; + (* User Status *) + user_status: int32 option [@default None]; +} [@@deriving yojson, show ];; + +(** A User who is purchasing from the pet store *) +let create () : t = { + id = None; + username = None; + first_name = None; + last_name = None; + email = None; + password = None; + phone = None; + user_status = None; +} + diff --git a/samples/client/petstore/ocaml/src/support/enums.ml b/samples/client/petstore/ocaml/src/support/enums.ml new file mode 100644 index 000000000000..0c64f8c042f6 --- /dev/null +++ b/samples/client/petstore/ocaml/src/support/enums.ml @@ -0,0 +1,30 @@ +(* + * This file has been generated by the OCamlClientCodegen generator for openapi-generator. + * + * Generated by: https://openapi-generator.tech + * + *) + +type 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 }];; + +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 pet_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 }];; + +let pet_status_of_yojson json = pet_status_of_yojson (`List [json]) +let pet_status_to_yojson e = + match pet_status_to_yojson e with + | `List [json] -> json + | json -> json diff --git a/samples/client/petstore/ocaml/src/support/jsonSupport.ml b/samples/client/petstore/ocaml/src/support/jsonSupport.ml new file mode 100644 index 000000000000..4b0fac77545a --- /dev/null +++ b/samples/client/petstore/ocaml/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 (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 diff --git a/samples/client/petstore/ocaml/src/support/request.ml b/samples/client/petstore/ocaml/src/support/request.ml new file mode 100644 index 000000000000..21b6f870ed98 --- /dev/null +++ b/samples/client/petstore/ocaml/src/support/request.ml @@ -0,0 +1,48 @@ +let api_key = "" +let base_url = "http://petstore.swagger.io/v2" +let default_headers = Cohttp.Header.init_with "Content-Type" "application/json" + +let build_uri operation_path = Uri.of_string (base_url ^ operation_path) +let write_json_body to_json payload = + to_json payload |> Yojson.Safe.to_string ~std:true |> Cohttp_lwt.Body.of_string + +let handle_response resp on_success_handler = + match Cohttp_lwt.Response.status resp with + | #Cohttp.Code.success_status -> on_success_handler () + | s -> failwith ("Server responded with status " ^ Cohttp.Code.(reason_phrase_of_code (code_of_status s))) + +let handle_unit_response resp = handle_response resp (fun () -> Lwt.return ()) + +let read_json_body resp body = + handle_response resp (fun () -> + (Lwt.(Cohttp_lwt.Body.to_string body >|= Yojson.Safe.from_string))) + +let read_json_body_as of_json resp body = + Lwt.(read_json_body resp body >|= of_json) + +let read_json_body_as_list resp body = + Lwt.(read_json_body resp body >|= Yojson.Safe.Util.to_list) + +let read_json_body_as_list_of of_json resp body = + Lwt.(read_json_body_as_list resp body >|= List.map of_json) + +let read_json_body_as_map_of of_json resp body = + Lwt.(read_json_body resp body >|= Yojson.Safe.Util.to_assoc >|= List.map (fun (s, v) -> (s, of_json v))) + +let replace_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.path uri) in + Uri.with_path uri path + +let init_form_encoded_body () = "" + +let add_form_encoded_body_param params (paramName, paramValue) = + let new_param_enc = Printf.sprintf {|%s=%s|} (Uri.pct_encode paramName) (Uri.pct_encode paramValue) in + if params = "" + then new_param_enc + else Printf.sprintf {|%s&%s|} params new_param_enc + +let add_form_encoded_body_params params (paramName, new_params) = + add_form_encoded_body_param params (paramName, String.concat "," new_params) + +let finalize_form_encoded_body body = Cohttp_lwt.Body.of_string body